Esempio n. 1
0
        //private object _timerSaveLock = new object();

        //void _runtimeTimer_NeedSave(object sender, EventArgs e)
        //{
        //    lock (_timerSaveLock)
        //    {
        //        _runtimePersistence.SaveTimer(Id, _runtimeTimer);
        //    }
        //}

        private void TimerComplete(object sender, RuntimeTimerEventArgs e)
        {
            TransitionDefinition currentTimerTransition;
            ProcessInstance      processInstance;

            try
            {
                processInstance = Builder.GetProcessInstance(e.ProcessId);
                PersistenceProvider.FillProcessParameters(processInstance);

                currentTimerTransition =
                    processInstance.ProcessScheme.GetTimerTransitionForActivity(processInstance.CurrentActivity).
                    FirstOrDefault(p => p.Trigger.Timer.Name == e.TimerName);
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Error Timer Complete Workflow UNKNOWN", ex);
                throw;
            }

            if (currentTimerTransition != null)
            {
                try
                {
                    SetProcessNewStatus(processInstance, ProcessStatus.Running);
                    var parametersLocal = new List <ParameterDefinitionWithValue>();
                    parametersLocal.Add(ParameterDefinition.Create(DefaultDefinitions.ParameterIdentityId, Guid.Empty));
                    parametersLocal.Add(ParameterDefinition.Create(DefaultDefinitions.ParameterImpersonatedIdentityId, Guid.Empty));
                    parametersLocal.Add(ParameterDefinition.Create(DefaultDefinitions.ParameterSchemeId, processInstance.SchemeId));
                    var newExecutionParameters = new List <ExecutionRequestParameters>();
                    newExecutionParameters.Add(ExecutionRequestParameters.Create(processInstance.ProcessId, processInstance.ProcessParameters, currentTimerTransition));
                    Bus.QueueExecution(newExecutionParameters);
                }
                catch (Exception ex)
                {
                    Logger.Log.Error(string.Format("Error Timer Complete Workflow Id={0}", processInstance.ProcessId), ex);
                    SetProcessNewStatus(processInstance, ProcessStatus.Idled);
                }
            }
        }
Esempio n. 2
0
        //private object _timerSaveLock = new object();
        //void _runtimeTimer_NeedSave(object sender, EventArgs e)
        //{
        //    lock (_timerSaveLock)
        //    {
        //        _runtimePersistence.SaveTimer(Id, _runtimeTimer);
        //    }
        //}
        private void TimerComplete(object sender, RuntimeTimerEventArgs e)
        {
            TransitionDefinition currentTimerTransition;
            ProcessInstance processInstance;
            try
            {
                processInstance = Builder.GetProcessInstance(e.ProcessId);
                PersistenceProvider.FillProcessParameters(processInstance);

                currentTimerTransition =
                    processInstance.ProcessScheme.GetTimerTransitionForActivity(processInstance.CurrentActivity).
                        FirstOrDefault(p => p.Trigger.Timer.Name == e.TimerName);
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Error Timer Complete Workflow UNKNOWN", ex);
                throw;
            }

            if (currentTimerTransition != null)
            {
                try
                {
                    SetProcessNewStatus(processInstance, ProcessStatus.Running);
                    var parametersLocal = new List<ParameterDefinitionWithValue>();
                    parametersLocal.Add(ParameterDefinition.Create(DefaultDefinitions.ParameterIdentityId, Guid.Empty));
                    parametersLocal.Add(ParameterDefinition.Create(DefaultDefinitions.ParameterImpersonatedIdentityId, Guid.Empty));
                    parametersLocal.Add(ParameterDefinition.Create(DefaultDefinitions.ParameterSchemeId, processInstance.SchemeId));
                    var newExecutionParameters = new List<ExecutionRequestParameters>();
                    newExecutionParameters.Add(ExecutionRequestParameters.Create(processInstance.ProcessId, processInstance.ProcessParameters, currentTimerTransition));
                    Bus.QueueExecution(newExecutionParameters);

                }
                catch (Exception ex)
                {
                    Logger.Log.Error(string.Format("Error Timer Complete Workflow Id={0}", processInstance.ProcessId), ex);
                    SetProcessNewStatus(processInstance, ProcessStatus.Idled);
                }
            }
        }
