Example #1
0
        public static UpdateRequest GetUploadRequest()
        {
            try
            {
                UpdateRequest updateRequest = null;

                string        url     = string.Format("{0}/devops/getTheLastVersion?productType={1}", EnvironmentInfo.ServerUrl, (int)enumProductType.DevOps);
                DevOpsProduct product = HttpHelper.Get <DevOpsProduct>(url, 3000);
                if (product == null)
                {
                    LogHelper.CommLogger.Error("获取最新版本失败");
                    return(null);
                }
                if (CompareVersion(EnvironmentInfo.CurrentVersion, product.ProductVersion) >= 0)
                {
                    LogHelper.CommLogger.Error("已经是最新版,不执行升级");
                    return(null);
                }
                LogHelper.CommLogger.Info("下载安装包开始");
                //拼接下载url
                string downloadUrl = product.DownloadUrl;
                if (!downloadUrl.StartsWith("http"))
                {
                    if (downloadUrl.StartsWith("/"))
                    {
                        downloadUrl = EnvironmentInfo.ServerUrl + downloadUrl;
                    }
                    else
                    {
                        downloadUrl = EnvironmentInfo.ServerUrl + "/" + downloadUrl;
                    }
                }
                //解析文件名
                string fileName = downloadUrl.Substring(downloadUrl.LastIndexOf('/') + 1);
                string guid     = Guid.NewGuid().ToString();
                //下载路径
                string downloadDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "update\\Temp");
                if (!Directory.Exists(downloadDir))
                {
                    Directory.CreateDirectory(downloadDir);
                }
                string downloadFile = Path.Combine(downloadDir, fileName);
                Download(downloadUrl, downloadFile);

                updateRequest             = new UpdateRequest();
                updateRequest.Guid        = Guid.NewGuid().ToString();
                updateRequest.Version     = product.ProductVersion;
                updateRequest.Product     = enumProductType.DevOps.ToString();
                updateRequest.RootPath    = AppDomain.CurrentDomain.BaseDirectory;
                updateRequest.PackagePath = downloadFile;
                LogHelper.CommLogger.Info("下载安装包完成");
                return(updateRequest);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                LogHelper.CommLogger.Error(ex, "GetUploadRequest失败");
                return(null);
            }
        }
Example #2
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                DevOpsProduct product = DevOpsAPI.ReportVersion();
                if (product != null)
                {
                    viewModel.LastVersion = product.ProductVersion;

                    if (CheckUpdateHelper.CompareVersion(EnvironmentInfo.CurrentVersion, product.ProductVersion) < 0)
                    {
                        viewModel.canExecute = true;
                    }
                    else
                    {
                        viewModel.BtnContent = "当前已是最新版本";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }