protected void SetupProfile(string storageName)
        {

            currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzureSMCmdlet.CurrentProfile = currentProfile;
            var subscription = new AzureSubscription { Id = new Guid(subscriptionId) };
            subscription.Properties[AzureSubscription.Property.Default] = "True";
            currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
            if (storageName != null)
            {
                currentProfile.Context.Subscription.Properties[AzureSubscription.Property.StorageAccount] = storageName;
            }
            currentProfile.Save();
        }
        private void UpgradeProfile()
        {
            string oldProfileFilePath = Path.Combine(AzureSession.ProfileDirectory, AzureSession.OldProfileFile);
            string oldProfileFilePathBackup = Path.Combine(AzureSession.ProfileDirectory, AzureSession.OldProfileFileBackup);
            string newProfileFilePath = Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile);
            if (AzureSession.DataStore.FileExists(oldProfileFilePath))
            {
                string oldProfilePath = Path.Combine(AzureSession.ProfileDirectory,
                    AzureSession.OldProfileFile);

                try
                {
                    // Try to backup old profile
                    try
                    {
                        AzureSession.DataStore.CopyFile(oldProfilePath, oldProfileFilePathBackup);
                    }
                    catch
                    {
                        // Ignore any errors here
                    }

                    AzureSMProfile oldProfile = new AzureSMProfile(oldProfilePath);

                    if (AzureSession.DataStore.FileExists(newProfileFilePath))
                    {
                        // Merge profile files
                        AzureSMProfile newProfile = new AzureSMProfile(newProfileFilePath);
                        foreach (var environment in newProfile.Environments.Values)
                        {
                            oldProfile.Environments[environment.Name] = environment;
                        }
                        foreach (var subscription in newProfile.Subscriptions.Values)
                        {
                            oldProfile.Subscriptions[subscription.Id] = subscription;
                        }
                        AzureSession.DataStore.DeleteFile(newProfileFilePath);
                    }

                    // If there were no load errors - delete backup file
                    if (oldProfile.ProfileLoadErrors.Count == 0)
                    {
                        try
                        {
                            AzureSession.DataStore.DeleteFile(oldProfileFilePathBackup);
                        }
                        catch
                        {
                            // Give up
                        }
                    }

                    // Save the profile to the disk
                    oldProfile.Save();

                    // Rename WindowsAzureProfile.xml to WindowsAzureProfile.json
                    AzureSession.DataStore.RenameFile(oldProfilePath, newProfileFilePath);

                }
                catch
                {
                    // Something really bad happened - try to delete the old profile
                    try
                    {
                        AzureSession.DataStore.DeleteFile(oldProfilePath);
                    }
                    catch
                    {
                        // Ignore any errors
                    }
                }

                // In case that we changed a disk profile, reload it
                if (Profile != null && Profile.ProfilePath == newProfileFilePath)
                {
                    Profile = new AzureSMProfile(Profile.ProfilePath);
                }
            }
        }
 private AzureSMProfile SetupCustomProfile(string path)
 {
     var profile =
         new AzureSMProfile(path);
     ProfileClient client = new ProfileClient(profile);
     client.AddOrSetEnvironment(azureEnvironment);
     client.AddOrSetAccount(azureAccount);
     client.AddOrSetSubscription(azureSubscription1);
     client.AddOrSetSubscription(azureSubscription2);
     profile.Save(path);
     return profile;
 }
        public void ProcessGetWebsiteWithNullSubscription()
        {
            currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            currentProfile.Subscriptions.Clear();
            currentProfile.Save();
            AzureSMCmdlet.CurrentProfile = currentProfile;

            // Test
            var getAzureWebsiteCommand = new GetAzureWebsiteCommand
            {
                CommandRuntime = new MockCommandRuntime()
            };

            Testing.AssertThrows<Exception>(getAzureWebsiteCommand.ExecuteWithProcessing, Resources.InvalidDefaultSubscription);
        }