internal static void LogObject(HostedServiceList hostedServiceList) { if (hostedServiceList == null) return; Console.WriteLine("HostedServiceList contains {0} item(s).", hostedServiceList.Count); foreach (var item in hostedServiceList) { LogObject(item); } }
/// <summary> /// Connect to an Azure subscription and obtain its service list. /// </summary> protected override void AzureExecute() { try { HostedServiceList hostedServices = this.RetryCall(s => this.Channel.ListHostedServices(s)); this.ServiceList.Set(this.ActivityContext, hostedServices); } catch (EndpointNotFoundException ex) { LogBuildMessage(ex.Message); this.ServiceList.Set(this.ActivityContext, null); } }
private void ListAllVMs() { using (new OperationContextScope(Channel.ToContextChannel())) { HostedServiceList services = this.RetryCall(s => this.Channel.ListHostedServices(s)); if (services != null) { foreach (HostedService service in services) { using (new OperationContextScope(Channel.ToContextChannel())) { try { var deployment = this.RetryCall(s => this.Channel.GetDeploymentBySlot(s, service.ServiceName, DeploymentSlotType.Production)); foreach (Role role in deployment.RoleList) { if (role.RoleType == "PersistentVMRole") { RoleInstance instance = deployment.RoleInstanceList.Where(r => r.RoleName == role.RoleName).First(); PersistentVMRoleListContext vmContext = new PersistentVMRoleListContext() { ServiceName = service.ServiceName, Status = instance.InstanceStatus, Name = instance.RoleName }; WriteObject(vmContext, true); } } } catch (ServiceManagementClientException exc) { if (exc.HttpStatus != HttpStatusCode.NotFound) { throw; } } } } } } }
protected override void ProcessRecord() { try { Func <AffinityGroup, AffinityGroupContext> func = null; base.ProcessRecord(); Operation operation = null; IEnumerable <AffinityGroup> affinityGroupProcess = this.GetAffinityGroupProcess(out operation); if (affinityGroupProcess != null) { IEnumerable <AffinityGroup> affinityGroups = affinityGroupProcess; if (func == null) { func = (AffinityGroup affinityGroup) => { string str; IEnumerable <AffinityGroupContext.Service> services; IEnumerable <AffinityGroupContext.Service> services1; AffinityGroupContext affinityGroupContext = new AffinityGroupContext(); affinityGroupContext.set_OperationId(operation.OperationTrackingId); affinityGroupContext.set_OperationDescription(this.CommandRuntime.ToString()); affinityGroupContext.set_OperationStatus(operation.Status); affinityGroupContext.Name = affinityGroup.Name; AffinityGroupContext affinityGroupContext1 = affinityGroupContext; if (string.IsNullOrEmpty(affinityGroup.Label)) { str = null; } else { str = ServiceManagementHelper.DecodeFromBase64String(affinityGroup.Label); } affinityGroupContext1.Label = str; affinityGroupContext.Description = affinityGroup.Description; affinityGroupContext.Location = affinityGroup.Location; AffinityGroupContext affinityGroupContext2 = affinityGroupContext; if (affinityGroup.HostedServices != null) { HostedServiceList hostedServices = affinityGroup.HostedServices; services = hostedServices.Select <HostedService, AffinityGroupContext.Service>((HostedService p) => { AffinityGroupContext.Service service = new AffinityGroupContext.Service(); service.Url = p.Url; service.ServiceName = p.ServiceName; return(service); }); } else { services = new AffinityGroupContext.Service[0]; } affinityGroupContext2.HostedServices = services; AffinityGroupContext affinityGroupContext3 = affinityGroupContext; if (affinityGroup.StorageServices != null) { StorageServiceList storageServices = affinityGroup.StorageServices; services1 = storageServices.Select <StorageService, AffinityGroupContext.Service>((StorageService p) => { AffinityGroupContext.Service service = new AffinityGroupContext.Service(); service.Url = p.Url; service.ServiceName = p.ServiceName; return(service); }); } else { services1 = new AffinityGroupContext.Service[0]; } affinityGroupContext3.StorageServices = services1; return(affinityGroupContext); } ; } IEnumerable <AffinityGroupContext> affinityGroupContexts = affinityGroups.Select <AffinityGroup, AffinityGroupContext>(func); base.WriteObject(affinityGroupContexts, true); } } catch (Exception exception1) { Exception exception = exception1; base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null)); } }
LogObject(item); } } internal static void LogObject(DeploymentList deploymentList) { if (deploymentList == null) return; Console.WriteLine("DeploymentList contains {0} item(s).", deploymentList.Count); foreach (var item in deploymentList)
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(); } } } }