Ejemplo n.º 1
0
 private static AsyncHTTPClient.DoneCallback WrapJsonCallback(AssetStoreClient.DoneCallback callback)
 {
     // ISSUE: object of a compiler-generated type is created
     // ISSUE: reference to a compiler-generated method
     return(new AsyncHTTPClient.DoneCallback(new AssetStoreClient.\u003CWrapJsonCallback\u003Ec__AnonStorey53()
     {
         callback = callback
     }.\u003C\u003Em__90));
 }
Ejemplo n.º 2
0
    public static ImageCache DownloadImage(Image img, ImageCache.DownloadCallback callback)
    {
        if (img == null || img.mUrl == null)
        {
            return(null);
        }
        ImageCache ic;

        if (ImageCache.EntriesByUrl.TryGetValue(img.mUrl, out ic))
        {
            if (ic.Texture != null || ic.Progress >= 0f || ic.Failed)
            {
                img.mImgCache = ic;
                return(ic);
            }
        }
        else
        {
            ImageCache.EnsureCacheSpace();
            ic                = new ImageCache();
            ic.Failed         = false;
            ic.Texture        = null;
            ic.m_DownloadedAt = -1.0;
            ic.LastUsed       = EditorApplication.timeSinceStartup;
            ImageCache.EntriesByUrl[img.mUrl] = ic;
        }
        img.mImgCache = ic;
        ic.Progress   = 0f;
        AssetStoreClient.ProgressCallback progress = delegate(double pctUp, double pctDown)
        {
            ic.Progress = (float)pctDown;
        };
        AssetStoreClient.DoneCallback callback2 = delegate(AssetStoreResponse resp)
        {
            ic.Progress       = -1f;
            ic.LastUsed       = EditorApplication.timeSinceStartup;
            ic.m_DownloadedAt = ic.LastUsed;
            ic.Failed         = resp.failed;
            if (resp.ok && resp.binData != null && resp.binData.Length > 0)
            {
                Texture2D texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                texture2D.LoadImage(resp.binData);
                ic.Texture = texture2D;
            }
            if (callback != null)
            {
                string text = string.Format("Error fetching {0}", img.Name);
                if (resp.failed)
                {
                    DebugUtils.LogWarning(text + string.Format(" : ({0}) {1} from {2}", resp.HttpStatusCode, resp.HttpErrorMessage ?? "n/a", img.mUrl));
                }
                callback(img, ic, (!resp.ok) ? text : null);
            }
        };
        AssetStoreClient.LoadFromUrl(img.mUrl, callback2, progress);
        return(ic);
    }
Ejemplo n.º 3
0
        private static AsyncHTTPClient CreateJSONRequestDelete(string url, AssetStoreClient.DoneCallback callback)
        {
            AsyncHTTPClient asyncHttpClient = new AsyncHTTPClient(url, "DELETE");

            asyncHttpClient.header["X-Unity-Session"] = AssetStoreClient.ActiveOrUnauthSessionID + AssetStoreClient.GetToken();
            asyncHttpClient.doneCallback = AssetStoreClient.WrapJsonCallback(callback);
            asyncHttpClient.Begin();
            return(asyncHttpClient);
        }
Ejemplo n.º 4
0
 public LargeFilePending(string url, string filepath, Dictionary <string, string> extraParams, AssetStoreClient.DoneCallback doneCallback, AssetStoreClient.ProgressCallback progressCallback)
 {
     this.Id                      = filepath;
     this.URI                     = url;
     this.FilePath                = filepath;
     this.RequestDoneCallback     = doneCallback;
     this.RequestProgressCallback = progressCallback;
     this.m_extraParams           = extraParams;
 }
