Esempio n. 1
0
        public override void  ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (Service.IsPresent)
            {
                IsDNSAvailable(CurrentSubscription.SubscriptionId, Name);
            }
            else if (Storage.IsPresent)
            {
                IsStorageServiceAvailable(CurrentSubscription.SubscriptionId, Name);
            }
            else
            {
                if (serviceBusChannel == null)
                {
                    serviceBusChannel = ServiceManagementHelper.CreateServiceManagementChannel <IServiceBusManagement>(
                        ServiceBinding,
                        new Uri(ServiceEndpoint),
                        CurrentSubscription.Certificate,
                        new HttpRestMessageInspector(text => this.WriteDebug(text)));
                }

                IsServiceBusNamespaceAvailable(CurrentSubscription.SubscriptionId, Name);
            }
        }
        protected override IServiceManagement CreateChannel()
        {
            // If ShareChannel is set by a unit test, use the same channel that
            // was passed into out constructor.  This allows the test to submit
            // a mock that we use for all network calls.
            if (ShareChannel)
            {
                return(Channel);
            }

            if (ServiceBinding == null)
            {
                ServiceBinding = ConfigurationConstants.WebHttpBinding(this.MaxStringContentLength);
            }

            if (string.IsNullOrEmpty(CurrentSubscription.ServiceEndpoint))
            {
                ServiceEndpoint = ConfigurationConstants.ServiceManagementEndpoint;
            }
            else
            {
                ServiceEndpoint = CurrentSubscription.ServiceEndpoint;
            }

            return(ServiceManagementHelper.CreateServiceManagementChannel(this.ServiceBinding, new Uri(this.ServiceEndpoint), CurrentSubscription.Certificate));
        }
        protected override IServiceManagement CreateChannel()
        {
            if (ServiceBinding == null)
            {
                ServiceBinding = ConfigurationConstants.WebHttpBinding();
            }

            ServiceEndpoint = string.IsNullOrEmpty(CurrentSubscription.ServiceEndpoint)
                ? ConfigurationConstants.ServiceManagementEndpoint
                : CurrentSubscription.ServiceEndpoint;

            return(ServiceManagementHelper.CreateServiceManagementChannel(ServiceBinding, new Uri(ServiceEndpoint), CurrentSubscription.Certificate));
        }
Esempio n. 4
0
        /// <summary>
        /// Connect to the Azure Management Service.
        /// </summary>
        /// <returns>An instance of the WCF service interface.</returns>
        protected IServiceManagement CreateChannel()
        {
            if (this.ServiceBinding == null)
            {
                this.ServiceBinding = ConfigurationConstants.WebHttpBinding();
            }

            if (string.IsNullOrEmpty(this.ServiceEndpoint))
            {
                this.ServiceEndpoint = ConfigurationConstants.ServiceEndpoint;
            }

            return(ServiceManagementHelper.CreateServiceManagementChannel(this.ServiceBinding, new Uri(this.ServiceEndpoint), this.ManagementCertificate));
        }
Esempio n. 5
0
        protected IDeploymentServiceManagement CreateDeploymentChannel(Repository repository)
        {
            // If ShareChannel is set by a unit test, use the same channel that
            // was passed into out constructor.  This allows the test to submit
            // a mock that we use for all network calls.
            if (ShareChannel)
            {
                return(DeploymentChannel);
            }

            return(ServiceManagementHelper.CreateServiceManagementChannel <IDeploymentServiceManagement>(
                       new Uri(repository.RepositoryUri),
                       repository.PublishingUsername,
                       repository.PublishingPassword,
                       new HttpRestMessageInspector(WriteDebug)));
        }
Esempio n. 6
0
        /// <summary>
        /// Creates new WebsitesClient.
        /// </summary>
        /// <param name="subscription">The Windows Azure subscription data object</param>
        /// <param name="logger">The logger action</param>
        public WebsitesClient(SubscriptionData subscription, Action <string> logger)
        {
            SubscriptionId = subscription.SubscriptionId;
            Logger         = logger;
            WebsiteChannel = ServiceManagementHelper.CreateServiceManagementChannel <IWebsitesServiceManagement>(
                ConfigurationConstants.WebHttpBinding(),
                new Uri(subscription.ServiceEndpoint),
                subscription.Certificate,
                new HttpRestMessageInspector(logger));

            ServiceManagementChannel = ServiceManagementHelper.CreateServiceManagementChannel <IServiceManagement>(
                ConfigurationConstants.WebHttpBinding(),
                new Uri(subscription.ServiceEndpoint),
                subscription.Certificate,
                new HttpRestMessageInspector(logger));
        }
