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 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 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);
 }
예제 #4
0
 private static void Upload(string path, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress = null)
 {
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingUpload(path, path, filepath, delegate(AssetStoreResponse resp)
     {
         string errorMessage = null;
         JSONValue jsonvalue;
         AssetStoreAPI.Parse(resp, out errorMessage, out jsonvalue);
         callback(errorMessage);
     });
     pending.progressCallback = progress;
 }
 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);
 }
 public static void Abort(AssetStoreClient.Pending removePending)
 {
     AssetStoreClient.pending.RemoveAll(delegate(AssetStoreClient.Pending p)
     {
         if (p != removePending)
         {
             return(false);
         }
         if (p.conn.IsBusy)
         {
             p.conn.CancelAsync();
         }
         return(true);
     });
 }
 private static void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
 {
     AssetStoreClient.Pending pending = (AssetStoreClient.Pending)e.UserState;
     pending.bytesReceived       = (uint)e.BytesReceived;
     pending.totalBytesToReceive = (uint)e.TotalBytesToReceive;
     pending.bytesSend           = 0u;
     pending.totalBytesToSend    = 0u;
     pending.statsUpdated        = true;
     Console.WriteLine("{0} downloaded {1} of {2} bytes. {3} % complete...", new object[]
     {
         pending.id,
         e.BytesReceived,
         e.TotalBytesToReceive,
         e.ProgressPercentage
     });
 }
 private static void UploadFileCallback(object sender, UploadFileCompletedEventArgs e)
 {
     AssetStoreClient.Pending pending = (AssetStoreClient.Pending)e.UserState;
     if (e.Error != null)
     {
         pending.ex = e.Error;
         return;
     }
     if (!e.Cancelled)
     {
         pending.bytesReceived = pending.totalBytesToReceive;
         pending.statsUpdated  = false;
         pending.data          = Encoding.UTF8.GetString(e.Result);
     }
     else
     {
         pending.data = string.Empty;
     }
 }
 private static void DownloadDataCallback(object sender, DownloadDataCompletedEventArgs e)
 {
     AssetStoreClient.Pending pending = (AssetStoreClient.Pending)e.UserState;
     if (e.Error != null)
     {
         pending.ex = e.Error;
         return;
     }
     if (!e.Cancelled)
     {
         pending.bytesReceived = pending.totalBytesToReceive;
         pending.statsUpdated  = false;
         pending.binData       = e.Result;
     }
     else
     {
         pending.binData = new byte[0];
     }
 }
        internal static void LoginWithRememberedSession(AssetStoreClient.DoneLoginCallback callback)
        {
            if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS)
            {
                DebugUtils.LogWarning("Tried to login with remembered session while already in progress of logging in");
                return;
            }
            AssetStoreClient.sLoginState        = AssetStoreClient.LoginState.IN_PROGRESS;
            AssetStoreClient.sLoginErrorMessage = null;
            if (!AssetStoreClient.RememberSession)
            {
                AssetStoreClient.SavedSessionID = string.Empty;
            }
            Uri address = new Uri(string.Format("{0}/login?reuse_session={1}&unityversion={2}&toolversion={3}&xunitysession={4}", new object[]
            {
                AssetStoreClient.AssetStoreUrl,
                AssetStoreClient.SavedSessionID,
                Uri.EscapeDataString(Application.unityVersion),
                Uri.EscapeDataString("V4.1.0"),
                "26c4202eb475d02864b40827dfff11a14657aa41"
            }));
            AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient();

            AssetStoreClient.Pending pending = new AssetStoreClient.Pending();
            pending.conn     = assetStoreWebClient;
            pending.id       = "login";
            pending.callback = AssetStoreClient.WrapLoginCallback(callback);
            AssetStoreClient.pending.Add(pending);
            assetStoreWebClient.Headers.Add("Accept", "application/json");
            assetStoreWebClient.DownloadStringCompleted += AssetStoreClient.DownloadStringCallback;
            try
            {
                assetStoreWebClient.DownloadStringAsync(address, pending);
            }
            catch (WebException ex)
            {
                pending.ex = ex;
                AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR;
            }
        }
        internal static void LoginWithCredentials(string username, string password, bool rememberMe, AssetStoreClient.DoneLoginCallback callback)
        {
            if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS)
            {
                DebugUtils.LogWarning("Tried to login with credentials while already in progress of logging in");
                return;
            }
            AssetStoreClient.sLoginState        = AssetStoreClient.LoginState.IN_PROGRESS;
            AssetStoreClient.RememberSession    = rememberMe;
            AssetStoreClient.sLoginErrorMessage = null;
            Uri address = new Uri(string.Format("{0}/login", AssetStoreClient.AssetStoreUrl));
            AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient();
            NameValueCollection nameValueCollection = new NameValueCollection();

            nameValueCollection.Add("user", username);
            nameValueCollection.Add("pass", password);
            nameValueCollection.Add("unityversion", Application.unityVersion);
            nameValueCollection.Add("toolversion", "V4.1.0");
            nameValueCollection.Add("license_hash", AssetStoreClient.GetLicenseHash());
            nameValueCollection.Add("hardware_hash", AssetStoreClient.GetHardwareHash());
            AssetStoreClient.Pending pending = new AssetStoreClient.Pending();
            pending.conn     = assetStoreWebClient;
            pending.id       = "login";
            pending.callback = AssetStoreClient.WrapLoginCallback(callback);
            AssetStoreClient.pending.Add(pending);
            assetStoreWebClient.Headers.Add("Accept", "application/json");
            assetStoreWebClient.UploadValuesCompleted += AssetStoreClient.UploadValuesCallback;
            try
            {
                assetStoreWebClient.UploadValuesAsync(address, "POST", nameValueCollection, pending);
            }
            catch (WebException ex)
            {
                pending.ex = ex;
                AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR;
            }
        }
 public static void LoadFromUrl(string url, AssetStoreClient.DoneCallback callback, AssetStoreClient.ProgressCallback progress)
 {
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingGetBinary(url, url, callback);
     pending.progressCallback = progress;
 }