Ejemplo n.º 5
0
    public static ImageCache DownloadImage(Image img, ImageCache.DownloadCallback callback)
    {
        ImageCache imageCache;

        if (img == null || img.mUrl == null)
        {
            return(null);
        }

        if (!ImageCache.EntriesByUrl.TryGetValue(img.mUrl, out imageCache))
        {
            ImageCache.EnsureCacheSpace();
            imageCache = new ImageCache()
            {
                Failed         = false,
                Texture        = null,
                m_DownloadedAt = -1,
                LastUsed       = EditorApplication.timeSinceStartup
            };
            ImageCache.EntriesByUrl[img.mUrl] = imageCache;
        }
        else if (imageCache.Texture != null || imageCache.Progress >= 0f || imageCache.Failed)
        {
            img.mImgCache = imageCache;
            return(imageCache);
        }

        img.mImgCache       = imageCache;
        imageCache.Progress = 0f;
        AssetStoreClient.ProgressCallback progress     = (double pctUp, double pctDown) => imageCache.Progress = (float)pctDown;
        AssetStoreClient.DoneCallback     doneCallback = (AssetStoreResponse resp) =>
        {
            imageCache.Progress       = -1f;
            imageCache.LastUsed       = EditorApplication.timeSinceStartup;
            imageCache.m_DownloadedAt = imageCache.LastUsed;
            imageCache.Failed         = resp.failed;
            if (resp.ok && resp.binData != null && (int)resp.binData.Length > 0)
            {
                Texture2D texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                texture2D.LoadImage(resp.binData);
                imageCache.Texture = texture2D;
            }

            if (callback != null)
            {
                string str = string.Format("Error fetching {0}", img.Name);
                if (resp.failed)
                {
                    DebugUtils.LogWarning(string.Concat(str, string.Format(" : ({0}) {1} from {2}", resp.HttpStatusCode, resp.HttpErrorMessage ?? "n/a", img.mUrl)));
                }

                callback(img, imageCache, (!resp.ok ? str : null));
            }
        };
        AssetStoreClient.LoadFromUrl(img.mUrl, doneCallback, progress);
        return(imageCache);
    }
 private static AssetStoreClient.Pending CreatePending(string name, AssetStoreClient.DoneCallback callback)
 {
     foreach (AssetStoreClient.Pending pending in AssetStoreClient.pending)
     {
         if (pending.id == name)
         {
             DebugUtils.Log("CreatePending name conflict!");
         }
     }
     AssetStoreClient.Pending pending2 = new AssetStoreClient.Pending();
     pending2.id       = name;
     pending2.callback = callback;
     AssetStoreClient.pending.Add(pending2);
     return(pending2);
 }
Ejemplo n.º 7
0
 private static AssetStoreClient.Pending CreatePending(string name, AssetStoreClient.DoneCallback callback)
 {
     foreach (AssetStoreClient.Pending pending in AssetStoreClient.pending)
     {
         if (pending.id != name)
         {
             continue;
         }
         DebugUtils.Log("CreatePending name conflict!");
     }
     AssetStoreClient.Pending pending1 = new AssetStoreClient.Pending()
     {
         id       = name,
         callback = callback
     };
     AssetStoreClient.pending.Add(pending1);
     return(pending1);
 }
Ejemplo n.º 8
0
 private static AsyncHTTPClient.DoneCallback WrapJsonCallback(AssetStoreClient.DoneCallback callback)
 {
     return(delegate(AsyncHTTPClient job)
     {
         if (job.IsDone())
         {
             try
             {
                 AssetStoreResponse response = AssetStoreClient.ParseContent(job);
                 callback(response);
             }
             catch (Exception ex)
             {
                 Debug.Log("Uncaught exception in async net callback: " + ex.Message);
                 Debug.Log(ex.StackTrace);
             }
         }
     });
 }
