// Returns a RoleNamesCollection based on instances in the roleInstanceList
        // whose RoleInstance.RoleName matches the roleName passed in.  Wildcards
        // are handled for the roleName passed in.
        // This function also verifies that the RoleInstance exists before adding the
        // RoleName to the RoleNamesCollection.
        public static RoleNamesCollection GetRoleNames(RoleInstanceList roleInstanceList, string roleName)
        {
            var roleNamesCollection = new RoleNamesCollection();
            if (!string.IsNullOrEmpty(roleName))
            {
                if (WildcardPattern.ContainsWildcardCharacters(roleName))
                {
                    WildcardOptions wildcardOptions = WildcardOptions.IgnoreCase | WildcardOptions.Compiled;
                    WildcardPattern wildcardPattern = new WildcardPattern(roleName, wildcardOptions);

                    foreach (RoleInstance role in roleInstanceList)
                        if (!string.IsNullOrEmpty(role.RoleName) && wildcardPattern.IsMatch(role.RoleName))
                        {
                            roleNamesCollection.Add(role.RoleName);
                        }
                }
                else
                {
                    var roleInstance = roleInstanceList.Where(r => r.RoleName != null).
                        FirstOrDefault(r => r.RoleName.Equals(roleName, StringComparison.InvariantCultureIgnoreCase));
                    if (roleInstance != null)
                    {
                        roleNamesCollection.Add(roleName);
                    }
                }
            }
            return roleNamesCollection;
        }
示例#2
0
        // Returns a RoleNamesCollection based on instances in the roleInstanceList
        // whose RoleInstance.RoleName matches the roleName passed in.  Wildcards
        // are handled for the roleName passed in.
        // This function also verifies that the RoleInstance exists before adding the
        // RoleName to the RoleNamesCollection.
        public static RoleNamesCollection GetRoleNames(RoleInstanceList roleInstanceList, string roleName)
        {
            var roleNamesCollection = new RoleNamesCollection();

            if (!string.IsNullOrEmpty(roleName))
            {
                if (WildcardPattern.ContainsWildcardCharacters(roleName))
                {
                    WildcardOptions wildcardOptions = WildcardOptions.IgnoreCase | WildcardOptions.Compiled;
                    WildcardPattern wildcardPattern = new WildcardPattern(roleName, wildcardOptions);

                    foreach (RoleInstance role in roleInstanceList)
                    {
                        if (!string.IsNullOrEmpty(role.RoleName) && wildcardPattern.IsMatch(role.RoleName))
                        {
                            roleNamesCollection.Add(role.RoleName);
                        }
                    }
                }
                else
                {
                    var roleInstance = roleInstanceList.Where(r => r.RoleName != null).
                                       FirstOrDefault(r => r.RoleName.Equals(roleName, StringComparison.InvariantCultureIgnoreCase));
                    if (roleInstance != null)
                    {
                        roleNamesCollection.Add(roleName);
                    }
                }
            }
            return(roleNamesCollection);
        }
