<commit_before>﻿namespace MicroServicesStarter.ServiceManagement.Action
{
    using System.IO;
    using System.Linq;
    using Chains;
    using Chains.Play.Web;
    using Ionic.Zip;
    using Services.Communication.Protocol;
    using Services.Management.Administration.Server;
    using Services.Management.Administration.Update;
    using Services.Management.Administration.Worker;

    public sealed class InstallProjects : IChainableAction<AdminSetupContext, AdminSetupContext>
    {
        private readonly string adminHost;

        private readonly int adminPort;

        public InstallProjects(string adminHost = StartAdmin.LocalAdminHost, int adminPort = StartAdmin.LocalAdminPort)
        {
            this.adminHost = adminHost;
            this.adminPort = adminPort;
        }

        public AdminSetupContext Act(AdminSetupContext context)
        {
            using (var adminConnection = new Client(adminHost, adminPort).Do(new WaitUntilClientConnects()))
            {
                var reports = adminConnection.Do(new Send<GetReportedDataReturnData>(new GetReportedData())).Reports;
                var repository =
                    adminConnection.Do(new Send<GetAllRepoServicesReturnData>(new GetAllRepoServices())).RepoServices;

                foreach (var project in context.Projects)
                {
                    if (repository.ContainsKey(project.Name))
                    {
                        context.LogToUi(string.Format("Housekeeping on service {0}...", project.Name));

                        if (
                            reports.Any(
                                x =>
                                    x.Value.StartData.ServiceName == project.Name
                                        && x.Value.WorkerState == WorkUnitState.Running))
                        {
                            // Stop the services
                            context.LogToUi(string.Format("Stopping instances of service {0}", project.Name));

                            reports.Where(
                                x =>
                                    x.Value.StartData.ServiceName == project.Name
                                        && x.Value.WorkerState == WorkUnitState.Running)
                                   .Select(<commit_msg>Only load the services provided by the json file when debugging.<commit_after>﻿namespace MicroServicesStarter.ServiceManagement.Action
{
    using System.IO;
    using System.Linq;
    using Chains;
    using Chains.Play;
    using Chains.Play.Web;
    using Ionic.Zip;
    using Services.Communication.Protocol;
    using Services.Management.Administration.Server;
    using Services.Management.Administration.Update;
    using Services.Management.Administration.Worker;

    public sealed class InstallProjects : IChainableAction<AdminSetupContext, AdminSetupContext>
    {
        private readonly string adminHost;

        private readonly int adminPort;

        public InstallProjects(string adminHost = StartAdmin.LocalAdminHost, int adminPort = StartAdmin.LocalAdminPort)
        {
            this.adminHost = adminHost;
            this.adminPort = adminPort;
        }

        public AdminSetupContext Act(AdminSetupContext context)
        {
            using (var adminConnection = new Client(adminHost, adminPort).Do(new WaitUntilClientConnects()))
            {
                var reports = adminConnection.Do(new Send<GetReportedDataReturnData>(new GetReportedData())).Reports;
                var repository =
                    adminConnection.Do(new Send<GetAllRepoServicesReturnData>(new GetAllRepoServices())).RepoServices;

                var jsonFileWithStartingServices = string.Format("services-{0}.json", context.SetupType.ToString());

                var servicesToStart =
                    Json<StartWorkerData[]>.Deserialize(File.ReadAllText(jsonFileWithStartingServices))
                        .Select(x => x.ServiceName)
                        .Distinct();

                foreach (var serviceName in servicesToStart)
                {
                    var project = context.Projects.FirstOrDefault(p => p.Name == serviceName);

                    if (project == null)
                    {
                        continue;
                    }

                    if (repository.ContainsKey(project.Name))
                    {
                        context.LogToUi(string.Format("Housekeeping on service {0}...", project.Name));

                        if (
                            reports.Any(
                                x =>
                                    x.Value.StartData.ServiceName == project.Name
                                        && x.Value.WorkerState == WorkUnitState.Running))
                        {
                            // Stop the services
                            context.LogToUi(string.Format("Stopping instances of service {0}", project.Name));

                            reports.Where(
                                x =>
                                    x.Value.StartData.ServiceName == project.Name
                                        && x.Value.WorkerState == WorkUnitState.Running)
                                   .Select(
{'fraction_non_alphanumeric': 0.07797902764537655, 'fraction_numerical': 0.0009532888465204957, 'mean_word_length': 1.5404358353510896, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6815643', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1131, 'n_words': 232}