Ejemplo n.º 9
0
        private static AsyncHTTPClient CreateJSONRequestPost(string url, Dictionary <string, string> param, AssetStoreClient.DoneCallback callback)
        {
            AsyncHTTPClient asyncHttpClient = new AsyncHTTPClient(url);

            asyncHttpClient.header["X-Unity-Session"] = AssetStoreClient.ActiveOrUnauthSessionID + AssetStoreClient.GetToken();
            asyncHttpClient.postDictionary            = param;
            asyncHttpClient.doneCallback = AssetStoreClient.WrapJsonCallback(callback);
            asyncHttpClient.Begin();
            return(asyncHttpClient);
        }
 public static AssetStoreClient.Pending CreatePendingUpload(string name, string path, string filepath, AssetStoreClient.DoneCallback callback)
 {
     DebugUtils.Log("CreatePendingUpload");
     AssetStoreClient.Pending p = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = delegate()
     {
         p.conn = AssetStoreClient.AcquireClient();
         if (p.conn == null)
         {
             return(false);
         }
         try
         {
             p.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             p.conn.UploadProgressChanged += AssetStoreClient.UploadProgressCallback;
             p.conn.UploadFileCompleted   += AssetStoreClient.UploadFileCallback;
             p.conn.UploadFileAsync(AssetStoreClient.APIUri(path), "PUT", filepath, p);
         }
         catch (WebException ex)
         {
             p.ex = ex;
             return(false);
         }
         return(true);
     };
     if (!pendingQueueDelegate())
     {
         p.queueDelegate = pendingQueueDelegate;
     }
     return(p);
 }
 public static void UploadLargeFile(string path, string filepath, Dictionary <string, string> extraParams, AssetStoreClient.DoneCallback callback, AssetStoreClient.ProgressCallback progressCallback)
 {
     AssetStoreClient.LargeFilePending item = new AssetStoreClient.LargeFilePending(path, filepath, extraParams, callback, progressCallback);
     AssetStoreClient.s_PendingLargeFiles.Add(item);
 }
 public static AssetStoreClient.Pending CreatePendingPost(string name, string path, NameValueCollection param, AssetStoreClient.DoneCallback callback)
 {
     AssetStoreClient.Pending p = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = delegate()
     {
         p.conn = AssetStoreClient.AcquireClient();
         if (p.conn == null)
         {
             return(false);
         }
         try
         {
             p.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             p.conn.UploadProgressChanged += AssetStoreClient.UploadProgressCallback;
             p.conn.UploadValuesCompleted += AssetStoreClient.UploadValuesCallback;
             p.conn.UploadValuesAsync(AssetStoreClient.APIUri(path), "POST", param, p);
         }
         catch (WebException ex)
         {
             p.ex = ex;
             return(false);
         }
         return(true);
     };
     if (!pendingQueueDelegate())
     {
         p.queueDelegate = pendingQueueDelegate;
     }
     return(p);
 }
 public static AssetStoreClient.Pending CreatePendingGetBinary(string name, string url, AssetStoreClient.DoneCallback callback)
 {
     AssetStoreClient.Pending p = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = delegate()
     {
         p.conn = AssetStoreClient.AcquireClient();
         if (p.conn == null)
         {
             return(false);
         }
         try
         {
             p.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             p.conn.DownloadProgressChanged += AssetStoreClient.DownloadProgressCallback;
             p.conn.DownloadDataCompleted   += AssetStoreClient.DownloadDataCallback;
             p.conn.DownloadDataAsync(new Uri(url), p);
         }
         catch (WebException ex)
         {
             p.ex = ex;
             return(false);
         }
         return(true);
     };
     if (!pendingQueueDelegate())
     {
         p.queueDelegate = pendingQueueDelegate;
     }
     return(p);
 }
 public static void LoadFromUrl(string url, AssetStoreClient.DoneCallback callback, AssetStoreClient.ProgressCallback progress)
 {
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingGetBinary(url, url, callback);
     pending.progressCallback = progress;
 }
Ejemplo n.º 15
0
 public static AssetStoreClient.Pending CreatePendingUpload(string name, string path, string filepath, AssetStoreClient.DoneCallback callback)
 {
     DebugUtils.Log("CreatePendingUpload");
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = () =>
     {
         bool flag;
         pending.conn = AssetStoreClient.AcquireClient();
         if (pending.conn == null)
         {
             return(false);
         }
         try
         {
             pending.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             pending.conn.UploadProgressChanged += new UploadProgressChangedEventHandler(AssetStoreClient.UploadProgressCallback);
             pending.conn.UploadFileCompleted   += new UploadFileCompletedEventHandler(AssetStoreClient.UploadFileCallback);
             pending.conn.UploadFileAsync(AssetStoreClient.APIUri(path), "PUT", filepath, pending);
             return(true);
         }
         catch (WebException webException)
         {
             pending.ex = webException;
             flag       = false;
         }
         return(flag);
     };
     if (!pendingQueueDelegate())
     {
         pending.queueDelegate = pendingQueueDelegate;
     }
     return(pending);
 }
Ejemplo n.º 16
0
 public static AssetStoreClient.Pending CreatePendingGetBinary(string name, string url, AssetStoreClient.DoneCallback callback)
 {
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePending(name, callback);
     AssetStoreClient.PendingQueueDelegate pendingQueueDelegate = () =>
     {
         bool flag;
         pending.conn = AssetStoreClient.AcquireClient();
         if (pending.conn == null)
         {
             return(false);
         }
         try
         {
             pending.conn.Headers.Set("X-Unity-Session", AssetStoreClient.ActiveOrUnauthSessionID);
             pending.conn.DownloadProgressChanged += new DownloadProgressChangedEventHandler(AssetStoreClient.DownloadProgressCallback);
             pending.conn.DownloadDataCompleted   += new DownloadDataCompletedEventHandler(AssetStoreClient.DownloadDataCallback);
             pending.conn.DownloadDataAsync(new Uri(url), pending);
             return(true);
         }
         catch (WebException webException)
         {
             pending.ex = webException;
             flag       = false;
         }
         return(flag);
     };
     if (!pendingQueueDelegate())
     {
         pending.queueDelegate = pendingQueueDelegate;
     }
     return(pending);
 }