Microsoft.WindowsAzure.Commands.CloudService.Development.EnableAzureServiceProjectRemoteDesktopCommand.UpdateServiceConfigurations C# (CSharp) Method

UpdateServiceConfigurations() private method

private UpdateServiceConfigurations ( CloudServiceProject service, string forwarderName, Certificate certElement, string encryptedPassword ) : void
service Microsoft.WindowsAzure.Commands.Utilities.CloudService.CloudServiceProject
forwarderName string
certElement Microsoft.WindowsAzure.Commands.Utilities.Common.XmlSchema.ServiceConfigurationSchema.Certificate
encryptedPassword string
return void
        private void UpdateServiceConfigurations(CloudServiceProject service, string forwarderName, Certificate certElement, string encryptedPassword)
        {
            foreach (ServiceConfiguration config in new[] { service.Components.LocalConfig, service.Components.CloudConfig })
            {
                foreach (RoleSettings role in config.Role)
                {
                    if (role.Certificates == null)
                    {
                        role.Certificates = new Certificate[0];
                    }

                    Certificate existingCert = role.Certificates.FirstOrDefault(c => c.name == certElement.name);
                    if (existingCert != null)
                    {
                        // ensure we're referencing the right cert
                        existingCert.thumbprint = certElement.thumbprint;
                    }
                    else
                    {
                        role.Certificates = role.Certificates.Concat(new[] { certElement }).ToArray();
                    }

                    Dictionary<string, string> settings = new Dictionary<string, string>();
                    foreach (ConfigurationSetting setting in role.ConfigurationSettings)
                    {
                        settings[setting.name] = setting.value;
                    }
                    settings["Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled"] = "true";
                    settings["Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername"] = Username;
                    settings["Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword"] = encryptedPassword;
                    settings["Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration"] = (DateTime.Now + TimeSpan.FromDays(365)).ToString("o");

                    if (role.name == forwarderName)
                    {
                        settings["Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled"] = "true";
                    }

                    role.ConfigurationSettings = settings.Select(pair => new ConfigurationSetting { name = pair.Key, value = pair.Value }).ToArray();
                }
            }
        }   
    }