示例#1
0
        public void TestSetCurrentSubscription()
        {
            var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var selectSubscriptionCommand = new SelectAzureSubscriptionCommand();

            // Check that current subscription is the default one
            Assert.AreEqual("Windows Azure Sandbox 9-220", selectSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Change it and make sure it got changed
            selectSubscriptionCommand.SelectSubscriptionProcess("Set", "mysub1", Data.ValidSubscriptionsData.First());
            Assert.AreEqual("mysub1", selectSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Clean
            globalComponents.DeleteGlobalComponents();
        }
        public void GlobalComponentsCreateNew()
        {
            foreach (string fileName in Data.ValidPublishSettings)
            {
                // Prepare
                GlobalComponents globalComponents        = new GlobalComponents(fileName, Data.AzureSdkAppDir);
                PublishData      actualPublishSettings   = General.DeserializeXmlFile <PublishData>(Path.Combine(Data.AzureSdkAppDir, Resources.PublishSettingsFileName));
                PublishData      expectedPublishSettings = General.DeserializeXmlFile <PublishData>(fileName);

                // Assert
                AzureAssert.AreEqualGlobalComponents(actualPublishSettings.Items[0].ManagementCertificate, new GlobalPathInfo(Data.AzureSdkAppDir), new ServiceSettings(), expectedPublishSettings, globalComponents);

                // Clean
                new RemoveAzurePublishSettingsCommand().RemovePublishSettingsProcess(Data.AzureSdkAppDir);
            }
        }
示例#3
0
        /// <summary>
        /// Create a temporary Azure SDK directory to simulate global files.
        /// </summary>
        /// <param name="publishSettingsPath">
        /// Path to the publish settings.
        /// </param>
        /// <returns>The path to the temporary Azure SDK directory.</returns>
        public string CreateAzureSdkDirectoryAndImportPublishSettings(string publishSettingsPath)
        {
            Debug.Assert(!string.IsNullOrEmpty(publishSettingsPath));
            Debug.Assert(File.Exists(publishSettingsPath));
            Debug.Assert(string.IsNullOrEmpty(AzureSdkPath));

            AzureSdkPath = CreateDirectory("AzureSdk");
            GlobalPathInfo.GlobalSettingsDirectory = AzureSdkPath;
            GlobalComponents globalComponents = GlobalComponents.CreateFromPublishSettings(
                GlobalPathInfo.GlobalSettingsDirectory,
                null,
                publishSettingsPath);

            GlobalPathInfo.GlobalSettingsDirectory = AzureSdkPath;

            return(AzureSdkPath);
        }
        public void TestImportSubscriptionProcess()
        {
            var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var importSubscriptionCommand = new ImportAzurePublishSettingsCommand();

            importSubscriptionCommand.ImportSubscriptionProcess(
                Data.ValidPublishSettings.First(),
                null);

            var currentSubscription = importSubscriptionCommand.GetCurrentSubscription();

            Assert.AreEqual(currentSubscription.SubscriptionName, "Windows Azure Sandbox 9-220");
            Assert.IsTrue(currentSubscription.IsDefault);

            globalComponents.DeleteGlobalComponents();
        }
 public void GlobalComponentsCreateNewEmptyAzureDirectoryFail()
 {
     foreach (string fileName in Data.ValidSubscriptionsData)
     {
         try
         {
             GlobalComponents.Load(string.Empty, fileName);
             Assert.Fail("No exception thrown");
         }
         catch (Exception ex)
         {
             Assert.IsTrue(ex is ArgumentException);
             Assert.AreEqual <string>(ex.Message, string.Format(Resources.InvalidOrEmptyArgumentMessage, Resources.AzureDirectoryName));
             Assert.IsFalse(Directory.Exists(Data.AzureAppDir));
         }
     }
 }
 public void GlobalComponentsCreateNewInvalidPublishSettingsSchemaFail()
 {
     foreach (string fileName in Data.InvalidPublishSettings)
     {
         try
         {
             GlobalComponents.CreateFromPublishSettings(Data.AzureAppDir, null, fileName);
             Assert.Fail("No exception thrown");
         }
         catch (Exception ex)
         {
             Assert.IsTrue(ex is InvalidOperationException);
             Assert.AreEqual <string>(ex.Message, string.Format(Resources.InvalidPublishSettingsSchema, fileName));
             Assert.IsFalse(Directory.Exists(Data.AzureAppDir));
         }
     }
 }
示例#7
0
        public void RemoveSubscriptionProcess(string subscriptionName, string subscriptionsDataFile)
        {
            // Import subscriptions from subscriptions file
            var globalComponents = GlobalComponents.Load(
                GlobalPathInfo.GlobalSettingsDirectory,
                this.ResolvePath(subscriptionsDataFile));

            if (globalComponents.Subscriptions.ContainsKey(subscriptionName))
            {
                var subscription = globalComponents.Subscriptions[subscriptionName];

                // Warn the user if the removed subscription is the default one.
                if (subscription.IsDefault)
                {
                    WriteWarning(Resources.RemoveDefaultSubscription);
                    // Change default to another one
                    var newSubscriptionDefault = globalComponents.Subscriptions.Values.FirstOrDefault(s => !s.SubscriptionId.Equals(subscription.SubscriptionId));
                    if (newSubscriptionDefault != null)
                    {
                        newSubscriptionDefault.IsDefault = true;
                    }
                }

                // Warn the user if the removed subscription is the current one.
                SubscriptionData currentSubscription = this.GetCurrentSubscription();
                if (currentSubscription != null && currentSubscription.SubscriptionId.Equals(subscription.SubscriptionId))
                {
                    WriteWarning(Resources.RemoveCurrentSubscription);

                    // Clear current subscription to another one
                    this.ClearCurrentSubscription();
                }

                globalComponents.Subscriptions.Remove(subscriptionName);
                globalComponents.SaveSubscriptions();

                if (PassThru.IsPresent)
                {
                    WriteObject(true);
                }
            }
            else
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.InvalidSubscription, subscriptionName));
            }
        }
 public void GlobalComponentsLoadExistingNullAzureDirectoryFail()
 {
     foreach (string fileName in Data.ValidPublishSettings)
     {
         try
         {
             GlobalComponents.Load(null);
             Assert.Fail("No exception thrown");
         }
         catch (Exception ex)
         {
             Assert.IsTrue(ex is ArgumentException);
             Assert.AreEqual <string>("Value cannot be null. Parameter name: 'azurePath'", ex.Message);
             Assert.IsFalse(Directory.Exists(Data.AzureAppDir));
         }
     }
 }
        public void TestSetDefaultSubscription()
        {
            var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that current subscription is the default one
            Assert.AreEqual("Windows Azure Sandbox 9-220", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Change it and make sure it got changed
            setSubscriptionCommand.SetSubscriptionProcess("DefaultSubscription", null, null, null, null, "TestSubscription1", null, null);
            Assert.AreEqual("TestSubscription1", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);
            Assert.AreEqual("TestSubscription1", setSubscriptionCommand.GetSubscriptions(null).Values.Single(sub => sub.IsDefault).SubscriptionName);

            // Clean
            globalComponents.DeleteGlobalComponents();
        }
 public void GlobalComponentsLoadExistingEmptyAzureDirectoryFail()
 {
     foreach (string fileName in Data.ValidPublishSettings)
     {
         try
         {
             GlobalComponents.Load("fake");
             Assert.Fail("No exception thrown");
         }
         catch (Exception ex)
         {
             Assert.IsTrue(ex is FileNotFoundException);
             Assert.AreEqual <string>(ex.Message, Resources.GlobalComponents_Load_PublishSettingsNotFound);
             Assert.IsFalse(Directory.Exists(Data.AzureAppDir));
         }
     }
 }
        public bool RemoveAzureServiceProcess(string rootName, string inSubscription)
        {
            string          serviceName;
            ServiceSettings settings = base.GetDefaultSettings(rootName, null, null, null, null, inSubscription, out serviceName);

            subscriptionId = new GlobalComponents(GlobalPathInfo.GlobalSettingsDirectory).GetSubscriptionId(settings.Subscription);
            if (!ShouldProcess("", string.Format(Resources.RemoveServiceWarning, serviceName), Resources.ShouldProcessCaption))
            {
                return(false);
            }
            SafeWriteObjectWithTimestamp(Resources.RemoveServiceStartMessage, serviceName);
            SafeWriteObjectWithTimestamp(Resources.RemoveDeploymentMessage);
            StopAndRemove(rootName, serviceName, settings.Subscription, ArgumentConstants.Slots[Slot.Production]);
            StopAndRemove(rootName, serviceName, settings.Subscription, ArgumentConstants.Slots[Slot.Staging]);
            SafeWriteObjectWithTimestamp(Resources.RemoveServiceMessage);
            RemoveService(serviceName);
            return(true);
        }
        public void TestRemoveNonDefaultSubscriptionProcess()
        {
            for (var i = 0; i < Data.ValidPublishSettings.Count; i++)
            {
                var targetFile = Path.Combine(Directory.GetParent(Data.ValidSubscriptionsData[i]).FullName, "removeagain" + Path.GetFileName(Data.ValidSubscriptionsData[i]));
                File.Copy(Data.ValidSubscriptionsData[i], targetFile, true);
                var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, targetFile, Data.ValidPublishSettings[i]);

                var removeSubscriptionCommand = new RemoveAzureSubscriptionCommand();
                removeSubscriptionCommand.RemoveSubscriptionProcess("mysub2", targetFile);

                var subscriptionsManager = GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory, targetFile);
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.SubscriptionName == "mysub2"));
                Assert.IsTrue(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.IsDefault));

                // Clean
                globalComponents.DeleteGlobalComponents();
            }
        }
        public void TestUpdateSubscription()
        {
            var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that current subscription is the default one
            Assert.AreEqual("Windows Azure Sandbox 9-220", setSubscriptionCommand.GetCurrentSubscription().SubscriptionName);

            // Change it and make sure it got changed
            setSubscriptionCommand.SetSubscriptionProcess("CommonSettings", "TestSubscription1", "newSubscriptionId", null, "newEndpoint", null, null, null);
            var updatedSubscription = setSubscriptionCommand.GetSubscriptions(null).Values.First(subscription => subscription.SubscriptionName == "TestSubscription1");

            Assert.AreEqual("newSubscriptionId", updatedSubscription.SubscriptionId);
            Assert.AreEqual("newEndpoint", updatedSubscription.ServiceEndpoint);

            // Clean
            globalComponents.DeleteGlobalComponents();
        }
