public void SetUp()
        {
            factory = new DslFactory
            {
                BaseDirectory = AppDomain.CurrentDomain.BaseDirectory
            };

            var engine = new StateMachineDSLEngine();

            engine.ImportedNamespaces.Add("Entropy.SimpleStateMachine.Tests");
            engine.ReferencedAssemblies.Add(GetType().Assembly);
            factory.Register <StateMachineBuilder>(engine);
        }
        protected override void OnLoad(EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }


            base.OnLoad(e);
            var factory = new DslFactory
            {
                BaseDirectory = AppDomain.CurrentDomain.BaseDirectory
            };

            var engine = new StateMachineDSLEngine();

            engine.ImportedNamespaces.Add("StateMachineDemo.Domain");
            engine.ReferencedAssemblies.Add(typeof(Order).Assembly);

            factory.Register <StateMachineBuilder>(engine);

            if (String.IsNullOrEmpty(WorkflowDirectory))
            {
                WorkflowDirectory = @"WorkflowDefinitions\Basic";
            }

            StateMachineBuilder[] machines = factory.CreateAll <StateMachineBuilder>(WorkflowDirectory);
            foreach (StateMachineBuilder builder in machines)
            {
                var newMachine = new StateMachine();

                //As an alternative to using the task_assembly "assemblyname"
                //feature of the DSL, you can manually
                //register any assemblites that contain StateTransitionTasks.
                //This step can be skipped, but then all loaded assemblies
                //will be checked for tasks and if your project has a lot
                //of references, this will be a lot of wasted CPU cycles.

                //In this case, we are using the DSL to register the assembly
                //newMachine.RegisterTaskAssembly(GetType().Assembly);

                builder.BuildStateMachine(newMachine);
                _machines.Add(newMachine.Name, newMachine);
                _stateMachinePicker.Items.Add(newMachine.Name);
            }
            if (_stateMachinePicker.Items.Count > 0)
            {
                _stateMachinePicker.SelectedIndex = 0;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StateMachineService"/> class.
        /// </summary>
        /// <param name="workflowDirectory">The workflow directory.</param>
        /// <param name="importedNamespaces">The imported namespaces.</param>
        /// <param name="referencedAssemblies">The referenced assemblies.</param>
        public StateMachineService(string workflowDirectory, IEnumerable <string> importedNamespaces,
                                   IEnumerable <Assembly> referencedAssemblies)
        {
            if (workflowDirectory == null)
            {
                throw new ArgumentNullException("workflowDirectory");
            }
            _workflowDirectory = workflowDirectory;

            _factory = new DslFactory
            {
                BaseDirectory = AppDomain.CurrentDomain.BaseDirectory
            };

            var engine = new StateMachineDSLEngine();

            engine.ImportedNamespaces.AddRange(importedNamespaces);
            engine.ReferencedAssemblies.AddRange(referencedAssemblies);

            _factory.Register <StateMachineBuilder>(engine);
        }