示例#3
0
        public void GetRoleProcess()
        {
            RoleList                  roleList;
            RoleInstanceList          roleInstanceList;
            Func <Role, bool>         func  = null;
            Func <RoleInstance, bool> func1 = null;

            this.GetCurrentDeployment();
            if (this.currentDeployment != null)
            {
                SwitchParameter instanceDetails = this.InstanceDetails;
                if (instanceDetails.IsPresent)
                {
                    Collection <RoleInstanceContext> roleInstanceContexts = new Collection <RoleInstanceContext>();
                    if (!string.IsNullOrEmpty(this.RoleName))
                    {
                        RoleInstanceList roleInstanceList1 = this.currentDeployment.RoleInstanceList;
                        if (func1 == null)
                        {
                            func1 = (RoleInstance r) => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase);
                        }
                        roleInstanceList = new RoleInstanceList(roleInstanceList1.Where <RoleInstance>(func1));
                    }
                    else
                    {
                        roleInstanceList = this.currentDeployment.RoleInstanceList;
                    }
                    foreach (RoleInstance roleInstance in roleInstanceList)
                    {
                        RoleInstanceContext roleInstanceContext = new RoleInstanceContext();
                        roleInstanceContext.ServiceName = this.ServiceName;
                        roleInstanceContext.set_OperationId(this.getDeploymentOperation.OperationTrackingId);
                        roleInstanceContext.set_OperationDescription(base.CommandRuntime.ToString());
                        roleInstanceContext.set_OperationStatus(this.getDeploymentOperation.Status);
                        roleInstanceContext.InstanceErrorCode     = roleInstance.InstanceErrorCode;
                        roleInstanceContext.InstanceFaultDomain   = roleInstance.InstanceFaultDomain;
                        roleInstanceContext.InstanceName          = roleInstance.InstanceName;
                        roleInstanceContext.InstanceSize          = roleInstance.InstanceSize;
                        roleInstanceContext.InstanceStateDetails  = roleInstance.InstanceStateDetails;
                        roleInstanceContext.InstanceStatus        = roleInstance.InstanceStatus;
                        roleInstanceContext.InstanceUpgradeDomain = roleInstance.InstanceUpgradeDomain;
                        roleInstanceContext.RoleName          = roleInstance.RoleName;
                        roleInstanceContext.DeploymentID      = this.currentDeployment.PrivateID;
                        roleInstanceContext.InstanceEndpoints = roleInstance.InstanceEndpoints;
                        RoleInstanceContext roleInstanceContext1 = roleInstanceContext;
                        roleInstanceContexts.Add(roleInstanceContext1);
                    }
                    base.WriteObject(roleInstanceContexts, true);
                }
                else
                {
                    Collection <RoleContext> roleContexts = new Collection <RoleContext>();
                    if (!string.IsNullOrEmpty(this.RoleName))
                    {
                        RoleList roleList1 = this.currentDeployment.RoleList;
                        if (func == null)
                        {
                            func = (Role r) => r.RoleName.Equals(this.RoleName, StringComparison.OrdinalIgnoreCase);
                        }
                        roleList = new RoleList(roleList1.Where <Role>(func));
                    }
                    else
                    {
                        roleList = this.currentDeployment.RoleList;
                    }
                    List <Role> .Enumerator enumerator = roleList.GetEnumerator();
                    try
                    {
                        Func <RoleInstance, bool> func2 = null;
                        while (enumerator.MoveNext())
                        {
                            Role             current           = enumerator.Current;
                            RoleContext      roleContext       = new RoleContext();
                            RoleContext      roleContext1      = roleContext;
                            RoleInstanceList roleInstanceList2 = this.currentDeployment.RoleInstanceList;
                            if (func2 == null)
                            {
                                func2 = (RoleInstance ri) => ri.RoleName.Equals(current.RoleName, StringComparison.OrdinalIgnoreCase);
                            }
                            roleContext1.InstanceCount = roleInstanceList2.Where <RoleInstance>(func2).Count <RoleInstance>();
                            roleContext.RoleName       = current.RoleName;
                            roleContext.set_OperationDescription(base.CommandRuntime.ToString());
                            roleContext.set_OperationStatus(this.getDeploymentOperation.Status);
                            roleContext.set_OperationId(this.getDeploymentOperation.OperationTrackingId);
                            roleContext.ServiceName  = this.ServiceName;
                            roleContext.DeploymentID = this.currentDeployment.PrivateID;
                            RoleContext roleContext2 = roleContext;
                            roleContexts.Add(roleContext2);
                        }
                    }
                    finally
                    {
                        enumerator.Dispose();
                    }
                    base.WriteObject(roleContexts, true);
                    return;
                }
            }
        }
示例#4
0
        private void ListAllVMs()
        {
            Func <string, HostedServiceList> func = null;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                GetAzureVMCommand getAzureVMCommand = this;
                if (func == null)
                {
                    func = (string s) => base.Channel.ListHostedServices(s);
                }
                HostedServiceList hostedServiceList = ((CmdletBase <IServiceManagement>)getAzureVMCommand).RetryCall <HostedServiceList>(func);
                if (hostedServiceList != null)
                {
                    List <HostedService> .Enumerator enumerator = hostedServiceList.GetEnumerator();
                    try
                    {
                        Func <string, Deployment> func1 = null;
                        while (enumerator.MoveNext())
                        {
                            HostedService current = enumerator.Current;
                            using (OperationContextScope operationContextScope1 = new OperationContextScope((IContextChannel)base.Channel))
                            {
                                try
                                {
                                    GetAzureVMCommand getAzureVMCommand1 = this;
                                    if (func1 == null)
                                    {
                                        func1 = (string s) => base.Channel.GetDeploymentBySlot(s, current.ServiceName, "Production");
                                    }
                                    Deployment deployment = ((CmdletBase <IServiceManagement>)getAzureVMCommand1).RetryCall <Deployment>(func1);
                                    List <Role> .Enumerator enumerator1 = deployment.RoleList.GetEnumerator();
                                    try
                                    {
                                        Func <RoleInstance, bool> func2 = null;
                                        while (enumerator1.MoveNext())
                                        {
                                            Role role = enumerator1.Current;
                                            if (role.RoleType != "PersistentVMRole")
                                            {
                                                continue;
                                            }
                                            RoleInstanceList roleInstanceList = deployment.RoleInstanceList;
                                            if (func2 == null)
                                            {
                                                func2 = (RoleInstance r) => r.RoleName == role.RoleName;
                                            }
                                            RoleInstance roleInstance = roleInstanceList.Where <RoleInstance>(func2).First <RoleInstance>();
                                            PersistentVMRoleListContext persistentVMRoleListContext = new PersistentVMRoleListContext();
                                            persistentVMRoleListContext.ServiceName = current.ServiceName;
                                            persistentVMRoleListContext.Status      = roleInstance.InstanceStatus;
                                            persistentVMRoleListContext.Name        = roleInstance.RoleName;
                                            PersistentVMRoleListContext persistentVMRoleListContext1 = persistentVMRoleListContext;
                                            base.WriteObject(persistentVMRoleListContext1, true);
                                        }
                                    }
                                    finally
                                    {
                                        enumerator1.Dispose();
                                    }
                                }
                                catch (CommunicationException communicationException1)
                                {
                                    CommunicationException communicationException = communicationException1;
                                    if (communicationException as EndpointNotFoundException == null)
                                    {
                                        throw;
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        enumerator.Dispose();
                    }
                }
            }
        }