public void ConstructModules(int streamType) { _configSection = _provideConfiguration.GetConfiguration <ModuleWiringConfigSection.ModuleWiringConfigSection>("moduleWiring" + streamType); _streamType = streamType; CreateModules(_configSection, streamType); foreach (var factory in _usedFactories) { factory.TriggerContainerRecomposition(); } CreateGraphAndWireUp(); Construct(streamType); CreateDependencies(); EventAggregator.Publish(new AllModulesCreatedEvent()); }
private void CreateModules(ModuleWiringConfigSection.ModuleWiringConfigSection configSection, int streamType) { foreach (ModuleConfig moduleConfig in configSection.Modules) { var module = GetModuleByName(moduleConfig.Name); // try to create new module if not available (at least one instance is exported by MEF) if (module == null || module.AdsPort != 0) { module = CreateModuleByType(moduleConfig.ModuleTypeId); if (module == null) { continue; } _logger.Debug("Created module " + moduleConfig.Name + " (ID=" + moduleConfig.ModuleTypeId + ")"); } // set parameters from App.config to module module.StreamType = streamType; module.ModuleTypeId = moduleConfig.ModuleTypeId; module.Name = moduleConfig.Name; int port = 0; Int32.TryParse(moduleConfig.Config.PlcPort, out port); module.AdsPort = port; module.PathRootController = moduleConfig.Config.PlcRootController; module.PlcAddress = moduleConfig.Config.PlcAddress; module.EnableStateLogging = bool.Parse(moduleConfig.Config.EnableStateLogging); module.EnableSubStateLogging = bool.Parse(moduleConfig.Config.EnableSubStateLogging); module.ModuleNbr = int.Parse(moduleConfig.Config.ModuleNbr); module.PlannedThroughput = int.Parse(moduleConfig.Config.PlannedThroughputPerHour); } }
private ModuleGraph CreateGraph(ModuleWiringConfigSection.ModuleWiringConfigSection configSection) { var graph = new ModuleGraph(); // create graph vertices foreach (ModuleConfig moduleConfig in configSection.Modules) { var module = GetModuleByName(moduleConfig.Name); if (module == null) { continue; } // create QuickGraph datastructure graph.AddVertex(module); } // create graph edges foreach (ModuleConfig moduleConfig in configSection.Modules) { var module = GetModuleByName(moduleConfig.Name); if (module == null) { continue; } foreach (ModuleReferenceConfig targetModuleConfig in moduleConfig.NextModules) { var targetModule = GetModuleByName(targetModuleConfig.Name); if (targetModule == null) { continue; } var edge = new ModuleGraphEdge( module.Name + "->" + targetModule.Name + ":" + targetModuleConfig.Port + targetModuleConfig.TargetPort, module, targetModule, targetModuleConfig.Port, targetModuleConfig.TargetPort); graph.AddEdge(edge); } } // enable forcing for one-way edges by default var modulesWithSingleEdge = from e in graph.Edges group e by e.Source into g where g.Count() == 1 select g.Key; foreach (var module in modulesWithSingleEdge) { var oneWayEdge = (from e in graph.Edges where e.Source == module select e).Single(); if (!IsCyclicEdge(graph, oneWayEdge)) { oneWayEdge.IsForcingEnabled = true; } } return(graph); }