コード例 #1
0
        private AutomaticTask CreateAutomaticTask(WizardContext wizardContext, FileBasedProject selectedProject, bool isBatchTask)
        {
            var projectInfo   = selectedProject.GetProjectInfo();
            var automaticTask = new AutomaticTask(wizardContext.Action)
            {
                CreatedAt   = GetDateToString(wizardContext.DateTimeStamp),
                StartedAt   = GetDateToString(wizardContext.DateTimeStamp),
                CompletedAt = GetDateToString(wizardContext.DateTimeStamp),
                CreatedBy   = Environment.UserDomainName + "\\" + Environment.UserName
            };

            foreach (var wcProjectFile in wizardContext.ProjectFiles)
            {
                if (wcProjectFile.Selected)
                {
                    var taskFile = new TaskFile
                    {
                        LanguageFileGuid = wcProjectFile.FileId
                    };
                    automaticTask.TaskFiles.Add(taskFile);

                    var outputFile = new OutputFile
                    {
                        LanguageFileGuid = wcProjectFile.FileId
                    };
                    automaticTask.OutputFiles.Add(outputFile);
                }
            }

            var languageDirections = GetLanguageDirectionFiles(selectedProject.FilePath, wizardContext);

            foreach (var languageDirection in languageDirections)
            {
                var actionName = wizardContext.Action == Enumerators.Action.Export
                                        ? "Export"
                                        : "Import";

                var reportName = string.Format("{0}_{1}_{2}_{3}.xml",
                                               actionName.Replace(" ", ""),
                                               wizardContext.DateTimeStampToString,
                                               languageDirection.Key.SourceLanguageCode,
                                               languageDirection.Key.TargetLanguageCode);

                var projectsReportsFolder = Path.Combine(projectInfo.LocalProjectFolder, "Reports");
                if (!Directory.Exists(projectsReportsFolder))
                {
                    Directory.CreateDirectory(projectsReportsFolder);
                }

                var reportFile = Path.Combine(wizardContext.WorkingFolder, reportName);

                var projectReportsFilePath         = Path.Combine(projectsReportsFolder, reportName);
                var relativeProjectReportsFilePath = Path.Combine("Reports", reportName);

                _reportService.CreateReport(wizardContext, reportFile, selectedProject, languageDirection.Key.TargetLanguageCode);

                // Copy to project reports folder
                if (!isBatchTask)
                {
                    File.Copy(reportFile, projectReportsFilePath, true);
                }

                var report = new Report(wizardContext.Action)
                {
                    Name                  = actionName,
                    Description           = actionName,
                    LanguageDirectionGuid = languageDirection.Key.Guid,
                    PhysicalPath          = relativeProjectReportsFilePath
                };

                automaticTask.Reports.Add(report);
            }

            return(automaticTask);
        }
コード例 #2
0
        private void UpdateProjectReports(WizardContext wizardContext, FileBasedProject project, AutomaticTask automaticTask)
        {
            if (project == null)
            {
                return;
            }

            try
            {
                _supressProjectControllerEvents = true;

                _projectsController.Close(project);
                _projectSettingsService.UpdateAnalysisTaskReportInfo(project, automaticTask);
                _projectsController.Add(project.FilePath);

                switch (wizardContext.Owner)
                {
                case Enumerators.Controller.Files:
                    _filesController.Activate();
                    break;

                case Enumerators.Controller.Projects:
                    _projectsController.Activate();
                    break;
                }
            }
            finally
            {
                _supressProjectControllerEvents = false;
            }
        }
コード例 #3
0
        private void CreateHtmlReport(WizardContext wizardContext, FileBasedProject selectedProject, AutomaticTask automaticTask)
        {
            var project            = _xliffProjects.FirstOrDefault(a => a.Id == wizardContext.Project.Id);
            var languageDirections = _projectSettingsService.GetLanguageDirections(selectedProject.FilePath);

            foreach (var taskReport in automaticTask.Reports)
            {
                var languageDirection = languageDirections.FirstOrDefault(a =>
                                                                          string.Compare(taskReport.LanguageDirectionGuid, a.Guid, StringComparison.CurrentCultureIgnoreCase) == 0);

                var reportName         = Path.GetFileName(taskReport.PhysicalPath);
                var reportFilePath     = Path.Combine(wizardContext.WorkingFolder, reportName);
                var htmlReportFilePath = CreateHtmlReportFile(reportFilePath);

                foreach (var wcProjectFile in wizardContext.ProjectFiles)
                {
                    if (!wcProjectFile.Selected || string.Compare(wcProjectFile.TargetLanguage, languageDirection?.TargetLanguageCode,
                                                                  StringComparison.CurrentCultureIgnoreCase) != 0)
                    {
                        continue;
                    }

                    var projectFile = project?.ProjectFiles.FirstOrDefault(a => a.FileId == wcProjectFile.FileId);
                    if (projectFile != null)
                    {
                        projectFile.Report = GetRelativePath(project.Path, htmlReportFilePath);

                        var activityfile = projectFile.ProjectFileActivities.OrderByDescending(a => a.Date).FirstOrDefault();
                        if (activityfile != null)
                        {
                            activityfile.Report = projectFile.Report;
                        }
                    }
                }
            }
        }