Beispiel #1
0
 /// <summary>
 ///     Serves as a hash function for a particular type.
 /// </summary>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = ProcessPlus?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ Handle.GetHashCode();
         return(hashCode);
     }
 }
Beispiel #2
0
 /// <summary>
 ///     Serves as a hash function for a particular type.
 /// </summary>
 public override int GetHashCode()
 {
     return(Id.GetHashCode() ^ ProcessPlus.GetHashCode());
 }
Beispiel #3
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
                }
            }
        }