Exemplo n.º 1
0
        public static void ValidateCustomSettings(GenericSettingsElement customSettings, SessionTypeEnum sessionType)
        {
            string settingXml = BusinessModelManager.GenericSettingXmlToString(customSettings.SettingXml);

            if (!string.IsNullOrEmpty(settingXml))
            {
                XmlDocument settingDoc = new XmlDocument();
                settingDoc.LoadXml(settingXml);

                string pathToXsd = string.Empty;
                switch (sessionType)
                {
                case SessionTypeEnum.WorkItemTracking:
                    pathToXsd = Constants.WITConfigXsdResourcePath;
                    break;

                case SessionTypeEnum.VersionControl:
                    pathToXsd = Constants.VCConfigXsdResourcePath;
                    break;

                default:
                    break;
                }

                if (!string.IsNullOrEmpty(pathToXsd))
                {
                    ConfigurationValidator configValidator = new ConfigurationValidator();
                    configValidator.ValidateXmlFragment(string.Empty, settingDoc.DocumentElement, pathToXsd);

                    var sessionConfigValidateResult = configValidator.ValidationResult;
                    if (!sessionConfigValidateResult.IsValid)
                    {
                        throw new ConfigurationSchemaViolationException(sessionConfigValidateResult);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void UpdateCustomSetting(object sessionTypeSpecificCustomSetting)
        {
            TryRegisterEventHandler();

            XmlSerializer serializer = null;

            if (sessionTypeSpecificCustomSetting is WIT.WITSessionCustomSetting)
            {
                serializer = new XmlSerializer(typeof(WIT.WITSessionCustomSetting));
            }
            else if (sessionTypeSpecificCustomSetting is VC.VCSessionCustomSetting)
            {
                serializer = new XmlSerializer(typeof(VC.VCSessionCustomSetting));
            }

            if (null != serializer)
            {
                using (var stream = new MemoryStream())
                {
                    serializer.Serialize(stream, sessionTypeSpecificCustomSetting);
                    stream.Seek(0, SeekOrigin.Begin);
                    string xmlContent;
                    using (StreamReader sw = new StreamReader(stream))
                    {
                        xmlContent = sw.ReadToEnd();
                    }

                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(xmlContent);

                    GenericSettingsElement updatedCustomSettings = new GenericSettingsElement();
                    updatedCustomSettings.SettingXml.Any = new XmlElement[] { xml.DocumentElement };
                    this.CustomSettings = updatedCustomSettings;
                }
            }
        }