Esempio n. 3
0
        private void OnTimer(object state)
        {
            //try
            //{
            //    _timer.Change(new TimeSpan(0, 0, 0, 0, -1), new TimeSpan(0, 0, 0, 0, -1));
            //}
            //catch (Exception)
            //{
            //    (state as Timer).Dispose();
            //    Logger.Log.Fatal("FATAL TimerError Timer Disposed");
            //    return;
            //}

            var keysToRemove = new List<TimerKey>();
            _lock.AcquireReaderLock(_lockTimeout);
            try
            {

                foreach (var processTimerItem in Timers)
                {
                    if (processTimerItem.Value <= DateTime.UtcNow)
                    {
                        keysToRemove.Add(processTimerItem.Key);
                    }
                }

                LockCookie lc = _lock.UpgradeToWriterLock(_lockTimeout);

                try
                {
                    var error = false;

                    foreach (var runtimeTimerEventArgs in keysToRemove)
                    {
                        var args = new RuntimeTimerEventArgs
                                       {
                                           ProcessId = runtimeTimerEventArgs.ProcessId,
                                           TimerName = runtimeTimerEventArgs.TimerName
                                       };

                        try
                        {
                            var value = Timers[runtimeTimerEventArgs];
                            //ThreadPool.QueueUserWorkItem(, runtimeTimerEventArgs);
                            if (TimerComplete != null)
                                TimerComplete(this, args);
                            Timers.Remove(runtimeTimerEventArgs);
                        }
                        catch (Exception)
                        {
                            Timers[runtimeTimerEventArgs] = DateTime.UtcNow.AddMinutes(10);
                            error = true;
                        }

                    }

                    //if (NeedSave != null)
                    //        NeedSave(this, EventArgs.Empty);

                    if (error)
                    {
                        throw new InvalidOperationException();
                    }
                }
                finally
                {
                    _lock.DowngradeFromWriterLock(ref lc);
                }

            }
            finally
            {
                _lock.ReleaseReaderLock();
            }

            RefreshTimer();
        }
Esempio n. 4
0
        private void OnTimer(object state)
        {
            //try
            //{
            //    _timer.Change(new TimeSpan(0, 0, 0, 0, -1), new TimeSpan(0, 0, 0, 0, -1));
            //}
            //catch (Exception)
            //{
            //    (state as Timer).Dispose();
            //    Logger.Log.Fatal("FATAL TimerError Timer Disposed");
            //    return;
            //}

            var keysToRemove = new List <TimerKey>();

            _lock.AcquireReaderLock(_lockTimeout);
            try
            {
                foreach (var processTimerItem in Timers)
                {
                    if (processTimerItem.Value <= DateTime.UtcNow)
                    {
                        keysToRemove.Add(processTimerItem.Key);
                    }
                }

                LockCookie lc = _lock.UpgradeToWriterLock(_lockTimeout);

                try
                {
                    var error = false;

                    foreach (var runtimeTimerEventArgs in keysToRemove)
                    {
                        var args = new RuntimeTimerEventArgs
                        {
                            ProcessId = runtimeTimerEventArgs.ProcessId,
                            TimerName = runtimeTimerEventArgs.TimerName
                        };

                        try
                        {
                            var value = Timers[runtimeTimerEventArgs];
                            //ThreadPool.QueueUserWorkItem(, runtimeTimerEventArgs);
                            if (TimerComplete != null)
                            {
                                TimerComplete(this, args);
                            }
                            Timers.Remove(runtimeTimerEventArgs);
                        }
                        catch (Exception)
                        {
                            Timers[runtimeTimerEventArgs] = DateTime.UtcNow.AddMinutes(10);
                            error = true;
                        }
                    }

                    //if (NeedSave != null)
                    //        NeedSave(this, EventArgs.Empty);

                    if (error)
                    {
                        throw new InvalidOperationException();
                    }
                }
                finally
                {
                    _lock.DowngradeFromWriterLock(ref lc);
                }
            }
            finally
            {
                _lock.ReleaseReaderLock();
            }

            RefreshTimer();
        }