private void InvalidConfigs(RemoteConfigSectionCollection lstParams) { if (lstParams.Count == 0) { return; } RemoteConfigSectionCollection newParams = GetServerVersions(lstParams); if (newParams.Count == 0) { return; } Dictionary <string, RemoteConfigSectionParam> tblOldParam = new Dictionary <string, RemoteConfigSectionParam>(lstParams.Count); foreach (RemoteConfigSectionParam item in lstParams) { tblOldParam.Add(item.SectionName, item); } foreach (RemoteConfigSectionParam param in newParams.Sections) { string localPath = GetPath(param.SectionName); if (!Download(param.SectionName, param.DownloadUrl, localPath, CheckDownloadStream)) { throw new System.Configuration.ConfigurationErrorsException("Unabled to download '" + param.DownloadUrl + "' to '" + localPath + "'"); } FileWatcher.Instance.ProcessFileChanged(localPath); Log(string.Format("Minor version of config '{0}({1})' has been updated manually from {2} to {3}", param.SectionName, param.MajorVersion, tblOldParam[param.SectionName].MinorVersion, param.MinorVersion)); } }
RemoteConfigSectionParam GetServerVersion(string name, int majorVersion) { RemoteConfigSectionCollection lstParams = new RemoteConfigSectionCollection(config.ApplicationName); lstParams.AddSection(name, majorVersion, XmlSerializerSectionHandler.DefaultUninitMinorVersion); lstParams = GetServerVersions(lstParams); if (lstParams.Count == 0) { return(null); } else { return(lstParams[0]); } }
public void InvalidAllConfigs() { 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); } } } InvalidConfigs(lstParams); }
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 InvalidConfig(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; } } } InvalidConfigs(lstParams); }
RemoteConfigSectionCollection GetServerVersions(RemoteConfigSectionCollection lstInputParams) { return(new RemoteConfigSectionCollection()); // send // <config machine=''application=''> // <section name='' majorVerion='' minorVersion='' /> // <section name='' majorVerion='' minorVersion='' /> // <section name='' majorVerion='' minorVersion='' /> // </config> // // receive // <config> // <section name='' majorVerion='' minorVersion='' downloadUrl='' /> // <section name='' majorVerion='' minorVersion='' downloadUrl='' /> // <section name='' majorVerion='' minorVersion='' downloadUrl='' /> // </config> try { MemoryStream ms = new MemoryStream(); XmlSerializer ser = new XmlSerializer(typeof(RemoteConfigSectionCollection)); ser.Serialize(ms, lstInputParams); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(config.RemoteConfigurationUrl); req.ContentType = "text/xml"; req.Method = "POST"; req.Timeout = config.Timeout; req.ReadWriteTimeout = config.ReadWriteTimeout; req.ContentLength = ms.Length; req.ServicePoint.Expect100Continue = false; req.ServicePoint.UseNagleAlgorithm = false; req.KeepAlive = false; using (Stream stream = req.GetRequestStream()) { byte[] buf = ms.ToArray(); stream.Write(buf, 0, buf.Length); //string str = System.Text.Encoding.Default.GetString(buf); stream.Close(); } RemoteConfigSectionCollection lstOutput; using (HttpWebResponse rsp = (HttpWebResponse)req.GetResponse()) { using (Stream stream = rsp.GetResponseStream()) { lstOutput = (RemoteConfigSectionCollection)ser.Deserialize(stream); stream.Close(); } rsp.Close(); } return(lstOutput); } catch (Exception ex) { HandleException(ex, "Unabled to GetServerVersions from '" + config.RemoteConfigurationUrl + "'", "RemoteConfigurationManager"); return(new RemoteConfigSectionCollection()); } }