示例#14
0
        public void TestGetCurrentSubscription()
        {
            var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var cmdletStub    = new CmdletStub();
            var subscriptions = cmdletStub.GetSubscriptions(null);

            var currentSubscription = subscriptions.Values.First();

            cmdletStub.SetCurrentSubscription(currentSubscription.SubscriptionName, null);

            // Test
            var actualCurrentSubscription = cmdletStub.GetCurrentSubscription();

            Assert.AreEqual(currentSubscription.SubscriptionName, actualCurrentSubscription.SubscriptionName);
            Assert.AreEqual(currentSubscription.SubscriptionId, actualCurrentSubscription.SubscriptionId);

            globalComponents.DeleteGlobalComponents();
        }
示例#15
0
        private void RegisterResourceProviders(GlobalComponents globalComponents, string subscriptionName)
        {
            SubscriptionData    subscription = globalComponents.SubscriptionManager.Subscriptions[subscriptionName];
            ISubscriptionClient client       = GetSubscriptionClient(subscription);
            var knownProviders      = new List <string>(ProviderRegistrationConstants.GetKnownResourceTypes());
            var providers           = new List <ProviderResource>(client.ListResources(knownProviders));
            var providersToRegister = providers
                                      .Where(p => p.State == ProviderRegistrationConstants.Unregistered)
                                      .Select(p => p.Type).ToList();

            try
            {
                Task.WaitAll(providersToRegister.Select(client.RegisterResourceTypeAsync).Cast <Task>().ToArray());
            }
            catch (AggregateException)
            {
                // It's ok for registration to fail.
            }
        }
        public void GlobalComponentsLoadExisting()
        {
            for (var i = 0; i < Data.ValidPublishSettings.Count; i++)
            {
                var publishSettingsFile = Data.ValidPublishSettings[i];

                // Prepare
                new ImportAzurePublishSettingsCommand().ImportSubscriptionProcess(publishSettingsFile, null);
                GlobalComponents globalComponents        = GlobalComponents.Load(Data.AzureAppDir);
                PublishData      actualPublishSettings   = General.DeserializeXmlFile <PublishData>(Path.Combine(Data.AzureAppDir, Resources.PublishSettingsFileName));
                PublishData      expectedPublishSettings = General.DeserializeXmlFile <PublishData>(publishSettingsFile);

                // Assert
                AzureAssert.AreEqualGlobalComponents(new GlobalPathInfo(Data.AzureAppDir), expectedPublishSettings, globalComponents);

                // Clean
                globalComponents.DeleteGlobalComponents();
            }
        }
