将代码从C#翻译到VB.NET时出现的小错误

将代码从C#翻译到VB.NET时出现的小错误,c#,vb.net,code-translation,C#,Vb.net,Code Translation,我几乎完成了从C#到VB.NET的翻译,但是,我遇到了一些小错误: “issuerId”已在此类中声明为“Private Shared issuerId()as String”。第17行 “字符串的一维数组”类型的值无法转换为“字符串”。 第215行 “字符串的一维数组”类型的值无法转换为“字符串”。 第223行 原始代码 using System; namespace sisow { public class Sisow { private static string[] i

我几乎完成了从C#到VB.NET的翻译,但是,我遇到了一些小错误:


  • “issuerId”已在此类中声明为“Private Shared issuerId()as String”。第17行
  • “字符串的一维数组”类型的值无法转换为“字符串”。
    第215行
  • “字符串的一维数组”类型的值无法转换为“字符串”。 第223行

原始代码

using System;

namespace sisow
{
public class Sisow
{
    private static string[] issuerid;
    private static string[] issuername;
    private static DateTime lastcheck;

    private string response;

    // Merchant data
    public string merchantId;
    public string merchantKey;
    public string shopId;           // voor toekomstige doeleinden

    // Transaction data
    public string payment;          // empty=iDEAL; ideal=iDEAL; sofort=DIRECTebanking; mistercash=MisterCash
    public string issuerId;         // mandatory; sisow bank code
    public string purchaseId;       // mandatory; max 16 alphanumeric
    public string entranceCode;     // max 40 strict alphanumeric (letters and numbers only)
    public string description;      // mandatory; max 32 alphanumeric
    public double amount;           // mandatory; min 0.45
    public string notifyUrl;
    public string returnUrl;        // mandatory
    public string cancelUrl;
    public string callbackUrl;

    // Status data
    public string status;
    public DateTime timeStamp;
    public string consumerAccount;
    public string consumerName;
    public string consumerCity;

    // Result/check data
    public string trxId;
    public string issuerUrl;

    // Error data
    public string errorCode;
    public string errorMessage;

    // Status
    public const string statusSuccess = "Success";
    public const string statusCancelled = "Cancelled";
    public const string statusExpired = "Expired";
    public const string statusFailure = "Failure";
    public const string statusOpen = "Open";

    public Sisow(string merchantid, string merchantkey)
    {
        this.merchantId = merchantid;
        this.merchantKey = merchantkey;
        shopId = "";
    }

    // voor toekomstige doeleinden
    public Sisow(string merchantid, string merchantkey, string shopid)
    {
        this.merchantId = merchantid;
        this.merchantKey = merchantkey;
        this.shopId = shopid;
    }

    private void error()
    {
        errorCode = parse("errorcode");
        errorMessage = System.Web.HttpUtility.UrlDecode(parse("errormessage"));
    }

    private string parse(string search)
    {
        return parse(response, search);
    }

    private string parse(string xml, string search)
    {
        int start, end;

        if ((start = xml.IndexOf("<" + search + ">")) < 0)
            return null;
        start += search.Length + 2;
        if ((end = xml.IndexOf("</" + search + ">", start)) < 0)
            return null;
        return xml.Substring(start, end - start);
    }

    private bool send(string method, params string[] keyvalue)
    {
        string parms = "";
        string url = "https://www.sisow.nl/Sisow/iDeal/RestHandler.ashx/" + method;
        try
        {
            for (int i = 0; i + 1 < keyvalue.Length; i += 2)
            {
                if (string.IsNullOrEmpty(keyvalue[i + 1]))
                    continue;
                if (!string.IsNullOrEmpty(parms))
                    parms += "&";
                parms += keyvalue[i] + "=" + System.Web.HttpUtility.UrlEncode(keyvalue[i + 1]);
            }
            System.Net.HttpWebRequest hwr = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
            hwr.ContentType = "application/x-www-form-urlencoded";
            hwr.Method = "POST";
            hwr.ContentLength = parms.Length;
            System.IO.StreamWriter sw = new System.IO.StreamWriter(hwr.GetRequestStream());
            sw.Write(parms);
            sw.Flush();
            sw.Close();
            System.Net.HttpWebResponse hws = (System.Net.HttpWebResponse)hwr.GetResponse();
            System.IO.StreamReader sr = new System.IO.StreamReader(hws.GetResponseStream());
            response = sr.ReadToEnd();
            hws.Close();
            return true;
        }
        catch (Exception)
        {
            response = "";
            error();
            return false;
        }
    }

