diff Implab/Components/RunnableComponent.cs @ 158:130781364799 v2

refactoring, code cleanup
author cin
date Thu, 18 Feb 2016 14:34:02 +0300
parents 948c015a9011
children c32688129f14
line wrap: on
line diff
--- a/Implab/Components/RunnableComponent.cs	Thu Feb 18 11:03:47 2016 +0300
+++ b/Implab/Components/RunnableComponent.cs	Thu Feb 18 14:34:02 2016 +0300
@@ -5,79 +5,14 @@
     public class RunnableComponent : Disposable, IRunnable, IInitializable {
         
 
-        class Automaton {
-            enum Operations {
-                Initialize,
-                Start,
-                Stop,
-                Fail,
-                Success,
-                Dispose
-            }
-
-            static readonly EDFADefinition<ExecutionState> _def = new EDFADefinition<ExecutionState>(EnumAlphabet<ExecutionState>.FullAlphabet);
-            static readonly DFAStateDescriptior[] _states;
-
-            static Automaton() {
-                var created = _def.AddState(); // initial state
-                var initializing = _def.AddState();
-                var ready = _def.AddState();
-                var starting = _def.AddState();
-                var running = _def.AddState();
-                var stopping = _def.AddState();
-                var error = _def.AddState();
-                var disposing = _def.AddState();
-                var disposed = _def.AddState(new int[] { 0 });
-
-                _def.DefineTransition(created,initializing,(int)Operations.Initialize);
-
-                _def.DefineTransition(initializing,ready,(int)Operations.Success);
-                _def.DefineTransition(initializing,error,(int)Operations.Fail);
-
-                _def.DefineTransition(ready, starting, (int)Operations.Start);
-                _def.DefineTransition(ready, disposing, (int)Operations.Dispose); 
 
 
-                _def.DefineTransition(starting, running, (int)Operations.Success);
-                _def.DefineTransition(starting, error, (int)Operations.Fail);
-
-                _def.DefineTransition(running, stopping, (int)Operations.Stop);
-                _def.DefineTransition(running, error, (int)Operations.Fail);
-
-                _def.DefineTransition(stopping, ready, (int)Operations.Success);
-                _def.DefineTransition(stopping, error, (int)Operations.Fail);
-
-                _def.DefineTransition(disposing, disposed, (int)Operations.Success);
-
-                _states = _def.States;
-            }
-
-            int m_state;
-
-            public Automaton() {
-                m_state = DFADefinitionBase.INITIAL_STATE;
-            }
-
-            void Move(Operations op) {
-                
-            }
-
-            public ExecutionState Current {
-                get { 
-                    return (ExecutionState)m_context.info;
-                }
-            }
-        }
-
-        readonly Automaton m_automaton = new Automaton();
+            
         IPromise m_pending;
         Exception m_lastError;
 
         protected RunnableComponent(bool initialized) {
-            if (initialized)
-                m_automaton.MoveTo(ExecutionState.Ready);
-            else
-                m_automaton.MoveTo(ExecutionState.Uninitialized);
+            
         }
 
         #region IInitializable implementation
@@ -91,37 +26,7 @@
         #region IRunnable implementation
 
         public IPromise Start() {
-            return Safe.InvokePromise(() => {
-                Promise promise;
-                lock (m_automaton) {
-                    if (m_automaton.Current == ExecutionState.Starting)
-                        return m_pending;
-                    m_automaton.MoveTo(ExecutionState.Starting);
-                    m_pending = promise = new Promise();
-                }
-
-                var start = Safe.InvokePromise(OnStart);
-                promise.On(null, null, start.Cancel);
-                start.On(promise.Resolve, promise.Reject, promise.CancelOperation);
-
-                return promise.Then(() => {
-                    lock(m_automaton) {
-                        m_automaton.MoveTo(ExecutionState.Running);
-                        m_pending = null;
-                    }
-
-                    Run();
-                }, err => {
-                    if (BeginTransition(RUNNING_REQUIRE)) {
-                        m_lastError = err;
-                        CompleteTransition(FAILED_STATE);
-                        throw new PromiseTransientException(err);
-                    }
-                    throw new OperationCanceledException();
-                }, reason => {
-                    throw new OperationCanceledException("The operation was cancelled", reason);
-                });
-            });
+            throw new NotImplementedException();
         }
 
         protected virtual IPromise OnStart() {