Пример #1
0
        public static SubscriptionData GetCurrentSubscription(this PSCmdlet cmdlet)
        {
            // Check if there is a current subscription already set
            var currentSubscription = SessionManager.GetVariable(cmdlet, ManagementConstants.CurrentSubscriptionEnvironmentVariable) as SubscriptionData;

            if (currentSubscription == null)
            {
                try
                {
                    // Check if there is a default subscription available
                    GlobalSettingsManager globalSettingsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory);
                    currentSubscription =
                        globalSettingsManager.Subscriptions.Values.FirstOrDefault(subscription => subscription.IsDefault);

                    if (currentSubscription != null)
                    {
                        // Set the default subscription to be the new current subscription
                        SessionManager.SetVariable(cmdlet, ManagementConstants.CurrentSubscriptionEnvironmentVariable,
                                                   currentSubscription);
                    }
                }
                catch (FileNotFoundException)
                {
                    return(null);
                }
            }

            return(currentSubscription);
        }
Пример #2
0
        public static void UpdateSubscriptions(this PSCmdlet cmdlet, IDictionary <string, SubscriptionData> subscriptionsData, string subscriptionDataFile)
        {
            GlobalSettingsManager globalSettingsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory, subscriptionDataFile);

            globalSettingsManager.SubscriptionManager.Subscriptions = subscriptionsData;
            globalSettingsManager.SaveSubscriptions();
        }
Пример #3
0
        public static void SetDefaultSubscription(this PSCmdlet cmdlet, string subscriptionName, string subscriptionDataFile)
        {
            GlobalSettingsManager globalSettingsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory, subscriptionDataFile);

            if (globalSettingsManager.Subscriptions.Count > 1)
            {
                var defaultSubscription = globalSettingsManager.Subscriptions.Values.FirstOrDefault(subscription => subscription.IsDefault);
                if (defaultSubscription != null)
                {
                    defaultSubscription.IsDefault = false;
                }

                if (subscriptionName != null)
                {
                    defaultSubscription           = globalSettingsManager.Subscriptions.Values.First(subscription => subscription.SubscriptionName == subscriptionName);
                    defaultSubscription.IsDefault = true;
                }
                else
                {
                    defaultSubscription           = globalSettingsManager.Subscriptions.Values.First();
                    defaultSubscription.IsDefault = true;
                }

                globalSettingsManager.SaveSubscriptions();
            }
        }
Пример #4
0
        public static GlobalSettingsManager Load(string azurePath, string subscriptionsDataFile)
        {
            var globalSettingsManager = new GlobalSettingsManager(azurePath, subscriptionsDataFile);

            globalSettingsManager.LoadCurrent();

            return(globalSettingsManager);
        }
Пример #5
0
 /// <summary>
 /// Sets the current subscription to the passed subscription name. If null, no changes.
 /// </summary>
 /// <param name="subscriptionName">The subscription name</param>
 public void SetCurrentSubscription(string subscriptionName)
 {
     if (!string.IsNullOrEmpty(subscriptionName))
     {
         GlobalSettingsManager globalSettingsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory);
         CurrentSubscription = globalSettingsManager.Subscriptions.Values.First(sub => sub.SubscriptionName == subscriptionName);
     }
 }
        public static GlobalSettingsManager Load(string azurePath, string subscriptionsDataFile)
        {
            Validate.ValidateNullArgument(azurePath, string.Format(Resources.InvalidNullArgument, "azurePath"));
            Validate.ValidateStringIsNullOrEmpty(azurePath, Resources.AzureDirectoryName);

            var globalSettingsManager = new GlobalSettingsManager(azurePath, subscriptionsDataFile);

            globalSettingsManager.LoadCurrent();

            return(globalSettingsManager);
        }
Пример #7
0
        public static GlobalSettingsManager CreateFromPublishSettings(
            string azurePath,
            string subscriptionsDataFile,
            string publishSettingsFile)
        {
            Validate.ValidateNullArgument(azurePath, string.Format(Resources.InvalidNullArgument, "azurePath"));

            var globalSettingsManager = new GlobalSettingsManager(azurePath, subscriptionsDataFile);

            globalSettingsManager.NewFromPublishSettings(
                globalSettingsManager.GlobalPaths.SubscriptionsDataFile,
                publishSettingsFile);
            globalSettingsManager.Save();

            return(globalSettingsManager);
        }
