<commit_before>﻿using System;
using System.IO;
using System.Xml.Serialization;
using Microsoft.Win32;

namespace car_management.Common
{
    public sealed class DataManager
    {
        private static readonly Lazy<DataManager> lazy =
            new Lazy<DataManager>(() => new DataManager());

        private DataManager()
        {
        }

        public static DataManager Instance
        {
            get { return lazy.Value; }
        }

        public string GetXmlDataFilePath()
        {
            var fileDialog = new OpenFileDialog();

            // Set filter options and filter index.
            fileDialog.Filter = "XML Files (.xml)|*.xml|All Files (*.*)|*.*";
            fileDialog.FilterIndex = 1;

            fileDialog.Multiselect = false;

            // Call the ShowDialog method to show the dialog box.
            var userClickedOk = fileDialog.ShowDialog();
            var filePath = "";
            // Process input if the user clicked OK.
            if (userClickedOk == true)
            {
                // Open the selected file to read.
                var fileStream = fileDialog.OpenFile();

                using (var reader = new StreamReader(fileStream))
                {
                    // Read the first line from the file and write it the textbox.
                    filePath = reader.ReadLine();
                }
                fileStream.Close();
            }

            return filePath;
        }

        public void SaveProject(Project project)
        {
            var serializer = new XmlSerializer(typeof (Project));
            using (TextWriter writer = new StreamWriter(GetAppDataProjectFilePath()))
            {
                serializer.Serialize(writer, project);
            }
        }

        public Project LoadProject()
        {
            if (File.Exists(GetAppDataProjectFilePath()))
            {
                using (TextReader reader = new StreamReader(GetAppDataProjectFilePath()))
                {
                    var deserializer = new XmlSerializer(typeof (Project));
                    var obj = deserializer.Deserialize(reader);
                    var loadProject = obj as Project;
                    return loadProject;
                }
            }
            return null;
        }

        public string GetAppDataPath()
        {
            var appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var appDataProjectDirectory = Path.Combine(appdata, "Broselge");
            Directory.CreateDirectory(appDataProjectDirectory);
            return appDataProjectDirectory;
        }

        public string GetAppDataProjectFilePath()
        {
            return GetAppDataPath() + "project.xml";
        }
    }<commit_msg>data manager bug fixes<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using Microsoft.Win32;

namespace car_management.Common
{
    public sealed class DataManager
    {
        private static readonly Lazy<DataManager> lazy =
            new Lazy<DataManager>(() => new DataManager());

        private List<Car> _cars;

        private DataManager()
        {
        }

        public static DataManager Instance
        {
            get { return lazy.Value; }
        }

        public Project Project { get; set; }

        public List<Car> Cars
        {
            get { return _cars ?? (_cars = new List<Car>()); }
            set { _cars = value; }
        }

        public string GetXmlDataFilePath()
        {
            var fileDialog = new OpenFileDialog();

            // Set filter options and filter index.
            fileDialog.Filter = "XML Files (.xml)|*.xml|All Files (*.*)|*.*";
            fileDialog.FilterIndex = 1;

            fileDialog.Multiselect = false;

            // Call the ShowDialog method to show the dialog box.
            var userClickedOk = fileDialog.ShowDialog();
            var filePath = "";
            // Process input if the user clicked OK.
            if (userClickedOk == true)
            {
                // Open the selected file to read.
                var fileStream = fileDialog.OpenFile();

                using (var reader = new StreamReader(fileStream))
                {
                    // Read the first line from the file and write it the textbox.
                    filePath = reader.ReadLine();
                }
                fileStream.Close();
            }
            return filePath;
        }

        public void SaveProject(Project project)
        {
            var serializer = new XmlSerializer(typeof (Project));
            using (TextWriter writer = new StreamWriter(GetAppDataProjectFilePath()))
            {
                serializer.Serialize(writer, project);
            }
        }

        public Project LoadProject()
        {
            if (File.Exists(GetAppDataProjectFilePath()))
            {
                using (TextReader reader = new StreamReader(GetAppDataProjectFilePath()))
                {
                    var deserializer = new XmlSerializer(typeof (Project));
                    var obj = deserializer.Deserialize(reader);
                    var loadProject = obj as Project;
                    return loadProject;
                }
            }
            return null;
        }

        public string GetAppDataPath()
        {
            var appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var appDataProjectDirectory = Path.Combine(appdata, "Broselge");
            Directory.CreateDirectory(appDataProjectDirectory);
            return appDataProjectDirectory;
        }

        public string GetAppDataProjectFilePath()
        {
            return Path.Combine(GetAppDataPath() + "project.xml");
        }
    }
{'fraction_non_alphanumeric': 0.081922353343595, 'fraction_numerical': 0.001026167265264238, 'mean_word_length': 1.569420035149385, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '524448', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1330, 'n_words': 367}