public void ListItemSetter_Execute_NullParameter_ThrowsException()
        {
            var listItemSetter = new ListItemSetter();
            dynamic config = new DynamicConfiguration();

            listItemSetter.Execute("SomeMethodCall", config, null);
        }
        private static IActivityMachine CreateMachineForCommandExecuting(DynamicConfiguration config)
        {
            CommandExecutingMachine activityMachine;

            // If no script treenode was given yet, try to create one here.
            if (config.HasDataKey("ScriptName") && config.HasDataKey("DeviceType") && !config.HasDataValue("TreeNode"))
            {
                config.Data.TreeNode = ((IExecuterLoader)config.Data.Loader).
                                       GetScriptNode(config.Data.ScriptName, config.Data.DeviceType);
            }

            if (config.HasDataValue("IsSubmachine") && config.Data.IsSubmachine)
            {
                activityMachine = new CommandExecutingMachine(config, config.Data.Name);
            }
            else
            {
                activityMachine = new CommandExecutingMachine(config.Data.ProcessName, config);
            }

            if (config.HasDataValue(Key.Instrument))
            {
                var instrument = config.Data.Instrument as IInstrument;
                config.Data.IsInServiceMode = (instrument != null && instrument.InServiceMode);
            }

            activityMachine.Builder = ActivityMachineBuilderLoader.GetActivityMachineBuilder(config);
            activityMachine.LogType = LogType.Script;

            return(activityMachine);
        }
Esempio n. 3
0
        public void CorrectlySerializesComplexObjects()
        {
            var dynamicConfiguration = new DynamicConfiguration();

            var complexSetting = new ComplexSetting
            {
                FirstName  = "Geert",
                MiddleName = "van",
                LastName   = "Horrik"
            };

            dynamicConfiguration.SetConfigurationValue("ComplexSetting", complexSetting);

            using (var memoryStream = new MemoryStream())
            {
                dynamicConfiguration.SaveAsXml(memoryStream);

                memoryStream.Position = 0L;

                var newDynamicConfiguration = SavableModelBase <DynamicConfiguration> .Load(memoryStream, SerializationFactory.GetXmlSerializer());

                var newComplexSetting = newDynamicConfiguration.GetConfigurationValue <ComplexSetting>("ComplexSetting", null);

                Assert.AreEqual(newComplexSetting.FirstName, complexSetting.FirstName);
                Assert.AreEqual(newComplexSetting.MiddleName, complexSetting.MiddleName);
                Assert.AreEqual(newComplexSetting.LastName, complexSetting.LastName);
            }
        }
        public void DynamicConfiguration_Indexer_AssignedStringValue_CreatesAPropertyWhichReturnsCorrectValue()
        {
            dynamic config = new DynamicConfiguration();
            config["MyPropName"] = "MyPropValue";

            Assert.IsTrue(config.MyPropName == "MyPropValue");
        }
        public void ListItemSetter_Execute_EmptyArray_ThrowsException()
        {
            var listItemSetter = new ListItemSetter();
            dynamic config = new DynamicConfiguration();

            listItemSetter.Execute("SomeMethodCall", config);
        }
        public void CallWithSection_ValueCanGetSet()
        {
            var     root    = ConfigHelper.CreateEmptyRoot();
            var     section = root.GetSection("W");
            dynamic dy      = new DynamicConfiguration(section);

            var a = dy.a();

            Assert.IsNull(a);
            dy.a = "dw123";
            a    = dy.a();
            Assert.AreEqual("dw123", a);
            Assert.AreEqual("dw123", section["a"]);

            var val = dy.a.b.c();

            Assert.IsNull(val);
            dy.a.b.c = "123";
            val      = dy.a.b.c();
            Assert.AreEqual("123", val);
            Assert.AreEqual("123", section["a:b:c"]);

            dy["w:q"] = 123;
            Assert.AreEqual("123", dy["w:q"]);
            Assert.AreEqual("123", dy.w.q());
        }
        public void CallWithPath_ValueCanGetSet()
        {
            var     root         = ConfigHelper.CreateEmptyRoot();
            var     cfg          = new DynamicConfiguration(root);
            string  changePath   = null;
            dynamic dy           = cfg;
            var     helloSection = dy.hello;

            ((INotifyPropertyChanged)helloSection).PropertyChanged += (o, e) =>
            {
                changePath = e.PropertyName;
            };
            helloSection.world = "123";
            Assert.AreEqual("hello:world", changePath);
            var val = dy.a.b.c();

            Assert.IsNull(val);
            dy.a.b.c = "123";
            val      = dy.a.b.c();
            Assert.AreEqual("123", val);
            Assert.AreEqual("123", root["a:b:c"]);

            dy["w:q"] = 123;
            Assert.AreEqual("123", dy["w:q"]);
            Assert.AreEqual("123", dy.w.q());

            dy[1] = 456;
            Assert.AreEqual("456", root["1"]);

            root["qwerty"] = "123";
            var v = dy.qwerty(typeof(int));

            Assert.AreEqual(123, v);
        }
        public void DynamicConfiguration_Indexer_AssignedIntValue_CreatesAPropertyOfTypeInt()
        {
            dynamic config = new DynamicConfiguration();
            config["MyPropName"] = 99;

            Assert.IsTrue(config.MyPropName.GetType().Name == "Int32");
        }
        public void DynamicConfiguration_Indexer_AssignedNullValue_CreatesAPropertyWhichReturnsNull()
        {
            dynamic config = new DynamicConfiguration();
            config["MyPropName"] = null;

            Assert.IsNull(config.MyPropName);
        }
        public void PropertySetter_Execute_MultipleParameters_ThrowsException()
        {
            var propertySetter = new PropertySetter();
            dynamic config = new DynamicConfiguration();

            propertySetter.Execute("SomeProperty", config, 1, 2);
        }
        public void DynamicConfiguration_Indexer_AssignedStringValue_CreatesAProperty()
        {
            dynamic config = new DynamicConfiguration();
            config["MyPropName"] = "MyPropValue";

            Assert.IsNotNull(config.MyPropName);
        }
