private void UpdateConfiguration() { string exePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), APP_CONFIGFILE); Configuration conf = ConfigurationManager.OpenExeConfiguration(exePath); LiveUpgradeConfigurationSection newCS = new LiveUpgradeConfigurationSection(); LiveUpgradeConfigurationSection cs = conf.GetSection(UPGRADE_SECTION) as LiveUpgradeConfigurationSection; if (cs != null) { foreach (UpgradeElement element in cs.UpgradeProducts) { if (element.Product != project.Product) { newCS.UpgradeProducts.AddElement(element); } } } UpgradeElement ele = new UpgradeElement(); ele.Product = project.Product; ele.UpgradeDate = DateTime.Now.ToLocalTime(); ele.LocalVersion = project.Version; newCS.UpgradeProducts.AddElement(ele); conf.Sections.Remove(UPGRADE_SECTION); conf.Sections.Add(UPGRADE_SECTION, newCS); conf.Save(); }
public LiveUpgradeService([ServiceDependency] WorkItem workItem, [ServiceDependency] IPropertyService propertyService) { this.workItem = workItem; this.propertyService = propertyService; LiveUpgradeConfigurationSection cs = ConfigurationManager.GetSection(LIVEUPGRADE_SECTION) as LiveUpgradeConfigurationSection; UpgradeSetting setting = GetSetting(); if (cs != null && setting != null) { detecter = new UpgradeDetecter(this); if (setting.CheckInterval > 0) { detecter.CheckInterval = setting.CheckInterval; detecter.Start(); } } }
public UpgradeProject GetValidUpgradeProject() { UpgradeElements upgradeElements = null; LiveUpgradeConfigurationSection cs = ConfigurationManager.GetSection(LIVEUPGRADE_SECTION) as LiveUpgradeConfigurationSection; if (cs != null) { upgradeElements = cs.UpgradeProducts; } // 检查需要更新的升级项目 // 先检查相对于本地版本号大1的版本如果没有的话则直接获取其服务器端最新的更新版本 foreach (UpgradeElement element in upgradeElements) { Version ver = new Version(element.LocalVersion); string upgradeVersion = String.Format("{0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision + 1); UpgradeProject proj = UpgradeService.GetUpgradeProject(element.Product, upgradeVersion); if (proj == null) { proj = UpgradeService.GetUpgradeProject(element.Product); if (proj == null) { continue; } } Version localVer = new Version(element.LocalVersion); Version newVer = new Version(proj.Version); if (localVer < newVer || proj.UpgradePatchTime > element.UpgradeDate) { return(proj); } } return(null); }