Esempio n. 1
0
        public bool ProcessNext()
        {
            if (IsCompleted)
            {
                throw new InvalidOperationException();
            }

            WorkItem currentItem = _nextWorkItem.Dequeue();
            var      activity    = (Activity)Activator.CreateInstance(currentItem.ActivityType);

            try
            {
                WorkLog?result = activity.DoWork(currentItem);
                if (result != null)
                {
                    _completedWorkLogs.Push(result);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, "Exception occurred during process next method.");
            }
            return(false);
        }
Esempio n. 2
0
        private State Perform(State initialState)
        {
            State currentState = initialState;
            var   doneActions  = new Stack <IStatefulTask <State> >();

            try
            {
                foreach (IStatefulTask <State> action in Actions)
                {
                    doneActions.Push(action);

                    currentState = action.DoAction(currentState);
                }
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, "Exception occured during perform.");
                Logger.Message($"Perform rollback for {doneActions.Count.ToString()} actions.");

                foreach (IStatefulTask <State> action in doneActions)
                {
                    currentState = action.RollbackSafe(currentState);
                }
            }

            return(currentState);
        }
Esempio n. 3
0
        private static int Main(string[] args)
        {
            try
            {
                Logger.Message("Console application started.");

                RunModules();

                return(0);
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, $"Exception occurred in {nameof(Main)} method.");

                return(-1);
            }
            finally
            {
                Logger.Message("Console application stopped.");
                Logger.Message("Press any key to close this window...");
                Console.ReadKey();
            }
        }