<commit_before>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using DeploymentSettings.Json;
using DeploymentSettings.Models;

namespace DeploymentSettings
{
    public class DeploymentSettingsDataStore : IDeploymentSettingsDataStore
    {
        private GlobalDeploymentSettings _deploymentSettings;

        private readonly object _lockObject = new object();

        public void SetGlobalDeploymentSettings(GlobalDeploymentSettingsJson settingsJson)
        {
            lock (_lockObject) 
            {
                var projectSettingsDictionary = settingsJson.Projects.ToDictionary(project => project.Key, project =>
                    new ProjectDeploymentSettings(
                        ConvertJsonDeploymentScripts(project.Value.Scripts), // project scripts

                        project.Value.Services.ToDictionary(service => service.Key, service => 
                            new ServiceDeploymentSettings(
                                service.Value.DisplayText, 
                                ConvertJsonDeploymentScripts(service.Value.Scripts) // service scripts
                            )),

                        project.Value.ServiceScriptsRootPath
                    ));

                _deploymentSettings = new GlobalDeploymentSettings(projectSettingsDictionary);
            }
        }

        private List<DeploymentScript> ConvertJsonDeploymentScripts(DeploymentScriptJson[] scripts, string rootPath = "") 
        {
            return scripts?.Select(script => new DeploymentScript(
                    Path.Combine(rootPath, script.Path), 
                    script.Arguments))
                .ToList();
        }

        public bool TryGetDeployScripts(<commit_msg>Fixed bug after refactoring of settings data store when converting json settings into internal format.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using DeploymentSettings.Json;
using DeploymentSettings.Models;

namespace DeploymentSettings
{
    public class DeploymentSettingsDataStore : IDeploymentSettingsDataStore
    {
        private GlobalDeploymentSettings _deploymentSettings;

        private readonly object _lockObject = new object();

        public void SetGlobalDeploymentSettings(GlobalDeploymentSettingsJson settingsJson)
        {
            lock (_lockObject) 
            {
                var projectSettingsDictionary = settingsJson.Projects.ToDictionary(project => project.Key, project =>
                    new ProjectDeploymentSettings(
                        ConvertJsonDeploymentScripts(project.Value.Scripts), // project scripts

                        project.Value.Services.ToDictionary(service => service.Key, service => 
                            new ServiceDeploymentSettings(
                                service.Value.DisplayText, 
                                ConvertJsonDeploymentScripts(service.Value.Scripts, project.Value.ServiceScriptsRootPath ?? "") // service scripts
                            )),

                        project.Value.ServiceScriptsRootPath
                    ));

                _deploymentSettings = new GlobalDeploymentSettings(projectSettingsDictionary);
            }
        }

        private List<DeploymentScript> ConvertJsonDeploymentScripts(DeploymentScriptJson[] scripts, string rootPath = "") 
        {
            return scripts?.Select(script => new DeploymentScript(
                    Path.Combine(rootPath, script.Path), 
                    script.Arguments))
                .ToList();
        }

        public bool TryGetDeployScripts(
{'fraction_non_alphanumeric': 0.0649315803595385, 'fraction_numerical': 0.0, 'mean_word_length': 2.1040799333888427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '6439013', 'n_tokens_mistral': 827, 'n_tokens_neox': 776, 'n_words': 164}