コード例 #1
0
 public RepProtocol(TextBox edLog)
 {
     server       = new RestServices();
     this.Timeout = RestServices.DefaultTimeout;
     this.edLog   = edLog;
     //this.baseAddress = "http://" + host + "/";
 }
コード例 #2
0
        public List <string> GetRegs(FiltroRegistro filtro, string rangeFrom, string rangeTo, Action <int, int> progressCallback)
        {
            cancelOperation = false;
            string uri = baseAddress + "MRP/Regs/" + filtro.ToString();

            if (filtro == FiltroRegistro.DateRange || filtro == FiltroRegistro.NsrRange)
            {
                uri += "/FROM/" + rangeFrom + "/TO/" + rangeTo;
            }
            string        resp      = new RestServices(10000).DoGetRequest(uri);
            uint          readSize  = 0;
            uint          totalSize = uint.Parse(Utils.GetRepResponseValue(resp, "TotalSize"));
            List <string> ret       = new List <string>();

            while (readSize < totalSize)
            {
                if (cancelOperation)
                {
                    new RestServices(10000).DoGetRequest(baseAddress + "MRP/Regs/Finish");
                    throw new Exception("Operação cancelada");
                }
                if (progressCallback != null)
                {
                    progressCallback((int)readSize, (int)totalSize);
                }
                uint blockSize = totalSize - readSize;
                Trace.WriteLine(DateTime.Now.ToLongTimeString() + ": Before request to " + baseAddress + "MRP/Regs/NextReg");
                resp = new RestServices(10000).DoGetRequest(baseAddress + "MRP/Regs/NextReg");
                Trace.WriteLine(DateTime.Now.ToLongTimeString() + ": After response, before parse");
                foreach (string kvp in resp.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (kvp.Contains(':'))
                    {
                        string k = kvp.Substring(0, kvp.IndexOf(':')).Trim();
                        string v = kvp.Substring(kvp.IndexOf(':') + 1).Trim();
                        switch (k)
                        {
                        case "BlockSize": blockSize = uint.Parse(v); break;

                        default: break;
                        }
                    }
                    else
                    {
                        string regs = kvp.TrimStart(new char[] { '{' }).TrimEnd(new char[] { '}' });
                        foreach (string r in regs.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            ret.Add(r);
                        }
                    }
                }
                Trace.WriteLine(DateTime.Now.ToLongTimeString() + ": After parse");
                readSize += blockSize;
            }
            new RestServices(10000).DoGetRequest(baseAddress + "MRP/Regs/Finish");
            return(ret);
        }
コード例 #3
0
 public RepProtocol(string host)
 {
     server           = new RestServices();
     this.Timeout     = RestServices.DefaultTimeout;
     this.baseAddress = "http://" + host + "/";
 }
コード例 #4
0
 private void tbAuthPwd_TextChanged(object sender, EventArgs e)
 {
     RestServices.SetDefaultAuth(System.Text.RegularExpressions.Regex.Replace(mtbAuthCpf.Text, "[^0-9]", ""), tbAuthPwd.Text);
     repProtocol.SetAuth(System.Text.RegularExpressions.Regex.Replace(mtbAuthCpf.Text, "[^0-9]", ""), tbAuthPwd.Text);
 }