Пример #1
0
        public Result Ini(ProjModel projModel)
        {
            Result res = new Result();

            try
            {
                _projModel      = projModel;
                _dirSimpleNames = ProjModel.ToDirSimpleNames(projModel.PublishDir);

                if (_projModel.ProjType == "Library")
                {
                    lbAppType.Text = "IIS";
                    _appViews      = TPublishService.GetAllIISAppNames();
                    if (_appViews == null || !_appViews.Any())
                    {
                        throw new Exception("未连接到可用的IIS服务");
                    }
                }
                else
                {
                    lbAppType.Text = "Exe";
                    _appViews      = TPublishService.GetExeAppView(_projModel.LibName);
                    if (_appViews == null || !_appViews.Any())
                    {
                        throw new Exception("未找到该进程");
                    }
                }
                cbAppName.DataSource    = _appViews;
                cbAppName.DisplayMember = "AppAlias";
                cbAppName.ValueMember   = "AppPhysicalPath";

                cbAppName.SelectedIndex = _appViews.FindIndex(n => n.Id == _projModel.LastChooseInfo.LastChooseAppName);

                showLbText(lbAppPath, (cbAppName.SelectedItem as AppView)?.AppPhysicalPath ?? string.Empty);

                cbAppPublishDir.DataSource    = _dirSimpleNames;
                cbAppPublishDir.DisplayMember = "Name";
                cbAppPublishDir.ValueMember   = "FullName";
                string lastChoosePublishDir = _projModel.LastChooseInfo.LastChoosePublishDir ?? _dirSimpleNames[0].FullName;
                _projModel.LastChooseInfo.LastChoosePublishDir = lastChoosePublishDir;
                cbAppPublishDir.SelectedIndex = cbAppPublishDir.FindString(_dirSimpleNames.Count > 0 ? new DirectoryInfo(_projModel.LastChooseInfo.LastChoosePublishDir ?? _dirSimpleNames[0].FullName)
                                                                           .Name
                    : string.Empty);

                lbChoosedFiles.Text = $"(已选择{_projModel?.LastChooseInfo?.LastChoosePublishFiles?.Where(n => !n.EndsWith("pdb"))?.Count() ?? 0}个文件)";

                isIni         = false;
                res.IsSucceed = true;
            }
            catch (Exception e)
            {
                res.Message = e.Message;
            }

            return(res);
        }
Пример #2
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)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                //string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()----", this.GetType().FullName);
                //string title = "Push";

                //// Show a message box to prove we were here
                //VsShellUtilities.ShowMessageBox(
                //    this.package,
                //    message,
                //    title,
                //    OLEMSGICON.OLEMSGICON_INFO,
                //    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                //    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);


                var projInfo = GetSelectedProjInfo();
                if (projInfo == null)
                {
                    throw new Exception("您还未选中项目");
                }

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

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

                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);
            }
        }
Пример #3
0
        private void bwUploadZip_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            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.ZipManyFilesOrDictorys(_projModel.LastChooseInfo.LastChoosePublishFiles, zipFullPath, _projModel.LastChooseInfo.LastChoosePublishDir);

            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          = $"{TPublishService.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;

            bwUploadZip.ReportProgress(100, msg);
        }