/// <inheritdoc /> public void AddTyped <T>(string path) { foreach (ConfigurationReference confRef in ConfigurationReference.CreateReference <T>(path)) { _references.Add(confRef.Path, confRef.Type); } }
/// <inheritdoc /> public void Register(string path, Type type) { if (type == null) { ConfigurationReference config = ConfigurationReference.CreateUntyped(path); _references.Add(config.Path, config.Type); } else { foreach (ConfigurationReference confRef in ConfigurationReference.CreateReference(path, type)) { _references.Add(confRef.Path, confRef.Type); } } }
/// <summary> /// Execute the pipeline. /// </summary> public void Execute() { DateTime startTime = DateTime.Now; Log("{0} started at time {1}.", _engineName, startTime.ToString()); foreach (FlowItem item in _items.Values) { try { // Check reference input. foreach (ConfigurationInput input in item.Config.Inputs.Values) { if (ConfigurationReference.IsReference(input.Value)) { ConfigurationReference reference = new ConfigurationReference(); reference.Parse(input.Value); if (!_items.ContainsKey(reference.Module)) { throw new ConfigurationException( Helper.NeutralFormat("Module \"{0}\" not found, one of below expected - {1}", reference.Module, string.Join(",", _items.Keys.ToArray()))); } // Finds the reference model and assign its value to this object. item.SetValue(input.Name, _items[reference.Module], reference.Name); } } // Give the handler a chance to obtain parameters in runtime. item.Handler.PrepareRuntimeInputs(); // Use this collection to avoid changing the directory while enumerate it. Collection<string> runtimeOutputKeys = new Collection<string>(); item.Handler.RuntimeOutputs.Keys.ForEach(k => runtimeOutputKeys.Add(k)); // Fill runtime inputs value foreach (string referencName in runtimeOutputKeys) { ConfigurationReference reference = new ConfigurationReference(); reference.Parse(referencName); if (!_items.ContainsKey(reference.Module)) { throw new ConfigurationException( Helper.NeutralFormat("Module \"{0}\" not found, one of below expected - {1}", reference.Module, string.Join(",", _items.Keys.ToArray()))); } if (!_items[reference.Module].TypeInfo.Outputs.ContainsKey(reference.Name)) { throw new InvalidDataException(Helper.NeutralFormat( "Can't find output property [{0}] in module [{1}]", reference.Name, reference.Module)); } // Finds the reference model and assign its value to this object. item.Handler.RuntimeOutputs[referencName] = _items[reference.Module].TypeInfo.Outputs[reference.Name].GetValue( _items[reference.Module].Handler, null); } // Executes the single item. item.Handler.Execute(!item.Config.Skip, item.Config.KeepIntermediateData); } catch (Exception e) { string log = Helper.NeutralFormat("Exception thrown - {0}!{1}{3} failed when module \"{2}\" was running.{1}", Helper.BuildExceptionMessage(e), Environment.NewLine, item.Name, _engineName); Log(log); throw; } } foreach (FlowItem item in _items.Values) { if (item.Handler is IDisposable) { ((IDisposable)item.Handler).Dispose(); } if (!string.IsNullOrEmpty(item.Handler.WarningFilePath) && File.Exists(item.Handler.WarningFilePath)) { int warningCount = Helper.FileLines(item.Handler.WarningFilePath, true).Count(); if (warningCount > 0) { Log("There are [{0}] lines of warnings of handler \"{1}\", warning file path: {2}", warningCount, item.Handler.Name, item.Handler.WarningFilePath); } } } DateTime endTime = DateTime.Now; Log("{0} finished at time {1}. Totally elapsed time [{2}].", _engineName, endTime.ToString(), (endTime - startTime).ToString()); }
/// <summary> /// Initializes the inputs of this engine item. /// </summary> /// <param name="items">The previous engine items.</param> public void InitializeInputs(Dictionary<string, FlowItem> items) { foreach (ConfigurationInput input in Config.Inputs.Values) { ValidateInput(input); // Sets the value. if (input.IsCdataSection) { // CDATA is always constant value. ParseCdata(input.Name, input.Value); } else { if (!ConfigurationReference.IsReference(input.Value)) { // Sets the constant value. SetValue(input.Name, input.Value); } else { // Parse the reference and test whether it is assignable. ConfigurationReference reference = new ConfigurationReference(); reference.Parse(input.Value); if (!items.ContainsKey(reference.Module)) { throw new ConfigurationException( Helper.NeutralFormat("Module \"{0}\" not found, one of below expected - {1}", reference.Module, string.Join(",", items.Keys.ToArray()))); } items[reference.Module].ValidateOutput(reference.Name); // Tests assignability. Type inputType = TypeInfo.Inputs[input.Name].PropertyType; Type outputType = items[reference.Module].TypeInfo.Outputs[reference.Name].PropertyType; if (!inputType.IsAssignableFrom(outputType)) { throw new ConfigurationException( Helper.NeutralFormat( "Type mismatched between input \"{0}\"({1}) of module \"{2}\" and output \"{3}\"({4}) of module \"{5}\"", input.Name, inputType.Name, Name, reference.Name, outputType.Name, reference.Module)); } } } } }
/// <summary> /// Parses the included file. /// </summary> /// <param name="resolver">The resolver to resolve the include file.</param> /// <returns>The Dictionary of ConfigurationModule.</returns> public Dictionary<string, ConfigurationModule> ParsesInclude(Configuration.ConfigurationResolver resolver) { Configuration config = new Configuration(); config.ConfigurationResolve += resolver; config.Load(Source); Dictionary<string, ConfigurationModule> modules = config.GetAllModules(); // Overwrite the inputs in the included file according to the inputs. foreach (ConfigurationInput item in Inputs.Values) { if (!ConfigurationReference.IsReference(item.Name)) { throw new ConfigurationException( Helper.NeutralFormat("Input \"{0}\" in include element isn't reference", item.Name)); } ConfigurationReference reference = new ConfigurationReference(); reference.Parse(item.Name); if (!modules.ContainsKey(reference.Module)) { throw new ConfigurationException( Helper.NeutralFormat( "No such module name \"{0}\" found in include file, one of below expected - {1}", reference.Module, string.Join(",", modules.Keys.ToArray()))); } if (reference.Name == ConfigurationModule.SkipAttribute) { // Overwrite the skip attribute. modules[reference.Module].Skip = bool.Parse(item.Value); } else if (reference.Name == ConfigurationModule.KeepIntermediateDataAttribute) { // Overwrite the keep intermediate data attribute. modules[reference.Module].KeepIntermediateData = bool.Parse(item.Value); } else { if (modules[reference.Module].Inputs.ContainsKey(reference.Name)) { // Overwrite the exist input. modules[reference.Module].Inputs[reference.Name].Value = item.Value; } else { // Create a new input. ConfigurationInput input = new ConfigurationInput { Name = reference.Name, Value = item.Value }; modules[reference.Module].Inputs.Add(input.Name, input); } modules[reference.Module].Inputs[reference.Name].IsCdataSection = item.IsCdataSection; } } return modules; }
/// <inheritdoc /> public void AddUntyped(string path) { ConfigurationReference config = ConfigurationReference.CreateUntyped(path); _references.Add(config.Path, config.Type); }
/// <summary> /// Parse ZipItem node. /// </summary> /// <param name="node">Xml document.</param> /// <param name="nsmgr">Namespace manager.</param> public void Parse(XmlNode node, XmlNamespaceManager nsmgr) { Debug.Assert(node != null, "Dom should not be null"); Debug.Assert(nsmgr != null, "Namespace manager should not be null"); string fullName = node.Attributes["name"].Value; Debug.Assert(ConfigurationReference.IsReference(fullName), "Name should be referance in the zip items."); Reference = new ConfigurationReference(); Reference.Parse(fullName); Type = (ZipItemType)Enum.Parse(typeof(ZipItemType), node.Attributes["type"].Value, true); IsReused = bool.Parse(node.Attributes["reused"].Value); Debug.Assert(!(Type == ZipItemType.DirectoryWithMD5 && !IsReused) && !(Type == ZipItemType.FileListDirectoryWithMD5 && !IsReused)); if (node.Attributes["fileExtension"] != null) { FileExtension = node.Attributes["fileExtension"].Value; } Debug.Assert( (Type == ZipItemType.Directory && string.IsNullOrEmpty(FileExtension)) || (Type == ZipItemType.FileListDirectory && string.IsNullOrEmpty(FileExtension)) || (Type == ZipItemType.DirectoryWithMD5 && !string.IsNullOrEmpty(FileExtension)) || (Type == ZipItemType.FileListDirectoryWithMD5 && !string.IsNullOrEmpty(FileExtension)) || (Type == ZipItemType.File && !string.IsNullOrEmpty(FileExtension)) || (Type == ZipItemType.Path && !string.IsNullOrEmpty(FileExtension))); if (node.Attributes["source"] != null) { Source = node.Attributes["source"].Value; } }
/// <summary> /// Initializes a new instance of the <see cref="TrainModelZipItem"/> class. /// </summary> /// <param name="moduleName">Module name.</param> /// <param name="parameterName">Parameter name.</param> public TrainModelZipItem(string moduleName, string parameterName) { Type = ZipItemType.None; Reference = new ConfigurationReference(moduleName, parameterName); }
/// <summary> /// Initializes a new instance of the <see cref="TrainModelZipItem"/> class. /// </summary> public TrainModelZipItem() { Type = ZipItemType.None; Reference = new ConfigurationReference(); }