public void ProcessRequest(HttpContext context)
        {
            if (context.Request.InputStream.Length == 0)
            {
                return;
            }
            XmlSerializer xser = new XmlSerializer(typeof(RemoteConfigSectionCollection));
            RemoteConfigSectionCollection rcc = (RemoteConfigSectionCollection)xser.Deserialize(context.Request.InputStream);

            RemoteConfigSectionCollection ret = new RemoteConfigSectionCollection();
            bool exitAppConfig = false;

            foreach (RemoteConfigSectionParam param in rcc)
            {
                int configType;
                if (!string.IsNullOrEmpty(rcc.Application))
                {
                    int minor = GetLastVersion(param.SectionName, rcc.Application, param.MajorVersion, out configType, out exitAppConfig);
                    if (minor > param.MinorVersion)
                    {
                        string url = GetDownloadUrl(param.SectionName, rcc.Application, param.MajorVersion, minor, configType);
                        ret.AddSection(param.SectionName, param.MajorVersion, minor, url);
                        continue;
                    }
                }
                //如果指定了应用程序,且应用程序有配置文件,就不再处理默认配置文件
                if (exitAppConfig)
                {
                    continue;
                }
                int minor2 = GetLastVersion(param.SectionName, NoAppPath, param.MajorVersion, out configType, out exitAppConfig);
                if (minor2 > param.MinorVersion)
                {
                    string url = GetDownloadUrl(param.SectionName, NoAppPath, param.MajorVersion, minor2, configType);
                    ret.AddSection(param.SectionName, param.MajorVersion, minor2, url);
                }
            }

            context.Response.ContentType = "text/xml";
            xser.Serialize(context.Response.OutputStream, ret);
        }
        public void RefreshAllConfigs()
        {
            RemoteConfigSectionCollection lstParams = new RemoteConfigSectionCollection(config.ApplicationName);

            lock (configLocker)
            {
                foreach (ConfigEntry entry in configEntries.Values)
                {
                    if (entry.IsSet)
                    {
                        lstParams.AddSection(entry.Name, entry.MajorVersion, entry.MinorVersion);
                    }
                }
            }
            RefreshConfigs(lstParams);
        }
        /// <summary>
        /// 取得服务器上的配置版本
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="majorVersion">The major version.</param>
        /// <returns></returns>
        private RemoteConfigSectionParam GetServerVersion(string name, int majorVersion)
        {
            RemoteConfigSectionCollection lstParams = new RemoteConfigSectionCollection(config.ApplicationName, config.Environment);

            lstParams.AddSection(name, majorVersion, XmlSerializerSectionHandler.DefaultUninitMinorVersion);
            RemoteConfigSectionCollection newParams = GetServerVersions(lstParams);

            if (newParams.Count == 0)
            {
                return(null);
            }
            else
            {
                return(newParams[0]);
            }
        }
        private void TimerCallback(object sender, System.Timers.ElapsedEventArgs args)
        {
            RemoteConfigSectionCollection lstParams = new RemoteConfigSectionCollection(config.ApplicationName);

            //configLocker.AcquireReaderLock(-1);
            //using (configLocker.AcquireReaderLock())
            lock (configLocker)
            {
                foreach (ConfigEntry entry in configEntries.Values)
                {
                    if (entry.IsSet)
                    {
                        lstParams.AddSection(entry.Name, entry.MajorVersion, entry.MinorVersion);
                    }
                }

                //configLocker.ReleaseReaderLock();
            }
            if (lstParams.Count == 0)
            {
                return;
            }

            //发送本地版本信息到服务器获取更新信息
            lstParams = GetServerVersions(lstParams);
            if (lstParams.Count == 0)
            {
                return;
            }

            //如果有更新则下载新的配置文件
            foreach (RemoteConfigSectionParam param in lstParams.Sections)
            {
                ThreadPool.QueueUserWorkItem(
                    delegate(object obj)
                {
                    DownloadParam dp = (DownloadParam)obj;
                    Download(dp.Name, dp.Url, dp.LocalPath, dp.Checker);
                },
                    new DownloadParam(param.SectionName,
                                      param.DownloadUrl,
                                      GetPath(param.SectionName),
                                      CheckDownloadStream)
                    );
            }
        }
        public void RefreshConfig(string name, int majorVersion)
        {
            RemoteConfigSectionCollection lstParams = new RemoteConfigSectionCollection(config.ApplicationName);
            int orgMinorVersion = 0;

            lock (configLocker)
            {
                foreach (ConfigEntry entry in configEntries.Values)
                {
                    if (entry.Name == name)
                    {
                        if (entry.IsSet && entry.MajorVersion == majorVersion)
                        {
                            orgMinorVersion = entry.MinorVersion;
                            lstParams.AddSection(entry.Name, entry.MajorVersion, entry.MinorVersion);
                        }
                        break;
                    }
                }
            }
            RefreshConfigs(lstParams);
        }