    private int getDirectory()
    {
        if (issuerid != null && lastcheck.AddDays(1).CompareTo(DateTime.Now) >= 0)
            return 0;
        if (!send("DirectoryRequest"))
            return -1;
        string search = parse("directory");
        if (string.IsNullOrEmpty(search))
        {
            error();
            return -2;
        }
        string[] iss = search.Replace("<issuer>", "").Split(new string[] { "</issuer>" }, StringSplitOptions.RemoveEmptyEntries);
        issuerid = new string[iss.Length];
        issuername = new string[iss.Length];
        for (int i = 0; i < iss.Length; i++)
        {
            issuerid[i] = parse(iss[i], "issuerid");
            issuername[i] = parse(iss[i], "issuername");
        }
        lastcheck = DateTime.Now;
        return 0;
    }

    // DirectoryRequest
    public int DirectoryRequest(bool test, out string select)
    {
        int ex;

        select = "<select id=\"sisowbank\" name=\"issuerid\">";
        ex = getDirectory();
        if (ex < 0)
            return ex;
        for (int i = 0; i < issuerid.Length; i++)
        {
            select += "<option value=\"" + issuerid[i] + "\">" + issuername[i] + "</option>";
        }
        select += "</select>";
        return 0;
    }

    // DirectoryRequest
    public int DirectoryRequest(bool test, out string[] issuers)
    {
        int ex;

        issuers = null;
        ex = getDirectory();
        if (ex < 0)
            return ex;
        issuers = new string[issuerid.Length * 2];
        for (int i = 0; i < issuerid.Length; i++)
        {
            issuers[i * 2] = issuerid[i];
            issuers[i * 2 + 1] = issuername[i];
        }
        return 0;
    }

    // compute SHA1
    private static string GetSHA1(string key)
    {
        System.Security.Cryptography.SHA1Managed sha = new System.Security.Cryptography.SHA1Managed();
        System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
        byte[] bytes = sha.ComputeHash(enc.GetBytes(key));
        //string sha1 = System.BitConverter.ToString(sha1).Replace("-", "");
        string sha1 = "";
        for (int j = 0; j < bytes.Length; j++)
            sha1 += bytes[j].ToString("x2");
        return sha1;
    }

    // TransactionRequest
    public int TransactionRequest()
    {
        trxId = issuerUrl = "";
        if (string.IsNullOrEmpty(merchantId))
            return -1;
        if (string.IsNullOrEmpty(merchantKey))
            return -2;
        if (string.IsNullOrEmpty(purchaseId))
            return -3;
        if (amount < 0.45)
            return -4;
        if (string.IsNullOrEmpty(description))
            return -5;
        if (string.IsNullOrEmpty(returnUrl))
            return -6;
        if (string.IsNullOrEmpty(issuerId) && string.IsNullOrEmpty(payment))
            return -7;
        if (string.IsNullOrEmpty(entranceCode))
            entranceCode = purchaseId;
        string sha1 = GetSHA1(purchaseId + entranceCode + (amount * 100).ToString() + shopId + merchantId + merchantKey);
        if (!send("TransactionRequest", "shopid", shopId, "merchantid", merchantId, "payment", payment, "issuerid", issuerId, "purchaseid", purchaseId, 
            "amount", (amount * 100).ToString(), "description", description, "entrancecode", entranceCode, "returnurl", returnUrl,
            "cancelurl", cancelUrl, "callbackurl", callbackUrl, "notifyurl", notifyUrl, "sha1", sha1))
            return -8;
        trxId = parse("trxid");
        if (string.IsNullOrEmpty(trxId))
        {
            error();
            return -2;
        }
        issuerUrl = System.Web.HttpUtility.UrlDecode(parse("issuerurl"));
        return 0;
    }

    private int GetStatus()
    {
        status = parse("status");
        if (string.IsNullOrEmpty(status))
        {
            error();
            return -5;
        }
        timeStamp = DateTime.Parse(parse("timestamp"));
        amount = long.Parse(parse("amount")) / 100.0;
        consumerAccount = parse("consumeraccount");
        consumerName = parse("consumername");
        consumerCity = parse("consumercity");
        purchaseId = parse("purchaseid");
        description = parse("description");
        entranceCode = parse("entrancecode");
        return 0;
    }

