public DeploymentSettings(ServiceSettings settings, string packagePath, string configPath, string label, string deploymentName)
        {
            Validate.ValidateNullArgument(settings, Resources.InvalidServiceSettingMessage);
            Validate.ValidateFileFull(packagePath, Resources.Package);
            Validate.ValidateFileFull(configPath, Resources.ServiceConfiguration);
            Validate.ValidateStringIsNullOrEmpty(label, "Label");
            Validate.ValidateStringIsNullOrEmpty(deploymentName, "Deployment name");

            this.ServiceSettings = settings;
            this.PackagePath = packagePath;
            this.ConfigPath = configPath;
            this.Label = label;
            this.DeploymentName = deploymentName;

            if (!string.IsNullOrEmpty(settings.Subscription))
            {
                GlobalComponents globalComponents = GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory);

                SubscriptionId = globalComponents.GetSubscriptionId(settings.Subscription);
            }
            else
            {
                throw new ArgumentNullException("settings.Subscription", Resources.InvalidSubscriptionNameMessage);
            }
        }
Esempio n. 2
0
        public static void AreEqualDeploymentSettings(ServiceSettings settings, string configPath, string deploymentName, string label, string packagePath, string subscriptionId, DeploymentSettings actual)
        {
            AreEqualServiceSettings(settings, actual.ServiceSettings);
            Assert.AreEqual<string>(configPath, actual.ConfigPath);
            Assert.AreEqual<string>(deploymentName, actual.DeploymentName);
            Assert.AreEqual<string>(label, actual.Label);
            Assert.AreEqual<string>(packagePath, actual.PackagePath);
            Assert.AreEqual<string>(subscriptionId, actual.SubscriptionId);

            Assert.IsTrue(File.Exists(actual.ConfigPath));
            Assert.IsTrue(File.Exists(actual.PackagePath));
        }
Esempio n. 3
0
        private void LoadComponents(ServicePathInfo paths)
        {
            Validate.ValidateNullArgument(paths, string.Format(Resources.NullObjectMessage, "paths"));
            Validate.ValidateFileFull(paths.CloudConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.LocalConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.Definition, Resources.ServiceDefinition);
            Validate.ValidateFileFull(paths.Settings, Resources.ServiceSettings);

            Definition = General.DeserializeXmlFile<ServiceDefinition>(paths.Definition);
            CloudConfig = General.DeserializeXmlFile<ServiceConfiguration>(paths.CloudConfiguration);
            LocalConfig = General.DeserializeXmlFile<ServiceConfiguration>(paths.LocalConfiguration);
            Settings = ServiceSettings.Load(paths.Settings);
        }
        public void SetAzureServiceProjectTestsLocationInvalidFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess("MyHome", null, null, null, paths.Settings), string.Format(Resources.InvalidServiceSettingElement, "Location"));
            }
        }
        private void InitializeData()
        {
            ServiceSettings settings;

            Data = new Dictionary<ServiceSettingsState, ServiceSettings>();
            Data.Add(ServiceSettingsState.Default, new ServiceSettings());

            settings = new ServiceSettings();
            settings.Location = ArgumentConstants.Locations[Location.SouthCentralUS];
            settings.Slot = ArgumentConstants.Slots[Slot.Production];
            settings.StorageAccountName = "mystore";
            settings.Subscription = "TestSubscription2";
            Data.Add(ServiceSettingsState.Sample1, settings);

            settings = new ServiceSettings();
            settings.Location = ArgumentConstants.Locations[Location.SouthCentralUS];
            settings.Slot = ArgumentConstants.Slots[Slot.Production];
            settings.StorageAccountName = "mystore";
            settings.Subscription = "Does not exist subscription";
            Data.Add(ServiceSettingsState.DoesNotExistSubscription, settings);
        }
        public void SetAzureServiceProjectTestsLocationValid()
        {
            foreach (KeyValuePair<Location, string> item in Microsoft.WindowsAzure.Management.CloudService.Model.ArgumentConstants.Locations)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    settings.Save(paths.Settings);

                    new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(item.Value, null, null, null, paths.Settings);

                    // Assert location is changed
                    //
                    settings = ServiceSettings.Load(paths.Settings);
                    Assert.AreEqual<string>(item.Value, settings.Location);
                }
            }
        }
        public void OnPublish(IServiceManagement channel, AzureService service, ServiceSettings publishSettings, string subscriptionId)
        {
            StorageService storageService = channel.GetStorageKeys(subscriptionId, publishSettings.StorageAccountName);
            string name = publishSettings.StorageAccountName;
            string key = storageService.StorageServiceKeys.Primary;

            ConfigConfigurationSetting connectionStringConfig = new ConfigConfigurationSetting { name = Resources.CachingConfigStoreConnectionStringSettingName, value = string.Empty };
            service.Components.ForEachRoleSettings(
            r => Array.Exists<ConfigConfigurationSetting>(r.ConfigurationSettings, c => c.Equals(connectionStringConfig)),
            delegate(RoleSettings r)
            {
                int index = Array.IndexOf<ConfigConfigurationSetting>(r.ConfigurationSettings, connectionStringConfig);
                r.ConfigurationSettings[index] = new ConfigConfigurationSetting
                {
                    name = Resources.CachingConfigStoreConnectionStringSettingName,
                    value = string.Format(Resources.CachingConfigStoreConnectionStringSettingValue, name, key)
                };
            });

            service.Components.Save(service.Paths);
        }