Esempio n. 7
0
 /// <summary>
 /// Creates new instance from CloudServiceClient.
 /// </summary>
 /// <param name="subscription">The subscription data</param>
 /// <param name="debugStream">Action used to log http requests/responses</param>
 /// <param name="verboseStream">Action used to log detailed client progress</param>
 /// <param name="warningStream">Action used to log warning messages</param>
 public CloudServiceClient(
     SubscriptionData subscription,
     string currentLocation        = null,
     Action <string> debugStream   = null,
     Action <string> verboseStream = null,
     Action <string> warningStream = null)
 {
     Subscription             = subscription;
     subscriptionId           = subscription.SubscriptionId;
     CurrentDirectory         = currentLocation;
     DebugStream              = debugStream;
     VerboseStream            = verboseStream;
     WarningeStream           = warningStream;
     HeadersInspector         = new HeadersInspector();
     ServiceManagementChannel = ServiceManagementHelper.CreateServiceManagementChannel <IServiceManagement>(
         ConfigurationConstants.WebHttpBinding(),
         new Uri(subscription.ServiceEndpoint),
         subscription.Certificate,
         new HttpRestMessageInspector(DebugStream),
         HeadersInspector);
     CloudBlobUtility = new CloudBlobUtility();
 }
Esempio n. 8
0
        /// <summary>
        /// Creates new instance from the store client.
        /// </summary>
        /// <param name="subscriptionId">The Windows Azure subscription id</param>
        /// <param name="storeEndpointUri">The service management endpoint uri</param>
        /// <param name="cert">The authentication certificate</param>
        /// <param name="logger">The logger for http request/response</param>
        /// <param name="serviceManagementChannel">The service management channel</param>
        public StoreClient(
            string subscriptionId,
            string storeEndpointUri,
            X509Certificate2 cert,
            Action <string> logger,
            IServiceManagement serviceManagementChannel)
        {
            Validate.ValidateStringIsNullOrEmpty(storeEndpointUri, null, true);
            Validate.ValidateStringIsNullOrEmpty(subscriptionId, null, true);
            Validate.ValidateNullArgument(cert, Resources.NullCertificateMessage);

            this.subscriptionId = subscriptionId;
            headersInspector    = new HeadersInspector();
            storeChannel        = ServiceManagementHelper.CreateServiceManagementChannel <IStoreManagement>(
                ConfigurationConstants.WebHttpBinding(0),
                new Uri(storeEndpointUri),
                cert,
                new HttpRestMessageInspector(logger),
                headersInspector);
            this.serviceManagementChannel = serviceManagementChannel;
            MarketplaceClient             = new MarketplaceClient();
        }
        public void Run()
        {
            if (!ReadFromConfigFile() || !ValidateSubscriptionId() || !ValidateCertificate() || !this.Validate())
            {
                Console.WriteLine("There was an error processing this command!");
                return;
            }

            var serviceManagement = ServiceManagementHelper.CreateServiceManagementChannel("WindowsAzureEndPoint", CSManageCommand.Certificate);

            Console.WriteLine("Using certificate: " + CSManageCommand.Certificate.SubjectName.Name);

            try
            {
                string         trackingId        = null;
                HttpStatusCode?statusCode        = null;
                string         statusDescription = null;

                using (OperationContextScope scope = new OperationContextScope((IContextChannel)serviceManagement))
                {
                    try
                    {
                        this.PerformOperation(serviceManagement);
                        if (WebOperationContext.Current.IncomingResponse != null)
                        {
                            trackingId        = WebOperationContext.Current.IncomingResponse.Headers[Constants.OperationTrackingIdHeader];
                            statusCode        = WebOperationContext.Current.IncomingResponse.StatusCode;
                            statusDescription = WebOperationContext.Current.IncomingResponse.StatusDescription;
                            Console.WriteLine("Operation ID: {0}", trackingId);
                        }
                    }
                    catch (CommunicationException ce)
                    {
                        ServiceManagementError error          = null;
                        HttpStatusCode         httpStatusCode = 0;
                        string operationId;
                        ServiceManagementHelper.TryGetExceptionDetails(ce, out error, out httpStatusCode, out operationId);
                        if (error == null)
                        {
                            Console.WriteLine(ce.Message);
                        }
                        else
                        {
                            Console.WriteLine("HTTP Status Code: {0}", httpStatusCode);
                            Console.WriteLine("Error Message: {0}", error.Message);
                            Console.WriteLine("Operation Id: {0}", operationId);
                        }
                    }
                    finally
                    {
                        if (statusCode != null)
                        {
                            Console.WriteLine("HTTP Status Code: {0}", statusCode);
                            Console.WriteLine("StatusDescription: {0}", statusDescription);
                        }
                    }
                }
                if (trackingId != null && statusCode != null && statusCode == HttpStatusCode.Accepted)
                {
                    Console.WriteLine("Waiting for async operation to complete:");
                    WaitForAsyncOperation(serviceManagement, trackingId);
                }
            }
            catch (TimeoutException)
            {
                Console.WriteLine("There was an error processing this command.");
            }
        }