Ejemplo n.º 1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                var projInfo = ThreadHelper.JoinableTaskFactory.Run(GetSelectedProjInfoAsync);
                if (projInfo == null)
                {
                    throw new Exception("您还未选中项目");
                }

                if (projInfo.Kind != "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}")
                {
                    throw new Exception("当前插件仅支持C#程序");
                }

                var projModel = projInfo.AnalysisProject();
                if (projModel == null)
                {
                    throw new Exception("项目信息解析失败");
                }

                OptionPageGrid settingInfo = PublishService.GetSettingPage();
                if (string.IsNullOrWhiteSpace(settingInfo?.IpAdress))
                {
                    throw new Exception("请先完善设置信息");
                }

                // 尝试连接服务器
                //var isConnected = PublishService.CheckConnection();
                //if (!isConnected)
                //{
                //    throw new Exception("尝试连接服务器失败");
                //}

                //var publishForm = new PublishForm();
                //publishForm.Show();
                //publishForm.Ini(projModel);

                var form   = new DeployForm();
                var iniRes = form.Ini(projModel);
                if (iniRes.IsSucceed)
                {
                    form.Show();
                }
                else
                {
                    MessageBox.Show(iniRes.Message);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Ejemplo n.º 2
0
        private void bwUploadZip_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            try
            {
                var    now     = DateTime.Now;
                string pathTmp = _projModel.LibDebugPath;
                if (_projModel.ProjType == "Library")
                {
                    pathTmp = new DirectoryInfo(pathTmp).Parent?.FullName ?? pathTmp;
                }
                string zipFullPath = Path.Combine(pathTmp, _projModel.LibName + ".zip");

                if (bwUploadZip.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                bwUploadZip.ReportProgress(50, "压缩文件中...");
                ZipHelper.BatchZip(_projModel.LastChooseInfo.LastChoosePublishFiles, zipFullPath, _projModel.LastChooseInfo.LastChoosePublishDir, (progressValue) =>
                {
                    bwUploadZip.ReportProgress(50 + (int)(progressValue * 0.4), "压缩文件中...");
                    if (bwUploadZip.CancellationPending)
                    {
                        e.Cancel = true;
                        return(true);
                    }
                    return(false);
                });

                NameValueCollection dic = new NameValueCollection();
                dic.Add("Type", _projModel.ProjType == "Library" ? "iis" : "exe");
                dic.Add("AppId", e.Argument.ToString());

                if (bwUploadZip.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                bwUploadZip.ReportProgress(90, "文件上传中...");

                string url          = $"{PublishService.GetSettingPage().GetApiUrl()}/UploadZip";
                string uploadResStr = HttpHelper.HttpPostData(url, 30000, _projModel.LibName + ".zip", zipFullPath, dic);
                var    uploadRes    = uploadResStr.DeserializeObject <Result>();
                string msg          = uploadRes.IsSucceed ? "部署成功" : "部署失败:" + uploadRes.Message;
                var    timeSpan     = (DateTime.Now - now).TotalMilliseconds;
                bwUploadZip.ReportProgress(100, msg + ",耗时:" + timeSpan);
            }
            catch (Exception exception)
            {
                bwUploadZip.ReportProgress(0, $"发布失败:{exception.Message }");
            }
        }