Esempio n. 1
0
        private static List <string> GetConfigData(PsConfiguration configuration)
        {
            List <string> configData = new List <string>
            {
                "$ConfigData_" + configuration.GetId() + " = @{",
                "AllNodes = @(",
                "@{",
                "NodeName = '*'",
                "PSDscAllowDomainUser = $true",
                "PSDscAllowPlainTextPassword = $true",
                "}"
            };

            foreach (string server in configuration.Servers)
            {
                configData.AddRange(new List <string>
                {
                    ",@{",
                    "NodeName = '" + server + "'",
                    "}"
                });
            }
            configData.AddRange(new List <string>
            {
                ")",
                "}"
            });

            return(configData);
        }
Esempio n. 2
0
        public List <PsConfiguration> GetConfigurations()
        {
            List <PsConfiguration> tempConfigs = new List <PsConfiguration>();

            if (Type == ServerType.Server)
            {
                tempConfigs.Add(new PsConfiguration(Name, GetRoles(), GetVariables()));
                return(tempConfigs);
            }
            foreach (DscServerNode child in Nodes)
            {
                tempConfigs.AddRange(child.GetConfigurations());
            }

            List <PsConfiguration> resultConfigs = new List <PsConfiguration>();

            foreach (PsConfiguration tempConfig in tempConfigs)
            {
                PsConfiguration existingConfiguration = PsConfiguration.FindEqual(resultConfigs, tempConfig);
                if (existingConfiguration != null)
                {
                    existingConfiguration.Servers.UnionWith(tempConfig.Servers);
                }
                else
                {
                    resultConfigs.Add(tempConfig);
                }
            }

            return(resultConfigs);
        }
Esempio n. 3
0
        public bool IsEqual(PsConfiguration configuration)
        {
            bool rolesEqual     = Roles.SetEquals(configuration.Roles);
            bool variablesEqual = (Variables.Count == configuration.Variables.Count &&
                                   !Variables.Except(configuration.Variables).Any());

            return(rolesEqual && variablesEqual);
        }
Esempio n. 4
0
 public static PsConfiguration FindEqual(List <PsConfiguration> list, PsConfiguration configuration)
 {
     foreach (PsConfiguration listConfiguration in list)
     {
         if (listConfiguration.IsEqual(configuration))
         {
             return(listConfiguration);
         }
     }
     return(null);
 }
Esempio n. 5
0
        private static List <string> GetConfigText(PsConfiguration configuration, DscRepository repository)
        {
            List <string> configText = new List <string> {
                "Configuration Config_" + configuration.GetId(), "{", "Param", "("
            };

            for (int i = 0; i < configuration.Variables.Keys.Count; i++)
            {
                if (i == configuration.Variables.Keys.Count - 1)
                {
                    configText.Add("$" + configuration.Variables.Keys.ElementAt(i));
                }
                else
                {
                    configText.Add("$" + configuration.Variables.Keys.ElementAt(i) + ",");
                }
            }
            configText.Add(")");
            configText.AddRange(configuration.GetUsedModules(repository).Select(module => "Import-DscResource -Module " + module));
            configText.AddRange(new List <string> {
                "Node $AllNodes.Nodename", "{"
            });
            HashSet <string> resourceStrings = new HashSet <string>();

            foreach (string roleString in configuration.Roles)
            {
                DscRoleNode roleNode = repository.Roles.GetRoleNode(roleString);
                resourceStrings.UnionWith(roleNode.Role.Resources);
            }
            foreach (string resourceString in resourceStrings)
            {
                DscConfigurationItemNode configurationItemNode = repository.GetConfigurationItemNode(resourceString);
                configText.AddRange(GetConfigurationItemText(configurationItemNode, repository));
            }
            configText.AddRange(new List <string> {
                "}", "}"
            });
            return(configText);
        }