private bool CheckUploading() { if (this.ID.IsNullOrEmptyOrWhiltSpace() || this.mDatabase is null) { return(System.IO.File.Exists(GoogleDrive.GetUploadStatusPath(this.FullPath))); } else { var rmtStatus = this.mDatabase.GetFileUploadStatus(this.ID, out var uid) ?? false; if (rmtStatus) { return(!rmtStatus); } if (!(uid?.IsNullOrEmptyOrWhiltSpace() ?? true)) //if uid is not null { if (uid.Length > 70) { return(true); } else { return(false); } } return(false); } }
private void UploadLogic() { try { do { UploadTokenSource?.Token.ThrowIfCancellationRequested(); ThreadControlName = "Pause"; this.mUpObj = null; try { this.mUpObj = FileList.First(x => !x.IsOver); } catch (Exception ex) { ex.Message.InfoLognConsole(); } if (!(this.mUpObj is null)) { this.mUpObj.RefreshData(); string remot = this.mUpObj.RemotePath; MainName = "[Uploading]" + this.mUpObj.FileName; NowProcressingContent = this.mUpObj; ProcessNow.SetValue(0, 0, "Initialize upload (MD5 File Checking...)"); ProcessNowState = true; bool isSuccess = false; bool isFirstTime = (this.mDatabase is null) ? !System.IO.File.Exists(GoogleDrive.GetUploadStatusPath(this.mUpObj)) : mDatabase.GetFileUploadID(this.mUpObj.ID).IsNullOrEmptyOrWhiltSpace(); if (isFirstTime) { //if this is the first time this file is being upload. var tID = Service.RemoteFileExists(this.mUpObj, remot, false); if (tID.IsNullOrEmptyOrWhiltSpace()) { ProcessNowState = false; if (this.mUpObj.IsChangeFather) { Google.Apis.Drive.v3.Data.File parent; string nowParentName = System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(this.mUpObj.FullPath)); string remotePath = this.mUpObj.RemotePath.Replace(nowParentName, this.mUpObj.OldFatherPath); if (!remotePath.IsNullOrEmptyOrWhiltSpace()) { parent = Service.GetGoogleFolderByPath(remotePath); Service.UpdateFile(parent.Id, nowParentName); } } isSuccess = this.mUpObj.Upload(Service); } else { ProcessNowState = false; isSuccess = true; mDatabase.SetUploadStatus(this.mUpObj.ID, tID, true); } } else { //if this is a resume upload. ProcessNowState = false; isSuccess = this.mUpObj.Upload(Service); } if (UploadTokenSource?.Token.IsCancellationRequested ?? false) { break; } Processed += this.mUpObj.Length; this.mUpObj.IsOver = isSuccess; } else { ProcessNow.SetValue(0, 0, "Done."); break; } } while (true); }