示例#1
0
        private void ProcessExecutionResults(IExecuteResults results, IProcessDetails pd)
        {
            // perform checks on process
            // execution state
            switch (results.State)
            {
            case ExecutionState.Success:
                // check if files were generated
                // and log?
                break;

            case ExecutionState.SuccessWithErrors:
                // log all errors
                // check for file names
                break;

            case ExecutionState.FailedCanRetry:
                // log all errors;
                // add to retry queue
                break;

            case ExecutionState.Failed:
                // log all errors
                // treat as fatal error
                // check if any files were generated before failure
                break;

            case ExecutionState.ProcessCompatExec:
                // log that the process was
                // executed using compatibility
                // from previous version
                break;
            }
        }
示例#2
0
        private void ExecuteProcess(IProcessDetails pd, HandlerEventArgs hargs)
        {
            IProcess        process  = null;
            IExecuteResults execRes  = null;
            var             transId  = Guid.NewGuid();
            Stopwatch       durWatch = null;
            long?           duration = null;

            bool hasDuration = false;

            try
            {
                IArguments pargs = null;

                // if there are any constructors with 1
                var ctors = pd.ProcessType.GetConstructors()
                            .Where(c => c.GetParameters().Count() == 1);

                if (ctors.Any())
                {
                    if (hargs is DirWatcherEventArgs)
                    {
                        var wa = (DirWatcherEventArgs)hargs;
                        pargs = new WatcherArguments(new TieFileInfo(wa.FullePath), pd.Id, pd.Name, DateTime.Now,
                                                     hargs.TriggerId, hargs.TriggerName, transId);

                        process = (TieProcess <WatcherArguments>)Activator.CreateInstance(pd.ProcessType, pargs);
                    }
                    else
                    {
                        var sa = (CronSchedulerEventArgs)hargs;
                        pargs = new SchedulerArguments(sa.QuartzCronExpression, pd.Id, pd.Name, DateTime.Now,
                                                       hargs.TriggerId, hargs.TriggerName, transId);


                        process = (TieProcess <SchedulerArguments>)Activator.CreateInstance(pd.ProcessType, pargs);
                    }
                }
                else
                {
                    // check if default constructor is present
                    var dctor = pd.ProcessType.GetConstructor(Type.EmptyTypes);

                    if (dctor != null)
                    {
                        process = (IProcess)Activator.CreateInstance(pd.ProcessType);
                    }
                }

                if (process != null)
                {
                    this._activeProcesses.Add(process);

                    durWatch = Stopwatch.StartNew();

                    execRes = process.Execute();

                    duration = durWatch.ElapsedMilliseconds;
                    durWatch.Stop();

                    hasDuration = true;
                }
            }
            catch (Exception pex)
            {
                // log error
                if (execRes == null)
                {
                    execRes = new ExecuteResults(false, ExecutionState.Failed, transId);
                }

                execRes.Errors.Add(pex.ToString());
            }
            finally
            {
                if (!hasDuration)
                {
                    duration = durWatch?.ElapsedMilliseconds;
                }


                if (execRes == null)
                {// here for backwards compatibility
                    execRes = new ExecuteResults(true, ExecutionState.ProcessCompatExec, transId);
                }

                ProcessExecutionResults(execRes, pd);

                if (process != null)
                {
                    this._activeProcesses.TryTake(out process);
                    this._logger.LogMessage(new StatusMessage("tie", $"{this._activeProcesses.Count} active processes"), process.GetHashCode().ToString());

                    process.Dispose();
                    process = null;
                }
                else
                {
                    // log that process was null and no work was performed
                    // give hargs details
                }
            }
        }