public void RenderSummary(SummaryDocument summary, ISummaryWriter writer, string baseSummaryFolderPath, out string actualFileName)
        {
            string hrvSummary = string.Format("{0,8}" + Formatter.DefaultSpacing + "{1,-20} {2}",
                                              summary.HrvConclusion.TestId, summary.HrvConclusion.Text, summary.HrvConclusion.Comment);

            string svmrSummary = string.Format("{0,8}" + Formatter.DefaultSpacing + "{1,-20} {2}",
                                               summary.SvmrConclusion.TestId, summary.SvmrConclusion.Text, summary.SvmrConclusion.Comment);

            string renderedSummary = string.Format(SummaryTextFormat,
                                                   summary.Employee,
                                                   summary.CompletionTime.ToString(strings.SummaryText_DateFormat),
                                                   summary.HostName,
                                                   hrvSummary,
                                                   svmrSummary,
                                                   summary.FinalConclusion.Text);

            // write out to file

            var writingParams = new SummaryWritingParameters();

            writingParams.baseSummaryFolderPath = baseSummaryFolderPath;
            writingParams.completionTime        = summary.CompletionTime;
            writingParams.filenameExtension     = FilenameExtension;
            writingParams.hostName = summary.HostName;
            writingParams.employee = summary.Employee;

            writer.SaveSummary(writingParams, renderedSummary, out actualFileName);
        }
예제 #2
0
        public bool SaveSummary(
            SummaryWritingParameters parameters,
            string summaryContent,
            out string usedSummaryFileName
            )
        {
            _parameters = parameters;
            InitFallbackPaths(parameters.baseSummaryFolderPath);
            _shiftStartDate = RusHydroScheduler.GetShiftStartDate(parameters.completionTime.DateTime, out _isDayShift, out int _);

            bool   bSummarySaved = false;
            string fullFileName  = string.Empty;
            int    attempt       = 0;

            do
            {
                string folderName = CreateFolderForSummary(_shiftStartDate, _isDayShift, _preferredPaths[attempt], attempt);
                if (string.IsNullOrEmpty(folderName))
                {
                    // cannot create required subfolders in any of fallback folders
                    break;
                }
                string fileName = BuildUniqueFileNameForSummary(
                    folderName,
                    parameters.filenameExtension,
                    parameters.completionTime,
                    parameters.employee,
                    parameters.hostName
                    );
                fullFileName  = Path.Combine(folderName, fileName);
                bSummarySaved = WriteSummaryToFile(fullFileName, summaryContent);
            }while (!bSummarySaved && ++attempt < _preferredPaths.Length);
            if (bSummarySaved)
            {
                usedSummaryFileName = fullFileName;
            }
            else
            {
                usedSummaryFileName = string.Empty;
            }

            return(bSummarySaved);
        }
예제 #3
0
        public void RenderSummary(SummaryDocument summary, ISummaryWriter writer, string baseFolderName, out string actualFileName)
        {
            try
            {
                string content = RenderSummaryInternal(summary);

                var writingParams = new SummaryWritingParameters();
                writingParams.baseSummaryFolderPath = baseFolderName;
                writingParams.completionTime        = summary.CompletionTime;
                writingParams.filenameExtension     = FilenameExtension;
                writingParams.hostName = summary.HostName;
                writingParams.employee = summary.Employee;

                writer.SaveSummary(writingParams, content, out actualFileName);
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                _log.Error("Cannot save summary in RTF format. See exception information above. Falling back to TXT format.");

                // cannot save summary in RTF format for some reason
                // fall back to TXT format
                // if cannot save in plain text format, show message box
                // and let user copy the summary to clipboard
                ISummaryRenderer plainTextRenderer = null;

                try
                {
                    plainTextRenderer = new SummaryRendererPlainText();
                    plainTextRenderer.RenderSummary(summary, writer, baseFolderName, out actualFileName);
                    _log.InfoFormat("Summary successfully written in TXT format to {0}", actualFileName);
                    return;
                }
                catch (Exception ex2)
                {
                    _log.Error("Cannot save summary in TXT format.");
                    _log.Error(ex2);
                }

                throw new Exception("Cannot save summary in neither TXT, nor RTF format!");
            }
        }