Exemplo n.º 1
0
 ///<summary>
 /// Gets the job instance based on a unique job ID.
 ///</summary>
 ///<param name="jobID"></param>
 ///<returns>Job</returns>
 public Job GetJob(string jobID)
 {
     return(jobDAL.GetJob(jobID));
 }
Exemplo n.º 2
0
        private async Task ExecuteJobAsync(string processID, string jobID, MethodInfo methodInfo, string parameters, object instance, CancellationToken?token, bool isSync)
        {
            try
            {
                //Set job to Running
                if (isSync)
                {
                    jobDAL.SetToRunning(processID, jobID);
                }
                else
                {
                    await jobDAL.SetToRunningAsync(processID, jobID);
                }
                jobDAL.SetCachedProgressStatusAsync(jobID, JobStatus.Running);

                var progress = isSync ? UpdateProgressEventAsync(jobID, true).GetAwaiter().GetResult() : await UpdateProgressEventAsync(jobID, false); //Need this to update the progress of the job's

                //Invoke Method
                if (token == null)
                {
                    var tokenSource = new CancellationTokenSource(); //not doing anything when using thread.Start()
                    token = tokenSource.Token;
                }
                var args = DALHelpers.DeserializeArguments(token.Value, progress, methodInfo, parameters);
                methodInfo.Invoke(instance, args);
            }
            catch (TargetInvocationException exc)
            {
                if (exc.InnerException is OperationCanceledException)
                {
                    if (isSync)
                    {
                        SetToStoppedAsync(new List <string> {
                            jobID
                        }, isSync).GetAwaiter().GetResult();
                    }
                    else
                    {
                        await SetToStoppedAsync(new List <string> {
                            jobID
                        }, isSync);
                    }

                    throw exc.InnerException;
                }
                else
                {
                    var job = isSync ? jobDAL.GetJob(jobID) : await jobDAL.GetJobAsync(jobID);

                    if (job != null)
                    {
                        var error = job.Error + " " + exc.ToString();
                        var count = isSync ? SetErrorAsync(processID, job.JobID, error, isSync).GetAwaiter().GetResult()
                            : await SetErrorAsync(processID, job.JobID, error, isSync);
                    }
                    throw exc;
                }
            }
            catch (Exception exc)
            {
                var job = isSync ? jobDAL.GetJob(jobID) : await jobDAL.GetJobAsync(jobID);

                if (job != null)
                {
                    var error = job.Error + " " + exc.ToString();
                    var count = isSync ? SetErrorAsync(processID, job.JobID, error, isSync).GetAwaiter().GetResult()
                        : await SetErrorAsync(processID, job.JobID, error, isSync);
                }
                throw exc;
            }

            //Completed successfully with no error
            if (isSync)
            {
                jobDAL.SetCompleted(processID, jobID);
            }
            else
            {
                await jobDAL.SetCompletedAsync(processID, jobID);
            }
            jobDAL.SetCachedProgressStatusAsync(jobID, JobStatus.Completed);
        }
Exemplo n.º 3
0
        private async Task ExecuteJobAsync(string processID, string jobID, MethodInfo methodInfo, string parameters, object instance, CancellationToken?cancelToken, PauseToken?pauseToken, bool isSync)
        {
            try
            {
                //Set job to Running
                if (isSync)
                {
                    jobDAL.SetToRunning(processID, jobID);
                }
                else
                {
                    await jobDAL.SetToRunningAsync(processID, jobID);
                }

                var progress = isSync ? UpdateProgressEventAsync(jobID, true).GetAwaiter().GetResult() : await UpdateProgressEventAsync(jobID, false); //Need this to update the progress of the job's

                //Invoke Method
                if (cancelToken == null)
                {
                    var cancelSource = new CancellationTokenSource();
                    cancelToken = cancelSource.Token;
                }

                if (pauseToken == null)
                {
                    var pauseSource = new PauseTokenSource();
                    pauseToken = pauseSource.Token;
                }

                var arguments = DALHelpers.DeserializeArguments(cancelToken.Value, pauseToken.Value, progress, methodInfo, parameters);

                var result = methodInfo.Invoke(instance, arguments);

                //handle async method invocation
                var task = result as Task;
                if (task != null)
                {
                    if (isSync)
                    {
                        task.GetAwaiter().GetResult();
                    }
                    else
                    {
                        await task;
                    }
                }
            }
            catch (OperationCanceledException exc)
            {
                if (isSync)
                {
                    SetToStoppedAsync(new List <string> {
                        jobID
                    }, isSync).GetAwaiter().GetResult();
                }
                else
                {
                    await SetToStoppedAsync(new List <string> {
                        jobID
                    }, isSync);
                }

                throw exc;
            }
            catch (TargetInvocationException exc)
            {
                if (exc.InnerException is OperationCanceledException)
                {
                    if (isSync)
                    {
                        SetToStoppedAsync(new List <string> {
                            jobID
                        }, isSync).GetAwaiter().GetResult();
                    }
                    else
                    {
                        await SetToStoppedAsync(new List <string> {
                            jobID
                        }, isSync);
                    }

                    throw exc.InnerException;
                }
                else
                {
                    var job = isSync ? jobDAL.GetJob(jobID) : await jobDAL.GetJobAsync(jobID);

                    if (job != null)
                    {
                        var error = job.Error + " " + exc.ToString();
                        var count = isSync ? SetErrorAsync(processID, job.JobID, error, isSync).GetAwaiter().GetResult()
                            : await SetErrorAsync(processID, job.JobID, error, isSync);
                    }
                    throw exc;
                }
            }
            catch (Exception exc)
            {
                var job = isSync ? jobDAL.GetJob(jobID) : await jobDAL.GetJobAsync(jobID);

                if (job != null)
                {
                    var error = job.Error + " " + exc.ToString();
                    var count = isSync ? SetErrorAsync(processID, job.JobID, error, isSync).GetAwaiter().GetResult()
                        : await SetErrorAsync(processID, job.JobID, error, isSync);
                }
                throw exc;
            }

            //Completed successfully with no error
            if (isSync)
            {
                jobDAL.SetToCompleted(processID, jobID);
            }
            else
            {
                await jobDAL.SetToCompletedAsync(processID, jobID);
            }
        }