Пример #1
0
        internal static void InsertOrReplaceFakesDataCollectorNode(XmlDocument runSettings, DataCollectorSettings settings)
        {
            // override current settings
            var navigator = runSettings.CreateNavigator();
            var nodes     = navigator.Select("/RunSettings/DataCollectionRunSettings/DataCollectors/DataCollector");

            foreach (XPathNavigator dataCollectorNavigator in nodes)
            {
                var uri = dataCollectorNavigator.GetAttribute("uri", string.Empty);
                // We assume that only one uri can exist in a given runsettings
                if (string.Equals(FakesMetadata.DataCollectorUriV1, uri, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(FakesMetadata.DataCollectorUriV2, uri, StringComparison.OrdinalIgnoreCase))
                {
                    dataCollectorNavigator.ReplaceSelf(settings.ToXml().CreateNavigator());
                    return;
                }
            }

            // insert new node
            XmlRunSettingsUtilities.InsertDataCollectorsNode(runSettings.CreateNavigator(), settings);
        }
Пример #2
0
        /// <summary>
        /// Inserts a data collector settings in the file
        /// </summary>
        /// <param name="runSettingDocument">runSettingDocument</param>
        /// <param name="settings">settings</param>
        public static void InsertDataCollectorsNode(IXPathNavigable runSettingDocument, DataCollectorSettings settings)
        {
            if (runSettingDocument == null)
            {
                throw new ArgumentNullException(nameof(runSettingDocument));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var navigator = runSettingDocument.CreateNavigator();

            MoveToDataCollectorsNode(ref navigator);

            var settingsXml       = settings.ToXml();
            var dataCollectorNode = settingsXml.CreateNavigator();

            dataCollectorNode.MoveToRoot();

            navigator.AppendChild(dataCollectorNode);
        }