Inheritance: IPlayFabHttp
Beispiel #1
0
 private static void Post(CallRequestContainer reqContainer)
 {
     try
     {
         reqContainer.HttpRequest             = (HttpWebRequest)WebRequest.Create(reqContainer.FullUrl);
         reqContainer.HttpRequest.UserAgent   = "UnityEngine-Unity; Version: " + PlayFabWebRequest._unityVersion;
         reqContainer.HttpRequest.SendChunked = false;
         reqContainer.HttpRequest.Proxy       = null;
         foreach (KeyValuePair <string, string> keyValuePair in reqContainer.RequestHeaders)
         {
             reqContainer.HttpRequest.Headers.Add(keyValuePair.Key, keyValuePair.Value);
         }
         reqContainer.HttpRequest.ContentType = "application/json";
         reqContainer.HttpRequest.Method      = "POST";
         reqContainer.HttpRequest.KeepAlive   = PlayFabSettings.RequestKeepAlive;
         reqContainer.HttpRequest.Timeout     = PlayFabSettings.RequestTimeout;
         reqContainer.HttpRequest.AllowWriteStreamBuffering = false;
         reqContainer.HttpRequest.Proxy            = null;
         reqContainer.HttpRequest.ContentLength    = reqContainer.Payload.LongLength;
         reqContainer.HttpRequest.ReadWriteTimeout = PlayFabSettings.RequestTimeout;
         using (Stream requestStream = reqContainer.HttpRequest.GetRequestStream())
         {
             requestStream.Write(reqContainer.Payload, 0, reqContainer.Payload.Length);
         }
         reqContainer.HttpState = HttpRequestState.Sent;
     }
     catch (WebException ex)
     {
         reqContainer.JsonResponse = (PlayFabWebRequest.ResponseToString(ex.Response) ?? (ex.Status + ": WebException making http request to: " + reqContainer.FullUrl));
         WebException ex2 = new WebException(reqContainer.JsonResponse, ex);
         PlayFabWebRequest.QueueRequestError(reqContainer);
     }
     catch (Exception innerException)
     {
         reqContainer.JsonResponse = "Unhandled exception in Post : " + reqContainer.FullUrl;
         Exception ex3 = new Exception(reqContainer.JsonResponse, innerException);
         PlayFabWebRequest.QueueRequestError(reqContainer);
     }
 }
Beispiel #2
0
        private static void WorkerThreadMainLoop()
        {
            try
            {
                object threadLock = PlayFabWebRequest._ThreadLock;
                lock (threadLock)
                {
                    PlayFabWebRequest._threadKillTime = DateTime.UtcNow + PlayFabWebRequest.ThreadKillTimeout;
                }
                List <CallRequestContainer> list = new List <CallRequestContainer>();
                bool flag;
                do
                {
                    object activeRequests = PlayFabWebRequest.ActiveRequests;
                    lock (activeRequests)
                    {
                        list.AddRange(PlayFabWebRequest.ActiveRequests);
                        PlayFabWebRequest.ActiveRequests.Clear();
                        PlayFabWebRequest._activeCallCount = list.Count;
                    }
                    int count = list.Count;
                    for (int i = count - 1; i >= 0; i--)
                    {
                        switch (list[i].HttpState)
                        {
                        case HttpRequestState.Sent:
                            if (list[i].HttpRequest.HaveResponse)
                            {
                                PlayFabWebRequest.ProcessHttpResponse(list[i]);
                            }
                            break;

                        case HttpRequestState.Received:
                            PlayFabWebRequest.ProcessJsonResponse(list[i]);
                            list.RemoveAt(i);
                            break;

                        case HttpRequestState.Idle:
                            PlayFabWebRequest.Post(list[i]);
                            break;

                        case HttpRequestState.Error:
                            list.RemoveAt(i);
                            break;
                        }
                    }
                    object threadLock2 = PlayFabWebRequest._ThreadLock;
                    lock (threadLock2)
                    {
                        DateTime utcNow = DateTime.UtcNow;
                        if (count > 0 && PlayFabWebRequest._isApplicationPlaying)
                        {
                            PlayFabWebRequest._threadKillTime = utcNow + PlayFabWebRequest.ThreadKillTimeout;
                        }
                        flag = (utcNow <= PlayFabWebRequest._threadKillTime);
                        if (!flag)
                        {
                            PlayFabWebRequest._requestQueueThread = null;
                        }
                    }
                    Thread.Sleep(1);
                }while (flag);
            }
            catch (Exception ex)
            {
                PlayFabWebRequest._requestQueueThread = null;
            }
        }