本文整理汇总了C#中Microsoft.Azure.Common.Authentication.Models.AzureProfile.Save方法的典型用法代码示例。如果您正苦于以下问题:C# AzureProfile.Save方法的具体用法?C# AzureProfile.Save怎么用?C# AzureProfile.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Common.Authentication.Models.AzureProfile
的用法示例。
在下文中一共展示了AzureProfile.Save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupProfile
protected void SetupProfile(string storageName)
{
currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
AzurePSCmdlet.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();
}
示例2: ProfileSaveDoesNotSerializeContext
public void ProfileSaveDoesNotSerializeContext()
{
var dataStore = new MockDataStore();
var currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
AzureSession.DataStore = dataStore;
var client = new ProfileClient(currentProfile);
var tenant = Guid.NewGuid().ToString();
var environment = new AzureEnvironment
{
Name = "testCloud",
Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } }
};
var account = new AzureAccount
{
Id = "[email protected]",
Type = AzureAccount.AccountType.User,
Properties = { { AzureAccount.Property.Tenants, tenant } }
};
var sub = new AzureSubscription
{
Account = account.Id,
Environment = environment.Name,
Id = new Guid(),
Name = "Contoso Test Subscription",
Properties = { { AzureSubscription.Property.Tenants, tenant } }
};
client.AddOrSetEnvironment(environment);
client.AddOrSetAccount(account);
client.AddOrSetSubscription(sub);
currentProfile.Save();
var profileFile = currentProfile.ProfilePath;
string profileContents = dataStore.ReadFileAsText(profileFile);
var readProfile = JsonConvert.DeserializeObject<Dictionary<string, object>>(profileContents);
Assert.False(readProfile.ContainsKey("Context"));
AzureProfile parsedProfile = new AzureProfile();
var serializer = new JsonProfileSerializer();
Assert.True(serializer.Deserialize(profileContents, parsedProfile));
Assert.NotNull(parsedProfile);
Assert.NotNull(parsedProfile.Environments);
Assert.True(parsedProfile.Environments.ContainsKey(environment.Name));
Assert.NotNull(parsedProfile.Accounts);
Assert.True(parsedProfile.Accounts.ContainsKey(account.Id));
Assert.NotNull(parsedProfile.Subscriptions);
Assert.True(parsedProfile.Subscriptions.ContainsKey(sub.Id));
}
示例3: SetupCustomProfile
private AzureProfile SetupCustomProfile(string path)
{
var profile =
new AzureProfile(path);
ProfileClient client = new ProfileClient(profile);
client.AddOrSetEnvironment(azureEnvironment);
client.AddOrSetAccount(azureAccount);
client.AddOrSetSubscription(azureSubscription1);
client.AddOrSetSubscription(azureSubscription2);
profile.Save(path);
return profile;
}
示例4: ProcessGetWebsiteWithNullSubscription
public void ProcessGetWebsiteWithNullSubscription()
{
currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
currentProfile.Subscriptions.Clear();
currentProfile.Save();
AzurePSCmdlet.CurrentProfile = currentProfile;
// Test
var getAzureWebsiteCommand = new GetAzureWebsiteCommand
{
CommandRuntime = new MockCommandRuntime()
};
Testing.AssertThrows<Exception>(getAzureWebsiteCommand.ExecuteWithProcessing, Resources.InvalidDefaultSubscription);
}
示例5: UpgradeProfile
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
}
AzureProfile oldProfile = new AzureProfile(oldProfilePath);
if (AzureSession.DataStore.FileExists(newProfileFilePath))
{
// Merge profile files
AzureProfile newProfile = new AzureProfile(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 AzureProfile(Profile.ProfilePath);
}
}
}