Esempio n. 12
0
            /// <summary>
            /// Caches all settings into the collections.
            /// </summary>
            public static void LoadComponentConfiguration()
            {
                foreach (XmlElement Component in ConfigFile.SelectNodes("/Trebuchet/Framework/Components/*"))
                {
                    ICollection <XmlElement> Elements = new List <XmlElement>();

                    foreach (XmlElement Element in Component.ChildNodes)
                    {
                        Elements.Add(Element);
                    }

                    if (Component.GetAttribute("Type") == "Static")
                    {
                        StaticConfiguration.TryAdd(Component.GetAttribute("Namespace"), Elements.AsQueryable());
                        continue;
                    }

                    if (string.IsNullOrEmpty(Component.GetAttribute("Namespace")))
                    {
                        Framework.LOG.WriteCritical("Found component without 'namespace': {0}", Component.LocalName);
                        continue;
                    }

                    Type Type = Type.GetType(Component.GetAttribute("Namespace"), false);
                    DynamicConfiguration.TryAdd(Type, Elements.AsQueryable());
                }
            }
Esempio n. 13
0
        private void OnApply(object sender, EventArgs e)
        {
            try
            {
                btnApply.Enabled = false;
                if (null == _sourceXmlDoc || string.IsNullOrEmpty(_sourceXmlDoc.OuterXml))
                {
                    return;
                }

                UpdateLogoutput();
                _sourceXmlDoc.Save(MainForm.DefaultDynamicConfigFileName);


                var dynamicconfig = new DynamicConfiguration();

                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine(string.Format(@"---- Switch config to <{0}>", txtConfigSource.Text));
                Console.WriteLine("");
                Console.WriteLine("");
                dynamicconfig.SwitchConfigSource(MainForm.DefaultDynamicConfigFileName);
                MainForm.InitializeLogger();
            }
            catch (Exception ex) { _maiForm.DisplayMessage(@"---OnApply", ex); }
        }
        public void DynamicConfiguration_Indexer_AssignedStringValue_CreatesAPropertyOfTypeString()
        {
            dynamic config = new DynamicConfiguration();
            config["MyPropName"] = "MyPropValue";

            Assert.IsTrue(config.MyPropName.GetType().Name == "String");
        }
        /// <summary>
        /// Ctor used for building nested machines because it tries to reuse the DataContext from a root machine.
        /// If the given config has a SimpleDispatcher included,  this machine will use it.
        /// Otherwise, this machine will create its own SimpleDispatcher.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="name"></param>
        public CommandExecutingMachine(DynamicConfiguration config, string name)
            : base(ExtractNamePrefix(config.Data as IDictionary <string, object>) + name, ExtractDispatcher(config))
        {
            DataContext = ExtractDataContext(config);

            InitializeComponents(config);
        }
