Exemplo n.º 1
0
    private IEnumerator OnStatusDone(WebServiceReturnStatus status)
    {
        Debug.Log("GOT A THING:" + JsonWriter.Serialize(status));
        Debug.Log(JsonWriter.Serialize(langGetter.Parse(status.text)));

        yield return null;
    }
Exemplo n.º 2
0
        private IEnumerator doWebRequest(ITransfluentParameters call, GotstatusUpdate onStatusDone)
        {
            var facade = new WWWFacade();
            var sw     = new Stopwatch();

            sw.Start();
            WWW www = facade.request(call);

            yield return(www);

            var status = new WebServiceReturnStatus {
                serviceParams = call
            };

            try
            {
                status = facade.getStatusFromFinishedWWW(www, sw, call);
            }
            catch (CallException e)
            {
                Debug.Log("Exception:" + e.Message);
            }

            if (onStatusDone != null)
            {
                runner.runRoutine(onStatusDone(status));
            }
        }
Exemplo n.º 3
0
        //throws TransportException,ApplicatonLevelException,HttpErrorCode
        public WebServiceReturnStatus getStatusFromFinishedWWW(WWW www, Stopwatch sw,
                                                               ITransfluentParameters originalCallParams)
        {
            //Debug.Log("WWW:" + www.url);

            var status = new WebServiceReturnStatus
            {
                serviceParams = originalCallParams
            };

            sw.Stop();
            status.requestTimeTaken = sw.Elapsed;

            if (!www.isDone && www.error == null)
            {
                throw new TransportException("Timeout total time taken:");
            }
            if (www.error == null)
            {
                status.text = www.text;
            }
            else
            {
                string error = www.error;
                if (knownTransportError(error))
                {
                    www.Dispose();
                    throw new TransportException(error);
                }
                status.httpErrorCode = -1;
                int firstSpaceIndex = error.IndexOf(" ");

                if (firstSpaceIndex > 0)
                {
                    www.Dispose();

                    int.TryParse(error.Substring(0, firstSpaceIndex), out status.httpErrorCode);
                    //there has to be a better way to get error codes.
                    if (status.httpErrorCode == 0)
                    {
                        throw new Exception("UNHANDLED ERROR CODE FORMAT:(" + error + ")");
                    }
                    if (status.httpErrorCode >= 400 && status.httpErrorCode <= 499)
                    {
                        throw new ApplicatonLevelException("HTTP Error code, application level:" + status.httpErrorCode,
                                                           status.httpErrorCode);
                    }
                    throw new HttpErrorCode(status.httpErrorCode);
                }
                throw new Exception("Unknown error:" + error);                 //can't parse error status
            }
            www.Dispose();
            return(status);
        }
Exemplo n.º 4
0
        //throws TransportException,ApplicatonLevelException,HttpErrorCode
        public WebServiceReturnStatus getStatusFromFinishedWWW(WWW www, Stopwatch sw,
            ITransfluentParameters originalCallParams)
        {
            UnityEngine.Debug.Log("WWW:" + www.url);

            var status = new WebServiceReturnStatus
            {
                serviceParams = originalCallParams
            };
            sw.Stop();
            status.requestTimeTaken = sw.Elapsed;

            if(!www.isDone && www.error == null)
            {
                throw new TransportException("Timeout total time taken:");
            }
            if(www.error == null)
            {
                status.text = www.text;
            }
            else
            {
                string error = www.error;
                if(knownTransportError(error))
                {
                    www.Dispose();
                    throw new TransportException(error);
                }
                status.httpErrorCode = -1;
                int firstSpaceIndex = error.IndexOf(" ");

                if(firstSpaceIndex > 0)
                {
                    www.Dispose();

                    int.TryParse(error.Substring(0, firstSpaceIndex), out status.httpErrorCode);
                    //there has to be a better way to get error codes.
                    if(status.httpErrorCode == 0)
                    {
                        throw new Exception("UNHANDLED ERROR CODE FORMAT:(" + error + ")");
                    }
                    if(status.httpErrorCode >= 400 && status.httpErrorCode <= 499)
                    {
                        throw new ApplicatonLevelException("HTTP Error code, application level:" + status.httpErrorCode,
                            status.httpErrorCode);
                    }
                    throw new HttpErrorCode(status.httpErrorCode);
                }
                throw new Exception("Unknown error:" + error); //can't parse error status
            }
            www.Dispose();
            return status;
        }
Exemplo n.º 5
0
        private WebServiceReturnStatus doCall(WebServiceParameters call)
        {
            IWebService req = new SyncronousEditorWebRequest();

            try
            {
                call.getParameters.Add("token", _token);

                WebServiceReturnStatus result = req.request(call);
                return(result);
            }
            catch (HttpErrorCode code)
            {
                Debug.Log(code.code + " http error");
                throw;
            }
        }
Exemplo n.º 6
0
        private IEnumerator doWebRequest(ITransfluentParameters call, GotstatusUpdate onStatusDone)
        {
            var facade = new WWWFacade();
            var sw = new Stopwatch();
            sw.Start();
            WWW www = facade.request(call);

            yield return www;
            var status = new WebServiceReturnStatus { serviceParams = call };
            try
            {
                status = facade.getStatusFromFinishedWWW(www, sw, call);
            }
            catch(CallException e)
            {
                Debug.Log("Exception:" + e.Message);
            }

            if(onStatusDone != null)
            {
                runner.runRoutine(onStatusDone(status));
            }
        }
Exemplo n.º 7
0
 private static IEnumerator OnStatusDoneStatic(WebServiceReturnStatus status)
 {
     Debug.Log("GOT A THING:" + JsonWriter.Serialize(status));
     Debug.Log("SERIALIZED:" + JsonWriter.Serialize(langParser.Parse(status.text)));
     yield return null;
 }