Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
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);
            if (!string.IsNullOrEmpty(PublishSettings.Items.First().ManagementCertificate))
            {
                Certificate = General.GetCertificateFromStore(PublishSettings.Items.First().ManagementCertificate);
            }

            SubscriptionManager  = SubscriptionsManager.Import(GlobalPaths.SubscriptionsDataFile);
            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;
            }
        }
Ejemplo n.º 3
0
        public void ImportSubscriptionsFile(string subscriptionsDataFile, X509Certificate2 publishSettingsCertificate)
        {
            var subscriptions = General.DeserializeXmlFile <Subscriptions>(subscriptionsDataFile, string.Format(Resources.InvalidSubscriptionsDataSchema, subscriptionsDataFile));

            if (subscriptions != null && subscriptions.Subscription != null)
            {
                Subscriptions = subscriptions.Subscription
                                .Select(subscription =>
                {
                    X509Certificate2 certificate = null;
                    if (subscription.Thumbprint != null)
                    {
                        if (publishSettingsCertificate != null && subscription.Thumbprint == publishSettingsCertificate.Thumbprint)
                        {
                            certificate = publishSettingsCertificate;
                        }
                        else
                        {
                            certificate = General.GetCertificateFromStore(subscription.Thumbprint);
                        }
                    }

                    var subscriptionData = new SubscriptionData
                    {
                        SubscriptionName        = subscription.name,
                        SubscriptionId          = subscription.SubscriptionId,
                        Certificate             = certificate,
                        ServiceEndpoint         = subscription.ServiceEndpoint,
                        SqlAzureServiceEndpoint = subscription.SQLAzureServiceEndpoint,
                        CurrentStorageAccount   = subscription.CurrentStorageAccount
                    };

                    return(subscriptionData);
                })
                                .ToDictionary(subscriptionData => subscriptionData.SubscriptionName, StringComparer.OrdinalIgnoreCase);
            }
        }