/// <summary> /// Initializes a new instance of the FlowEngine class. /// </summary> /// <param name="configItems"> The given all configuration items. .</param> /// <param name="logFile"> The given file name to store the log. .</param> /// <param name="statusRecorder"> The status recorder for the engine. .</param> public FlowEngine(Dictionary<string, ConfigurationModule> configItems, string logFile, StatusRecorder statusRecorder) { if (configItems == null) { throw new ArgumentNullException("configItems"); } if (string.IsNullOrEmpty(logFile)) { throw new ArgumentNullException("logFile"); } // Initializes the loggers. Helper.TestWritable(logFile); _detailLogger = new TextLogger(logFile, Encoding.Unicode); _compactLogger = new ConsoleLogger(); if (statusRecorder != null) { SkipFinishedModules(statusRecorder, configItems); } // Creates the object to place the items. _items = new Dictionary<string, FlowItem>(); try { // Setups the pipeline. foreach (ConfigurationModule config in configItems.Values) { // Creates the item. FlowItem item = new FlowItem(config); item.Handler.StepStatusRecorder = statusRecorder; // Initializes the inputs. item.InitializeInputs(_items); // Updates the implicit inputs. item.UpdateImplictInputs(_items); // Initializes the loggers. item.InitializeLogger(_detailLogger, _compactLogger); // Adds the item into the pipeline. _items.Add(item.Name, item); } } catch (ConfigurationException e) { Log("Failed to setup the pipeline because of exception - {0}{1}.", Environment.NewLine, Helper.BuildExceptionMessage(e)); throw; } Log("All configuration loaded and pipeline is ready."); _detailLogger.LogLine("The configuration file can be re-written as:"); _detailLogger.LogLine("{0}{1}", ToString(), Environment.NewLine); }
/// <summary> /// Sets the value to the given instance from another instance. /// </summary> /// <param name="inputName">The property's name of the given instance will be set the value to.</param> /// <param name="item">The instance which will be get the value from.</param> /// <param name="outputName">The property's name of the given instatnce will be get the value from.</param> public void SetValue(string inputName, FlowItem item, string outputName) { if (string.IsNullOrEmpty(inputName)) { throw new ArgumentNullException("inputName"); } if (item == null) { throw new ArgumentNullException("item"); } if (string.IsNullOrEmpty(outputName)) { throw new ArgumentNullException("outputName"); } if (!TypeInfo.Inputs.ContainsKey(inputName)) { throw new ArgumentException(Helper.NeutralFormat("Input property \"{0}\" not found in model \"{1}\"", inputName, Name)); } if (!item.TypeInfo.Outputs.ContainsKey(outputName)) { throw new ArgumentException(Helper.NeutralFormat("Input property \"{0}\" not found in model \"{1}\"", outputName, item.Name)); } TypeInfo.Inputs[inputName].SetValue(Handler, item.TypeInfo.Outputs[outputName].GetValue(item.Handler, null), null); }