    // StatusRequest
    public int StatusRequest()
    {
        if (string.IsNullOrEmpty(merchantId))
            return -1;
        if (string.IsNullOrEmpty(merchantKey))
            return -2;
        if (string.IsNullOrEmpty(trxId))
            return -3;
        string sha1 = GetSHA1(trxId + shopId + merchantId + merchantKey);
        if (!send("StatusRequest", "shopid", shopId, "merchantid", merchantId, "trxid", trxId, "sha1", sha1))
            return -4;
        return GetStatus();
    }

    // StatusRequest
    public int StatusRequest(string trxid)
    {
        if (string.IsNullOrEmpty(merchantId))
            return -1;
        if (string.IsNullOrEmpty(merchantKey))
            return -2;
        if (string.IsNullOrEmpty(trxid))
            return -3;
        trxId = trxid;
        string sha1 = GetSHA1(trxId + shopId + merchantId + merchantKey);
        if (!send("StatusRequest", "shopid", shopId, "merchantid", merchantId, "trxid", trxId, "sha1", sha1))
            return -4;
        return GetStatus();
    }
}
}
使用系统;
名称空间sisow
{
公共类西索
{
私有静态字符串[]issuerid;
私有静态字符串[]issuername;
私有静态日期时间最后检查;
私有字符串响应;
//商户数据
公共商品部;
公共字符串密钥;
公共字符串shopId;//voor toekomstige doeleinden
//交易数据
公共字符串支付;//empty=iDEAL;iDEAL=iDEAL;sofort=DIRECTebanking;mistercash=mistercash
公共字符串issuerId;//必填;sisow银行代码
公共字符串purchaseId;//必填;最多16个字母数字
公共字符串输入代码;//最多40个严格字母数字(仅限字母和数字)
公共字符串说明;//必填;最多32个字母数字
公共双倍金额;//必填;最小值0.45
公共字符串通知URL;
公共字符串returnUrl;//必须
公共字符串取消URL;
公共字符串回调URL;
//状态数据
公共字符串状态;
公共日期时间戳;
公共字符串consumerAccount;
公共字符串consumerName;
公共消费;
//结果/检查数据
公共字符串trxId;
公共字符串发行器URL;
//错误数据
公共字符串错误码;
公共字符串错误消息;
//地位
public const string statusSuccess=“Success”;
public const string statusCancelled=“Cancelled”;
public const string statusExpired=“Expired”;
public const string statusFailure=“Failure”;
public const string statusOpen=“打开”;
公共Sisow(字符串merchantid、字符串merchantkey)
{
this.merchantId=merchantId;
this.merchantKey=merchantKey;
shopId=“”;
}
//沃尔·托康斯蒂奇·杜莱登
公共Sisow(字符串merchantid、字符串merchantkey、字符串shopid)
{
this.merchantId=merchantId;
this.merchantKey=merchantKey;
this.shopId=shopId;
}
私有无效错误()
{
errorCode=解析(“errorCode”);
errorMessage=System.Web.HttpUtility.UrlDecode(解析(“errorMessage”);
}
私有字符串解析(字符串搜索)
{
返回解析(响应、搜索);
}
私有字符串解析(字符串xml、字符串搜索)
{
int开始,结束;
如果((start=xml.IndexOf(“”)<0)
返回null;
开始+=搜索。长度+2;
如果((end=xml.IndexOf(“,start))<0)
返回null;
返回xml.Substring(start,end-start);
}
private bool send(string方法,params string[]keyvalue)
{
字符串parms=“”;
字符串url=”https://www.sisow.nl/Sisow/iDeal/RestHandler.ashx/“+方法;
尝试
{
对于(int i=0;i+1=0)
返回0;
如果(!发送(“目录请求”))
返回-1;
字符串搜索=解析(“目录”);
if(string.IsNullOrEmpty(搜索))
{
错误();
返回-2;
}
string[]iss=search.Replace(“,”).Split(新字符串[]{”“},StringSplitOptions.RemoveEmptyEntries);
issuerid=新字符串[iss.Length];
issuername=新字符串[iss.Length];
对于(int i=0;i