/// <summary> /// Starts handling files. /// </summary> /// <param name="plugIn">The plugin that should handle files.</param> /// <param name="context">The underlying context.</param> public bool HandleFiles(IPlugIn plugIn, IHandleFilesContext context) { bool result = false; Exception occuredException = null; lock (this._SYNC) { if (this.IsRunning == false) { try { var newTask = CreateHandleFilesTask(this, plugIn, context); this.Task = newTask; newTask.Start(); result = true; } catch (Exception ex) { this.Task = null; occuredException = ex; } } } if (occuredException != null) { this.OnError(occuredException); } return(result); }
/// <inheriteddoc /> protected override void OnHandleFiles(IHandleFilesContext context) { for (var i = 0; i < 2; i++) { for (var ii = 0; ii < 10; ii++) { context.StatusText = string.Format("{0} / 10; {1} / 2", ii + 1, i + 1); Thread.Sleep(1000); context.SetCurrentStepProgess(ii + 1, 10); } context.SetOverallProgess(i + 1, 2); } }
/// <inheriteddoc /> protected override void OnHandleFiles(IHandleFilesContext context) { }
/// <summary> /// The logic for the <see cref="PlugInBase.HandleFiles(IHandleFilesContext)" /> method. /// </summary> /// <param name="context">The underlying context.</param> protected abstract void OnHandleFiles(IHandleFilesContext context);
/// <inheriteddoc /> public void HandleFiles(IHandleFilesContext context) { this.OnHandleFiles(context); }
// Private Methods (1) private static Task CreateHandleFilesTask(MainViewModel viewModel, IPlugIn plugIn, IHandleFilesContext ctx) { return(new Task((state) => { MainViewModel vm = (MainViewModel)state; try { plugIn.HandleFiles(ctx); } catch (Exception ex) { vm.OnError(ex); } finally { vm.Task = null; } }, state: viewModel , creationOptions: TaskCreationOptions.LongRunning)); }