Esempio n. 16
0
        public static void Merge(string dynamicConfigFileName,
                                 ILog logger,
                                 XmlDocument targetXmlDoc,
                                 XmlDocument mergeScriptXmlDoc)
        {
            if (null == targetXmlDoc || null == mergeScriptXmlDoc)
            {
                return;
            }

            try
            {
                var mergeworker = new MergeWorker(logger, mergeScriptXmlDoc, targetXmlDoc);
                mergeworker.Merge();

                //var dynamicConfigFileName = @".\Dynamic.config";
                mergeworker.MergedXmlDoc.Save(dynamicConfigFileName);
                using (var dynamicconfig = new DynamicConfiguration())
                {
                    dynamicconfig.SwitchConfigSource(dynamicConfigFileName);
                }
            }
            catch (Exception ex)
            {
                var errorMessage = string.Format(@"---Exception caught at XmlMergeUtil, error was:{0}", ex);
                if (null != logger)
                {
                    logger.Error(errorMessage, ex);
                }
                else
                {
                    System.Diagnostics.Trace.WriteLine(errorMessage);
                }
            }
        }
        public void PropertySetter_Execute_EmptyArray_ThrowsException()
        {
            var propertySetter = new PropertySetter();
            dynamic config = new DynamicConfiguration();

            propertySetter.Execute("SomeProperty", config);
        }
        public void PropertySetter_Execute_NullParameter_ThrowsException()
        {
            var propertySetter = new PropertySetter();
            dynamic config = new DynamicConfiguration();

            propertySetter.Execute("SomeProperty", config, null);
        }
Esempio n. 19
0
        public static void FixtureSetUp()
        {
            CreateConfigFile();

            m_Config = new DynamicUrlConfiguration(100, 500, false, m_ConfigFile);
            Console.WriteLine("Initializing with sources: " + m_Config.Source);
            DynamicPropertyFactory.InitWithConfigurationSource(m_Config);
        }
        public void PropertySetter_Execute_ValidMethodNameAndStringValue_SetsConfigProperty()
        {
            var propertySetter = new PropertySetter();
            dynamic config = new DynamicConfiguration();

            propertySetter.Execute("HasSomePropertySetTo", config, "Value");
            Assert.IsTrue(config.SomeProperty == "Value");
        }
