Beispiel #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      = PublishService.GetAllIISAppNames();
                    if (_appViews == null || !_appViews.Any())
                    {
                        throw new Exception("未连接到可用的IIS服务");
                    }
                }
                else
                {
                    lbAppType.Text = "Exe";
                    _appViews      = PublishService.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);
        }
Beispiel #2
0
        public Result Ini(ProjModel projModel)
        {
            Result res = new Result();

            try
            {
                _projModel           = projModel;
                step_Pubsh.StepIndex = 1;
            }
            catch (Exception e)
            {
                txtLog.AppendText($"{e.Message}{Environment.NewLine}");
            }
            return(res);
        }
Beispiel #3
0
        public static ProjModel AnalysisProject(this Project project)
        {
            string    projName = project.FullName;
            ProjModel model    = new ProjModel
            {
                Key            = Guid.NewGuid().ToString(),
                LibName        = Path.GetFileNameWithoutExtension(projName),
                PublishDir     = new List <string>(),
                LastChooseInfo = new LastChooseInfo(),
                LibDebugPath   = string.Empty,
                LibReleasePath = string.Empty,
                ProjType       = string.Empty,
            };
            string txt = File.ReadAllText(projName);

            Regex regex    = new Regex(@"<PropertyGroup(\s|\S)*?>(\s|\S)*?</PropertyGroup>");
            var   regexRes = regex.Matches(txt);

            foreach (Match match in regexRes)
            {
                if (match.Value.Contains("Debug|AnyCPU"))
                {
                    Regex reg       = new Regex(@"<OutputPath>(?<Word>(\s|\S)*?)</OutputPath>");
                    var   typeMatch = reg.Match(match.Value);
                    if (typeMatch.Success)
                    {
                        string val = typeMatch.Groups["Word"].Value.TrimEnd('\\');
                        model.LibDebugPath = typeMatch.Value.Contains(":")
                            ? val
                            : Path.Combine(Path.GetDirectoryName(projName) ?? string.Empty, val);
                    }
                }
                if (match.Value.Contains("Release|AnyCPU"))
                {
                    Regex reg       = new Regex(@"<OutputPath>(?<Word>(\s|\S)*?)</OutputPath>");
                    var   typeMatch = reg.Match(match.Value);
                    if (typeMatch.Success)
                    {
                        string val = typeMatch.Groups["Word"].Value.TrimEnd('\\');
                        model.LibReleasePath = typeMatch.Value.Contains(":")
                            ? val
                            : Path.Combine(Path.GetDirectoryName(projName) ?? string.Empty, val);
                    }
                }
                if (match.Value.Contains("OutputType"))
                {
                    Regex reg       = new Regex(@"<OutputType>(?<Word>(\s|\S)*?)</OutputType>");
                    var   typeMatch = reg.Match(match.Value);
                    if (typeMatch.Success)
                    {
                        model.ProjType = typeMatch.Groups["Word"].Value;
                    }
                }
            }

            DirectoryInfo dir = new DirectoryInfo(model.LibDebugPath);

            dir = dir.Parent;
            if (dir != null)
            {
                if (model.ProjType == "Library")
                {
                    model.PublishDir.Add(dir.FullName);
                }
                else
                {
                    model.PublishDir.Add(model.LibDebugPath);
                    model.PublishDir.Add(model.LibReleasePath);
                }
                var propDir = dir.GetDirectories("Properties");
                if (propDir.Any())
                {
                    propDir = propDir[0].GetDirectories("PublishProfiles");
                    if (propDir.Any())
                    {
                        var files = propDir[0].GetFiles("*.pubxml");
                        foreach (FileInfo file in files)
                        {
                            var str = GetFilePath(file.FullName, dir.FullName);
                            if (str != null && !model.PublishDir.Contains(str))
                            {
                                model.PublishDir.Add(str);
                            }
                        }
                    }
                }
            }

            string   lastChooseSetting = Path.Combine(model.LibDebugPath, "TPublish.setting");
            FileInfo settingFile       = new FileInfo(lastChooseSetting);

            if (settingFile.Exists)
            {
                try
                {
                    model.LastChooseInfo = File.ReadAllText(lastChooseSetting).DeserializeObject <LastChooseInfo>();
                }
                catch (Exception e)
                {
                    model.LastChooseInfo = null;
                }
            }

            return(model);
        }
Beispiel #4
0
        /// <summary>
        /// 解析项目信息
        /// </summary>
        /// <param name="project">项目</param>
        /// <returns>项目信息</returns>
        public static ProjModel AnalysisProject(this Project project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string    projName = project.FullName;
            ProjModel model    = new ProjModel
            {
                Key                 = Guid.NewGuid().ToString(),
                LibName             = Path.GetFileNameWithoutExtension(projName),
                PublishDir          = new List <string>(),
                LastChooseInfo      = new LastChooseInfo(),
                LibDebugPath        = project.GetFullOutputPath(),
                LibReleasePath      = string.Empty,
                ProjType            = project.Properties.Item("OutputType").Value.ToString(),
                NetFrameworkVersion = NuGetFramework.Parse(project.GetProjectProperty("TargetFrameworkMoniker")).GetShortFolderName(),
                MsBuildPath         = GetMsBuildPath1(),
                ProjPath            = projName,
            };

            model.ProjType = model.ProjType == "2" ? "Library" : "";

            DirectoryInfo dir = new DirectoryInfo(model.LibDebugPath);

            dir = dir.Parent;
            if (dir != null)
            {
                if (model.ProjType == "Library")
                {
                    model.PublishDir.Add(dir.FullName);
                }
                else
                {
                    model.PublishDir.Add(model.LibDebugPath);
                    model.PublishDir.Add(model.LibReleasePath);
                }
                var propDir = dir.GetDirectories("Properties");
                if (propDir.Any())
                {
                    propDir = propDir[0].GetDirectories("PublishProfiles");
                    if (propDir.Any())
                    {
                        var files = propDir[0].GetFiles("*.pubxml");
                        foreach (FileInfo file in files)
                        {
                            var str = GetFilePath(file.FullName, dir.FullName);
                            if (!string.IsNullOrWhiteSpace(str) && !model.PublishDir.Contains(str))
                            {
                                model.PublishDir.Add(str);
                            }
                        }
                    }
                }
            }

            string   lastChooseSetting = Path.Combine(model.LibDebugPath, "Publish.setting");
            FileInfo settingFile       = new FileInfo(lastChooseSetting);

            if (settingFile.Exists)
            {
                try
                {
                    model.LastChooseInfo = JsonConvert.DeserializeObject <LastChooseInfo>(File.ReadAllText(lastChooseSetting));
                }
                catch (Exception e)
                {
                    model.LastChooseInfo = null;
                }
            }

            return(model);
        }