示例#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
文件: Job.cs 项目: dekkerb115/Bam.Net
        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);