Esempio n. 21
0
        private LocalizationManager GetLocalizationManager(string customLanguage)
        {
            var configuration = new DynamicConfiguration
            {
                Language = customLanguage
            };

            return(new LocalizationManager(configuration, Logger.Instance, LibraryAssembly));
        }
        public void ListItemSetter_Execute_ValidMethodName_CreatesConfigProperty()
        {
            var listItemSetter = new ListItemSetter();
            dynamic config = new DynamicConfiguration();

            listItemSetter.Execute("HasNamesListItem", config, "SomeValue");

            Assert.IsNotNull(config.Names);
        }
        public static object ExtractDataContext(DynamicConfiguration config)
        {
            object dataContext = null;

            if (config.HasDataKey(Key.DataContext))
            {
                dataContext = config.Data.DataContext;
            }
            return(dataContext);
        }
        public static string ExtractThreadName(DynamicConfiguration config)
        {
            ActivityMachine rootMachine = ExtractRootMachine(config.Data as IDictionary <string, object>);

            if (rootMachine != null)
            {
                return(rootMachine.ThreadName);
            }
            return(string.Empty);
        }
        public static SimpleDispatcher ExtractDispatcher(DynamicConfiguration config)
        {
            SimpleDispatcher dispatcher = null;

            if (config.HasDataKey("Dispatcher"))
            {
                dispatcher = config.Data.Dispatcher as SimpleDispatcher;
            }
            return(dispatcher);
        }
        public void Should_ThrowsFormatException_WhenKeysRequireParams([ValueSource(nameof(SupportedLanguages))] string language, [ValueSource(nameof(KeysWithParams))] string key)
        {
            var configuration = new DynamicConfiguration
            {
                Language = language
            };

            Assert.Throws <FormatException>(() =>
                                            new LocalizationManager(configuration, Logger.Instance).GetLocalizedMessage(key));
        }
        public void Should_ReturnNonKeyValue_ForKeysPresentInCore_IfLanguageMissedInSiblingAssembly()
        {
            var configuration = new DynamicConfiguration
            {
                Language = "en"
            };
            var localizedValue = new LocalizationManager(configuration, Logger.Instance, GetType().Assembly).GetLocalizedMessage(ClickingKey);

            Assert.AreEqual(ClickingValueEn, localizedValue, "Value should match to expected");
        }
        public void ListItemSetter_Execute_SingleValidMethodName_CreatesListConfigPropertyWithCorrect()
        {
            var listItemSetter = new ListItemSetter();
            dynamic config = new DynamicConfiguration();

            listItemSetter.Execute("HasNamesListItem", config, "SomeValue");

            Assert.IsTrue(config.Names.Count == 1);
            Assert.AreEqual(config.Names[0], "SomeValue");
        }
Esempio n. 29
0
        public void KnowsWhatPropertiesAreSetUsingSetConfigurationValue()
        {
            var configuration = new DynamicConfiguration();

            configuration.SetConfigurationValue("A", "1");
            configuration.SetConfigurationValue("B", "2");

            Assert.IsTrue(configuration.IsConfigurationValueSet("A"));
            Assert.IsTrue(configuration.IsConfigurationValueSet("B"));
            Assert.IsFalse(configuration.IsConfigurationValueSet("C"));
        }
        public void Should_ReturnNonKeyValues_AndNotEmptyValues_ForKeysWithoutParams([ValueSource(nameof(SupportedLanguages))] string language, [ValueSource(nameof(KeysWithoutParams))] string key)
        {
            var configuration = new DynamicConfiguration
            {
                Language = language
            };
            var localizedValue = new LocalizationManager(configuration, Logger.Instance).GetLocalizedMessage(key);

            Assert.AreNotEqual(key, localizedValue, "Value should be defined in resource files");
            Assert.IsNotEmpty(localizedValue, "Value should not be empty");
        }
        /// <summary>
        /// Gets the configuration value.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="dynamicConfiguration">The dynamic configuration.</param>
        /// <param name="name">The name.</param>
        /// <param name="defaultValue">The default value if the configuration value is not of type TValue.</param>
        /// <returns>System.String.</returns>
        public static TValue GetConfigurationValue <TValue>(this DynamicConfiguration dynamicConfiguration, string name, TValue defaultValue)
        {
            var value = dynamicConfiguration.GetConfigurationValue(name);

            if (value is TValue)
            {
                return((TValue)value);
            }

            return(defaultValue);
        }
        public void ConfigurationBuilder_TryInvokeMember_KnownMethodStrategy_IsExecuted()
        {
            var strategyMock = new Mock<IMethodStrategy>();
            var config = new DynamicConfiguration();
            strategyMock.Setup(s => s.IsMatch(It.IsAny<string>())).Returns(true);

            var strategyList = new List<IMethodStrategy> { strategyMock.Object };

            dynamic configurationBuilder = new ConfigurationBuilder(config, strategyList);
            configurationBuilder.SomeExpectedMethod();
            strategyMock.Verify(s => s.Execute(It.IsAny<string>(), It.IsAny<Object>(), It.IsAny<Object[]>()));
        }
        public void ConfigurationBuilder_TryInvokeMember_KnownMethodStrategy_IsExecutedWithCorrectParameters()
        {
            var strategyMock = new Mock<IMethodStrategy>();
            var config = new DynamicConfiguration();
            strategyMock.Setup(s => s.IsMatch(It.IsAny<string>())).Returns(true);

            var strategyList = new List<IMethodStrategy> { strategyMock.Object };

            dynamic configurationBuilder = new ConfigurationBuilder(config, strategyList);
            configurationBuilder.SomeExpectedMethod("ParamValue");
            strategyMock.Verify(s => s.Execute("SomeExpectedMethod", config, new object[] { "ParamValue" }));
        }
