Beispiel #1
0
        private static async Task <bool> UploadBlock(SendQueue block)
        {
            block.ReadBuffer();
            if (block.Buffer == null || block.Buffer.Length != block.Length)
            {
                block.Buffer = null;
                return(false);
            }
            int i = 0;

            while (i++ < 5)
            {
                NormalResponse np = await API.UploadFileBlock(block);

                if (np != null)
                {
                    if (np.result)
                    {
                        block.Buffer = null;
                        return(np.result);
                    }
                    else
                    {
                        Program.Log("   -->Retry code=1");
                    }
                }
                else
                {
                    Program.Log("   -->Retry code=2");
                }
            }
            return(false);
        }
Beispiel #2
0
        public static async Task <NormalResponse> Get(string url, Dictionary <string, object> dik = null)
        {
            try
            {
                url = ConfigHelper.mConfig.ServerUrl + url;
                string param = "?";
                if (dik == null)
                {
                    dik = new Dictionary <string, object>();
                }
                foreach (string k in dik.Keys)
                {
                    param = param + k + "=" + dik[k].ToString() + "&";
                }
                param = param.Substring(0, param.Length - 1);
                url   = url + param;
                string result = await GetResponse(url);

                if (string.IsNullOrEmpty(result))
                {
                    return(new NormalResponse(false, "接口调用失败"));
                }
                NormalResponse np = JsonConvert.DeserializeObject <NormalResponse>(result);
                if (np == null)
                {
                    return(new NormalResponse(false, "接口调用失败"));
                }
                return(np);
            }
            catch (Exception)
            {
                return(new NormalResponse(false, "接口调用失败"));
            }
        }
Beispiel #3
0
        public static async Task <NormalResponse> Post(string url, string data)
        {
            try
            {
                url = ConfigHelper.mConfig.ServerUrl + url;
                string result = await PostResponse(url, data);

                if (string.IsNullOrEmpty(result))
                {
                    return(new NormalResponse(false, "接口调用失败"));
                }
                NormalResponse np = JsonConvert.DeserializeObject <NormalResponse>(result);
                if (np == null)
                {
                    return(new NormalResponse(false, "接口调用失败"));
                }
                return(np);
            }
            catch (Exception)
            {
                return(new NormalResponse(false, "接口调用失败"));
            }
        }