Exemplo n.º 1
0
        private void ProcessError(MegaRequest req, int errno)
        {
            switch (errno)
            {
                case MegaApiError.EAGAIN:
                    if (req.retries >= 30)
                    {
                        req.HandleError(MegaApiError.EAPI);
                        ProcessNext();
                        break;
                    }
                    Debug.WriteLine("Received -3, retrying");
                    ProcessAgain(req);
                    break;

                case MegaApiError.EARGS:
                    req.HandleError(MegaApiError.EAPI);
                    ProcessNext();
                    break;

                case MegaApiError.ESID:
                    if (req.retries >= 3)
                    {
                        req.HandleError(MegaApiError.EBROKEN);
                        ProcessNext();
                    }
                    else
                    {
                        if (Auth == null) { req.HandleError(MegaApiError.EBROKEN); }
                        else
                        {
                            var sidReq = new MRequestGetSid<MResponseGetSid>(Auth);
                            sidReq.Success += (s, a) =>
                            {
                                req.Sid = a.SessionId;
                                ProcessAgain(req);
                            };
                            sidReq.Error += (s, a) => req.HandleError(MegaApiError.EBROKEN);
                            ProcessRequest(sidReq);
                        }
                    }
                    break;

                default:
                    req.HandleError(errno);
                    ProcessNext();
                    break;
            }
        }
Exemplo n.º 2
0
        private void ProcessError(MegaRequest req, int errno)
        {
            switch (errno)
            {
            case MegaApiError.EAGAIN:
                if (req.retries >= 30)
                {
                    req.HandleError(MegaApiError.EAPI);
                    ProcessNext();
                    break;
                }
                Debug.WriteLine("Received -3, retrying");
                ProcessAgain(req);
                break;

            case MegaApiError.EARGS:
                req.HandleError(MegaApiError.EAPI);
                ProcessNext();
                break;

            case MegaApiError.ESID:
                if (req.retries >= 3)
                {
                    req.HandleError(MegaApiError.EBROKEN);
                    ProcessNext();
                }
                else
                {
                    if (Auth == null)
                    {
                        req.HandleError(MegaApiError.EBROKEN);
                    }
                    else
                    {
                        var sidReq = new MRequestGetSid <MResponseGetSid>(Auth);
                        sidReq.Success += (s, a) =>
                        {
                            req.Sid = a.SessionId;
                            ProcessAgain(req);
                        };
                        sidReq.Error += (s, a) => req.HandleError(MegaApiError.EBROKEN);
                        ProcessRequest(sidReq);
                    }
                }
                break;

            default:
                req.HandleError(errno);
                ProcessNext();
                break;
            }
        }
Exemplo n.º 3
0
        private void ProcessRequest(MegaRequest req)
        {
            if (req.retries > 1)
            {
                Thread.Sleep((int)(Math.Pow(2, req.retries) * 100));
                // 0,400,800,1600,3200ms etc
            }
            var wc = new WebClient();

            wc.Proxy = Proxy;
            wc.UploadStringCompleted += (s, e) =>
            {
                if (e.Error == null)
                {
                    try
                    {
                        var response = String.Format("{{root:{0}}}", e.Result);
                        var r        = JObject.Parse(response)["root"];

                        #region error handling
                        if (r.Type == JTokenType.Integer && r.ToObject <int>() < 0)
                        {
                            ProcessError(req, r.ToObject <int>());
                            return;
                        }
                        if (r.Type == JTokenType.Array)
                        {
                            if (r[0].Type == JTokenType.Integer && r[0].ToObject <int>() < 0)
                            {
                                ProcessError(req, r[0].ToObject <int>());
                                return;
                            }
                        }
                        else
                        {
                            req.HandleError(MegaApiError.EUNEXPECTED);
                            ProcessNext();
                            return;
                        }
                        #endregion

                        req.HandleSuccess(r[0]);
                        ProcessNext();
                    }
                    catch (JsonException)
                    {
                        req.HandleError(MegaApiError.EUNEXPECTED);
                        ProcessNext();
                    }
                }
                else
                {
                    ProcessAgain(req);
                }
            };
            try
            {
                if (req.IsTracking)
                {
                    tracking.Add(((ITrackingRequest)req).TrackingId);
                }

                wc.UploadStringAsync(BuildCsUri(req), GetData(req));
            }
            catch (WebException) { ProcessAgain(req, false); }
        }
Exemplo n.º 4
0
        private void ProcessRequest(MegaRequest req)
        {
            if (req.retries > 1)
            {
                Thread.Sleep((int)(Math.Pow(2, req.retries) * 100));
                // 0,400,800,1600,3200ms etc
            }
            var wc = new WebClient();
            wc.Proxy = Proxy;
            wc.UploadStringCompleted += (s, e) =>
            {
                if (e.Error == null)
                {
                    try
                    {
                        var response = String.Format("{{root:{0}}}", e.Result);
                        var r = JObject.Parse(response)["root"];

                        #region error handling
                        if (r.Type == JTokenType.Integer && r.ToObject<int>() < 0)
                        {
                            ProcessError(req, r.ToObject<int>());
                            return;
                        }
                        if (r.Type == JTokenType.Array)
                        {
                            if (r[0].Type == JTokenType.Integer && r[0].ToObject<int>() < 0)
                            {
                                ProcessError(req, r[0].ToObject<int>());
                                return;
                            }
                        }
                        else
                        {
                            req.HandleError(MegaApiError.EUNEXPECTED);
                            ProcessNext();
                            return;
                        }
                        #endregion

                        req.HandleSuccess(r[0]);
                        ProcessNext();
                    }
                    catch (JsonException)
                    {
                        req.HandleError(MegaApiError.EUNEXPECTED);
                        ProcessNext();
                    }
                }
                else { ProcessAgain(req); }
            };
            try
            {
                if (req.IsTracking) { tracking.Add(((ITrackingRequest)req).TrackingId); }

                wc.UploadStringAsync(BuildCsUri(req), GetData(req));
            }
            catch (WebException) { ProcessAgain(req, false); }
        }