Esempio n. 34
0
        protected ExecuteMachineActivity(string name, TPreconditionParam preconditionParam,
                                         Func <TPreconditionParam, bool> precondition, DynamicConfiguration machineConfig,
                                         Func <DynamicConfiguration, IActivityMachine> create) : base(name)
        {
            PreconditionParam   = preconditionParam;
            ExecutePrecondition = precondition;
            MachineConfig       = machineConfig;
            CreateMachine       = create;
            var root = ExtractRootMachine(machineConfig);

            RootName = root == null ? "unknown" : root.Name;
        }
        public static IActivityMachine CreateMachineForTrayProcessorErrorHandling(DynamicConfiguration config)
        {
            var ae = config.Data.Exception as AtlasException;

            config.Data.Station = ae.Station;

            var activityMachine = new ErrorHandlingActivityMachine(GetErrorMachineName(ae));

            activityMachine.Builder = ActivityMachineBuilderLoader.GetActivityMachineBuilder(config);

            return(activityMachine);
        }
        public void ConfigurationBuilder_TryInvokeMember_KnownMethodStrategy_IsReturnsBuilder()
        {
            var strategyMock = new Mock<IMethodStrategy>();
            var config = new DynamicConfiguration();
            strategyMock.Setup(s => s.IsMatch(It.IsAny<string>())).Returns(true);

            var strategyList = new List<IMethodStrategy> { strategyMock.Object };

            dynamic configurationBuilder = new ConfigurationBuilder(config, strategyList);
            dynamic returnedValue = configurationBuilder.SomeExpectedMethod();

            Assert.AreEqual(configurationBuilder, returnedValue);
        }
        public void Should_ReturnNonKeyValues_AndNotEmptyValues_ForKeysWithParams([ValueSource(nameof(SupportedLanguages))] string language, [ValueSource(nameof(KeysWithParams))] string key)
        {
            var configuration = new DynamicConfiguration
            {
                Language = language
            };
            var paramsArray    = new[] { "a", "b", "c" };
            var localizedValue = new LocalizationManager(configuration, Logger.Instance).GetLocalizedMessage(key, paramsArray);

            Assert.AreNotEqual(key, localizedValue, "Value should be defined in resource files");
            Assert.IsNotEmpty(localizedValue, "Value should not be empty");
            Assert.IsTrue(localizedValue.Contains(paramsArray[0]), "Value should contain at least first parameter");
        }
Esempio n. 38
0
        public static ActivityMachine ExtractRootMachine(DynamicConfiguration configuration)
        {
            ActivityMachine rootMachine = null;

            if (configuration.HasDataKey(Key.RootMachine))
            {
                rootMachine = configuration.Data.RootMachine as ActivityMachine;
            }
            else if (configuration.HasDataContextKey(Key.RootMachine))
            {
                rootMachine = configuration.Data.DataContext.RootMachine as ActivityMachine;
            }
            return(rootMachine);
        }
