Exemplo n.º 1
0
        protected virtual IEnumerator DownloadAsset(SwrveAssetsQueueItem item)
        {
            string cdn = (item.IsImage ? CdnImages : CdnFonts);
            string url = cdn + item.Name;

            SwrveLog.Log("Downloading asset: " + url);
            WWW www = new WWW(url);

            yield return(www);

            WwwDeducedError err = UnityWwwHelper.DeduceWwwError(www);

            if (www != null && err == WwwDeducedError.NoError && www.isDone)
            {
                if (item.IsImage)
                {
                    SaveImageAsset(item, www);
                }
                else
                {
                    SaveBinaryAsset(item, www);
                }
            }
            TaskFinished("SwrveAssetsManager.DownloadAsset");
        }
Exemplo n.º 2
0
        protected virtual IEnumerator DownloadAsset(SwrveAssetsQueueItem item)
        {
            string str  = (!item.IsImage) ? this.CdnFonts : this.CdnImages;
            string text = str + item.Name;

            SwrveLog.Log("Downloading asset: " + text);
            WWW wWW = new WWW(text);

            yield return(wWW);

            WwwDeducedError wwwDeducedError = UnityWwwHelper.DeduceWwwError(wWW);

            if (wWW != null && wwwDeducedError == WwwDeducedError.NoError && wWW.isDone)
            {
                if (item.IsImage)
                {
                    this.SaveImageAsset(item, wWW);
                }
                else
                {
                    this.SaveBinaryAsset(item, wWW);
                }
            }
            this.TaskFinished("SwrveAssetsManager.DownloadAsset");
            yield break;
        }
Exemplo n.º 3
0
 public RESTResponse(long responseCode = 0, string responseBody = "", Dictionary <string, string> headers = null, WwwDeducedError error = WwwDeducedError.NoError)
 {
     ResponseCode = responseCode;
     Body         = responseBody;
     Error        = error;
     Headers      = headers;
     Error        = error;
 }
Exemplo n.º 4
0
        protected void ProcessResponse(WWW www, long wwwTime, string url, Action <RESTResponse> listener)
        {
#if SWRVE_SUPPORTED_PLATFORM
            try {
                WwwDeducedError deducedError = UnityWwwHelper.DeduceWwwError(www);
                if (deducedError == WwwDeducedError.NoError)
                {
                    // - made it there and it was ok
                    string responseBody = null;
                    bool   success      = ResponseBodyTester.TestUTF8(www.bytes, out responseBody);
                    Dictionary <string, string> headers = new Dictionary <string, string> ();

                    string contentEncodingHeader = null;
                    if (www.responseHeaders != null)
                    {
                        Dictionary <string, string> .Enumerator headersEnum = www.responseHeaders.GetEnumerator();
                        while (headersEnum.MoveNext())
                        {
                            KeyValuePair <string, string> header = headersEnum.Current;
                            headers.Add(header.Key.ToUpper(), header.Value);
                        }
                        // Get the content encoding header, if present
                        if (headers.ContainsKey(CONTENT_ENCODING_HEADER_KEY))
                        {
                            contentEncodingHeader = headers[CONTENT_ENCODING_HEADER_KEY];
                        }
                    }

                    // BitConverter.ToInt32 needs at least 4 bytes
                    if (www.bytes != null && www.bytes.Length > 4 && contentEncodingHeader != null && string.Equals(contentEncodingHeader, "gzip", StringComparison.OrdinalIgnoreCase))
                    {
                        // Check if the response is gzipped or json (eg. iOS automatically unzips it already)
                        if (responseBody != null && !((responseBody.StartsWith("{") && responseBody.EndsWith("}")) || (responseBody.StartsWith("[") && responseBody.EndsWith("]"))))
                        {
                            int dataLength = BitConverter.ToInt32(www.bytes, 0);
                            if (dataLength > 0)
                            {
                                var buffer = new byte[dataLength];

                                using (var ms = new MemoryStream(www.bytes)) {
                                    using (var gs = new GZipInputStream(ms)) {
                                        gs.Read(buffer, 0, buffer.Length);
                                        gs.Close();
                                    }

                                    success = ResponseBodyTester.TestUTF8(buffer, out responseBody);
                                    ms.Close();
                                }
                            }
                        }
                    }

                    if (success)
                    {
                        AddMetrics(url, wwwTime, false);
                        listener.Invoke(new RESTResponse(responseBody, headers));
                    }
                    else
                    {
                        AddMetrics(url, wwwTime, true);
                        listener.Invoke(new RESTResponse(WwwDeducedError.ApplicationErrorBody));
                    }
                }
                else
                {
                    AddMetrics(url, wwwTime, true);
                    listener.Invoke(new RESTResponse(deducedError));
                }
            } catch (Exception exp) {
                SwrveLog.LogError(exp);
            }
#endif
        }
Exemplo n.º 5
0
 public RESTResponse(WwwDeducedError error)
 {
     Error = error;
 }