Пример #1
0
        protected override WorkState Do(WorkState currentWorkState)
        {
            try
            {
                Args.ThrowIf(string.IsNullOrEmpty(Destination), "Destination not specified");

                Parallel.ForEach(FilePaths, (filePath) =>
                {
                    FileInfo file            = new FileInfo(filePath);
                    FileInfo destinationFile = new FileInfo(Path.Combine(Destination, file.Name));
                    File.Copy(filePath, destinationFile.FullName);
                });
                return(new WorkState(this)
                {
                    Status = Status.Succeeded, PreviousWorkState = currentWorkState
                });
            }
            catch (Exception ex)
            {
                return(new WorkState(this, ex)
                {
                    PreviousWorkState = currentWorkState
                });
            }
        }
Пример #2
0
        protected override WorkState Do(WorkState currentWorkState)
        {
            this.CheckRequiredProperties();

            WorkState result = new WorkState(this)
            {
                Status            = Status.Succeeded,
                PreviousWorkState = currentWorkState
            };

            object formatValues = new
            {
                JobName  = Job.Name.Or("[JobName Not Set]"),
                WorkName = Job.CurrentWorkerName.Or("[WorkName Not Specified]"),
                Status   = Job.CurrentWorkState.Status.ToString(),
                Message  = Job.CurrentWorkState.Message.Or(" ")
            };

            Email email = new Email();

            email.Server(SmtpHost)
            .Port(int.Parse(Port))
            .IsBodyHtml(_isBodyHtml)
            .From(From)
            .To(Recipients.DelimitSplit(",", ";"))
            .Subject(SubjectFormat.NamedFormat(formatValues))
            .Body(BodyFormat.NamedFormat(formatValues))
            .UserName(UserName)
            .Password(Password)
            .EnableSsl(_enableSsl)
            .Send();

            return(result);
        }
Пример #3
0
        protected override WorkState Do()
        {
            SuspendedJob             suspended = JobConductorService.Default.SuspendJob(Job);;
            WorkState <SuspendedJob> result    = new WorkState <SuspendedJob>(this, suspended);

            result.Status = Status.Suspended;
            return(result);
        }
Пример #4
0
 protected override WorkState Do(WorkState currentWorkState)
 {
     if (Job.CurrentWorkState != currentWorkState)
     {
         Job.CurrentWorkState = currentWorkState;
     }
     return(EvaluateWorkState(Job.CurrentWorkState) ? IfTrueWorker.Do(Job) : ElseWorker.Do(Job));
 }
Пример #5
0
        protected override WorkState Do()
        {
            WorkState workstate = new WorkState(this);
            bool      success   = new FileInfo(SourceFile).TransformXml(TransformFile, DestinationFile);

            workstate.Status = success ? Status.Succeeded : Status.Failed;
            return(workstate);
        }
Пример #6
0
        /// <summary>
        /// Gets or sets the current WorkState of this Worker
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="state"></param>
        /// <returns></returns>
        public WorkState <T> State <T>(WorkState <T> state = null)
        {
            if (state != null)
            {
                _state = state;
            }

            return((WorkState <T>)_state);
        }
Пример #7
0
        public WorkState State(WorkState state = null)
        {
            if (state != null)
            {
                _state = state;
            }

            return((WorkState)_state);
        }
Пример #8
0
        protected override WorkState Do(WorkState currentWorkState)
        {
            SuspendedJob             suspended = JobConductorService.SuspendJob(Job);;
            WorkState <SuspendedJob> result    = new WorkState <SuspendedJob>(this, suspended)
            {
                Status = Status.Suspended
            };

            return(result);
        }
Пример #9
0
        protected override WorkState Do()
        {
            WorkState result = new WorkState(this)
            {
                Message = "({0}) uploaded to ({1}) successfully"._Format(Source, Destination)
            };

            Ftp.Server(Destination).UserName(UserName).Password(Password).Upload(Source);

            return(result);
        }
Пример #10
0
        protected override WorkState Do()
        {
            Validate.RequiredProperties(this);

            DirectoryInfo dir = new DirectoryInfo(SourceDirectory);

            ZipFile.CreateFromDirectory(dir.FullName, TargetPath);
            WorkState workstate = new WorkState(this, "Sucessfully zipped file to {0}"._Format(SourceDirectory));

            return(workstate);
        }
Пример #11
0
        protected override WorkState Do()
        {
            Args.ThrowIfNullOrEmpty(CommandLine, "CommandLine");

            ProcessOutput             output = CommandLine.Run();
            WorkState <ProcessOutput> result = new WorkState <ProcessOutput>(this, output)
            {
                Message = "{0} exited with code {1}"._Format(CommandLine, output.ExitCode)
            };

            return(result);
        }
