static AssetStoreClient() { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_OUT; AssetStoreClient.sLoginErrorMessage = null; AssetStoreClient.s_PendingLargeFiles = new List <AssetStoreClient.LargeFilePending>(); AssetStoreClient.s_UploadingLargeFile = null; AssetStoreClient.pending = new List <AssetStoreClient.Pending>(); ServicePointManager.ServerCertificateValidationCallback = ((object obj, X509Certificate x509Certificate, X509Chain x509Chain, SslPolicyErrors sslPolicyErrors) => true); }
public static void AbortLargeFilesUpload() { if (AssetStoreClient.s_PendingLargeFiles.Count == 0) { return; } AssetStoreClient.s_PendingLargeFiles.RemoveAll((AssetStoreClient.LargeFilePending assetUpload) => { if (assetUpload == null) { return(true); } AssetStoreResponse assetStoreResponse = AssetStoreClient.parseAssetStoreResponse(null, null, null, null); assetStoreResponse.HttpStatusCode = -2; if (assetUpload.RequestDoneCallback != null) { assetUpload.RequestDoneCallback(assetStoreResponse); } assetUpload.Close(); return(true); }); AssetStoreClient.s_UploadingLargeFile = null; }
private static string UpdateLargeFilesUpload() { if (AssetStoreClient.s_UploadingLargeFile == null) { if (AssetStoreClient.s_PendingLargeFiles.Count == 0) { return(null); } AssetStoreClient.s_UploadingLargeFile = AssetStoreClient.s_PendingLargeFiles[0]; try { AssetStoreClient.s_UploadingLargeFile.Open(); } catch (Exception ex) { DebugUtils.LogError("Unable to start uploading:" + AssetStoreClient.s_UploadingLargeFile.FilePath + " Reason: " + ex.Message); AssetStoreClient.s_PendingLargeFiles.Remove(AssetStoreClient.s_UploadingLargeFile); AssetStoreClient.s_PendingLargeFiles = null; string result = null; return(result); } } AssetStoreClient.LargeFilePending largeFilePending = AssetStoreClient.s_UploadingLargeFile; StreamReader streamReader = null; WebResponse webResponse = null; try { string result; if (largeFilePending == null || largeFilePending.Request == null) { result = null; return(result); } byte[] buffer = largeFilePending.Buffer; int num = 0; for (int i = 0; i < 2; i++) { num = largeFilePending.RequestFileStream.Read(buffer, 0, buffer.Length); if (num == 0) { break; } largeFilePending.RequestStream.Write(buffer, 0, num); largeFilePending.BytesSent += (long)num; } if (num != 0) { try { double num2 = (double)largeFilePending.BytesSent; double num3 = (double)largeFilePending.BytesToSend; double pctUp = num2 / num3 * 100.0; if (largeFilePending.RequestProgressCallback != null) { largeFilePending.RequestProgressCallback(pctUp, 0.0); } } catch (Exception ex2) { DebugUtils.LogWarning("Progress update error " + ex2.Message); } result = null; return(result); } AssetStoreClient.s_PendingLargeFiles.Remove(largeFilePending); AssetStoreClient.s_UploadingLargeFile = null; DebugUtils.Log("Finished Uploading: " + largeFilePending.Id); webResponse = largeFilePending.Request.GetResponse(); Stream responseStream = webResponse.GetResponseStream(); string text; try { streamReader = new StreamReader(responseStream); text = streamReader.ReadToEnd(); streamReader.Close(); } catch (Exception ex3) { DebugUtils.LogError("StreamReader sr"); throw ex3; } AssetStoreResponse job = AssetStoreClient.parseAssetStoreResponse(text, null, null, webResponse.Headers); largeFilePending.Close(); largeFilePending.RequestDoneCallback(job); result = text; return(result); } catch (Exception ex4) { DebugUtils.LogError("UploadingLarge Files Exception:" + ex4.Source); if (streamReader != null) { streamReader.Close(); } AssetStoreResponse job2 = AssetStoreClient.parseAssetStoreResponse(null, null, ex4, (webResponse == null) ? null : webResponse.Headers); largeFilePending.RequestDoneCallback(job2); largeFilePending.Close(); AssetStoreClient.s_PendingLargeFiles.Remove(largeFilePending); } return(null); }
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); }
private static string UpdateLargeFilesUpload() { string end; string str; WebHeaderCollection headers; if (AssetStoreClient.s_UploadingLargeFile == null) { if (AssetStoreClient.s_PendingLargeFiles.Count == 0) { return(null); } AssetStoreClient.s_UploadingLargeFile = AssetStoreClient.s_PendingLargeFiles[0]; try { AssetStoreClient.s_UploadingLargeFile.Open(); } catch (Exception exception1) { Exception exception = exception1; DebugUtils.LogError(string.Concat("Unable to start uploading:", AssetStoreClient.s_UploadingLargeFile.FilePath, " Reason: ", exception.Message)); AssetStoreClient.s_PendingLargeFiles.Remove(AssetStoreClient.s_UploadingLargeFile); AssetStoreClient.s_PendingLargeFiles = null; str = null; return(str); } } AssetStoreClient.LargeFilePending sUploadingLargeFile = AssetStoreClient.s_UploadingLargeFile; StreamReader streamReader = null; WebResponse response = null; try { if (sUploadingLargeFile == null || sUploadingLargeFile.Request == null) { str = null; } else { byte[] buffer = sUploadingLargeFile.Buffer; int num = 0; int num1 = 0; while (num1 < 2) { num = sUploadingLargeFile.RequestFileStream.Read(buffer, 0, (int)buffer.Length); if (num != 0) { sUploadingLargeFile.RequestStream.Write(buffer, 0, num); sUploadingLargeFile.BytesSent += (long)num; num1++; } else { break; } } if (num == 0) { AssetStoreClient.s_PendingLargeFiles.Remove(sUploadingLargeFile); AssetStoreClient.s_UploadingLargeFile = null; DebugUtils.Log(string.Concat("Finished Uploading: ", sUploadingLargeFile.Id)); response = sUploadingLargeFile.Request.GetResponse(); Stream responseStream = response.GetResponseStream(); try { streamReader = new StreamReader(responseStream); end = streamReader.ReadToEnd(); streamReader.Close(); } catch (Exception exception3) { Exception exception2 = exception3; DebugUtils.LogError("StreamReader sr"); throw exception2; } AssetStoreResponse assetStoreResponse = AssetStoreClient.parseAssetStoreResponse(end, null, null, response.Headers); sUploadingLargeFile.Close(); sUploadingLargeFile.RequestDoneCallback(assetStoreResponse); str = end; } else { try { double bytesSent = (double)sUploadingLargeFile.BytesSent; double bytesToSend = bytesSent / (double)sUploadingLargeFile.BytesToSend * 100; if (sUploadingLargeFile.RequestProgressCallback != null) { sUploadingLargeFile.RequestProgressCallback(bytesToSend, 0); } } catch (Exception exception4) { DebugUtils.LogWarning(string.Concat("Progress update error ", exception4.Message)); } str = null; } } } catch (Exception exception7) { Exception exception5 = exception7; DebugUtils.LogError(string.Concat("UploadingLarge Files Exception:", exception5.Source)); if (streamReader != null) { streamReader.Close(); } Exception exception6 = exception5; if (response == null) { headers = null; } else { headers = response.Headers; } AssetStoreResponse assetStoreResponse1 = AssetStoreClient.parseAssetStoreResponse(null, null, exception6, headers); sUploadingLargeFile.RequestDoneCallback(assetStoreResponse1); sUploadingLargeFile.Close(); AssetStoreClient.s_PendingLargeFiles.Remove(sUploadingLargeFile); return(null); } return(str); }