/// <summary> /// Initial a new LogFile-Writer /// </summary> /// <param name="procControle">Controle to controle the backup or restore process</param> /// <param name="procControle">Logfile Mode, create or restore a backup</param> /// <param name="progressStore">The store for the progress</param> /// <param name="writeLogFile">Should Logfiles been written. If it is false, no Logfiles will be created.</param> public LogFile(Settings.Settings procControle, TaskControle.ControleMode mode, ProgressStore progressStore, bool writeLogFile) { this._mode = mode; this._progressStore = progressStore; this._procControle = procControle; this._writeLogFile = writeLogFile; }
/// <summary> /// Set controles for state: DeleteBusy /// </summary> internal void SetPRogress_DeleteBusy(ProgressStore progressStore) { LabelInv.Text(this._progressControle.lblStepText, Stringtable._0x0022); TextBoxInv.Text(this._progressControle.txtCopyElapsed, this.TimeSpanForamt(this._progressControle.ElapsedTime)); this._setControleValue.SetProgressCluster(this._progressControle.expActualDir, progressStore.DirectroyFiles); this._setControleValue.SetProgressCluster(this._progressControle.expActualFile, progressStore.FileBytes); }
/// <summary> /// Iniital a new ProgressState with ProgressStore /// </summary> /// <param name="progressStore">The prograss store</param> /// <param name="forceReportProgress">Should reporting the prgoress been forced</param> public ProgressState(ProgressStore progressStore, bool forceReportProgress) { if (progressStore != null) { this.ProgressStore = progressStore.Clone(); } this.ForceReportProgress = forceReportProgress; }
/// <summary> /// Set controles for state: CountBusy /// </summary> internal void SetPRogress_CountBusy(ProgressStore progressStore) { LabelInv.Text(this._progressControle.lblStepText, Stringtable._0x0016); TextBoxInv.Text(this._progressControle.txtCopyElapsed, this.TimeSpanForamt(this._progressControle.ElapsedTime)); this._setControleValue.SetProgressCluster(this._progressControle.expAllItems, progressStore.TotalItems); this._setControleValue.SetProgressCluster(this._progressControle.expAllByte, progressStore.TotalBytes); this._setControleValue.SetProgressCluster(this._progressControle.expAllDir, progressStore.DirectroyFiles); this._setControleValue.SetProgressCluster(this._progressControle.expActualDir, progressStore.DirectroyFiles); }
/// <summary> /// Set controles for state: CopyStart /// Also set progress start time /// </summary> internal void SetProgress_CopyStart(ProgressStore progressStore) { DateTime StartTime = DateTime.Now; this._progressControle._progressStart = StartTime; // Set controles this._setControleValue.InitialControles(); LabelInv.Text(this._progressControle.lblStepText, Stringtable._0x0018); TextBoxInv.Text(this._progressControle.txtCopyStart, StartTime.ToString(FORMAT_TIME)); if (progressStore.TotalItems.MaxValue == null) { ExtProgrBarInv.Style(this._progressControle.expAllByte, ProgressBarStyle.Marquee); ExtProgrBarInv.Style(this._progressControle.expAllDir, ProgressBarStyle.Marquee); this._progressControle.expAllItems.Style = ProgressBarStyle.Marquee; } }
/// <summary> /// Set controles for state: CopyBusy /// </summary> internal void SetProgress_CopyBusy(ProgressStore progressStore) { LabelInv.Text(this._progressControle.lblStepText, Stringtable._0x0019); TextBoxInv.Text(this._progressControle.txtCopyElapsed, this.TimeSpanForamt(this._progressControle.ElapsedTime)); TextBoxInv.Text(this._progressControle._conclusionDirectoriesTextBox, string.Format(FORMAT_VALUE, progressStore.TotalDirectories.ActualValue)); TextBoxInv.Text(this._progressControle._conclusionFilesTextBox, string.Format(FORMAT_VALUE, progressStore.TotalFiles.ActualValue)); this._setControleValue.SetProgressCluster(this._progressControle.expAllItems, progressStore.TotalItems); this._setControleValue.SetProgressCluster(this._progressControle.expAllByte, progressStore.TotalBytes); this._setControleValue.SetProgressCluster(this._progressControle.expAllDir, progressStore.TotalDirectories); this._setControleValue.SetProgressCluster(this._progressControle.expActualDir, progressStore.DirectroyFiles); this._setControleValue.SetProgressCluster(this._progressControle.expActualFile, progressStore.FileBytes); // Get remaining time if counting was done if (progressStore.TotalItems.MaxValue != null && progressStore.TotalItems.MaxValue > 0) { TimeSpan RemainingTimeByte = OLKI.Toolbox.Common.Matehmatics.RemainingTime(this._progressControle.ElapsedTime, progressStore.TotalBytes.ActualValue, progressStore.TotalBytes.MaxValue); TimeSpan RemainingTimeItem = OLKI.Toolbox.Common.Matehmatics.RemainingTime(this._progressControle.ElapsedTime, progressStore.TotalItems.ActualValue, progressStore.TotalItems.MaxValue); TimeSpan RemainingTime = RemainingTimeByte > RemainingTimeItem ? RemainingTimeByte : RemainingTimeItem; TextBoxInv.Text(this._progressControle.txtCopyRemainTime, this.TimeSpanForamt(RemainingTime)); } }
/// <summary> /// Clone the ProgressStore /// </summary> /// <returns>The cloned ProgressStore</returns> public ProgressStore Clone() { ProgressStore ThisClone = (ProgressStore)this.MemberwiseClone(); return(ThisClone); }
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { // Use the progress in percentage to differ the different steps. // It looks a little bit stange. The real progress is stored in an member of this class. // Try to save the step in an member, lead to glitches. I used the ProgressPercentage as work around ProgressState ProgressState = (ProgressState)e.UserState; // Report Progress by time Interval or if report is forced if (ProgressState.ForceReportProgress || this._uscProgress.CheckUpdateInterval(this._lastReportTime)) { this._lastReportTime = DateTime.Now; this._taskStep = (TaskStep)e.ProgressPercentage; if (this._taskStep != TaskStep.Copy_Busy) { _ = this._taskStep; } switch (this._taskStep) { case TaskStep.Count_Start: this._logFile.WriteCountStart(); this._uscProgress.SetProgressStates.SetProgress_CountStart(); break; case TaskStep.Count_Busy: this._uscProgress.SetProgressStates.SetPRogress_CountBusy(ProgressState.ProgressStore); break; case TaskStep.Count_Finish: this._logFile.WriteCountFinish(); this._uscProgress.SetProgressStates.SetProgress_CountFinish(); break; case TaskStep.Copy_Start: this._logFile.WriteCopyStart(); this._uscProgress.SetProgressStates.SetProgress_CopyStart(ProgressState.ProgressStore); break; case TaskStep.Copy_Busy: this._uscProgress.SetProgressStates.SetProgress_CopyBusy(ProgressState.ProgressStore); break; case TaskStep.Copy_Finish: this._logFile.WriteCopyFinish(); this._uscProgress.SetProgressStates.SetProgress_CopyFinish(); break; case TaskStep.DeleteOldItems_Start: this._logFile.WriteDeleteSart(); this._uscProgress.SetProgressStates.SetProgress_DeleteStart(); break; case TaskStep.DeleteOldItems_Busy: this._uscProgress.SetProgressStates.SetPRogress_DeleteBusy(ProgressState.ProgressStore); break; case TaskStep.DeleteOldItems_Finish: this._logFile.WriteDeleteFinish(); this._uscProgress.SetProgressStates.SetProgress_DeleteFinish(); break; case TaskStep.Cancel: this._uscProgress.SetProgressStates.SetProgress_Cancel(); break; case TaskStep.Exception: this._logFile.WriteException(ProgressState.ProgressStore.Exception); this._uscProgress.SetProgressStates.SetProgress_Exception(ProgressState.ProgressStore.Exception); if (ProgressState.ProgressStore.Exception.Level != TaskException.ExceptionLevel.Critical) { ProgressState.ProgressStore.Exception = null; } break; default: throw new ArgumentException("uscTaskControle->worker_ProgressChanged->Invalid value", nameof(this._taskStep)); } } this._progressStore = ProgressState.ProgressStore; }
private void worker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; //Initial Progress Store this._progressStore = new ProgressStore(); //The procedures use Invoke, otherwise the application will crash in some conditions. //This can also be prevented by replace this two function calls to the _worker_ProgressChanged function this._uscProgress.SetProgressStates.SetControlesValue.InitialControles(); //Initial LogFile Writer this._logFile = new LogFile(this._projectManager.ActiveProject.Settings, this.Mode, this._progressStore, this.chkLogFileCreate.Checked) { LogFilePath = this._logFilePath }; this._logFile.WriteHead(this.txtHandleExistingFileText.Text); this._uscProgress.SetProgressStates.ClearExceptionlog(); try { // Count Data if (this.chkCountItemsAndBytes.Checked) { // Initial counter this._counter.Project = this._projectManager.ActiveProject; //Start count progress worker.ReportProgress((int)TaskStep.Count_Start, new ProgressState(this._progressStore, true)); switch (this._mode) { //Start Counting in backup mode case ControleMode.CreateBackup: this._counter.Backup(worker, e, this._progressStore); break; //Start Counting in restore mode case ControleMode.RestoreBackup: this._counter.Restore(worker, e, this._progressStore); break; default: throw new ArgumentException("uscTaskControle->worker_DoWork(Count)->Invalid value", nameof(this._mode)); } worker.ReportProgress((int)TaskStep.Count_Finish, new ProgressState(this._progressStore, true)); } //Copy Data if (this.chkCopyData.Checked) { // Initial copier this._copier = new CopyItems(this._mainForm) { Project = this._projectManager.ActiveProject }; //Start copy progress worker.ReportProgress((int)TaskStep.Copy_Start, new ProgressState(this._progressStore, true)); switch (this._mode) { //Start Counting in backup mode case ControleMode.CreateBackup: this._copier.Backup(worker, e, this._progressStore); break; //Start Counting in restore mode case ControleMode.RestoreBackup: switch ((DialogResult)this.Invoke((Func <DialogResult>)(() => MessageBox.Show(this._mainForm, Properties.Stringtable._0x002Fm, Properties.Stringtable._0x002Fc, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)))) { case DialogResult.Yes: this._copier.Restore(worker, e, this._progressStore); break; case DialogResult.No: case DialogResult.Cancel: if (worker.IsBusy) { worker.CancelAsync(); } break; default: break; } break; default: throw new ArgumentException("uscTaskControle->worker_DoWork(CopyData)->Invalid value", nameof(this._mode)); } if (!e.Cancel) { worker.ReportProgress((int)TaskStep.Copy_Finish, new ProgressState(true)); } } //Delete old Data at Backup Target if (this._mode == ControleMode.CreateBackup && this.chkRootDirectory.Checked && this.chkDeleteOld.Checked) { // Initial deleter this._deleter = new DeleteOldItems() { Project = this._projectManager.ActiveProject }; //Start delete old items worker.ReportProgress((int)TaskStep.DeleteOldItems_Start, new ProgressState(this._progressStore, true)); this._deleter.Backup(worker, e, this._progressStore); if (!e.Cancel) { worker.ReportProgress((int)TaskStep.DeleteOldItems_Finish, new ProgressState(true)); } } } catch (Exception ex) { this._progressStore.Exception = new TaskException { Description = "", Exception = ex, Level = TaskException.ExceptionLevel.Critical, Source = "", Target = "" }; worker.ReportProgress((int)TaskControle.TaskStep.Exception, new ProgressState(this._progressStore, true)); } }
/// <summary> /// Iniital a new ProgressState with ProgressStore /// </summary> /// <param name="progressStore">The prograss store</param> public ProgressState(ProgressStore progressStore) : this(progressStore, DEFAULT_FORCE_REPORT_PROGRRESS) { }