Пример #12
0
        protected override WorkState Do(WorkState currentWorkState)
        {
            Args.ThrowIfNullOrEmpty(CommandLine, "CommandLine");

            ProcessOutput             output = CommandLine.Run();
            WorkState <ProcessOutput> result = new WorkState <ProcessOutput>(this, output)
            {
                Message           = string.Format("{0} exited with code {1}", CommandLine, output.ExitCode),
                PreviousWorkState = currentWorkState
            };

            return(result);
        }
Пример #13
0
        protected override WorkState Do(WorkState currentWorkState)
        {
            string jobName = this.Job != null ? this.Job.Name : "null";

            DirectoryInfo src = new DirectoryInfo(Source);

            ThrowIfDirectoryNotFound(jobName, src);

            DirectoryInfo dst = new DirectoryInfo(Destination);

            ThrowIfDirectoryNotFound(jobName, dst);

            src.Copy(dst);

            return(new WorkState(this, "Directory {0} copied successfully to {1}"._Format(src.FullName, dst.FullName)));
        }
Пример #14
0
        protected override WorkState Do(WorkState currentWorkState)
        {
            string jobName = this.Job != null ? this.Job.Name : "null";

            FileInfo src = new FileInfo(Source);

            ThrowIfFileNotFound(jobName, src);

            FileInfo dst = new FileInfo(Destination);

            File.Copy(src.FullName, dst.FullName);

            return(new WorkState(this, "File {0} copied successfully to {1}"._Format(src.FullName, dst.FullName))
            {
                PreviousWorkState = currentWorkState
            });
        }
Пример #15
0
        /// <summary>
        /// Sets all the properties of the current
        /// worker from the properties of the current
        /// WorkState.  All writable string properties that
        /// match in name will be copied to the
        /// current worker
        /// </summary>
        protected internal void ConfigureFromWorkstate()
        {
            WorkState state = State();

            if (state != null)
            {
                Type           stateType       = state.GetType();
                Type           currentType     = this.GetType();
                PropertyInfo[] stateProperties = stateType.GetProperties().Where(pi => pi.PropertyType == typeof(string)).ToArray();
                stateProperties.Each(prop =>
                {
                    PropertyInfo currentProp = currentType.GetProperty(prop.Name);
                    if (currentProp.PropertyType == typeof(string) && currentProp.CanWrite)
                    {
                        currentProp.SetValue(this, prop.GetValue(state));
                    }
                });
            }
        }
Пример #16
0
        public void Run()
        {
            OnJobStarted();
            bool addToQueue;

            WorkerNames.Each((workerName, i) =>
            {
                addToQueue = i >= StepNumber;
                if (addToQueue)
                {
                    IWorker work     = this[workerName];
                    CurrentWorkState = new WorkState(work, "queueing worker");
                    WorkQueue.Enqueue(work);
                    OnWorkerQueued();
                }
            });

            while (WorkQueue.Count > 0)
            {
                IWorker work = WorkQueue.Dequeue();

                CurrentWorkState = new WorkState(work, string.Format("starting work {0}", work.Name))
                {
                    PreviousWorkState = CurrentWorkState
                };

                OnWorkerStarting();

                CurrentWorkState = work.Do(this);

                OnWorkerFinished();

                if (CurrentWorkState.Status == Status.Failed)
                {
                    OnWorkerException();
                    break;
                }
            }

            OnJobFinished();
        }
Пример #17
0
        public WorkState Do(Job job)
        {
            lock (_doLock)
            {
                Busy = true;
                Job  = job;
                WorkState state = null;

                try
                {
                    state = Do();
                }
                catch (Exception ex)
                {
                    state = new WorkState(this, ex);
                }

                Busy = false;
                return(state);
            }
        }
Пример #18
0
        public WorkState Do(Job job)
        {
            lock (_doLock)
            {
                Busy = true;
                Job  = job;
                WorkState nextWorkState = null;

                try
                {
                    nextWorkState = Do(job.CurrentWorkState);
                }
                catch (Exception ex)
                {
                    nextWorkState = new WorkState(this, ex);
                }

                Busy = false;
                return(nextWorkState);
            }
        }
Пример #19
0
 protected void OnWorkerStarting(WorkState state)
 {
     WorkStarting?.Invoke(this, new WorkStateEventArgs(state));
 }
Пример #20
0
 public WorkStateEventArgs(WorkState state)
 {
     this.WorkState = state;
 }
Пример #21
0
 protected void OnJobFinished(WorkState state)
 {
     JobFinished?.Invoke(this, new WorkStateEventArgs(state));
 }
Пример #22
0
 protected void OnWorkerException(WorkState state)
 {
     WorkerException?.Invoke(this, new WorkStateEventArgs(state));
 }
Пример #23
0
 protected abstract WorkState Do(WorkState currentWorkState);