コード例 #1
0
        public bool Execute(IEnumerable <UpdateConnector> updateConnectors)
        {
            if (updateConnectors == null)
            {
                throw new ArgumentNullException(nameof(updateConnectors));
            }

            var currentDirectory     = _directoryHelper.GetCurrentDirectory();
            var configurationPath    = Path.Combine(currentDirectory, Constants.ConfigurationFileName);
            var projectConfiguration = JsonConvert.DeserializeObject <ProjectResponse>(File.ReadAllText(configurationPath));
            var connectors           = new List <ProjectConnectorResponse>();

            foreach (var updateConnector in updateConnectors)
            {
                connectors.Add(new ProjectConnectorResponse
                {
                    Library    = updateConnector.Library,
                    Name       = updateConnector.Name,
                    Parameters = updateConnector.Parameters,
                    Version    = updateConnector.Version
                });
            }

            projectConfiguration.Connectors = connectors;
            var json = JsonConvert.SerializeObject(projectConfiguration);

            File.WriteAllText(configurationPath, json);
            return(true);
        }
コード例 #2
0
        public GetModulesResponse Execute()
        {
            // NOTE : This operation should be called only if the dependencies have been resolved.
            var currentDirectory          = _directoryHelper.GetCurrentDirectory();
            var configurationPath         = Path.Combine(currentDirectory, Constants.ConfigurationFileName);
            var configurationTemplatePath = Path.Combine(currentDirectory, Constants.ConfigurationTemplateFileName);

            if (!File.Exists(configurationPath))
            {
                throw new ConfigurationNotFoundException();
            }

            if (!File.Exists(configurationTemplatePath))
            {
                throw new NotRestoredException();
            }

            var projectConfiguration = JsonConvert.DeserializeObject <ProjectResponse>(File.ReadAllText(configurationPath));

            if (projectConfiguration == null)
            {
                throw new BadConfigurationException($"the {Constants.ConfigurationFileName} is not correct");
            }

            var projectTemplateConfiguration = JsonConvert.DeserializeObject <ProjectResponse>(File.ReadAllText(configurationTemplatePath));

            if (projectTemplateConfiguration == null)
            {
                throw new BadConfigurationException($"The {Constants.ConfigurationTemplateFileName} is not correct");
            }

            return(new GetModulesResponse
            {
                ProjectUnits = projectConfiguration.Units,
                ProjectTemplateUnits = projectTemplateConfiguration.Units
            });
        }
コード例 #3
0
        public GetConnectorsResponse Execute()
        {
            var currentDirectory          = _directoryHelper.GetCurrentDirectory();
            var configurationPath         = Path.Combine(currentDirectory, Constants.ConfigurationFileName);
            var configurationTemplatePath = Path.Combine(currentDirectory, Constants.ConfigurationTemplateFileName);

            if (!File.Exists(configurationPath))
            {
                throw new ConfigurationNotFoundException();
            }

            if (!File.Exists(configurationTemplatePath))
            {
                throw new NotRestoredException();
            }

            var projectConfiguration = JsonConvert.DeserializeObject <ProjectResponse>(File.ReadAllText(configurationPath));

            if (projectConfiguration == null)
            {
                throw new BadConfigurationException($"the {Constants.ConfigurationFileName} is not correct");
            }

            var projectTemplateConfiguration = JsonConvert.DeserializeObject <ProjectResponse>(File.ReadAllText(configurationTemplatePath));

            if (projectTemplateConfiguration == null)
            {
                throw new BadConfigurationException($"The {Constants.ConfigurationTemplateFileName} is not correct");
            }

            return(new GetConnectorsResponse
            {
                Connectors = projectConfiguration.Connectors,
                TemplateConnectors = projectTemplateConfiguration.Connectors
            });
        }
        public bool Execute(IEnumerable <UpdateParameter> updateParameters)
        {
            if (updateParameters == null)
            {
                throw new ArgumentNullException(nameof(updateParameters));
            }

            var currentDirectory             = _directoryHelper.GetCurrentDirectory();
            var configurationPath            = Path.Combine(currentDirectory, Constants.ConfigurationFileName);
            var configurationTemplatePath    = Path.Combine(currentDirectory, Constants.ConfigurationTemplateFileName);
            var projectConfiguration         = JsonConvert.DeserializeObject <ProjectResponse>(File.ReadAllText(configurationPath));
            var projectTemplateConfiguration = JsonConvert.DeserializeObject <ProjectResponse>(File.ReadAllText(configurationTemplatePath));

            if (projectConfiguration == null)
            {
                throw new BadConfigurationException($"the {Constants.ConfigurationFileName} is not correct");
            }

            if (projectTemplateConfiguration == null)
            {
                throw new BadConfigurationException($"the {Constants.ConfigurationTemplateFileName} is not correct");
            }

            if (projectConfiguration.Units == null || !projectConfiguration.Units.Any())
            {
                throw new BadConfigurationException("No units in the configuration file");
            }

            var errors = new List <string>();

            foreach (var updateParameter in updateParameters)
            {
                var projectUnit = projectConfiguration.Units.FirstOrDefault(u => u.UnitName == updateParameter.UnitName);
                if (projectUnit == null)
                {
                    errors.Add($"The unit {updateParameter.UnitName} doesn't exist");
                    continue;
                }

                if (projectUnit.Packages == null)
                {
                    errors.Add($"The unit {updateParameter.UnitName} doesn't contain package");
                    continue;
                }

                var projectUnitPackage = projectUnit.Packages.FirstOrDefault(p => p.CategoryName == updateParameter.CategoryName);
                if (projectUnitPackage == null)
                {
                    errors.Add($"The category {updateParameter.UnitName}\\{updateParameter.CategoryName} doesn't exist");
                    continue;
                }

                var projectTemplateUnit        = projectTemplateConfiguration.Units.First(u => u.UnitName == updateParameter.UnitName);
                var projectTemplateUnitPackage = projectTemplateUnit.Packages.FirstOrDefault(p => p.Library == updateParameter.LibraryName && p.CategoryName == updateParameter.CategoryName);
                if (projectTemplateUnitPackage == null)
                {
                    errors.Add($"The library {updateParameter.LibraryName} doesn't exist in the unit {updateParameter.UnitName}");
                    continue;
                }

                projectUnitPackage.Library = updateParameter.LibraryName;
                if (updateParameter.Parameters == null)
                {
                    updateParameter.Parameters = new Dictionary <string, string>();
                    continue;
                }

                foreach (var parameter in updateParameter.Parameters)
                {
                    if (projectUnitPackage.Parameters.ContainsKey(parameter.Key))
                    {
                        projectUnitPackage.Parameters[parameter.Key] = parameter.Value;
                    }
                    else
                    {
                        if (!projectTemplateUnitPackage.Parameters.ContainsKey(parameter.Key))
                        {
                            errors.Add($"The parameter {parameter.Key} doesn't exist in the package {updateParameter.LibraryName}\\{updateParameter.CategoryName}");
                            continue;
                        }

                        projectUnitPackage.Parameters.Add(parameter.Key, parameter.Value);
                    }
                }
            }

            if (errors.Any())
            {
                throw new ParameterAggregateException(errors);
            }

            var json = JsonConvert.SerializeObject(projectConfiguration);

            File.WriteAllText(configurationPath, json);
            return(true);
        }