private async Task <GetServerInfoResult> GetServerInfoForVideoAsync(IUploadable uploadable)
        {
            var vidResponse = await _inTouchWrapper.ExecuteRequest(_inTouch.Videos.Save(
                                                                       new VideoSaveParams
            {
                Name          = uploadable.AdditionalData["name"],
                Description   = uploadable.AdditionalData["description"],
                PublishToWall = uploadable.AdditionalData["wallpost"] == "true",
                Repeat        = uploadable.AdditionalData["repeat"] == "true"
            }));

            if (vidResponse.IsError)
            {
                return(new GetServerInfoResult
                {
                    Result = UploadsPreprocessorResultType.ServerError,
                    ErrorCode = vidResponse.Error.Code
                });
            }
            else
            {
                return(new GetServerInfoResult
                {
                    Result = UploadsPreprocessorResultType.Success,
                    Info = vidResponse.Data
                });
            }
        }
 public UploadCompletedEventArgs(DateTime time, IUploadable uploadedData, OutputResult outputResult, bool uploaded)
 {
     this.UploadTime            = time;
     this.UploadedData          = uploadedData;
     this.UploadedResult        = outputResult;
     this.HasSuccessfulUploaded = uploaded;
 }
        private async Task <GetServerInfoResult> GetServerInfoForTypeAsync(IUploadable uploadable)
        {
            try
            {
                Response <ServerInfo> response = null;
                switch (uploadable.ContentType)
                {
                case FileContentType.Music:
                    response = await _inTouchWrapper.ExecuteRequest(_inTouch.Audio.GetUploadServer());

                    break;

                case FileContentType.Video:
                    return(await GetServerInfoForVideoAsync(uploadable));

                default:
                    response = await _inTouchWrapper.ExecuteRequest(_inTouch.Docs.GetUploadServer());

                    break;
                }

                if (response.IsError)
                {
                    return(new GetServerInfoResult
                    {
                        Result = UploadsPreprocessorResultType.ServerError,
                        ErrorCode = response.Error.Code
                    });
                }

                return(new GetServerInfoResult
                {
                    Result = UploadsPreprocessorResultType.Success,
                    Info = response.Data
                });
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is HttpRequestException)
                {
                    return(new GetServerInfoResult
                    {
                        Result = UploadsPreprocessorResultType.ConnectionError
                    });
                }
                else
                {
                    return(new GetServerInfoResult
                    {
                        Result = UploadsPreprocessorResultType.UnknownError
                    });
                }
            }
        }
        /// <summary>
        /// 记录上传情况:上传时间、上传数据、返回结果
        /// </summary>
        /// <param name="time"></param>
        /// <param name="data"></param>
        /// <param name="result"></param>
        private void SaveUpload(DateTime time, IUploadable data, OutputResult result)
        {
            bool   is_success = false;
            string code       = result.code;
            string status     = result.data?.SelectToken("status")?.ToString();

            if (OutputCode.成功.Equals(code) && AsyncStatus.处理成功.Equals(status))
            {
                is_success = true;
            }

            string sql = $"INSERT INTO upload_record ( data_type, data_id, upload_time, is_success, uploaded_data, upload_result, project_name ) VALUES  ( '{ data.GetType().Name }', { data.DataId }, '{ time.ToString("yyyy-MM-dd HH:mm:ss") }', { Convert.ToInt32(is_success) }, '{ data.Serialize2JSON() }', '{ result.Serialize2JSON() }', '{ HjApiCaller.ProjectName }' );";

            ArDBConnection.ExceuteSQLNoReturn(sql);
        }
Exemple #5
0
        public async Task <bool> StartUploadingAsync(IUploadable item)
        {
            var preResult = await _uploadsPreprocessor.ProcessUploadableAsync(item);

            if (preResult.Item2 != UploadsPreprocessorResultType.Success)
            {
                return(false);
            }

            var error = await _uploadsService.StartUploadingAsync(preResult.Item1);

            if (error == null)
            {
                return(true);
            }

            ShowInitError(error);
            return(false);
        }
        private void ShowError(IUploadable uploadable, UploadsPreprocessorResultType error, int errorCode)
        {
            string text = null;

            if (error == UploadsPreprocessorResultType.ServerError)
            {
                text = String.Format(_locService["Message_Uploads_PreprocessionServerError_Text"],
                                     uploadable.Name, errorCode, GetServerErrorDescription(errorCode));
            }
            else if (error == UploadsPreprocessorResultType.ConnectionError)
            {
                text = String.Format(_locService["Message_Uploads_PreprocessionConnectionError_Text"],
                                     uploadable.Name);
            }
            else
            {
                text = String.Format(_locService["Message_Uploads_PreprocessionUnknownError_Text"],
                                     uploadable.Name);
            }

            _dialogsService.Show(text, _locService["Message_Uploads_PreprocessionError_Title"]);
        }
Exemple #7
0
 public AllocateResult(bool upload, string phid, IUploadable uploadable)
 {
     this.Upload     = upload;
     this.PHID       = phid;
     this.Uploadable = uploadable;
 }
Exemple #8
0
 public void Enqueue(IUploadable operation)
 {
     queue.Enqueue(operation);
 }
Exemple #9
0
        public async System.Threading.Tasks.Task <bool> UploadAsync <T>(List <string> jsonStructureForUpload, IUploadable <T> api)
        {
            bool          result   = true;
            StringBuilder sbErrors = new StringBuilder();
            string        syncType = typeof(T).ToString();

            foreach (string objectJson in jsonStructureForUpload)
            {
                bool resultId = await api.UploadToServerAsync(objectJson);

                bool AuthRequired = (api.GetLastHttpStatusCode() == HttpStatusCode.Forbidden || api.GetLastHttpStatusCode() == HttpStatusCode.Unauthorized);
                if (!resultId)
                {
                    sbErrors.AppendLine($"uploading {syncType}:{objectJson}");
                    result = resultId;
                }
            }
            Analytics.TrackEvent("Route sync, upload", new Dictionary <string, string> {
                { "Errors", sbErrors.ToString() }
            });

            return(result);
        }
        public async Task <Tuple <IUpload, UploadsPreprocessorResultType> > ProcessUploadableAsync(IUploadable uploadable)
        {
            var result = await GetServerInfoForTypeAsync(uploadable);

            if (result.Result != UploadsPreprocessorResultType.Success)
            {
                ShowError(uploadable, result.Result, result.ErrorCode);
                return(new Tuple <IUpload, UploadsPreprocessorResultType>(null, result.Result));
            }

            return(new Tuple <IUpload, UploadsPreprocessorResultType>(new Upload
            {
                Uploadable = uploadable,
                UploadUrl = result.Info.UploadUrl
            }, UploadsPreprocessorResultType.Success));
        }