Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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);
            }
        }
Пример #3
0
 /// <inheriteddoc />
 protected override void OnHandleFiles(IHandleFilesContext context)
 {
 }
Пример #4
0
 /// <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);
Пример #5
0
 /// <inheriteddoc />
 public void HandleFiles(IHandleFilesContext context)
 {
     this.OnHandleFiles(context);
 }
Пример #6
0
        // 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));
        }