예제 #1
0
        private void New(string subscriptionsDataFile, X509Certificate2 certificate, string serviceEndpoint)
        {
            Validate.ValidateStringIsNullOrEmpty(GlobalPaths.AzureDirectory, Resources.AzureDirectoryName);

            Certificate          = certificate;
            SubscriptionManager  = SubscriptionsManager.Import(subscriptionsDataFile, null, certificate);
            ServiceConfiguration = new ServiceConfiguration {
                endpoint = serviceEndpoint
            };
            PublishSettings = new PublishData();

            var publishDataProfile = new PublishDataPublishProfile
            {
                ManagementCertificate = certificate.Thumbprint,
                Url = ServiceConfiguration.endpoint
            };

            if (SubscriptionManager.Subscriptions != null &&
                SubscriptionManager.Subscriptions.Count > 0)
            {
                var subscription = SubscriptionManager.Subscriptions.Values.First();

                ServiceConfiguration.subscription     = subscription.SubscriptionId;
                ServiceConfiguration.subscriptionName = subscription.SubscriptionName;
                publishDataProfile.Subscription       = new [] {
                    new PublishDataPublishProfileSubscription
                    {
                        Id   = subscription.SubscriptionId,
                        Name = subscription.SubscriptionName
                    }
                };
            }

            PublishSettings.Items = new [] { publishDataProfile };
        }
예제 #2
0
        private void NewFromPublishSettings(string subscriptionsDataFile, string publishSettingsPath)
        {
            Validate.ValidateStringIsNullOrEmpty(GlobalPaths.AzureDirectory, Resources.AzureDirectoryName);
            Validate.ValidateFileFull(publishSettingsPath, Resources.PublishSettings);
            Validate.ValidateFileExtention(publishSettingsPath, Resources.PublishSettingsFileExtention);

            PublishSettings = General.DeserializeXmlFile <PublishData>(publishSettingsPath, string.Format(Resources.InvalidPublishSettingsSchema, publishSettingsPath));
            Certificate     = new X509Certificate2(Convert.FromBase64String(PublishSettings.Items[0].ManagementCertificate), string.Empty);
            PublishSettings.Items[0].ManagementCertificate = Certificate.Thumbprint;
            SubscriptionManager  = SubscriptionsManager.Import(subscriptionsDataFile, PublishSettings, Certificate);
            ServiceConfiguration = new ServiceConfiguration
            {
                endpoint         = PublishSettings.Items.First().Url,
                subscription     = PublishSettings.Items.First().Subscription.First().Id,
                subscriptionName = PublishSettings.Items.First().Subscription.First().Name
            };
        }
예제 #3
0
        internal void LoadCurrent()
        {
            Validate.ValidateDirectoryExists(GlobalPaths.AzureDirectory, Resources.GlobalComponents_Load_PublishSettingsNotFound);
            Validate.ValidateFileExists(GlobalPaths.PublishSettingsFile, string.Format(Resources.PathDoesNotExistForElement, Resources.PublishSettingsFileName, GlobalPaths.PublishSettingsFile));

            PublishSettings      = General.DeserializeXmlFile <PublishData>(GlobalPaths.PublishSettingsFile);
            Certificate          = General.GetCertificateFromStore(PublishSettings.Items.First().ManagementCertificate);
            SubscriptionManager  = SubscriptionsManager.Import(GlobalPaths.SubscriptionsDataFile);
            ServiceConfiguration = new JavaScriptSerializer().Deserialize <ServiceConfiguration>(File.ReadAllText(GlobalPaths.ServiceConfigurationFile));
            var defaultSubscription = SubscriptionManager.Subscriptions.Values.FirstOrDefault(subscription =>
                                                                                              subscription.SubscriptionId == ServiceConfiguration.subscription &&
                                                                                              (string.IsNullOrEmpty(ServiceConfiguration.subscriptionName) || subscription.SubscriptionName == ServiceConfiguration.subscriptionName));

            if (defaultSubscription != null)
            {
                defaultSubscription.IsDefault = true;
            }
        }