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 uri = 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("V5.0.0"), "26c4202eb475d02864b40827dfff11a14657aa41" })); AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient(); AssetStoreClient.Pending pending = new AssetStoreClient.Pending() { conn = assetStoreWebClient, id = "login", callback = AssetStoreClient.WrapLoginCallback(callback) }; AssetStoreClient.pending.Add(pending); assetStoreWebClient.Headers.Add("Accept", "application/json"); assetStoreWebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AssetStoreClient.DownloadStringCallback); try { assetStoreWebClient.DownloadStringAsync(uri, pending); } catch (WebException webException) { pending.ex = webException; AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; } }
private static void ReleaseClient(AssetStoreWebClient client) { AssetStoreClient.InitClientPool(); if (client != null) { client.Headers.Remove("X-HttpMethod"); AssetStoreClient.sClientPool.Push(client); } }
private static void InitClientPool() { if (AssetStoreClient.sClientPool != null) { return; } AssetStoreClient.sClientPool = new Stack <AssetStoreWebClient>(5); for (int i = 0; i < 5; i++) { AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient(); assetStoreWebClient.Encoding = Encoding.UTF8; AssetStoreClient.sClientPool.Push(assetStoreWebClient); } }
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 uri = new Uri(string.Format("{0}/login", AssetStoreClient.AssetStoreUrl)); AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient(); NameValueCollection nameValueCollection = new NameValueCollection() { { "user", username }, { "pass", password }, { "unityversion", Application.unityVersion }, { "toolversion", "V5.0.0" }, { "license_hash", AssetStoreClient.GetLicenseHash() }, { "hardware_hash", AssetStoreClient.GetHardwareHash() } }; AssetStoreClient.Pending pending = new AssetStoreClient.Pending() { conn = assetStoreWebClient, id = "login", callback = AssetStoreClient.WrapLoginCallback(callback) }; AssetStoreClient.pending.Add(pending); assetStoreWebClient.Headers.Add("Accept", "application/json"); assetStoreWebClient.UploadValuesCompleted += new UploadValuesCompletedEventHandler(AssetStoreClient.UploadValuesCallback); try { assetStoreWebClient.UploadValuesAsync(uri, "POST", nameValueCollection, pending); } catch (WebException webException) { pending.ex = webException; AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; } }