Example #1
0
        /// <summary>
        /// Wraps a task for calling all reports when it is done.
        /// </summary>
        /// <param name="jobResult"></param>
        /// <returns></returns>
        private Task <JobResult> ForEachReport(Task <JobResult> realJob)
        {
            if (this.Reports.Count == 0)
            {
                return(realJob);
            }

            return(new Task <JobResult>(() =>
            {
                realJob.Start();
                JobResult result = realJob.Result;

                foreach (var item in this.Reports)
                {
                    item.Report(result);
                }

                return result;
            }));
        }
Example #2
0
        /// <summary>
        /// <para>
        /// Creates and starts the job.
        /// </para>
        ///
        /// <para>
        /// Concurrent calls to this method will create and start
        /// the same job.
        /// </para>
        /// </summary>
        /// <returns>A running task with a job.</returns>
        public Task <JobResult> Work()
        {
            return(new Task <JobResult>(() =>
            {
                SourceType data;
                DestinationType destinationData;

                lock (this.Extractor)
                {
                    try
                    {
                        data = this.Extractor.Extract();
                    }
                    catch (Exception ExtractionException)
                    {
                        return JobResult.BuildWithError(
                            this.Extractor.GetID(),
                            this.Transformer.GetID(),
                            this.loader.GetID(),
                            new JobException(
                                $"Unhandled exception proccesing extractor '{this.Extractor.GetID()}'.",
                                this.Extractor.GetID(),
                                Phase.EXTRACTION,
                                ExtractionException
                                )
                            );
                    }
                }

                lock (this.Transformer)
                {
                    try
                    {
                        destinationData = this.Transformer.Transform(data);
                    }
                    catch (Exception TransformationException)
                    {
                        return JobResult.BuildWithError(
                            this.Extractor.GetID(),
                            this.Transformer.GetID(),
                            this.loader.GetID(),
                            new JobException(
                                $"Unhandled exception processing transformer '{this.Transformer.GetID()}'.",
                                this.Transformer.GetID(),
                                Phase.TRANSFORMATION,
                                TransformationException
                                )
                            );
                    }
                }

                lock (this.loader)
                {
                    try
                    {
                        this.loader.Load(destinationData);
                    }
                    catch (Exception eLoading)
                    {
                        return JobResult.BuildWithError(
                            this.Extractor.GetID(),
                            this.Transformer.GetID(),
                            this.loader.GetID(),
                            new JobException(
                                $"Unhandled exception processing loader '{this.loader.GetID()}'.",
                                this.loader.GetID(),
                                Phase.LOADING,
                                eLoading
                                )
                            );
                    }
                }

                return JobResult.BuildCompletedWithoutErrors(
                    this.Extractor.GetID(),
                    this.Transformer.GetID(),
                    this.loader.GetID()
                    );
            }));
        }