示例#1
0
        public async Task <string> Upload(Stream stream, string name, string uploadFolderDriveItemId)
        {
            string fileType = Path.GetExtension(name);

            // Show user we're uploading.
            string uploadingMessage = string.Format("Uploading {0}...", name);

            ShowBalloonInfo(uploadingMessage);
            SetTrayIcon(Resources.Uploading, uploadingMessage);

            string fileId;

            // Call MHW API to upload file.
            try
            {
                MhwAccount selected  = GetSelectedAccount();
                ApiFile    driveItem =
                    await Task.Run(() => Sdk.Account.UploadFile(selected.AccountId, name, fileType, stream, uploadFolderDriveItemId));

                fileId = driveItem.FileId;
            }
            catch (Exception ex)
            {
                ShowBalloonError(ex.Message);
                NotifyIfNetworkUnavailable();
                return(null);
            }
            finally
            {
                // Change tray icon back to normal.
                SetTrayIcon();
            }

            return(fileId);
        }
示例#2
0
        protected IEnumerator UploadFile(string filename, string existingFileUrl, string friendlyFilename, string fileType, Action <string> onSuccess)
        {
            if (string.IsNullOrEmpty(filename))
            {
                yield break;
            }
            VRC.Core.Logger.Log("Uploading " + fileType + "(" + filename + ") ...", DebugLevel.All);
            SetUploadProgress("Uploading " + fileType + "...", "", 0.0f);

            string fileId = GetUploadRetryStateValue(filename);

            if (string.IsNullOrEmpty(fileId))
            {
                fileId = isUpdate ? ApiFile.ParseFileIdFromFileAPIUrl(existingFileUrl) : "";
            }
            string errorStr   = "";
            string newFileUrl = "";


            yield return(StartCoroutine(ApiFileHelper.Instance.UploadFile(filename, forceNewFileCreation ? "" : fileId, friendlyFilename,
                                                                          delegate(ApiFile apiFile, string message)
            {
                newFileUrl = apiFile.GetFileURL();
                if (VRC.Core.Logger.DebugLevelIsEnabled(DebugLevel.API))
                {
                    VRC.Core.Logger.Log(fileType + " upload succeeded: " + message + " (" + filename +
                                        ") => " + apiFile.ToString(), DebugLevel.API);
                }
                else
                {
                    VRC.Core.Logger.Log(fileType + " upload succeeded ", DebugLevel.Always);
                }
            },
                                                                          delegate(ApiFile apiFile, string error)
            {
                SaveUploadRetryState(filename, apiFile.id);

                errorStr = error;
                Debug.LogError(fileType + " upload failed: " + error + " (" + filename +
                               ") => " + apiFile.ToString());
            },
                                                                          delegate(ApiFile apiFile, string status, string subStatus, float pct)
            {
                SetUploadProgress("Uploading " + fileType + "...", status + (!string.IsNullOrEmpty(subStatus) ? " (" + subStatus + ")" : ""), pct);
            },
                                                                          WasCancelRequested
                                                                          )));

            if (!string.IsNullOrEmpty(errorStr))
            {
                OnSDKPipelineError(fileType + " upload failed.", errorStr);
                yield break;
            }

            if (onSuccess != null)
            {
                onSuccess(newFileUrl);
            }
        }
示例#3
0
 private void CreateNews()
 {
     uploadFileNamePath = ApiFile.Upload(uploadFileName, $"news_{((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString()}", ApiFilePath.News);
     News.Create(new News
     {
         title     = TextBoxTitle.Text,
         messages  = TextBoxMessage.Text,
         date      = DateTimePublication.Value,
         image_url = uploadFileNamePath,
         id_user   = User.GetInstance().id
     });
     MetroMessageBox.Show(this, "Новость опубликована", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Question);
     Close();
 }
        public new static async Task <ApiFile> FromMessage(HttpResponseMessage message)
        {
            var response = new ApiFile {
                Message = message
            };

            if (message.IsSuccessStatusCode)
            {
                response.Data = await message.Content.ReadAsStreamAsync();
            }
            else
            {
                await response.HandleFailedCall();
            }

            return(response);
        }
示例#5
0
        private async Task <ApiFile> SendHttpFile(Func <HttpRequestMessage> requestFunc)
        {
            try
            {
                var request  = requestFunc();
                var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

                return(await ApiFile.FromMessage(response));
            }
            catch (Exception ex)
            {
                return(new ApiFile()
                {
                    Error = new ApiError {
                        Message = GetRecursiveErrorMessage(ex)
                    }
                });
            }
        }
示例#6
0
 protected bool WasCancelRequested(ApiFile apiFile)
 {
     return(cancelRequested);
 }
示例#7
0
 public ApiProductFiles(string Symbol, ApiFile Files)
 {
     this.Symbol = Symbol;
     this.Files  = Files;
 }