Esempio n. 1
0
        private void CreateReport(FormMain postEditCompare)
        {
            var projectController  = SdlTradosStudio.Application.GetController <ProjectsController>();
            var selectedProjectsId = new List <string>();
            var comparer           = postEditCompare.CreateProcessor();
            var cancel             = false;

            foreach (var studioProject in projectController.SelectedProjects)
            {
                var id = studioProject.GetProjectInfo().Id.ToString();
                selectedProjectsId.Add(id);
            }

            var projectsFromSettings    = Controller.Settings.projects;
            var selectedVersionProjects = projectsFromSettings
                                          .Where(proj => selectedProjectsId.Any(p => p.Equals(proj.id))).ToList();

            var projectSettingsPath = Application.Settings.ApplicationSettingsPath;
            var excelReportName     = Guid.NewGuid().ToString() + ".xlsx";
            var excelReportFullPath = Path.Combine(projectSettingsPath, excelReportName);

            // create excel report
            ExcelReportHelper.CreateExcelReport(excelReportFullPath, selectedVersionProjects[0].name);

            foreach (var project in selectedVersionProjects)
            {
                // excel report path is cleared after each autosave, set the path again
                postEditCompare.SetExcelReportPath(excelReportFullPath);
                var package         = ExcelReportHelper.GetExcelPackage(excelReportFullPath);
                var normalizedName  = ExcelReportHelper.NormalizeWorksheetName(project.name);
                var worksheetExists = Helper.WorksheetExists(package, project.name);
                if (!worksheetExists)
                {
                    Helper.AddNewWorksheetToReport(package, normalizedName);
                }

                postEditCompare.SetExcelSheetName(normalizedName);
                var versionDetails = Helper.CreateVersionDetails(project);

                var filesPairs = Helper.GetPairedFiles(versionDetails, project);

                postEditCompare.ParseContentFromFiles(comparer, filesPairs, ref cancel);
                postEditCompare.CreateComparisonReport(cancel, comparer);
            }

            //Auto save the report only after the report was generated for selected projects
            if (Application.Settings.ReportsAutoSave)
            {
                if (Application.Settings.ReportsAutoSaveFullPath.Trim() != string.Empty && Directory.Exists(Application.Settings.ReportsAutoSaveFullPath))
                {
                    // autosave excel report file
                    var reportPathAutoSave = Application.Settings.ReportsAutoSaveFullPath;

                    var reportNameAutoSavePath = postEditCompare.SetAutoSavePath();
                    reportNameAutoSavePath = postEditCompare.GetAutoSaveFileName(reportNameAutoSavePath);

                    if (Application.Settings.ReportsCreateMonthlySubFolders)
                    {
                        reportPathAutoSave = Path.Combine(reportPathAutoSave,
                                                          DateTime.Now.Year + "-" + DateTime.Now.Month.ToString().PadLeft(2, '0'));
                        if (!Directory.Exists(reportPathAutoSave))
                        {
                            Directory.CreateDirectory(reportPathAutoSave);
                        }
                    }

                    var reportNameAutoSave     = reportNameAutoSavePath.Substring(reportNameAutoSavePath.LastIndexOf(@"\") + 1);
                    var reportFullPathAutoSave = Path.Combine(reportPathAutoSave, reportNameAutoSave);
                    File.Copy(excelReportFullPath, reportFullPathAutoSave + ".xlsx", true);
                }
            }
            postEditCompare.SetExcelReportPath(string.Empty);
        }