<commit_before>﻿using NLog;
using SyncTrayzor.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace SyncTrayzor.Services.Config
{
    public class ConfigurationChangedEventArgs : EventArgs
    {
        private readonly Configuration baseConfiguration;
        public Configuration NewConfiguration
        {
            // Ensure we always clone it, so people can modify
            get { return new Configuration(this.baseConfiguration); }
        }

        public ConfigurationChangedEventArgs(Configuration newConfiguration)
        {
            this.baseConfiguration = newConfiguration;
        }
    }

    public interface IConfigurationProvider
    {
        event EventHandler<ConfigurationChangedEventArgs> ConfigurationChanged;

        bool HadToCreateConfiguration { get; }
        string LogFilePath { get; }
        string SyncthingPath { get; }
        string SyncthingCustomHomePath { get; }

        void Initialize(PathConfiguration pathConfiguration, Configuration defaultConfiguration);
        Configuration Load();
        void Save(Configuration config);
    }

    public class ConfigurationProvider : IConfigurationProvider
    {
        private const string apiKeyChars = "<KEY>";
        private const int apiKeyLength = 40;

        private readonly Logger logger = LogManager.GetCurrentClassLogger();
        private readonly SynchronizedEventDispatcher eventDispatcher;
        private readonly XmlSerializer serializer = new XmlSerializer(typeof(Configuration));
        private PathConfiguration pathConfiguration;

        private readonly object currentConfigLock = new object();
        private Configuration currentConfig;

        public event EventHandler<ConfigurationChangedEventArgs> ConfigurationChanged;

        public bool HadToCreateConfiguration { get; private set; }

        public string ExePath
        {
            get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
        }

        public string LogFilePath
        {
            get { return this.pathConfiguration.LogFilePath; }
        }

        public string SyncthingCustomHomePath
        {
            get { return this.pathConfiguration.SyncthingCustomHomePath; }
        }
        
        public string SyncthingPath
        {
            get { return this.pathConfiguration.SyncthingPath; }
        }

        public string SyncthingBackupPath
        {
            get { return Path.Combine(this.ExePath, "syncthing.exe"); }
        }

        public string ConfigurationFilePath
        {
            get { return this.pathConfiguration.ConfigurationFilePath; }
        }

        public ConfigurationProvider()
        {
            this.eventDispatcher = new SynchronizedEventDispatcher(this);
        }

        public void Initialize(PathConfiguration pathConfiguration, Configuration defaultConfiguration)
        {
            if (pathConfiguration == null)
                throw new ArgumentNullException("pathConfiguration");
            if (defaultConfiguration == null)
                throw new ArgumentNullException("defaultConfiguration");

            this.pathConfiguration = pathConfiguration;

            logger.Debug("ExePath: {0}", this.ExePath);
            logger.Debug("LogFilePath: {0}", this.LogFilePath);
            logger.Debug("SyncthingCustomHomePath: {0}", this.LogFilePath);
            logger.Debug("SyncThingPath: {0}", this.SyncthingPath);
            logger.Debug("SyncThingBackupPath: {0}", this.SyncthingBackupPath);
            logger.Debug("ConfigurationFilePath: {0}", this.ConfigurationFilePath);<commit_msg>Fix logging of SyncthingCustomHomePath<commit_after>﻿using NLog;
using SyncTrayzor.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace SyncTrayzor.Services.Config
{
    public class ConfigurationChangedEventArgs : EventArgs
    {
        private readonly Configuration baseConfiguration;
        public Configuration NewConfiguration
        {
            // Ensure we always clone it, so people can modify
            get { return new Configuration(this.baseConfiguration); }
        }

        public ConfigurationChangedEventArgs(Configuration newConfiguration)
        {
            this.baseConfiguration = newConfiguration;
        }
    }

    public interface IConfigurationProvider
    {
        event EventHandler<ConfigurationChangedEventArgs> ConfigurationChanged;

        bool HadToCreateConfiguration { get; }
        string LogFilePath { get; }
        string SyncthingPath { get; }
        string SyncthingCustomHomePath { get; }

        void Initialize(PathConfiguration pathConfiguration, Configuration defaultConfiguration);
        Configuration Load();
        void Save(Configuration config);
    }

    public class ConfigurationProvider : IConfigurationProvider
    {
        private const string apiKeyChars = "<KEY>";
        private const int apiKeyLength = 40;

        private readonly Logger logger = LogManager.GetCurrentClassLogger();
        private readonly SynchronizedEventDispatcher eventDispatcher;
        private readonly XmlSerializer serializer = new XmlSerializer(typeof(Configuration));
        private PathConfiguration pathConfiguration;

        private readonly object currentConfigLock = new object();
        private Configuration currentConfig;

        public event EventHandler<ConfigurationChangedEventArgs> ConfigurationChanged;

        public bool HadToCreateConfiguration { get; private set; }

        public string ExePath
        {
            get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
        }

        public string LogFilePath
        {
            get { return this.pathConfiguration.LogFilePath; }
        }

        public string SyncthingCustomHomePath
        {
            get { return this.pathConfiguration.SyncthingCustomHomePath; }
        }
        
        public string SyncthingPath
        {
            get { return this.pathConfiguration.SyncthingPath; }
        }

        public string SyncthingBackupPath
        {
            get { return Path.Combine(this.ExePath, "syncthing.exe"); }
        }

        public string ConfigurationFilePath
        {
            get { return this.pathConfiguration.ConfigurationFilePath; }
        }

        public ConfigurationProvider()
        {
            this.eventDispatcher = new SynchronizedEventDispatcher(this);
        }

        public void Initialize(PathConfiguration pathConfiguration, Configuration defaultConfiguration)
        {
            if (pathConfiguration == null)
                throw new ArgumentNullException("pathConfiguration");
            if (defaultConfiguration == null)
                throw new ArgumentNullException("defaultConfiguration");

            this.pathConfiguration = pathConfiguration;

            logger.Debug("ExePath: {0}", this.ExePath);
            logger.Debug("LogFilePath: {0}", this.LogFilePath);
            logger.Debug("SyncthingCustomHomePath: {0}", this.SyncthingCustomHomePath);
            logger.Debug("SyncThingPath: {0}", this.SyncthingPath);
            logger.Debug("SyncThingBackupPath: {0}", this.SyncthingBackupPath);
            logger.Debug("ConfigurationFilePath: {0}", this.ConfigurationFilePath);
{'fraction_non_alphanumeric': 0.07091643853474124, 'fraction_numerical': 0.0020857776039629773, 'mean_word_length': 2.7134559535333977, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '528102', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1706, 'n_words': 434}