Ejemplo n.º 1
0
        public VirtualNetworkConfigContext GetVirtualNetworkConfigProcess()
        {
            this.ValidateParameters();

            VirtualNetworkConfigContext result = null;

            InvokeInOperationContext(() =>
            {
                try
                {
                    WriteVerboseWithTimestamp(string.Format(Resources.AzureVNetConfigBeginOperation, CommandRuntime.ToString()));

                    var netcfg    = this.NetworkClient.Networks.GetConfiguration();
                    var operation = GetOperationNewSM(netcfg.RequestId);

                    WriteVerboseWithTimestamp(string.Format(Resources.AzureVNetConfigCompletedOperation, CommandRuntime.ToString()));

                    if (netcfg != null)
                    {
                        // TODO: might want to change this to an XML object of some kind...
                        var xml = netcfg.Configuration;

                        var networkConfig = new VirtualNetworkConfigContext
                        {
                            XMLConfiguration     = xml,
                            OperationId          = operation.Id,
                            OperationDescription = CommandRuntime.ToString(),
                            OperationStatus      = operation.Status.ToString()
                        };

                        if (!string.IsNullOrEmpty(this.ExportToFile))
                        {
                            networkConfig.ExportToFile(this.ExportToFile);
                        }

                        result = networkConfig;
                    }
                }
                catch (CloudException ex)
                {
                    if (ex.Response.StatusCode == HttpStatusCode.NotFound && !IsVerbose())
                    {
                        result = null;
                    }
                    else
                    {
                        this.WriteExceptionDetails(ex);
                    }
                }
            });

            return(result);
        }
Ejemplo n.º 2
0
        public VirtualNetworkConfigContext GetVirtualNetworkConfigProcess()
        {
            this.ValidateParameters();

            VirtualNetworkConfigContext result = null;

            InvokeInOperationContext(() =>
            {
                try
                {
                    WriteVerboseWithTimestamp(string.Format(Resources.AzureVNetConfigBeginOperation, CommandRuntime.ToString()));

                    var netcfg = this.NetworkClient.Networks.GetConfiguration();
                    var operation = GetOperationNewSM(netcfg.RequestId);

                    WriteVerboseWithTimestamp(string.Format(Resources.AzureVNetConfigCompletedOperation, CommandRuntime.ToString()));

                    if (netcfg != null)
                    {
                        // TODO: might want to change this to an XML object of some kind...
                        var xml = netcfg.Configuration;

                        var networkConfig = new VirtualNetworkConfigContext
                        {
                            XMLConfiguration = xml,
                            OperationId = operation.Id,
                            OperationDescription = CommandRuntime.ToString(),
                            OperationStatus = operation.Status.ToString()
                        };

                        if (!string.IsNullOrEmpty(this.ExportToFile))
                        {
                            networkConfig.ExportToFile(this.ExportToFile);
                        }

                        result = networkConfig;
                    }
                }
                catch (CloudException ex)
                {
                    if (ex.Response.StatusCode == HttpStatusCode.NotFound && !IsVerbose())
                    {
                        result = null;
                    }
                    else
                    {
                        this.WriteExceptionDetails(ex);
                    }
                }
            });

            return result;
        }