示例#17
0
        /// <summary>
        /// Initialize our model of the AzureService located at the given
        /// path along with its DeploymentSettings and SubscriptionId.
        /// </summary>
        /// <param name="rootPath">Root path of the Azure service.</param>
        internal void InitializeSettingsAndCreatePackage(string rootPath)
        {
            Debug.Assert(!string.IsNullOrEmpty(rootPath), "rootPath cannot be null or empty.");
            Debug.Assert(Directory.Exists(rootPath), "rootPath does not exist.");

            _azureService = new AzureService(rootPath, null);

            // If user provided a service name, change current service name to use it.
            //
            if (!string.IsNullOrEmpty(Name))
            {
                _azureService.ChangeServiceName(Name, _azureService.Paths);
            }

            ServiceSettings defaultSettings = ServiceSettings.LoadDefault(
                _azureService.Paths.Settings,
                Slot,
                Location,
                Subscription,
                StorageAccountName,
                Name,
                _azureService.ServiceName,
                out _hostedServiceName);

            subscriptionId =
                new GlobalComponents(GlobalPathInfo.GlobalSettingsDirectory)
                .GetSubscriptionId(defaultSettings.Subscription);

            SafeWriteObjectWithTimestamp(String.Format(Resources.PublishPreparingDeploymentMessage,
                                                       _hostedServiceName, subscriptionId));

            UpdateLocation(_azureService.Paths.Definition, defaultSettings.Location.ToUpper());

            CreatePackage();

            _deploymentSettings = new DeploymentSettings(
                defaultSettings,
                _azureService.Paths.CloudPackage,
                _azureService.Paths.CloudConfiguration,
                _hostedServiceName,
                string.Format(Resources.ServiceDeploymentName, defaultSettings.Slot));
        }
 public void GlobalComponentsLoadExistingInvalidDirectoryNameAzureDirectoryFail()
 {
     foreach (string fileName in Data.ValidPublishSettings)
     {
         foreach (string invalidDirectoryName in Data.InvalidServiceRootName)
         {
             try
             {
                 GlobalComponents.Load(invalidDirectoryName);
                 Assert.Fail("No exception thrown");
             }
             catch (Exception ex)
             {
                 Assert.IsTrue(ex is ArgumentException);
                 Assert.AreEqual <string>(ex.Message, "Illegal characters in path.");
                 Assert.IsFalse(Directory.Exists(Data.AzureAppDir));
             }
         }
     }
 }
