コード例 #1
0
        public void AddSection(string sectionName, int major, int minor, string url)
        {
            RemoteConfigSectionParam param = new RemoteConfigSectionParam();

            param.SectionName  = sectionName;
            param.MajorVersion = major;
            param.MinorVersion = minor;
            param.DownloadUrl  = url;
            Sections.Add(param);
        }
コード例 #2
0
        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);
        }