Example #1
0
        private void UpdateCSDEF()
        {
            string normalizedRoleName = this.RoleName.ToUpperInvariant();

            ServiceDefinitionSchema.ServiceDefinition destCSDEF = SerializationUtils.DeserializeXmlFile <ServiceDefinitionSchema.ServiceDefinition>(ServiceCSDEFFile);

            if (destCSDEF.WebRole != null)
            {
                //Check if destination csdef already has a role.
                ServiceDefinitionSchema.WebRole roleToAddInDestCSDEF = destCSDEF.WebRole.Where(eachRole => eachRole.name.ToUpperInvariant() == normalizedRoleName).FirstOrDefault();
                //If found just update VMSize and exit.
                if (roleToAddInDestCSDEF != null)
                {
                    roleToAddInDestCSDEF.vmsize = this.VMSize == null ? roleToAddInDestCSDEF.vmsize : this.VMSize.Value;
                    SerializationUtils.SerializeXmlFile <ServiceDefinitionSchema.ServiceDefinition>(destCSDEF, ServiceCSDEFFile);
                    WriteObject(string.Format(CultureInfo.InvariantCulture, Resources.RoleAlreadyPresentInCSDEF, this.RoleName, roleToAddInDestCSDEF.vmsize.ToString()));
                    return;
                }
            }

            ServiceDefinitionSchema.ServiceDefinition sourceCSDEF = SerializationUtils.DeserializeXmlFile <ServiceDefinitionSchema.ServiceDefinition>(CsdefFile);
            if (sourceCSDEF.WebRole == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.RoleNotFoundInCSDEF, this.RoleName));
            }

            ServiceDefinitionSchema.WebRole roleToAdd = sourceCSDEF.WebRole.Where(eachRole => eachRole.name.ToUpperInvariant() == normalizedRoleName).FirstOrDefault();
            if (roleToAdd == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.RoleNotFoundInCSDEF, this.RoleName));
            }

            if (roleToAdd.Runtime == null || roleToAdd.Runtime.EntryPoint == null)
            {
                throw new ApplicationFailedException(string.Format(CultureInfo.InvariantCulture, Resources.EntryPointConfigMissing, this.RoleName));
            }

            List <ServiceDefinitionSchema.WebRole> webRoles = new List <ServiceDefinitionSchema.WebRole>();

            //Retain old roles if any.
            if (destCSDEF.WebRole != null)
            {
                webRoles.AddRange(destCSDEF.WebRole);
            }
            webRoles.Add(roleToAdd);
            destCSDEF.WebRole = webRoles.ToArray();

            SerializationUtils.SerializeXmlFile <ServiceDefinitionSchema.ServiceDefinition>(destCSDEF, ServiceCSDEFFile);
        }
 public static void VerifyWebRole(ServiceDefinitionSchema.WebRole role, bool isForwarder)
 {
     Assert.AreEqual(isForwarder ? 1 : 0, role.Imports.Where(i => i.moduleName == "RemoteForwarder").Count());
     Assert.AreEqual(1, role.Imports.Where(i => i.moduleName == "RemoteAccess").Count());
 }