示例#19
0
        public void TestUpdateSubscriptions()
        {
            var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var cmdletStub    = new CmdletStub();
            var subscriptions = cmdletStub.GetSubscriptions(Data.ValidSubscriptionsData[0]);

            var deleteSubscriptionKey = subscriptions.Keys.First();

            subscriptions.Remove(deleteSubscriptionKey);

            var newPath = Path.Combine(GlobalPathInfo.GlobalSettingsDirectory, "test.xml");

            cmdletStub.UpdateSubscriptions(subscriptions, newPath);

            var newSubscriptions = cmdletStub.GetSubscriptions(newPath);

            Assert.IsFalse(newSubscriptions.ContainsKey(deleteSubscriptionKey));

            globalComponents.DeleteGlobalComponents();
        }
示例#20
0
        public static void SetCurrentSubscription(this PSCmdlet cmdlet, string subscriptionName, string subscriptionDataFile)
        {
            if (subscriptionName == null)
            {
                throw new ArgumentNullException("subscriptionName", Resources.InvalidSubscriptionName);
            }

            var globalComponents = GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory, subscriptionDataFile);

            SubscriptionData subscriptionData;

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

            SetCurrentSubscription(cmdlet, subscriptionData);
        }
示例#21
0
        public void TestImportSubscriptionProcess()
        {
            MockCommandRuntime mockCommandRuntime;
            ImportAzurePublishSettingsCommand cmdlet;

            mockCommandRuntime    = new MockCommandRuntime();
            cmdlet                = new ImportAzurePublishSettingsCommand();
            cmdlet.CommandRuntime = mockCommandRuntime;
            var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());


            cmdlet.ImportSubscriptionFile(
                Data.ValidPublishSettings.First(),
                null);

            var currentSubscription = cmdlet.GetCurrentSubscription();

            Assert.AreEqual(currentSubscription.SubscriptionName, Data.Subscription1);
            Assert.IsTrue(currentSubscription.IsDefault);

            globalComponents.DeleteGlobalComponents();
        }
        public void TestCreateSubscriptionNoImport()
        {
            var setSubscriptionCommand = new SetSubscriptionCommandStub();

            // Check that we cant get a current subscription as there is no working directory
            Assert.IsNull(setSubscriptionCommand.GetCurrentSubscription());

            // Create a new subscription and a new working directory implicitly.
            var publishSettings = General.DeserializeXmlFile <PublishData>(Data.ValidPublishSettings.First(), string.Empty);
            var certificate     = new X509Certificate2(Convert.FromBase64String(publishSettings.Items[0].ManagementCertificate), string.Empty);

            setSubscriptionCommand.SetSubscriptionProcess("CommonSettings", "newSubscription", "newSubscriptionId", certificate, "newEndpoint", null, null, null);
            var updatedSubscription = setSubscriptionCommand.GetSubscriptions(null).Values.First(subscription => subscription.SubscriptionName == "newSubscription");

            Assert.AreEqual("newSubscriptionId", updatedSubscription.SubscriptionId);
            Assert.AreEqual("newEndpoint", updatedSubscription.ServiceEndpoint);

            // Clean
            var globalComponents = GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory);

            globalComponents.DeleteGlobalComponents();
        }
