Elastacloud.AzureManagement.Fluent.Services.Classes.RoleReference.ICloudConfig C# (CSharp) Method

ICloudConfig() private method

This method updates the cloud config to ensure that all roles have their instance count updated
private ICloudConfig ( System.Xml.Linq.XDocument document ) : System.Xml.Linq.XDocument
document System.Xml.Linq.XDocument
return System.Xml.Linq.XDocument
        XDocument ICloudConfig.ChangeConfig(XDocument document)
        {
            // TODO: this whole bit needs to be updated!!! It's beginning to look like a mess and can be replaced with 3-4 lines of code
            document.Declaration = new XDeclaration("1.0", "utf-8", "");
            foreach (string rn in _manager.RolesInstances.Keys)
            {
                int instanceCount = _manager.RolesInstances[rn];
                XElement role = document.Descendants(Namespaces.NsServiceManagement + "Role")
                    .Where(a => (string) a.Attribute("name") == rn)
                    .FirstOrDefault();
                // updates the instance count number here
                role.Elements(Namespaces.NsServiceManagement + "Instances")
                    .FirstOrDefault()
                    .Attribute("count").SetValue(instanceCount.ToString());
            }
            return document;
        }