protected override object OnCreate(string sectionName, Type type, out int major, out int minor) { major = XmlSerializerSectionHandler.GetConfigurationClassMajorVersion(type); minor = XmlSerializerSectionHandler.DefaultUninitMinorVersion; string configPath = GetConfigSectionFileName(sectionName); if (configPath.Length == 0) { return(null); } object retVal; try { XmlDocument doc = new XmlDocument(); doc.Load(configPath); retVal = XmlSerializerSectionHandler.GetConfigInstance(doc.DocumentElement, type); XmlSerializerSectionHandler.GetConfigVersion(doc.DocumentElement, out major, out minor); } catch (Exception ex) { HandleException(ex, "Error when create local configuration: sectionName=" + sectionName + ",type=" + type.Name + ", create entry config instead", sectionName); //if exception here, return default configuration class and then setup watch retVal = Activator.CreateInstance(type); } XmlSerializerSectionHandler.SetupWatcher(configPath, retVal); return(retVal); }
protected override object OnCreate(string sectionName, Type type, out int major, out int minor) { string fileName = GetFileName(sectionName); string path = GetPath(sectionName); object obj = CreateLocalObject(type, path, out major, out minor); if (obj != null) { return(obj); } //Get Remote Config version major = XmlSerializerSectionHandler.GetConfigurationClassMajorVersion(type); minor = XmlSerializerSectionHandler.DefaultUninitMinorVersion; try { RemoteConfigSectionParam param = GetServerVersion(sectionName, major); if (param != null) { //download from remote! if (Download(param.SectionName, param.DownloadUrl, path, CheckDownloadStream)) { obj = CreateLocalObject(type, path, out major, out minor); } } } catch (Exception ex) { HandleException(ex, "Error when download configuration '" + sectionName + "' from remote server for the firet time", sectionName); } //if object is null use default object instead if (obj == null) { Log("Cannot get section '" + sectionName + "' with type '" + type.Name + "' from RemoteConfiguration, create empty instance instead"); obj = Activator.CreateInstance(type); XmlSerializerSectionHandler.SetupWatcher(path, obj); XmlSerializerSectionHandler.RegisterReloadNotification(path, OnConfigFileChanged); } return(obj); }