示例#23
0
        public void TestRemoveCurrentSubscriptionProcess()
        {
            for (var i = 0; i < Data.ValidPublishSettings.Count; i++)
            {
                var targetFile = Path.Combine(Directory.GetParent(Data.ValidSubscriptionsData[i]).FullName, "removeonce" + Path.GetFileName(Data.ValidSubscriptionsData[i]));
                File.Copy(Data.ValidSubscriptionsData[i], targetFile, true);
                var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, targetFile, Data.ValidPublishSettings[i]);
                MockCommandRuntime mockCommandRuntime = new MockCommandRuntime();

                var removeSubscriptionCommand = new RemoveAzureSubscriptionCommand();
                removeSubscriptionCommand.SetCurrentSubscription(globalComponents.Subscriptions["mysub1"]);
                removeSubscriptionCommand.CommandRuntime = mockCommandRuntime;
                removeSubscriptionCommand.RemoveSubscriptionProcess("mysub1", targetFile);

                var subscriptionsManager = SubscriptionsManager.Import(targetFile);
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.SubscriptionName == "mysub1"));
                Assert.IsFalse(subscriptionsManager.Subscriptions.Values.Any(subscription => subscription.IsDefault));
                Assert.IsNull(removeSubscriptionCommand.GetCurrentSubscription());

                // Clean
                globalComponents.DeleteGlobalComponents();
            }
        }
