private void EnsureFolderExists(string folderPath)
 {
     if (!_fileProcessor.DirectoryExists(folderPath))
     {
         _fileProcessor.DirectoryCreate(folderPath);
     }
 }
Пример #2
0
        private void CreateReport(ReportInformation reportInformation)
        {
            string filePath = null;

            try
            {
                if (!_fileProcessor.DirectoryExists(ReportFolderPath))
                {
                    _fileProcessor.DirectoryCreate(ReportFolderPath);
                }

                filePath = GeneratorHelper.GetFilePathFormatted(
                    ReportFolderPath,
                    ReportFileNameFormat,
                    reportInformation.FeedId.ToString(),
                    reportInformation.FeedRunId.HasValue ? reportInformation.FeedRunId.Value.ToString() : "0",
                    reportInformation.ExecutionStartTime.ToString("yyyy-MM-dd_hh-mm-ss-fff"));

                using (var fileStream = _fileProcessor.FileCreate(filePath))
                {
                    using (StreamWriter writer = new StreamWriter(fileStream))
                    {
                        using (JsonWriter jsonWriter = new JsonTextWriter(writer))
                        {
                            var serializer = new JsonSerializer();
                            serializer.NullValueHandling = NullValueHandling.Ignore;
                            serializer.Serialize(jsonWriter, reportInformation);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.Error(ex, string.Format("Failed to create a report for {0}", filePath));
            }
        }