// Load in the settings from file private static void GetSettings() { _configAggregatorItems = new List <ConfigAggregatorItem>(); XDocument doc; // Load the options if (string.IsNullOrEmpty(SettingsOverride)) { string xmlFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), "AggregatorItems.xml"); doc = XDocument.Load(xmlFileName); } else { doc = XDocument.Parse(SettingsOverride); } // Save off the TFS server name _tfsUri = doc.Element("AggregatorItems").Attribute("tfsServerUrl").Value; //Save off the Logging level _loggingVerbosity = doc.Element("AggregatorItems").LoadEnumAttribute("loggingVerbosity", MiscHelpers.LoggingLevel.None); // Get all the AggregatorItems loaded in foreach (XElement xmlAggItem in doc.Element("AggregatorItems").Elements()) { // Setup the actual item ConfigAggregatorItem aggItem = new ConfigAggregatorItem(); aggItem.Operation = xmlAggItem.LoadEnumAttribute("operation", OperationEnum.Sum); aggItem.LinkType = xmlAggItem.LoadEnumAttribute("linkType", ConfigLinkTypeEnum.Self); aggItem.OperationType = xmlAggItem.LoadEnumAttribute("operationType", OperationTypeEnum.Numeric); aggItem.LinkLevel = xmlAggItem.LoadAttribute("linkLevel", 1); aggItem.Name = xmlAggItem.LoadAttribute("name", "Name not set"); aggItem.WorkItemType = xmlAggItem.Attribute("workItemType").Value; aggItem.TargetWorkItemType = xmlAggItem.LoadAttribute("targetWorkItemType", ""); // Iterate through all the sub items (Mappings, source and target items.)) foreach (XElement xmlConfigItem in xmlAggItem.Elements()) { // If this is a target item then add it as such if (xmlConfigItem.Name == "TargetField") { aggItem.TargetField = new ConfigItemType { Name = xmlConfigItem.Attribute("name").Value }; } // If this is a source item then add it as such if (xmlConfigItem.Name == "SourceField") { aggItem.SourceFields.Add(new ConfigItemType { Name = xmlConfigItem.Attribute("name").Value }); } // If this is an outputFormat item then add it as such if (xmlConfigItem.Name == "OutputFormat") { aggItem.OutputFormat = xmlConfigItem.Attribute("formatString").Value; } // If this is conditions (for the target) then read them in. if (xmlConfigItem.Name == "Conditions") { // Iterate all the conditions we have. foreach (XElement xmlCondition in xmlConfigItem.Elements()) { Condition condition = new Condition { LeftFieldName = xmlCondition.LoadAttribute("leftField", ""), LeftValue = xmlCondition.LoadAttribute <string>("leftValue", null), CompOperator = xmlCondition.LoadEnumAttribute("operator", ComparisionOperator.EqualTo), RightValue = xmlCondition.LoadAttribute <string>("rightValue", null), RightFieldName = xmlCondition.LoadAttribute <string>("rightField", null) }; aggItem.Conditions.Add(condition); } } // If this is the mappings then read them in if (xmlConfigItem.Name == "Mappings") { // Iterate all the mappings we have. foreach (XElement xmlMappingItem in xmlConfigItem.Elements()) { Mapping mapping = new Mapping(); // Read in the target and source values (we set the target field // to this value if all of the source fields are in the list of source values) mapping.TargetValue = xmlMappingItem.Attribute("targetValue").Value; // load in the inclusivity of the mapping (default to "And") mapping.Inclusive = xmlMappingItem.LoadAttribute("inclusive", "And") == "And"; foreach (XElement xmlSourceValue in xmlMappingItem.Elements()) { mapping.SourceValues.Add(xmlSourceValue.Value); } aggItem.Mappings.Add(mapping); } } } // add this one to the list _configAggregatorItems.Add(aggItem); } // Indicate that we don't need to load the settings again. _settingsRetrieved = true; }
// Load in the settings from file private static void GetSettings() { _configAggregatorItems = new List<ConfigAggregatorItem>(); // Load the options string xmlFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), "AggregatorItems.xml"); XDocument doc = XDocument.Load(xmlFileName); // Save off the TFS server name _tfsUri = doc.Element("AggregatorItems").Attribute("tfsServerUrl").Value; //Save off the Logging level _loggingVerbosity = doc.Element("AggregatorItems").LoadEnumAttribute("loggingVerbosity", MiscHelpers.LoggingLevel.None); // Get all the AggregatorItems loaded in foreach (XElement xmlAggItem in doc.Element("AggregatorItems").Elements()) { // Setup the actual item ConfigAggregatorItem aggItem = new ConfigAggregatorItem(); aggItem.Operation = xmlAggItem.LoadEnumAttribute("operation", OperationEnum.Sum); aggItem.LinkType = xmlAggItem.LoadEnumAttribute("linkType", ConfigLinkTypeEnum.Self); aggItem.OperationType = xmlAggItem.LoadEnumAttribute("operationType", OperationTypeEnum.Numeric); aggItem.LinkLevel = xmlAggItem.LoadAttribute("linkLevel", 1); aggItem.Name = xmlAggItem.LoadAttribute("name", "Name not set"); aggItem.WorkItemType = xmlAggItem.Attribute("workItemType").Value; // Iterate through all the sub items (Mappings, source and target items.)) foreach (XElement xmlConfigItem in xmlAggItem.Elements()) { // If this is a target item then add it as such if (xmlConfigItem.Name == "TargetItem") { aggItem.TargetItem = new ConfigItemType { Name = xmlConfigItem.Attribute("name").Value }; } // If this is a source item then add it as such if (xmlConfigItem.Name == "SourceItem") { aggItem.SourceItems.Add(new ConfigItemType { Name = xmlConfigItem.Attribute("name").Value }); } // If this is conditions (for the target) then read them in. if (xmlConfigItem.Name == "Conditions") { // Iterate all the conditions we have. foreach (XElement xmlCondition in xmlConfigItem.Elements()) { Condition condition = new Condition(); condition.LeftFieldName = xmlCondition.LoadAttribute("leftField", ""); condition.CompOperator = xmlCondition.LoadEnumAttribute("operator", ComparisionOperator.EqualTo); condition.RightValue = xmlCondition.LoadAttribute<string>("rightValue", null); condition.RightFieldName = xmlCondition.LoadAttribute<string>("rightField", null); aggItem.Conditions.Add(condition); } } // If this is the mappings then read them in if (xmlConfigItem.Name == "Mappings") { // Iterate all the mappings we have. foreach (XElement xmlMappingItem in xmlConfigItem.Elements()) { Mapping mapping = new Mapping(); // Read in the target and source values (we set the target field // to this value if all of the source fields are in the list of source values) mapping.TargetValue = xmlMappingItem.Attribute("targetValue").Value; // load in the inclusivity of the mapping (default to "And") mapping.Inclusive = xmlMappingItem.LoadAttribute("inclusive", "And") == "And"; foreach (XElement xmlSourceValue in xmlMappingItem.Elements()) { mapping.SourceValues.Add(xmlSourceValue.Value); } aggItem.Mappings.Add(mapping); } } } // add this one to the list _configAggregatorItems.Add(aggItem); } // Indicate that we don't need to load the settings again. _settingsRetrieved = true; }