public override IEnumerable <Processor> CreateProcessors(ProcessorArgs args, IPipelineController controller)
 {
     return(new[]
     {
         (Processor)ReflectionUtil.CreateObject(Type)
     });
 }
 public override IEnumerable<Processor> CreateProcessors(ProcessorArgs args)
 {
   return new[]
   {
     (Processor)ReflectionUtil.CreateObject(this.Type)
   };
 }
 public override IEnumerable <Processor> CreateProcessors(ProcessorArgs args)
 {
     return(new[]
     {
         (Processor)ReflectionUtil.CreateObject(Type)
     });
 }
        public static long GetProcessorsCount([NotNull] ProcessorArgs args, [NotNull] List <Step> steps)
        {
            Assert.ArgumentNotNull(args, nameof(args));
            Assert.ArgumentNotNull(steps, nameof(steps));

            return(steps.Select(step => step.Processors).Select(list => GetProcessorsCount(args, list)).Sum());
        }
        protected override void Process(ProcessorArgs args)
        {
            var download = (DownloadArgs)args;
              var cookies = download.Cookies;
              var localRepository = download.LocalRepository;
              var fileNames = download.FileNames;
              var links = download.Links;
              var fileSizes = download.Sizes;

              int parallelDownloadsNumber = WindowsSettings.AppDownloaderParallelThreads.Value;

              var cancellation = new CancellationTokenSource();
              var urls = links.Where(link => this.RequireDownloading(fileNames[link], fileSizes[link], localRepository)).ToArray();
              for (int i = 0; i < urls.Length; i += parallelDownloadsNumber)
              {
            int remains = urls.Length - i;
            var tasks = urls
              .Skip(i)
              .Take(Math.Min(parallelDownloadsNumber, remains))
              .Select(url => Task.Factory.StartNew(() => this.DownloadFile(url, fileNames[url], fileSizes[url], localRepository, cookies, cancellation.Token), cancellation.Token))
              .ToArray();

            try
            {
              Task.WaitAll(tasks, WindowsSettings.AppDownloaderTotalTimeout.Value * WebRequestHelper.Hour);
            }
            catch (Exception ex)
            {
              Log.Warn("An error occurred during downloading files", this, ex);

              cancellation.Cancel();
              throw;
            }
              }
        }
    protected override void Process(ProcessorArgs args)
    {
      var download = (DownloadArgs)args;

      foreach (var link in download.Links)
      {
        download.FileNames[link] = WebRequestHelper.GetFileName(link, download.Cookies);
      }
    }
 protected override void Process(ProcessorArgs processorArgs)
 {
     var args = (SetupArgs)processorArgs;
       var profile = ProfileManager.Profile ?? new Profile();
       profile.ConnectionString = args.ConnectionString;
       profile.InstancesFolder = args.InstancesRootFolderPath;
       profile.License = args.LicenseFilePath;
       profile.LocalRepository = args.LocalRepositoryFolderPath;
       ProfileManager.SaveChanges(profile);
 }
        public override IEnumerable <Processor> CreateProcessors(ProcessorArgs args, IPipelineController controller)
        {
            var hive = (ProcessorHive)ReflectionUtil.CreateObject(Type, this);
            IEnumerable <Processor> proc = hive.CreateProcessors(args);

            if (controller != null)
            {
                this.SetControllerForDynamicNestedProcessors(proc, controller);
            }

            return(proc);
        }
        public Pipeline([NotNull] PipelineDefinition pipelineDefinition, [NotNull] ProcessorArgs args, [CanBeNull] IPipelineController controller = null, bool isAsync = true)
        {
            Assert.ArgumentNotNull(pipelineDefinition, "pipelineDefinition");
              Assert.ArgumentNotNull(args, "args");

              this.controller = controller;
              this.pipelineDefinition = pipelineDefinition;
              this.title = pipelineDefinition.Title;
              this.steps = Step.CreateSteps(this.pipelineDefinition.Steps, args, controller);
              this.isAsync = isAsync;

              // Storing args for restarting pipeline
              this.processorArgs = args;
        }
        public bool Execute([NotNull] ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            var controller = Controller;

            if (!IsDone)
            {
                try
                {
                    State = ProcessorState.Running;
                    if (controller != null)
                    {
                        controller.ProcessorStarted(Title);
                    }

                    Process(args);
                    if (controller != null)
                    {
                        controller.ProcessorDone(Title);
                    }

                    State = ProcessorState.Done;
                    return(true);
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    State = ProcessorState.Error;
                    Error = ex;
                    if (controller != null)
                    {
                        controller.ProcessorCrashed(ex.Message);
                    }

                    Log.Error(ex, $"Processor of type '{ProcessorDefinition.Type.FullName}' failed. {ex.Message}");
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 11
0
        public bool Execute([NotNull] ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var controller = this.Controller;

            if (!this.IsDone)
            {
                try
                {
                    this.State = ProcessorState.Running;
                    if (controller != null)
                    {
                        controller.ProcessorStarted(this.Title);
                    }

                    this.Process(args);
                    if (controller != null)
                    {
                        controller.ProcessorDone(this.Title);
                    }

                    this.State = ProcessorState.Done;
                    return(true);
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    this.State = ProcessorState.Error;
                    this.Error = ex;
                    if (controller != null)
                    {
                        controller.ProcessorCrashed(ex.Message);
                    }

                    Log.Error("Processor of type '{0}' (a part of the '{1}' pipeline) failed. {2}".FormatWith(this.ProcessorDefinition.Type.FullName, this.ProcessorDefinition.OwnerPipelineName, ex.Message), typeof(Processor), ex);
                    return(false);
                }
            }

            return(true);
        }
        public static long GetProcessorsCount([NotNull] ProcessorArgs args, [NotNull] List <Processor> list)
        {
            Assert.ArgumentNotNull(args, nameof(args));
            Assert.ArgumentNotNull(list, nameof(list));

            return(list.Sum(item =>
            {
                long itemStepsCount = 1;
                try
                {
                    itemStepsCount = item.EvaluateStepsCount(args);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, $"Error during evaluating steps count of {item.GetType().FullName}");
                }

                return itemStepsCount + GetProcessorsCount(args, item.NestedProcessors);
            }));
        }
        protected override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              this.Process((InstallModulesArgs)args);
        }
 public override long EvaluateStepsCount(ProcessorArgs args)
 {
   return ((MultipleDeletionArgs)args).Instances.Count;
 }
        public virtual long EvaluateStepsCount([NotNull] ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            return(1);
        }
        public override sealed bool IsRequireProcessing(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              return this.IsRequireProcessing((InstallModulesArgs)args);
        }
 public abstract IEnumerable <Processor> CreateProcessors(ProcessorArgs args);
 protected override void Process(ProcessorArgs args)
 {
     actions.Add("Process|{0}|{1}".FormatWith(this.ProcessorDefinition.Param, this.number));
 }
 public override long EvaluateStepsCount(ProcessorArgs args)
 {
     return this.number;
 }
 public override long EvaluateStepsCount(ProcessorArgs args)
 {
     var download = (Download8Args)args;
       var count = download.FileNames.Count(x => this.RequireDownloading(x.Value, download.LocalRepository));
       return count * scale;
 }
        private static IEnumerable <Processor> CreateProcessorsPrivate([NotNull] IEnumerable <ProcessorDefinition> processorDefinitions, [NotNull] ProcessorArgs args, [CanBeNull] IPipelineController controller)
        {
            Assert.ArgumentNotNull(processorDefinitions, nameof(processorDefinitions));
            Assert.ArgumentNotNull(args, nameof(args));

            foreach (ProcessorDefinition processorDefinition in processorDefinitions)
            {
                foreach (Processor processor in processorDefinition.CreateProcessors(args))
                {
                    processor.ProcessorDefinition = processorDefinition;
                    bool isRequireProcessing = true;
                    try
                    {
                        isRequireProcessing = processor.IsRequireProcessing(args);
                    }
                    catch (Exception ex)
                    {
                        Log.Warn(ex, $"Cannot detect if the processor {processor.ProcessorDefinition.Type} requires processing");
                    }

                    if (isRequireProcessing)
                    {
                        List <Processor> nested = CreateProcessors(processorDefinition.NestedProcessorDefinitions, args, controller);
                        processor.NestedProcessors.AddRange(nested);
                        processor.Controller = controller;
                        yield return(processor);
                    }
                }
            }
        }
        public override bool IsRequireProcessing(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              return this.IsRequireProcessing((BackupArgs)args);
        }
 protected abstract void Process([NotNull] ProcessorArgs args);
        public virtual bool IsRequireProcessing([NotNull] ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            return(true);
        }
            public PipelineStartInfo([NotNull] ProcessorArgs processorArgs, [NotNull] List<Step> steps, [CanBeNull] IPipelineController pipelineController = null)
            {
                Assert.ArgumentNotNull(processorArgs, "processorArgs");
                Assert.ArgumentNotNull(steps, "steps");

                this.ProcessorArgs = processorArgs;
                this.PipelineController = pipelineController;
                this.Steps = steps;
            }
        public override long EvaluateStepsCount(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              return InstallHelper.GetStepsCount(((ReinstallArgs)args).PackagePath);
        }
 public abstract IEnumerable<Processor> CreateProcessors(ProcessorArgs args);
Exemplo n.º 28
0
 public abstract IEnumerable <Processor> CreateProcessors(ProcessorArgs args, IPipelineController controller);
        public override long EvaluateStepsCount(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              return ((ReinstallArgs)args).InstanceDatabases.Count;
        }
        protected override void Process(ProcessorArgs args)
        {
            var download = (Download8Args)args;
              var cookies = download.Cookies;
              var localRepository = download.LocalRepository;
              var fileNames = download.FileNames;
              var links = download.Links;

              var cancellation = new CancellationTokenSource();
              var urls = links.Where(link => this.RequireDownloading(fileNames[link], localRepository)).ToArray();
              var n = urls.Length;
              for (int index = 0; index < n; index++)
              {
            var url = urls[index];
            try
            {
              var fileName = fileNames[url];
              fileName = FixFileName(fileName);

              var destFileName = Path.Combine(localRepository, fileName);
              Assert.IsTrue(!FileSystem.FileSystem.Local.File.Exists(destFileName), "The {0} file already exists".FormatWith(destFileName));
              Log.Info("Downloading " + destFileName, this);

              if (this.TryCopyFromExternalRepository(fileName, destFileName))
              {
            this.Controller.SetProgress(index * scale + scale);
            return;
              }

              var downloadOptions = new DownloadOptions
              {
            Uri = url,
            BlockOptions = new BlocksCount(WindowsSettings.AppDownloader8ParallelThreads.Value),
            CancellationToken = cancellation.Token,
            Cookies = cookies,
            FilePath = destFileName,
            RequestTimeout = new TimeSpan(0, WindowsSettings.AppDownloaderTotalTimeout.Value, 0, 0)
              };

              var done = false;
              Exception exception = null;
              var context = new DownloadContext(downloadOptions);
              context.OnProgressChanged += (x, y, z) => this.Controller.SetProgress(index * scale + z);
              context.OnDownloadCompleted += () => done = true;
              context.OnErrorOccurred += ex => exception = ex;
              ApplicationManager.AttemptToClose += (x, y) => cancellation.Cancel(true);
              context.DownloadAsync();
              while (!done && exception == null)
              {
            Thread.Sleep(1000);
              }

              if (exception != null)
              {
            cancellation.Cancel();
            throw new InvalidOperationException("Downloading file '{0}' failed with exception".FormatWith(url), exception);
              }
            }
            catch (Exception ex)
            {
              Log.Warn("An error occurred during downloading files", this, ex);

              cancellation.Cancel();
              throw new InvalidOperationException("An unhandled exception happened during downloading '{0}' file".FormatWith(url), ex);
            }
              }
        }
 protected override void Process(ProcessorArgs args)
 {
   File.WriteAllText(Path.Combine(ApplicationManager.TempFolder, "agreement-accepted.txt"), @"agreement accepted");
 }
        public static List <Processor> CreateProcessors([NotNull] IEnumerable <ProcessorDefinition> processorDefinitions, [NotNull] ProcessorArgs args, [CanBeNull] IPipelineController controller = null)
        {
            Assert.ArgumentNotNull(processorDefinitions, nameof(processorDefinitions));
            Assert.ArgumentNotNull(args, nameof(args));

            return(new List <Processor>(CreateProcessorsPrivate(processorDefinitions, args, controller)));
        }
        public override sealed long EvaluateStepsCount(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              return this.EvaluateStepsCount((InstallModulesArgs)args);
        }
    public static void Start(string name, Window owner, ProcessorArgs args = null, bool? isAsync = null, Action action = null, params object[] wizardArgsParameters)
    {
      Log.Info("Wizard pipeline '{0}' starts", name);
      using (new ProfileSection("Start wizard"))
      {
        ProfileSection.Argument("name", name);
        ProfileSection.Argument("owner", owner);
        ProfileSection.Argument("args", args);
        ProfileSection.Argument("wizardArgsParameters", wizardArgsParameters);

        WizardPipeline wizardPipeline = Definitions[name];
        var wizard = CreateWizardWindow(wizardPipeline, args, wizardArgsParameters);
        var isSync = !(isAsync ?? !AppSettings.AppSysIsSingleThreaded.Value);
        if (isSync)
        {
          WindowHelper.ShowDialog(wizard, owner);
          if (action != null)
          {
            action();
          }
        }
        else
        {
          if (action != null && !flag)
          {
            flag = true;
            wizard.Closed += (o, e) =>
            {
              action();
              flag = false;
            };
          }

          WindowHelper.ShowWindow(wizard, owner);
        }
      }
    }
        public override IEnumerable <Processor> CreateProcessors(ProcessorArgs args)
        {
            var hive = (ProcessorHive)ReflectionUtil.CreateObject(Type);

            return(hive.CreateProcessors(args));
        }
 public override sealed long EvaluateStepsCount(ProcessorArgs args)
 {
     return this.EvaluateStepsCount((BackupArgs)args);
 }
 public override long EvaluateStepsCount(ProcessorArgs args)
 {
     return ((DownloadArgs)args).Sizes.Sum(size => size.Value);
 }
        protected override void Process(ProcessorArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

              this.Process((BackupArgs)args);
        }
 public override IEnumerable<Processor> CreateProcessors(ProcessorArgs args)
 {
   var hive = (ProcessorHive)ReflectionUtil.CreateObject(this.Type);
   return hive.CreateProcessors(args);
 }