示例#24
0
        public void TestSetDefaultSubscription()
        {
            var globalComponents = GlobalComponents.CreateFromPublishSettings(GlobalPathInfo.GlobalSettingsDirectory, null, Data.ValidPublishSettings.First());

            var newPath = Path.Combine(GlobalPathInfo.GlobalSettingsDirectory, "test.xml");

            File.Copy(Data.ValidSubscriptionsData[0], newPath, true);

            var cmdletStub    = new CmdletStub();
            var subscriptions = cmdletStub.GetSubscriptions(Data.ValidSubscriptionsData[0]);

            var newDefaultSubscription = subscriptions.Values.First(subscription => !subscription.IsDefault);

            cmdletStub.SetDefaultSubscription(newDefaultSubscription.SubscriptionName, newPath);

            // Test - reimport and make sure the current subscription after import is the correct one
            var subscriptionsManager = GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory, newPath).SubscriptionManager;
            var defaultSubscription  = subscriptionsManager.Subscriptions.Values.First(subscription => subscription.IsDefault);

            Assert.AreEqual(newDefaultSubscription.SubscriptionName, defaultSubscription.SubscriptionName);

            globalComponents.DeleteGlobalComponents();
        }
示例#25
0
        public virtual string SetDeploymentStatusProcess(string rootPath, string newStatus, string slot, string subscription, string serviceName)
        {
            if (!string.IsNullOrEmpty(subscription))
            {
                var globalComponents = GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory);
                CurrentSubscription = globalComponents.Subscriptions.Values.First(
                    sub => sub.SubscriptionName == subscription);
            }

            string result = CheckDeployment(newStatus, serviceName, slot);

            if (string.IsNullOrEmpty(result))
            {
                SetDeployment(newStatus, serviceName, slot);
                var deploymentStatusCommand = new GetDeploymentStatus(Channel)
                {
                    ShareChannel = ShareChannel, CurrentSubscription = CurrentSubscription
                };
                deploymentStatusCommand.WaitForState(newStatus, rootPath, serviceName, slot, CurrentSubscription.SubscriptionName);
            }

            return(result);
        }
        public void GlobalComponentsLoadIgnoresPublishExisting()
        {
            var publishSettingsFile        = Data.ValidPublishSettings.First();
            var subscriptionDataFile       = Data.ValidSubscriptionsData.First();
            var outputSubscriptionDataFile = Path.Combine(Directory.GetParent(subscriptionDataFile).FullName, "outputNoPublish.xml");

            File.Copy(subscriptionDataFile, outputSubscriptionDataFile);

            // Create with both an existing ouput subscription data file and the publish settings file
            GlobalComponents globalComponents = GlobalComponents.CreateFromPublishSettings(Data.AzureAppDir, outputSubscriptionDataFile, publishSettingsFile);

            Assert.AreEqual(5, globalComponents.Subscriptions.Count);

            // Remove one of the subscriptions from the publish settings file
            globalComponents.Subscriptions.Remove("TestSubscription1");
            globalComponents.SaveSubscriptions();

            // Load and make sure the subscription is still gone although it still is in the publish settings file
            globalComponents = GlobalComponents.Load(Data.AzureAppDir, outputSubscriptionDataFile);
            Assert.AreEqual(4, globalComponents.Subscriptions.Count);

            // Clean
            globalComponents.DeleteGlobalComponents();
        }
