Пример #1
0
        public void CreateAndSave(RepositoryInfo repositoryInfo, IList<Issue> issues)
        {
            var wordObject = new Application();
            var documentInformations = _documentService.GetDocumentInformations(repositoryInfo.ProjectId);
            object templateFile = documentInformations.FileTemplateName;
            Document document = null;

            try
            {
                document = wordObject.Documents.Open(ref templateFile);

                document.Activate();
                ComposeDocument(repositoryInfo, issues, document);

                object documentFile = documentInformations.FileName;
                object missing = Type.Missing;

                document.SaveAs(ref documentFile);
                document.Close(ref missing, ref missing, ref missing);
            }
            catch (Exception ex)
            {
                if (document != null)
                {
                    document.Close();
                }

                throw new ErrorWhileCreatingDocument(ex.Message, ex);
            }
        }
Пример #2
0
 private void ComposeDocument(RepositoryInfo repositoryInfo, IList<Issue> issues, Document document)
 {
     foreach (Range tmpRange in document.StoryRanges)
     {
         Replace(repositoryInfo.ProjectName, ProjectNameContainer, tmpRange);
         Replace(repositoryInfo.Hash, VersionContainer, tmpRange);
         Replace(repositoryInfo.Date, PublicationDateContainer, tmpRange);
         Replace(issues.ToText(), SolvedTicketsContainer, tmpRange);
     }
 }
Пример #3
0
        public void ShouldInitializeProperties()
        {
            var commitDate = new DateTime(2012, 1, 31);
            string hash = Guid.NewGuid().ToString();
            var repositoryInfo = new RepositoryInfo(
                new Repository
                    {
                        Id = "repoId", Name = "repoName", Path = "repoPath"
                    }, new DateTimeOffset(commitDate), hash);

            Assert.That("repoId", Is.EqualTo(repositoryInfo.ProjectId));
            Assert.That("repoName", Is.EqualTo(repositoryInfo.ProjectName));
            Assert.That(commitDate.Date.ToShortDateString(), Is.EqualTo(repositoryInfo.Date));
            Assert.That(hash, Is.EqualTo(repositoryInfo.Hash));
        }
Пример #4
0
        private void CreatePachagesAsync(object sender, DoWorkEventArgs e)
        {
            ScriptsReturnValue = string.Empty;

            var repositoriesInfo = new List<RepositoryInfo>();
            var scriptsReturnValue = new StringBuilder();
            var errors = new StringBuilder();

            foreach (var project in SelectedProjects)
            {
                var issues = new List<Issue>();
                try
                {
                    issues = _issueService.GetIssues(project.Id.ToString(CultureInfo.InvariantCulture),
                                                         IssueStatuses.TestPassed, null).ToList();
                }
                catch (RedmineException exception)
                {
                    errors.Append(string.Format(Resources.MainWindowViewModel_ErrorWhileFetchingFromRedmine, project.Name, exception.Message));
                }

                //if (!issues.Any())
                //{
                //    continue;
                //}

                var repository = _repositoryService.GetRepository(project.Name);
                var scriptReturnValue = _scriptService.CreatePackages(repository.Id);

                scriptsReturnValue.Append(scriptReturnValue);

                if (!scriptReturnValue.Contains(Resources.MainWindowViewModel_EverythingIsOk))
                {
                    errors.Append(string.Format(Resources.MainWindowViewModel_ErrorDuringRunningScript, project.Name));
                    ScriptsReturnValue = scriptsReturnValue.ToString();
                    continue;
                }

                RepositoryInfo repositoryInfo;
                try
                {
                    var gitRepository = new Repository(repository.Path);
                    repositoryInfo = new RepositoryInfo(repository, gitRepository.CurrentBranch.CurrentCommit.CommitDate,
                        gitRepository.CurrentBranch.CurrentCommit.Hash);
                }
                catch (DirectoryNotFoundException)
                {
                    errors.Append(string.Format(Resources.MainWindowViewModel_WrongRepositoryPathPleaseSeeYourConfig, project.Name));
                    continue;
                }

                repositoriesInfo.Add(repositoryInfo);

                try
                {
                    _documentBuilder.CreateAndSave(repositoryInfo, issues);
                }
                catch (ErrorWhileCreatingDocument errorWhileCreatingDocument)
                {
                    Messenger.Default.Send(errorWhileCreatingDocument.Message);
                    continue;
                }

                _issueService.CloseIssues(issues);
            }

            ScriptsReturnValue = scriptsReturnValue.ToString();

            if (errors.Length != 0)
            {
                Messenger.Default.Send(errors.ToString());
                return;
            }

            try
            {
                ScriptsReturnValue += _mailService.SendMail(repositoriesInfo);
            }
            catch (Exception)
            {
                Messenger.Default.Send(Resources.MainWindowViewModel_CouldNotSendEmail);
            }
        }