Esempio n. 39
0
 public bool Update(DynamicConfiguration config)
 {
     try
     {
         using (StreamWriter file = new StreamWriter(Filepath))
             using (JsonTextWriter writer = new JsonTextWriter(file))
                 JObject.FromObject(config).WriteTo(writer);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 40
0
        protected void InitializeModuleDynamicConfig()
        {
            const string dynamicConfigFileName = @".\Dyanmic.config";
            var          serviceNamespace      = this.GetType().Namespace;
            string       mergeScriptName       = @"DefaultPlugins.XpathMergeRelease.xml";

            #if DEBUG
            mergeScriptName = @"DefaultPlugins.XpathMergeDebug.xml";
            #endif
            var dynamicconfig     = new DynamicConfiguration();
            var executingAssembly = Assembly.GetExecutingAssembly();
            var pluginFolder      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginManager.DefaultDomainName);

            ModulePluginLoader.LoadDefaultModulePlugins(pluginFolder,
                                                        new SQLConfigProvider(executingAssembly));

            //Merge the profile database connection in order to query configuration from DB
            XmlMergeUtil.MergeConfiguration(serviceNamespace,
                                            mergeScriptName,
                                            executingAssembly,
                                            dynamicConfigFileName,
                                            _logger);

            var profile = _modulename.QueryProfile(AppTypeEnum.exe, _profileName, ProfileTypeEnum.config);
            File.Delete(dynamicConfigFileName);

            if (null == profile || string.IsNullOrEmpty(profile.XmlPayload))
            {
                //Switch back to original configuration if failed to query configuration from DB
                //If query the centralized configuration failed for any reason.
                var currentConfigPath = string.Format(@"{0}{1}.exe.config", AppDomain.CurrentDomain.BaseDirectory, _entryAssembly.GetName().Name);
                dynamicconfig.SwitchConfigSource(currentConfigPath);
                ModulePluginLoader.InitializeLogger(out _logger, this);
                Directory.Delete(pluginFolder, true);
                return;
            }

            //hook up configuration update notification when the updating occurs from DB, the loacal configuration will sync automatically. Then this call is
            //done the current configuration will sync the the configuration retrieved from the Db and automatically synchronized if there are updated from Db.
            ModulePluginLoader.LoadModulePlugin(_defaultPluginsDomainFolder,
                                                new SQLConfigProvider(_entryAssembly)
            {
                ProfileFileName     = _profileName,
                UpdateCheckInterval = 10 * 1000,
                TargetPath          = @".\"
            },
                                                this);
        }
        public void ListItemSetter_Execute_MultipleValidMethodName_CreatesListConfigPropertyWithMultipleItems()
        {
            var listItemSetter = new ListItemSetter();
            dynamic config = new DynamicConfiguration();

            listItemSetter.Execute("HasNamesListItem", config, "SomeValue1");
            listItemSetter.Execute("HasNamesListItem", config, "SomeValue2");
            listItemSetter.Execute("HasNamesListItem", config, "SomeValue3");

            Assert.IsTrue(config.Names.Count == 3);

            Assert.AreEqual(config.Names[0], "SomeValue1");

            Assert.AreEqual(config.Names[1], "SomeValue2");

            Assert.AreEqual(config.Names[2], "SomeValue3");
        }
Esempio n. 42
0
        public static DynamicConfiguration CreateTrayMoverConfig(ITrayDetector source, ITrayHandler destination, IInstrument instrument, object sourceLocker)
        {
            var transport     = instrument.FindStation("Transportation");
            var machineConfig = new DynamicConfiguration(BuilderTypes.TrayMovingMachineBuilder);

            machineConfig.Data.DestinationStation = destination;
            machineConfig.Data.SourceStation      = source;
            machineConfig.Data.Instrument         = instrument;
            machineConfig.Data.Transport          = transport as ITransport;
            machineConfig.Data.NumberOfRetries    = 0;
            machineConfig.Data.SourceLockOwner    = sourceLocker;

            machineConfig.Data.ProcessType = CodeProcess.MoveTray;
            machineConfig.Data.ProcessName = CodeProcess.MoveTray.ToString();

            return(machineConfig);
        }
Esempio n. 43
0
        public void CorrectlySerializesConfiguration()
        {
            var dynamicConfiguration = new DynamicConfiguration();

            dynamicConfiguration.SetConfigurationValue("KeyX", "Value X");
            dynamicConfiguration.SetConfigurationValue("KeyY", "Value Y");
            dynamicConfiguration.SetConfigurationValue("KeyZ.SomeAddition", "Value Z");

            using (var memoryStream = new MemoryStream())
            {
                dynamicConfiguration.SaveAsXml(memoryStream);

                var outputXml = memoryStream.GetUtf8String();

                Assert.AreEqual(ExpectedXml, outputXml);
            }
        }
        public static IActivityMachine CreateMachineForTrayMoving(DynamicConfiguration config)
        {
            var source      = config.Data.SourceStation as ITrayDetector;
            var destination = config.Data.DestinationStation as ITrayHandler;

            var activityMachine = new TrayMover(source.Name, destination.Name);

            activityMachine.Instrument      = config.Data.Instrument as IInstrument;
            activityMachine.NumberOfRetries = config.Data.NumberOfRetries;
            activityMachine.Destination     = destination;
            activityMachine.Source          = source;
            activityMachine.Transport       = config.Data.Transport as ITransport;
            activityMachine.SourceLockOwner = config.Data.SourceLockOwner;
            activityMachine.Configuration   = config;

            // No Builder needed for this machine

            return(activityMachine);
        }
        private void InitializeComponents(DynamicConfiguration config)
        {
            HaltOnFault   = true;
            Configuration = config;
            ThreadName    = ExtractThreadName(config);
            // On the Started event, machine assembly has already transpired but execution hasn't actually started.
            // Time to set any existing breakpoints on the pausable nodes.
            Started += ApplyPreexistingBreakpoints;

            var rootMachine = ExtractRootMachine(config.Data);

            if (DataContext != null && rootMachine != null)
            {
                DataContext.RootMachine = rootMachine;
            }

            // Give the dispatcher to the config so that any nested machine may use it.
            config.Data.Dispatcher = Dispatcher;
        }
Esempio n. 46
0
        public static DynamicConfiguration CreateTransportOperationConfig(TransportOperation operation, ITrayDetector station, ITransport transport, IInstrument instrument, object sourceLocker, ITransportDock destination = null)
        {
            var config = new DynamicConfiguration(BuilderTypes.TransportOperationMachineBuilder);

            config.Data.Instrument            = instrument;
            config.Data.Station               = station;
            config.Data.Transport             = transport;
            config.Data.TransportOperation    = operation;
            config.Data.SourceLockOwner       = sourceLocker;
            config.Data.MoveCancellationToken = new MoveCancellationToken();
            // This will be the time allotted to each transport operation machine.
            config.Data.ExpirationTimespan = new TimeSpan(0, 0, 1, 15);
            // The source as an obstruction is only relevant for CompletePickup from Stainer.
            if (destination != null)
            {
                config.Data.DestinationZLocation = destination.DockZ;
            }
            return(config);
        }
        //private int _pauseCount;

        /// <summary>
        /// Ctor for building a top-level machine that may own submachines.  This creates a new
        /// DataContext.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="config"></param>
        public CommandExecutingMachine(string name, DynamicConfiguration config)
            : base(ExtractNamePrefix(config.Data as IDictionary <string, object>) + name)
        {
            DataContext        = new ExpandoObject();
            DataContext.Device = config.Data.Device;
            //TODO: get rid of Station and only use Module
            DataContext.Station    = config.Data.Station;
            DataContext.Module     = config.Data.Module;
            DataContext.ErrorLevel = 0;
            DataContext.Variables  = new Dictionary <string, object>();
            if (config.HasDataKey(Key.Translator))
            {
                DataContext.Translator = config.Data.Translator;
            }
            if (config.HasDataKey(Key.Instrument))
            {
                DataContext.Instrument = config.Data.Instrument;
            }

            InitializeComponents(config);
        }
        public void ListItemSetter_Execute_ValidMethodName_CreatesListConfigProperty()
        {
            var listItemSetter = new ListItemSetter();
            dynamic config = new DynamicConfiguration();

            listItemSetter.Execute("HasNamesListItem", config, "SomeValue");

            Assert.IsTrue(config.Names.GetType().Name.StartsWith("List"));
        }
        public void DynamicConfiguration_DynamicProperty_WhenNotPreviouslyAssigned_ReturnsNull()
        {
            dynamic config = new DynamicConfiguration();

            Assert.IsNull(config.MyPropName);
        }