/// <summary> /// Takes an <see cref="XDocument"/> representing the whole MapForce mapping model as input and returns a set /// of ConstantComponents. /// </summary> /// <param name="mappingFiles"></param> /// <returns></returns> private static IEnumerable <ConstantComponent> ImportConstantComponents(string[] mappingFiles) { foreach (var mappingFile in mappingFiles) { var mappingDocument = XDocument.Load(mappingFile); IEnumerable <XElement> constantComponentElements = from c in mappingDocument.Descendants("component") where (string)c.Attribute("name") == "constant" select c; foreach (XElement constantComponentElement in constantComponentElements) { var constantElement = constantComponentElement.XPathSelectElement("data/constant"); if (constantElement == null) { // TODO report error } else { var datapointElement = constantComponentElement.XPathSelectElement("targets/datapoint"); InputOutputKey outputKey = datapointElement != null?InputOutputKey.Output(mappingFile, (string)datapointElement.Attribute("key")) : InputOutputKey.None; yield return(new ConstantComponent((string)constantElement.Attribute("value"), outputKey)); } } } }
/// <summary> /// Takes an <see cref="XElement"/> representing the root entry as input and returns the root Entry object with all its children /// by recursively calling itself. /// </summary> /// <param name="entryElement"></param> /// <param name="mappingFile"></param> /// <returns></returns> private static Entry ImportEntry(XElement entryElement, string mappingFile) { InputOutputKey inputOutputKey; var inputKey = (string)entryElement.Attribute("inpkey"); if (string.IsNullOrEmpty(inputKey)) { var outputKey = (string)entryElement.Attribute("outkey"); inputOutputKey = string.IsNullOrEmpty(outputKey) ? InputOutputKey.None : InputOutputKey.Output(mappingFile, outputKey); } else { inputOutputKey = InputOutputKey.Input(mappingFile, inputKey); } var entryTypeStr = (string)entryElement.Attribute("type"); XsdObjectType xsdObjectType = XsdObjectType.Element; if (entryTypeStr == "attribute") { xsdObjectType = XsdObjectType.Attribute; } return(new Entry((string)entryElement.Attribute("name"), inputOutputKey, xsdObjectType, from childElement in entryElement.Elements("entry") select ImportEntry(childElement, mappingFile))); }