Пример #8
0
        public static GlobalSettingsManager Create(
            string azurePath,
            string subscriptionsDataFile,
            X509Certificate2 certificate,
            string serviceEndpoint)
        {
            Validate.ValidateNullArgument(azurePath, string.Format(Resources.InvalidNullArgument, "azurePath"));
            Validate.ValidateNullArgument(certificate, string.Format(Resources.InvalidCertificateSingle, "certificate"));
            Validate.ValidateNullArgument(serviceEndpoint, string.Format(Resources.InvalidEndpoint, "serviceEndpoint"));

            var globalSettingsManager = new GlobalSettingsManager(azurePath, subscriptionsDataFile);

            globalSettingsManager.New(globalSettingsManager.GlobalPaths.SubscriptionsDataFile, certificate, serviceEndpoint);
            globalSettingsManager.Save();

            return(globalSettingsManager);
        }
Пример #9
0
        public static void SetCurrentSubscription(this PSCmdlet cmdlet, string subscriptionName, string subscriptionDataFile)
        {
            if (subscriptionName == null)
            {
                throw new ArgumentNullException("subscriptionName", Resources.InvalidSubscriptionName);
            }

            var globalSettingsManager = GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory, subscriptionDataFile);

            SubscriptionData subscriptionData;

            if (!globalSettingsManager.Subscriptions.TryGetValue(subscriptionName, out subscriptionData))
            {
                throw new ArgumentException(string.Format(
                                                CultureInfo.InvariantCulture,
                                                Resources.InvalidSubscription,
                                                subscriptionName));
            }

            SetCurrentSubscription(cmdlet, subscriptionData);
        }
        public static GlobalSettingsManager Load(string azurePath, string subscriptionsDataFile)
        {
            var globalSettingsManager = new GlobalSettingsManager(azurePath, subscriptionsDataFile);
            globalSettingsManager.LoadCurrent();

            return globalSettingsManager;
        }
        public static GlobalSettingsManager CreateFromPublishSettings(
            string azurePath,
            string subscriptionsDataFile,
            string publishSettingsFile)
        {
            Validate.ValidateNullArgument(azurePath, string.Format(Resources.InvalidNullArgument, "azurePath"));

            var globalSettingsManager = new GlobalSettingsManager(azurePath, subscriptionsDataFile);
            globalSettingsManager.NewFromPublishSettings(
                globalSettingsManager.GlobalPaths.SubscriptionsDataFile,
                publishSettingsFile);
            globalSettingsManager.Save();

            return globalSettingsManager;
        }
        public static GlobalSettingsManager Create(
            string azurePath,
            string subscriptionsDataFile,
            X509Certificate2 certificate,
            string serviceEndpoint)
        {
            Validate.ValidateNullArgument(azurePath, string.Format(Resources.InvalidNullArgument, "azurePath"));
            Validate.ValidateNullArgument(certificate, string.Format(Resources.InvalidCertificateSingle, "certificate"));
            Validate.ValidateNullArgument(serviceEndpoint, string.Format(Resources.InvalidEndpoint, "serviceEndpoint"));

            var globalSettingsManager = new GlobalSettingsManager(azurePath, subscriptionsDataFile);
            globalSettingsManager.New(globalSettingsManager.GlobalPaths.SubscriptionsDataFile, certificate, serviceEndpoint);
            globalSettingsManager.Save();

            return globalSettingsManager;
        }
        public static GlobalSettingsManager Load(string azurePath, string subscriptionsDataFile)
        {
            Validate.ValidateNullArgument(azurePath, string.Format(Resources.InvalidNullArgument, "azurePath"));
            Validate.ValidateStringIsNullOrEmpty(azurePath, Resources.AzureDirectoryName);

            var globalSettingsManager = new GlobalSettingsManager(azurePath, subscriptionsDataFile);
            globalSettingsManager.LoadCurrent();

            return globalSettingsManager;
        }
Пример #14
0
 public static void AreEqualGlobalSettingsManager(GlobalPathInfo paths, PublishData publishSettings, GlobalSettingsManager actual)
 {
     AreEqualGlobalPathInfo(paths, actual.GlobalPaths);
 }
Пример #15
0
 public static void AreEqualGlobalSettingsManager(GlobalSettingsManager expected, GlobalSettingsManager actual)
 {
     AreEqualGlobalSettingsManager(expected.GlobalPaths, expected.PublishSettings, actual);
 }
Пример #16
0
 public static IDictionary <string, SubscriptionData> GetSubscriptions(this PSCmdlet cmdlet, string subscriptionDataFile)
 {
     return(GlobalSettingsManager.Load(GlobalPathInfo.GlobalSettingsDirectory, subscriptionDataFile).Subscriptions);
 }