<commit_before>﻿// <copyright file="FileReader.cs" company="YAGNI">
// All rights reserved.
// </copyright>
// <summary>Holds implementation of abstract file reader.</summary>
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using LibrarySystem.Models;

namespace LibrarySystem.FileExporters
{
    /// <summary>
    /// 
    /// </summary>
    public class JsonWriter
    {
        /// <summary>
        /// 
        /// </summary>
        private string directory;

        /// <summary>
        /// 
        /// </summary>
        private string fileName;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileName"></param>
        public JsonWriter(string directory, string fileName)
        {
            if (string.IsNullOrEmpty(directory))
            {
                throw new ArgumentException("Direcotry path cannot be null or empty string!");
            }

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("File name cannot be null or empty string!");
            }

            this.directory = directory;
            this.fileName = fileName;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public void ExportJournals(IEnumerable<DTOJournal> journals)
        {
            string journalsJson = JsonConvert.SerializeObject(journals, Formatting.Indented);
            File.WriteAllText(this.directory + "\\" + this.fileName, journalsJson);<commit_msg>Adding directory creation for JSON writer.<commit_after>﻿// <copyright file="FileReader.cs" company="YAGNI">
// All rights reserved.
// </copyright>
// <summary>Holds implementation of abstract file reader.</summary>
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using LibrarySystem.Models;

namespace LibrarySystem.FileExporters
{
    /// <summary>
    /// 
    /// </summary>
    public class JsonWriter
    {
        /// <summary>
        /// 
        /// </summary>
        private string directory;

        /// <summary>
        /// 
        /// </summary>
        private string fileName;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileName"></param>
        public JsonWriter(string directory, string fileName)
        {
            if (string.IsNullOrEmpty(directory))
            {
                throw new ArgumentException("Direcotry path cannot be null or empty string!");
            }

            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("File name cannot be null or empty string!");
            }

            this.directory = directory;
            this.fileName = fileName;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public void ExportJournals(IEnumerable<DTOJournal> journals)
        {
            if (!Directory.Exists(this.directory))
            {
                Directory.CreateDirectory(this.directory);
            }

            string journalsJson = JsonConvert.SerializeObject(journals, Formatting.Indented);
            File.WriteAllText(this.directory + "\\" + this.fileName, journalsJson);
{'fraction_non_alphanumeric': 0.12898465171192444, 'fraction_numerical': 0.0, 'mean_word_length': 1.7530463038180342, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4736339', 'n_tokens_mistral': 861, 'n_tokens_neox': 838, 'n_words': 201}