Exemple #1
0
        protected RemoteConfigurationManager()
            : base()
        {
            string configFile = GetRemoteConfigFile();

            try
            {
                config =
                    XmlSerializerSectionHandler.CreateAndSetupWatcher <RemoteConfigurationManagerConfiguration>(configFile);

                if (config.CheckRemoteConfig)
                {
                    System.Timers.Timer timer = new System.Timers.Timer(config.TimerInterval);
                    timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerCallback);
                    timer.Start();
                }
            }
            catch (Exception ex)
            {
                HandleException(ex,
                                "Unabled to load RemoteConfigurationManager configuration file, Please set '" + RemoteConfigFileAppSettingKey + "' in appSettings",
                                "RemoteConfigurationManager");
                throw ex;
            }
        }
Exemple #2
0
 public static T GetSection <T>(string name, string path, out bool fromRemote)
 {
     if (System.IO.File.Exists(path))
     {
         fromRemote = false;
         return(XmlSerializerSectionHandler.CreateAndSetupWatcher <T>(LocalConfigurationManager.MapConfigPath(path)));
     }
     else
     {
         fromRemote = true;
         return(RemoteConfigurationManager.Instance.GetSection <T>(name));
     }
 }
Exemple #3
0
        object CreateLocalObject(Type type, string path, out int major, out int minor)
        {
            try
            {
                if (File.Exists(path))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(path);
                    object obj = XmlSerializerSectionHandler.CreateAndSetupWatcher(doc.DocumentElement,
                                                                                   path, type, OnConfigFileChanged);

                    XmlSerializerSectionHandler.GetConfigVersion(doc.DocumentElement, out major, out minor);
                    return(obj);
                }

                //相对目录 自动同步xml文件
                string source   = "SourceV2";
                string fileName = Path.GetFileName(path);
                string mapPath  = LocalConfigurationManager.MapConfigPath("");
                if (mapPath.IndexOf(source) > 0)
                {
                    var sourceDir      = mapPath.Substring(0, mapPath.IndexOf(source) + source.Length);
                    var sourceFilePath = Path.Combine(sourceDir, "MB.configs//" + fileName);
                    if (File.Exists(sourceFilePath))
                    {
                        File.Copy(sourceFilePath, path, true);
                        if (File.Exists(path))
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.Load(path);
                            object obj = XmlSerializerSectionHandler.CreateAndSetupWatcher(doc.DocumentElement,
                                                                                           path, type, OnConfigFileChanged);

                            XmlSerializerSectionHandler.GetConfigVersion(doc.DocumentElement, out major, out minor);
                            return(obj);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, "RemoteConfigurationManager.CreateLocalObject,type=" + type.Name + ",path=" + path, type.Name);
            }
            major = XmlSerializerSectionHandler.GetConfigurationClassMajorVersion(type);
            minor = XmlSerializerSectionHandler.DefaultUninitMinorVersion;
            return(null);
        }