예제 #1
0
        /// <summary>
        /// Выполняет деплой модуля.
        /// </summary>
        /// <param name="deployInfo"></param>
        internal override bool Deploy(DeployInfo deployInfo)
        {
            if (deployInfo == null)
            {
                throw new ArgumentNullException(nameof(deployInfo));
            }

            if (!(this.TestComboBox.SelectedItem is OptionItem item))
            {
                throw new NotificationException("Не выбрана папка тестирования");
            }

            //получаем папку тестирования
            DirectoryInfo testDir = new DirectoryInfo(item.DirectoryPath);

            //формируем имя папки с комплектом
            string description =
                this.TestFoldersBox.SelectedIndex >= 0
                                ? ((OptionItem)this.TestFoldersBox.SelectedItem).DirectoryPath
                                : this.TestFoldersBox.Text;

            /*string targetDirName = Path.Combine(testDir.FullName, String.Format("{0:yyyy.MM.dd}{1}", DateTime.Now,
             *                                                      String.IsNullOrEmpty(description)
             *                                                          ? null
             *                                                          : " - " + description));*/
            if (String.IsNullOrEmpty(description?.Trim()))
            {
                throw new NotificationException("Не задано название папки");
            }

            string targetDirName = Path.Combine(testDir.FullName, description);

            //создаём папку
            DirectoryInfo targetDir = this.CreateDirectory(targetDirName);

            //деплоим в папку
            if (deployInfo.CreateReleaseDirectory(targetDir, true) == null)
            {
                return(false);
            }

            deployInfo.CreateSourcesDirectory(targetDir, false);

            this.Form.Command.Package.WriteToOutput(
                $"Сформирован комплект для проекта {deployInfo.Project.Name} по пути:\n<file://{targetDir.FullName.TrimStart('\\').Replace('\\', '/')}>");
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Выкладывает модуль в папку.
        /// </summary>
        /// <param name="deployInfo"></param>
        /// <param name="directory"></param>
        /// <param name="prevReadmePath"></param>
        private bool CreatePackage(DeployInfo deployInfo, DirectoryInfo directory, string prevReadmePath)
        {
            if (deployInfo == null)
            {
                throw new ArgumentNullException(nameof(deployInfo));
            }
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }

            //README
            string readmePath = Path.Combine(directory.FullName, "Readme.txt");

            if (!File.Exists(readmePath))
            {
                if (String.IsNullOrEmpty(prevReadmePath))
                {
                    File.Copy(deployInfo.LogFile.GetFullPath(), readmePath);
                }
                else
                {
                    if (this.IsASCIIFile(prevReadmePath))
                    {
                        File.WriteAllLines(readmePath, this.GetUTF8LinesFromASCIIFile(prevReadmePath), Encoding.UTF8);
                    }
                    else
                    {
                        File.Copy(prevReadmePath, readmePath);
                    }
                }
            }

            if (deployInfo.Logs != null && deployInfo.Logs.Count > 0)
            {
                List <string> lines = this.GetNewReadmeLines(deployInfo, prevReadmePath);
                File.WriteAllLines(readmePath, lines, Encoding.UTF8);
            }

            DirectoryInfo releaseDir = deployInfo.CreateReleaseDirectory(directory, false);

            deployInfo.CreateSourcesDirectory(directory, false);
            this.Form.Command.Package.WriteToOutput(
                $"Сформирован комплект для проекта {deployInfo.Project.Name} по пути:\n<file://{releaseDir.FullName.TrimStart('\\').Replace('\\', '/')}>");
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Выполняет деплой модуля.
        /// </summary>
        /// <param name="deployInfo"></param>
        internal override bool Deploy(DeployInfo deployInfo)
        {
            if (deployInfo == null)
            {
                throw new ArgumentNullException(nameof(deployInfo));
            }

            OptionItem item = this.CustomerComboBox.SelectedItem as OptionItem;

            if (item == null)
            {
                throw new NotificationException("Не выбрана папка комплекта");
            }

            //получение папки
            string todayDirName   = DateTime.Now.ToString("yyyy.MM.dd");
            string readmeFilePath = null;

            string[]      dateFolders = Directory.GetDirectories(item.DirectoryPath).Where(x => Regex.IsMatch(x, @"[\d\.]+")).ToArray();
            string        todayDir    = dateFolders.FirstOrDefault(x => x.EndsWith("\\" + todayDirName));
            DirectoryInfo dir;

            if (todayDir == null)
            {
                dir = Directory.CreateDirectory(Path.Combine(item.DirectoryPath, todayDirName));
            }
            else
            {
                dir            = new DirectoryInfo(todayDir);
                readmeFilePath = Directory.GetFiles(dir.FullName, "readme.txt", SearchOption.TopDirectoryOnly).FirstOrDefault();
            }

            if (readmeFilePath == null)
            {
                //получаем уже существующий файл readme
                IOrderedEnumerable <string> orderedDirectories = dateFolders.OrderByDescending(x => x);
                readmeFilePath = orderedDirectories
                                 .Select(d => Directory.GetFiles(d, "readme.txt", SearchOption.TopDirectoryOnly).FirstOrDefault())
                                 .FirstOrDefault(x => x != null);
            }

            //формируем комплект
            return(this.CreatePackage(deployInfo, dir, readmeFilePath));
        }
 /// <summary>
 /// Нажатие "ОК".
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_OK_Click(object sender, EventArgs e)
 {
     try
     {
         DeployInfo deployInfo = new DeployInfo(this.Command.DTEInfo.SelectedProject);
         if (this.ActiveDeploy.Deploy(deployInfo))
         {
             this.CloseForm(DialogResult.OK);
         }
     }
     catch (NotificationException nex)
     {
         WSSDeveloperPackage.ShowUserWarn(nex.Message, "Ошибка");
         this.CloseForm(DialogResult.Cancel);
     }
     catch (Exception ex)
     {
         WSSDeveloperPackage.ShowUserError(ex.ToString(), "Критическая ошибка");
         this.CloseForm(DialogResult.Cancel);
     }
 }
예제 #5
0
        /// <summary>
        /// Формирует новое содержание файла Readme.
        /// </summary>
        /// <param name="deployInfo"></param>
        /// <param name="prevReadmePath"></param>
        /// <returns></returns>
        private List <string> GetNewReadmeLines(DeployInfo deployInfo, string prevReadmePath)
        {
            string        projectName = deployInfo.Project.Name;
            List <string> lines       = null;
            string        today       = DateTime.Now.ToString("yyyy.MM.dd");
            List <string> prevLogs    = new List <string>();

            if (!String.IsNullOrEmpty(prevReadmePath))
            {
                lines = this.IsASCIIFile(prevReadmePath)
                                        ? this.GetUTF8LinesFromASCIIFile(prevReadmePath).ToList()
                                        : File.ReadAllLines(prevReadmePath).ToList();

                int todayIndex = -1;
                for (int i = 0; i < lines.Count; i++)
                {
                    string line = lines[0];
                    if (Regex.IsMatch(line, Constants.LogDatePattern))
                    {
                        if (line.Contains(today))
                        {
                            todayIndex = i;
                        }

                        break;
                    }
                }

                if (todayIndex == -1)                 //вставляем логи с новой датой
                {
                    List <string> rows = new List <string>();
                    rows.Add(today);
                    rows.Add(projectName);
                    rows.AddRange(deployInfo.Logs);
                    rows.Add(String.Empty);
                    lines.InsertRange(0, rows);
                }
                else if (todayIndex + 1 < lines.Count)                 //добавляем логи к старой дате
                {
                    int insertIndex     = todayIndex + 1;
                    int lastOldLogIndex = -1;
                    for (int i = todayIndex + 1; i < lines.Count; i++)
                    {
                        string todayLog = lines[i].Trim('\r', '\n');
                        if (String.IsNullOrEmpty(todayLog) || Regex.IsMatch(todayLog, Constants.LogDatePattern))
                        {
                            lastOldLogIndex = i - 1;
                            break;
                        }

                        prevLogs.Add(todayLog);
                    }
                    if (lastOldLogIndex != -1)
                    {
                        lines.RemoveRange(insertIndex, lastOldLogIndex - todayIndex);
                    }

                    Dictionary <string, List <string> > logsByProject = this.GroupLogsByProjectName(prevLogs);
                    IEnumerable <string> currentLogs = deployInfo.Logs.Where(x => !logsByProject.ContainsKey(x));
                    if (logsByProject.TryGetValue(projectName, out List <string> currentProjectLogs))
                    {
                        logsByProject[projectName] = currentProjectLogs.Union(currentLogs).Distinct().ToList();
                    }
                    else
                    {
                        logsByProject.Add(projectName, deployInfo.Logs.ToList());
                    }

                    lines.InsertRange(todayIndex + 1, logsByProject.SelectMany(x =>
                    {
                        List <string> logsForProj = x.Value;
                        logsForProj.Insert(0, x.Key);
                        return(logsForProj);
                    }));
                }
            }
            else
            {
                lines = new List <string> {
                    today, projectName
                };
                lines.AddRange(deployInfo.Logs);
            }
            return(lines);
        }