/// <summary> /// 获取指定软件项目的最新版本 /// </summary> /// <param name="product">项目名称</param> /// <returns>返回更新项目配置情况</returns> public UpgradeProject GetUpgradeProject(string product) { lock (SyncObj) { IList <UpgradeProject> projects = db.Load <UpgradeProject>(delegate(UpgradeProject project) { return(product == project.Product); }); if (projects.Count > 0) { UpgradeProject project = projects[0]; foreach (UpgradeProject proj in projects) { Version ver1 = new Version(project.Version); Version ver2 = new Version(proj.Version); if (ver1 < ver2 || project.UpgradePatchTime < proj.UpgradePatchTime) { project = proj; } } return(project); } else { return(null); } } }
/// <summary> /// 创建一个软件更新项目 /// </summary> /// <param name="project">软件更新项目配置信息</param> public void CreateUpgradeProject(UpgradeProject project) { db.Store(project); if (UpgradeProjectCreated != null) { UpgradeProjectCreated(this, new EventArgs <UpgradeProject>(project)); } }
/// <summary> /// 删除一个软件更新项目 /// </summary> /// <param name="product">项目名称</param> /// <param name="version">软件版本</param> public void DeleteUpgradeProject(string product, string version) { UpgradeProject project = GetUpgradeProject(product, version); if (project != null) { db.Delete(project); } }
public UpgradeProcess(UpgradeProject upgradeProject, string upgradeUrl) { this.upgradeProject = upgradeProject; this.upgradeUrl = upgradeUrl; this.upgradeTempPath = FileUtility.ConvertToFullPath(@"..\Upgrade\") + upgradeProject.Product + @"\" + upgradeProject.Version + @"\"; if (!Directory.Exists(upgradeTempPath)) Directory.CreateDirectory(upgradeTempPath); downloadItems.Clear(); foreach (UpgradeGroup group in upgradeProject.Groups) downloadItems.AddRange(group.Items); InitializeComponent(); }
/// <summary> /// 获取指定版本的升级项目的升级URL /// </summary> /// <param name="product">项目名称</param> /// <param name="version">版本号</param> /// <returns>返回指定版本升级项目的升级URL,如果服务器端不存在其路径返回空</returns> public string GetUpgradeUrl(string product, string version) { UpgradeProject project = GetUpgradeProject(product, version); if (project != null) { IISManager iisManager = new IISManager(project.UpgradeServer); iisManager.Connect(); string virtualPath = UPGRADE_PATH + product + "/" + version; return(GetUpgradeAbsoluteUrl(virtualPath)); } else { return(String.Empty); } }
public LaunchProgress(string upgradePath) : this() { this.upgradePath = upgradePath; string configfile = Path.Combine(upgradePath, UPGRADE_CONFIGFILE); if (!File.Exists(configfile)) throw new Exception(String.Format("���������������ļ� {0}��", configfile)); // ������־��� XmlConfigurator.Configure(new FileInfo(UPGRADE_LOGCONFIGFILE)); logger = LogManager.GetLogger(typeof(LaunchProgress)); // �����л����������ļ� FileStream fs = new FileStream(configfile, FileMode.Open); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); Serializer serializer = new Serializer(); project = serializer.Deserialize<UpgradeProject>(buffer); }
/// <summary> /// 创建更新服务所用的虚拟目录 /// </summary> /// <param name="server">服务器名称</param> /// <param name="proj">更新项目</param> /// <returns>如果创建成功则返回true,否则为false</returns> public string CreateVirtualDirectory(string server, UpgradeProject proj) { Guard.ArgumentNotNull(proj, "Upgrade project"); string virtualPath = String.Empty; //IISManager iisManager = new IISManager(server); try { //iisManager.Connect(); string physicalPath = HttpContext.Current.Server.MapPath(UPGRADE_PATH + proj.Product + "/" + proj.Version); virtualPath = UPGRADE_PATH + proj.Product + "/" + proj.Version; logger.Debug("创建升级虚拟目录: " + virtualPath + ", 物理路径为: " + physicalPath); //VirtualDirectory vd = new VirtualDirectory(virtualPath, physicalPath); //vd.AccessExecute = true; //vd.AccessWrite = true; IISUtility.CreateVDir("localhost", virtualPath, physicalPath, false, true, true, true, true, true, 1, server); //iisManager.CreateVirtualDirectory(vd); } catch(Exception ex) { logger.Debug("创建升级虚拟目录: " + virtualPath + " 失败, " + ex.Message); return String.Empty; } return GetUpgradeAbsoluteUrl(virtualPath); }
/// <summary> /// 创建更新服务所用的虚拟目录 /// </summary> /// <param name="server">服务器名称</param> /// <param name="proj">更新项目</param> /// <returns>如果创建成功则返回true,否则为false</returns> public string CreateVirtualDirectory(string server, UpgradeProject proj) { Guard.ArgumentNotNull(proj, "Upgrade project"); string virtualPath = String.Empty; //IISManager iisManager = new IISManager(server); try { //iisManager.Connect(); string physicalPath = HttpContext.Current.Server.MapPath(UPGRADE_PATH + proj.Product + "/" + proj.Version); virtualPath = UPGRADE_PATH + proj.Product + "/" + proj.Version; logger.Debug("创建升级虚拟目录: " + virtualPath + ", 物理路径为: " + physicalPath); //VirtualDirectory vd = new VirtualDirectory(virtualPath, physicalPath); //vd.AccessExecute = true; //vd.AccessWrite = true; IISUtility.CreateVDir("localhost", virtualPath, physicalPath, false, true, true, true, true, true, 1, server); //iisManager.CreateVirtualDirectory(vd); } catch (Exception ex) { logger.Debug("创建升级虚拟目录: " + virtualPath + " 失败, " + ex.Message); return(String.Empty); } return(GetUpgradeAbsoluteUrl(virtualPath)); }
public UpgradeProject WrapUpgradeProject() { UpgradeProject proj = new UpgradeProject(); proj.StartUpApp = txtStartUpApp.Text.Trim(); proj.UpgradeServer = txtUpgradeUrl.Text.Trim(); proj.Product = txtProduct.Text.Trim(); proj.Version = txtVersion.Text.Trim(); proj.Description = txtDescription.Text; foreach (ListViewItem item in lvGroups.Items) { UpgradeGroup group = item.Tag as UpgradeGroup; if (group != null) proj.Groups.Add(group); } return proj; }
/// <summary> /// 保存更新配置文件 /// </summary> /// <param name="project">更新项目</param> private void SerializeUpgrade(UpgradeProject project) { string upgradeConfigfile = FileUtility.ConvertToFullPath(@"..\Upgrade\") + project.Product + @"\" + project.Version + @"\Upgrade.dat"; Serializer serializer = new Serializer(); try { byte[] buffer = serializer.Serialize<UpgradeProject>(project); FileStream fs = new FileStream(upgradeConfigfile, FileMode.Create); fs.Write(buffer, 0, buffer.Length); fs.Close(); } catch { } }
/// <summary> /// 重启程序 /// </summary> /// <param name="project"></param> private void ReStartApplication(UpgradeProject project) { string upgradeLaunch = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), UPGRADELAUNCH_FILE); if (File.Exists(upgradeLaunch)) { string upgradePath = FileUtility.ConvertToFullPath(@"..\Upgrade\") + project.Product + @"\" + project.Version; Process.Start(upgradeLaunch, upgradePath); Environment.Exit(0); } }
/// <summary> /// 系统升级提示 /// </summary> /// <param name="project"></param> public void UpgradeNotify(UpgradeProject project) { string upgradeUrl = UpgradeService.GetUpgradeUrl(project.Product, project.Version); if (XtraMessageBox.Show(String.Format("服务器发布了 \'{0}\" 的新版本 {1},您要立即升级到新版本吗?", project.Product, project.Version), "升级提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { UpgradeProcess up = new UpgradeProcess(project, upgradeUrl); if (up.ShowDialog() == DialogResult.OK) { SerializeUpgrade(project); ReStartApplication(project); } } }
/// <summary> /// 创建一个软件更新项目 /// </summary> /// <param name="project">软件更新项目配置信息</param> public void CreateUpgradeProject(UpgradeProject project) { db.Store(project); if (UpgradeProjectCreated != null) UpgradeProjectCreated(this, new EventArgs<UpgradeProject>(project)); }