public static SubscriptionsManager Import(string subscriptionsDataFile, PublishData publishSettings, X509Certificate2 certificate) { var subscriptionsManager = new SubscriptionsManager(); if (File.Exists(subscriptionsDataFile)) { subscriptionsManager.ImportSubscriptionsFile(subscriptionsDataFile, certificate); } if (publishSettings != null) { foreach (var subscription in publishSettings.Items.Single().Subscription) { var subscriptionData = subscriptionsManager.Subscriptions.ContainsKey(subscription.Name) ? subscriptionsManager.Subscriptions[subscription.Name] : new SubscriptionData { SubscriptionName = subscription.Name }; subscriptionData.SubscriptionId = subscription.Id; if (!string.IsNullOrEmpty(subscription.ManagementCertificate)) { subscriptionData.Certificate = new X509Certificate2(Convert.FromBase64String(subscription.ManagementCertificate), string.Empty); } else { subscriptionData.Certificate = certificate; } if (!string.IsNullOrEmpty(subscription.ServiceManagementUrl)) { subscriptionData.ServiceEndpoint = subscription.ServiceManagementUrl; } else { subscriptionData.ServiceEndpoint = publishSettings.Items.Single().Url; } subscriptionsManager.Subscriptions[subscriptionData.SubscriptionName] = subscriptionData; } } return subscriptionsManager; }
internal void LoadCurrent() { // Try load environments.xml try { customEnvironments = General.DeserializeXmlFile<List<WindowsAzureEnvironment>>( GlobalPaths.EnvironmentsFile); } catch { customEnvironments = new List<WindowsAzureEnvironment>(); } // Try load publishSettings.xml try { PublishSettings = General.DeserializeXmlFile<PublishData>(GlobalPaths.PublishSettingsFile); if (!string.IsNullOrEmpty(PublishSettings.Items.First().ManagementCertificate)) { Certificate = General.GetCertificateFromStore(PublishSettings.Items.First().ManagementCertificate); } } catch { PublishSettings = null; Certificate = null; } // Try load subscriptionsData.xml try { SubscriptionManager = SubscriptionsManager.Import(GlobalPaths.SubscriptionsDataFile); } catch { SubscriptionManager = new SubscriptionsManager(); } // Try load config.json try { ServiceConfiguration = new JavaScriptSerializer().Deserialize<CloudServiceProjectConfiguration>( 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; } } catch { ServiceConfiguration = null; } }