Esempio n. 8
0
        public static ServiceSettings LoadDefault(
            string path,
            string slot,
            string location,
            string affinityGroup,
            string subscription,
            string storageAccountName,
            string suppliedServiceName,
            string serviceDefinitionName,
            out string serviceName)
        {
            ServiceSettings local;
            ServiceSettings defaultServiceSettings = new ServiceSettings();

            if (string.IsNullOrEmpty(path))
            {
                local = new ServiceSettings();
            }
            else
            {
                Validate.ValidateFileFull(path, Resources.ServiceSettings);
                local = Load(path);
            }

            defaultServiceSettings._slot = GetDefaultSlot(local.Slot, null, slot);
            defaultServiceSettings._location = GetDefaultLocation(local.Location, location);
            defaultServiceSettings._subscription = GetDefaultSubscription(local.Subscription, subscription);
            serviceName = GetServiceName(suppliedServiceName, serviceDefinitionName);
            defaultServiceSettings._storageAccountName = GetDefaultStorageName(local.StorageAccountName, null, storageAccountName, serviceName).ToLower();
            defaultServiceSettings._affinityGroup = affinityGroup;

            return defaultServiceSettings;
        }
 public void ServiceSettingsTest()
 {
     ServiceSettings settings = new ServiceSettings();
     AzureAssert.AreEqualServiceSettings(string.Empty, string.Empty, string.Empty, string.Empty, settings);
 }
Esempio n. 10
0
 public static void AreEqualServiceSettings(ServiceSettings expected, ServiceSettings actual)
 {
     AreEqualServiceSettings(expected.Location, expected.Slot, expected.StorageAccountName, expected.Subscription, actual);
 }
        public void SetAzureServiceProjectTestsSubscriptionValid()
        {
            foreach (string item in Data.ValidSubscriptionName)
            {
                using (FileSystemHelper files = new FileSystemHelper(this))
                {
                    // Create new empty settings file
                    //
                    ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                    ServiceSettings settings = new ServiceSettings();
                    settings.Save(paths.Settings);

                    new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, null, item, paths.Settings);

                    // Assert subscription is changed
                    //
                    settings = ServiceSettings.Load(paths.Settings);
                    Assert.AreEqual<string>(item, settings.Subscription);
                }
            }
        }
        public void SetAzureServiceProjectTestsSubscriptionEmptyFail()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                Testing.AssertThrows<ArgumentException>(() => new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, null, string.Empty, paths.Settings), string.Format(Resources.InvalidOrEmptyArgumentMessage, "Subscription"));
            }
        }
        public void SetAzureServiceProjectTestsStorageTests()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                // Create new empty settings file
                //
                ServicePathInfo paths = new ServicePathInfo(files.RootPath);
                ServiceSettings settings = new ServiceSettings();
                settings.Save(paths.Settings);

                new SetAzureServiceProjectCommand().SetAzureServiceProjectProcess(null, null, "companystore", null, paths.Settings);

                // Assert storageAccountName is changed
                //
                settings = ServiceSettings.Load(paths.Settings);
                Assert.AreEqual<string>("companystore", settings.StorageAccountName);
            }
        }