示例#27
0
        internal SubscriptionData ImportSubscriptionFile(string publishSettingsFile, string subscriptionsDataFile)
        {
            GlobalComponents globalComponents = CreateGlobalComponents(subscriptionsDataFile, publishSettingsFile);

            return(SetCurrentAndDefaultSubscriptions(globalComponents, subscriptionsDataFile));
        }
示例#28
0
 public static IDictionary <string, SubscriptionData> GetSubscriptions(this PSCmdlet cmdlet, string subscriptionDataFile)
 {
     return(GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory, subscriptionDataFile).Subscriptions);
 }
示例#29
0
 public static void AreEqualGlobalComponents(GlobalPathInfo paths, PublishData publishSettings, GlobalComponents actual)
 {
     AreEqualGlobalPathInfo(paths, actual.GlobalPaths);
 }
        private SubscriptionData SetCurrentAndDefaultSubscriptions(GlobalComponents globalComponents, string subscriptionsDataFile)
        {
            // Set a current and default subscription if possible
            if (globalComponents.Subscriptions != null && globalComponents.Subscriptions.Count > 0)
            {
                var currentDefaultSubscription = globalComponents.Subscriptions.Values.FirstOrDefault(subscription =>
                    subscription.IsDefault);
                if (currentDefaultSubscription == null)
                {
                    // Sets the a new default subscription from the imported ones
                    currentDefaultSubscription = globalComponents.Subscriptions.Values.First();
                    currentDefaultSubscription.IsDefault = true;
                }

                if (this.GetCurrentSubscription() == null)
                {
                    this.SetCurrentSubscription(currentDefaultSubscription);
                }

                // Save subscriptions file to make sure publish settings subscriptions get merged
                // into the subscriptions data file and the default subscription is updated.
                globalComponents.SaveSubscriptions(subscriptionsDataFile);

                return currentDefaultSubscription;
            }

            return null;
        }
示例#31
0
        /// <summary>
        /// Initializes a new instance of the CloudCmdlet class.
        /// </summary>
        public CloudCmdlet()
        {
            GlobalComponents globalComponents = new GlobalComponents(GlobalPathInfo.GlobalSettingsDirectory);

            certificate = globalComponents.Certificate;
        }
 public static void AreEqualGlobalComponents(GlobalPathInfo paths, PublishData publishSettings, GlobalComponents actual)
 {
     AreEqualGlobalPathInfo(paths, actual.GlobalPaths);
 }
        private void RegisterResourceProviders(GlobalComponents globalComponents, string subscriptionName)
        {
            SubscriptionData subscription = globalComponents.SubscriptionManager.Subscriptions[subscriptionName];
            ISubscriptionClient client = GetSubscriptionClient(subscription);
            var knownProviders = new List<string>(ProviderRegistrationConstants.GetKnownResourceTypes());
            var providers = new List<ProviderResource>(client.ListResources(knownProviders));
            var providersToRegister = providers
                .Where(p => p.State == ProviderRegistrationConstants.Unregistered)
                .Select(p => p.Type).ToList();

            try
            {
                Task.WaitAll(providersToRegister.Select(client.RegisterResourceTypeAsync).Cast<Task>().ToArray());
            }
            catch (AggregateException)
            {
                // It's ok for registration to fail.
            }
        }
 public static void AreEqualGlobalComponents(GlobalComponents expected, GlobalComponents actual)
 {
     AreEqualGlobalComponents(expected.GlobalPaths, expected.PublishSettings, actual);
 }