Ejemplo n.º 3
0
        public VirtualNetworkConfigContext GetVirtualNetworkConfigProcess()
        {
            this.ValidateParameters();

            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                try
                {
                    WriteVerboseWithTimestamp(string.Format(Resources.AzureVNetConfigBeginOperation, CommandRuntime.ToString()));

                    var       netConfigStream = this.RetryCall(s => this.Channel.GetNetworkConfiguration(s)) as Stream;
                    Operation operation       = GetOperation();

                    WriteVerboseWithTimestamp(string.Format(Resources.AzureVNetConfigCompletedOperation, CommandRuntime.ToString()));

                    if (netConfigStream != null)
                    {
                        // TODO: might want to change this to an XML object of some kind...
                        var configReader = new StreamReader(netConfigStream);
                        var xml          = configReader.ReadToEnd();

                        var networkConfig = new VirtualNetworkConfigContext
                        {
                            XMLConfiguration     = xml,
                            OperationId          = operation.OperationTrackingId,
                            OperationDescription = CommandRuntime.ToString(),
                            OperationStatus      = operation.Status
                        };

                        if (!string.IsNullOrEmpty(this.ExportToFile))
                        {
                            networkConfig.ExportToFile(this.ExportToFile);
                        }

                        return(networkConfig);
                    }
                }
                catch (ServiceManagementClientException ex)
                {
                    if (ex.HttpStatus == HttpStatusCode.NotFound && !IsVerbose())
                    {
                        return(null);
                    }
                    else
                    {
                        this.WriteErrorDetails(ex);
                    }
                }

                return(null);
            }
        }
        public VirtualNetworkConfigContext GetVirtualNetworkConfigProcess()
        {
            VirtualNetworkConfigContext virtualNetworkConfigContext;
            Func <string, Stream>       func = null;

            this.ValidateParameters();
            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    GetAzureVNetConfigCommand getAzureVNetConfigCommand = this;
                    if (func == null)
                    {
                        func = (string s) => base.Channel.GetNetworkConfiguration(s);
                    }
                    Stream    stream    = ((CmdletBase <IServiceManagement>)getAzureVNetConfigCommand).RetryCall <Stream>(func);
                    Operation operation = base.WaitForOperation(base.CommandRuntime.ToString());
                    if (stream != null)
                    {
                        StreamReader streamReader = new StreamReader(stream);
                        string       end          = streamReader.ReadToEnd();
                        VirtualNetworkConfigContext virtualNetworkConfigContext1 = new VirtualNetworkConfigContext();
                        virtualNetworkConfigContext1.XMLConfiguration = end;
                        virtualNetworkConfigContext1.set_OperationId(operation.OperationTrackingId);
                        virtualNetworkConfigContext1.set_OperationDescription(base.CommandRuntime.ToString());
                        virtualNetworkConfigContext1.set_OperationStatus(operation.Status);
                        VirtualNetworkConfigContext virtualNetworkConfigContext2 = virtualNetworkConfigContext1;
                        if (!string.IsNullOrEmpty(this.ExportToFile))
                        {
                            virtualNetworkConfigContext2.ExportToFile(this.ExportToFile);
                        }
                        virtualNetworkConfigContext = virtualNetworkConfigContext2;
                        return(virtualNetworkConfigContext);
                    }
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    if (communicationException as EndpointNotFoundException == null || base.IsVerbose())
                    {
                        this.WriteErrorDetails(communicationException);
                    }
                    else
                    {
                        virtualNetworkConfigContext = null;
                        return(virtualNetworkConfigContext);
                    }
                }
                virtualNetworkConfigContext = null;
            }
            return(virtualNetworkConfigContext);
        }
 protected override void ProcessRecord()
 {
     try
     {
         base.ProcessRecord();
         VirtualNetworkConfigContext virtualNetworkConfigProcess = this.GetVirtualNetworkConfigProcess();
         if (virtualNetworkConfigProcess != null)
         {
             base.WriteObject(virtualNetworkConfigProcess, true);
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
     }
 }
        public VirtualNetworkConfigContext GetVirtualNetworkConfigProcess()
        {
            this.ValidateParameters();

            using (new OperationContextScope(Channel.ToContextChannel()))
            {
                try
                {
                    var netConfigStream = this.RetryCall(s => this.Channel.GetNetworkConfiguration(s)) as Stream;
                    Operation operation = WaitForOperation(CommandRuntime.ToString());

                    if (netConfigStream != null)
                    {
                        // TODO: might want to change this to an XML object of some kind...
                        var configReader = new StreamReader(netConfigStream);
                        var xml = configReader.ReadToEnd();

                        var networkConfig = new VirtualNetworkConfigContext
                        {
                            XMLConfiguration = xml,
                            OperationId = operation.OperationTrackingId,
                            OperationDescription = CommandRuntime.ToString(),
                            OperationStatus = operation.Status
                        };

                        if (!string.IsNullOrEmpty(this.ExportToFile))
                        {
                            networkConfig.ExportToFile(this.ExportToFile);
                        }

                        return networkConfig;
                    }
                }
                catch (ServiceManagementClientException ex)
                {
                    if (ex.HttpStatus == HttpStatusCode.NotFound && !IsVerbose())
                    {
                        return null;
                    }
                    else
                    {
                        this.WriteErrorDetails(ex);
                    }
                }

                return null;
            }
        }