<commit_before>﻿using Devkoes.JenkinsManager.APIHandler.Properties;
using Devkoes.JenkinsManager.Model.Schema;
using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace Devkoes.JenkinsManager.APIHandler.Managers
{
    public static class SettingManager
    {
        private static ObservableCollection<JenkinsServer> _serversCopy;

        static SettingManager()
        {
            _serversCopy = new ObservableCollection<JenkinsServer>();

            if (Settings.Default.SolutionJobs == null)
            {
                Settings.Default.SolutionJobs = new SolutionJenkinsJobLinkList();
            }

            if (Settings.Default.JenkinsServers != null)
            {
                foreach (var s in Settings.Default.JenkinsServers)
                {
                    s.Version = JenkinsServerValidator.GetJenkinsVersion(s.Url);
                    _serversCopy.Add(s);
                }
            }

            Settings.Default.Save();
        }

        public static void SaveJobForSolution(string jobUri, string solutionPath, string jenkinsServerUri)
        {
            var existingSolutionJob = Settings.Default.SolutionJobs.FirstOrDefault((sj) => string.Equals(sj.SolutionPath, solutionPath, StringComparison.InvariantCultureIgnoreCase));
            if (existingSolutionJob != null)
            {
                Settings.Default.SolutionJobs.Remove(existingSolutionJob);
            }

            Settings.Default.SolutionJobs.Add(new SolutionJenkinsJobLink()
            {
                SolutionPath = solutionPath,
                JobUrl = jobUri,
                JenkinsServerUrl = jenkinsServerUri
            });

            Settings.Default.Save();
        }

        public static SolutionJenkinsJobLink GetJobUri(string solutionPath)
        {
            return Settings.Default.SolutionJobs.FirstOrDefault((sj) => string.Equals(sj.SolutionPath, solutionPath, StringComparison.InvariantCultureIgnoreCase));
        }

        public static JenkinsServer GetJenkinsServer(string solutionUrl)
        {
            return _serversCopy.FirstOrDefault((js) => string.Equals(js.Url, solutionUrl, StringComparison.InvariantCultureIgnoreCase));
        }

        public static bool ContainsSolutionPreference(string solutionPath)
        {
            return Settings.Default.SolutionJobs.Any((sj) => string.Equals(sj.SolutionPath, solutionPath, StringComparison.InvariantCultureIgnoreCase));
        }

        public static void AddServer(JenkinsServer server)
        {
            _serversCopy.Add(server);
            SaveJenkinsServers();
        }

        public static ObservableCollection<JenkinsServer> GetServers()
        {
            return _serversCopy;
        }

        public static void RemoveServer(JenkinsServer server)
        {
            _serversCopy.Remove(server);
            SaveJenkinsServers();
        }

        public static bool DebugEnabled
        {
            get { return Settings.Default.DebugOutputEnabled; }
            set
            {
                if (value != Settings.Default.DebugOutputEnabled)
                {
                    Settings.Default.DebugOutputEnabled = value;
                    Settings.Default.Save();
                }
            }
        }

        public static void UpdateServer(
            JenkinsServer originalJenkinsServer,
            JenkinsServer newJenkinsServer)
        {
            if (!_serversCopy.Contains(originalJenkinsServer))
            {
                return;
            }

            originalJenkinsServer.Name = newJenkinsServer.Name;
            originalJenkinsServer.Url = newJenkinsServer.Url;
            originalJenkinsServer.UserName = newJenkinsServer.UserName;
            originalJenkinsServer.ApiToken = <PASSWORD>JenkinsServer.ApiToken;

            SaveJenkinsServers();
        }

        private static void SaveJenkinsServers()
        {
            var newJenkinsServerList = new JenkinsServerList();
            newJenkinsServerList.AddRange(_serversCopy);

            Settings.Default.Save();
        }
    }
}<commit_msg>Fixed small bug preventing jenkins server preference save<commit_after>﻿using Devkoes.JenkinsManager.APIHandler.Properties;
using Devkoes.JenkinsManager.Model.Schema;
using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace Devkoes.JenkinsManager.APIHandler.Managers
{
    public static class SettingManager
    {
        private static ObservableCollection<JenkinsServer> _serversCopy;

        static SettingManager()
        {
            _serversCopy = new ObservableCollection<JenkinsServer>();

            if (Settings.Default.SolutionJobs == null)
            {
                Settings.Default.SolutionJobs = new SolutionJenkinsJobLinkList();
            }

            if (Settings.Default.JenkinsServers != null)
            {
                foreach (var s in Settings.Default.JenkinsServers)
                {
                    s.Version = JenkinsServerValidator.GetJenkinsVersion(s.Url);
                    _serversCopy.Add(s);
                }
            }

            Settings.Default.Save();
        }

        public static void SaveJobForSolution(string jobUri, string solutionPath, string jenkinsServerUri)
        {
            var existingSolutionJob = Settings.Default.SolutionJobs.FirstOrDefault((sj) => string.Equals(sj.SolutionPath, solutionPath, StringComparison.InvariantCultureIgnoreCase));
            if (existingSolutionJob != null)
            {
                Settings.Default.SolutionJobs.Remove(existingSolutionJob);
            }

            Settings.Default.SolutionJobs.Add(new SolutionJenkinsJobLink()
            {
                SolutionPath = solutionPath,
                JobUrl = jobUri,
                JenkinsServerUrl = jenkinsServerUri
            });

            Settings.Default.Save();
        }

        public static SolutionJenkinsJobLink GetJobUri(string solutionPath)
        {
            return Settings.Default.SolutionJobs.FirstOrDefault((sj) => string.Equals(sj.SolutionPath, solutionPath, StringComparison.InvariantCultureIgnoreCase));
        }

        public static JenkinsServer GetJenkinsServer(string solutionUrl)
        {
            return _serversCopy.FirstOrDefault((js) => string.Equals(js.Url, solutionUrl, StringComparison.InvariantCultureIgnoreCase));
        }

        public static bool ContainsSolutionPreference(string solutionPath)
        {
            return Settings.Default.SolutionJobs.Any((sj) => string.Equals(sj.SolutionPath, solutionPath, StringComparison.InvariantCultureIgnoreCase));
        }

        public static void AddServer(JenkinsServer server)
        {
            _serversCopy.Add(server);
            SaveJenkinsServers();
        }

        public static ObservableCollection<JenkinsServer> GetServers()
        {
            return _serversCopy;
        }

        public static void RemoveServer(JenkinsServer server)
        {
            _serversCopy.Remove(server);
            SaveJenkinsServers();
        }

        public static bool DebugEnabled
        {
            get { return Settings.Default.DebugOutputEnabled; }
            set
            {
                if (value != Settings.Default.DebugOutputEnabled)
                {
                    Settings.Default.DebugOutputEnabled = value;
                    Settings.Default.Save();
                }
            }
        }

        public static void UpdateServer(
            JenkinsServer originalJenkinsServer,
            JenkinsServer newJenkinsServer)
        {
            if (!_serversCopy.Contains(originalJenkinsServer))
            {
                return;
            }

            originalJenkinsServer.Name = newJenkinsServer.Name;
            originalJenkinsServer.Url = newJenkinsServer.Url;
            originalJenkinsServer.UserName = newJenkinsServer.UserName;
            originalJenkinsServer.ApiToken = <PASSWORD>.ApiToken;

            SaveJenkinsServers();
        }

        private static void SaveJenkinsServers()
        {
            var newJenkinsServerList = new JenkinsServerList();
            newJenkinsServerList.AddRange(_serversCopy);

            Settings.Default.JenkinsServers = newJenkinsServerList;
            Settings.Default.Save();
        }
    }
}
{'fraction_non_alphanumeric': 0.07395845839836715, 'fraction_numerical': 0.0, 'mean_word_length': 2.001801801801802, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '5650311', 'n_tokens_mistral': 2124, 'n_tokens_neox': 1971, 'n_words': 339}