Esempio n. 14
0
        public static void AzureServiceExists(string serviceRootPath, string scaffoldFilePath, string serviceName, ServiceSettings settings = null, WebRoleInfo[] webRoles = null, WorkerRoleInfo[] workerRoles = null, string webScaff = null, string workerScaff = null, RoleInfo[] roles = null)
        {
            ServiceComponents components = new Microsoft.WindowsAzure.Management.CloudService.Model.ServiceComponents(new Microsoft.WindowsAzure.Management.CloudService.Model.ServicePathInfo(serviceRootPath));

            ScaffoldingExists(serviceRootPath, scaffoldFilePath);

            if (webRoles != null)
            {
                for (int i = 0; i < webRoles.Length; i++)
                {
                    ScaffoldingExists(Path.Combine(serviceRootPath, webRoles[i].Name), webScaff);
                }
            }

            if (workerRoles != null)
            {
                for (int i = 0; i < workerRoles.Length; i++)
                {
                    ScaffoldingExists(Path.Combine(serviceRootPath, workerRoles[i].Name), workerScaff);
                }
            }

            AreEqualServiceConfiguration(components.LocalConfig, serviceName, roles);
            AreEqualServiceConfiguration(components.CloudConfig, serviceName, roles);
            IsValidServiceDefinition(components.Definition, serviceName, webRoles, workerRoles);
            AreEqualServiceSettings(settings ?? new ServiceSettings(), components.Settings);
        }
Esempio n. 15
0
 public static void AreEqualServiceSettings(string location, string slot, string storageAccountName, string subscriptionName, ServiceSettings actual)
 {
     Assert.AreEqual<string>(location, actual.Location);
     Assert.AreEqual<string>(slot, actual.Slot);
     Assert.AreEqual<string>(storageAccountName, actual.StorageAccountName);
     Assert.AreEqual<string>(subscriptionName, actual.Subscription);
 }
Esempio n. 16
0
        private void LoadComponents(ServicePathInfo paths)
        {
            Validate.ValidateNullArgument(paths, string.Format(Resources.NullObjectMessage, "paths"));
            Validate.ValidateFileFull(paths.CloudConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.LocalConfiguration, Resources.ServiceConfiguration);
            Validate.ValidateFileFull(paths.Definition, Resources.ServiceDefinition);

            try
            {
                Validate.ValidateFileFull(paths.Settings, Resources.ServiceSettings);
            }
            catch (FileNotFoundException)
            {
                // Try recreating the settings file
                File.WriteAllText(paths.Settings, Resources.SettingsFileEmptyContent);
            }

            Definition = CloudServiceUtilities.DeserializeXmlFile<ServiceDefinition>(paths.Definition);
            CloudConfig = CloudServiceUtilities.DeserializeXmlFile<ServiceConfiguration>(paths.CloudConfiguration);
            LocalConfig = CloudServiceUtilities.DeserializeXmlFile<ServiceConfiguration>(paths.LocalConfiguration);
            Settings = ServiceSettings.Load(paths.Settings);
        }
        public void TestInitialize()
        {
            Management.Extensions.CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();

            serviceName = Path.GetRandomFileName();
            GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir;
            service = new AzureServiceWrapper(Directory.GetCurrentDirectory(), Path.GetRandomFileName(), null);
            service.CreateVirtualCloudPackage();
            packagePath = service.Paths.CloudPackage;
            configPath = service.Paths.CloudConfiguration;
            settings = ServiceSettingsTestData.Instance.Data[ServiceSettingsState.Default];
            new ImportAzurePublishSettingsCommand().ImportSubscriptionProcess(Resources.PublishSettingsFileName, null);
        }