本文整理汇总了C#中Microsoft.Azure.Common.Authentication.Models.AzureProfile类的典型用法代码示例。如果您正苦于以下问题:C# AzureProfile类的具体用法?C# AzureProfile怎么用?C# AzureProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AzureProfile类属于Microsoft.Azure.Common.Authentication.Models命名空间,在下文中一共展示了AzureProfile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StopsWebsiteSlot
public void StopsWebsiteSlot()
{
const string slot = "staging";
const string websiteName = "website1";
// Setup
Mock<IWebsitesClient> websitesClientMock = new Mock<IWebsitesClient>();
websitesClientMock.Setup(f => f.StopWebsite(websiteName, slot));
// Test
StopAzureWebsiteCommand stopAzureWebsiteCommand = new StopAzureWebsiteCommand()
{
CommandRuntime = new MockCommandRuntime(),
Name = websiteName,
WebsitesClient = websitesClientMock.Object,
Slot = slot
};
currentProfile = new AzureProfile();
var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) };
subscription.Properties[AzureSubscription.Property.Default] = "True";
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
stopAzureWebsiteCommand.ExecuteCmdlet();
websitesClientMock.Verify(f => f.StopWebsite(websiteName, slot), Times.Once());
}
示例2: DisableAzureWebsiteApplicationDiagnosticApplication
public void DisableAzureWebsiteApplicationDiagnosticApplication()
{
// Setup
websitesClientMock.Setup(f => f.DisableApplicationDiagnostic(
websiteName,
WebsiteDiagnosticOutput.FileSystem, null));
disableAzureWebsiteApplicationDiagnosticCommand = new DisableAzureWebsiteApplicationDiagnosticCommand()
{
CommandRuntime = commandRuntimeMock.Object,
Name = websiteName,
WebsitesClient = websitesClientMock.Object,
File = true,
};
currentProfile = new AzureProfile();
var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) };
subscription.Properties[AzureSubscription.Property.Default] = "True";
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
// Test
disableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet();
// Assert
websitesClientMock.Verify(f => f.DisableApplicationDiagnostic(
websiteName,
WebsiteDiagnosticOutput.FileSystem, null), Times.Once());
commandRuntimeMock.Verify(f => f.WriteObject(true), Times.Never());
}
示例3: RemovesAzureEnvironment
public void RemovesAzureEnvironment()
{
var commandRuntimeMock = new Mock<ICommandRuntime>();
commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
const string name = "test";
var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
AzurePSCmdlet.CurrentProfile = profile;
ProfileClient client = new ProfileClient(profile);
client.AddOrSetEnvironment(new AzureEnvironment
{
Name = name
});
client.Profile.Save();
var cmdlet = new RemoveAzureEnvironmentCommand()
{
CommandRuntime = commandRuntimeMock.Object,
Force = true,
Name = name
};
cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
Assert.False(client.Profile.Environments.ContainsKey(name));
}
示例4: WebsitesClient
/// <summary>
/// Creates new WebsitesClient
/// </summary>
/// <param name="subscription">Subscription containing websites to manipulate</param>
/// <param name="logger">The logger action</param>
public WebsitesClient(AzureProfile profile, AzureSubscription subscription, Action<string> logger)
{
Logger = logger;
cloudServiceClient = new CloudServiceClient(profile, subscription, debugStream: logger);
WebsiteManagementClient = AzureSession.ClientFactory.CreateClient<WebSiteManagementClient>(profile, subscription, AzureEnvironment.Endpoint.ServiceManagement);
this.subscription = subscription;
}
示例5: DetermineApiVersion
/// <summary>
/// Determines the API version.
/// </summary>
/// <param name="profile">The azure profile.</param>
/// <param name="providerNamespace">The provider namespace.</param>
/// <param name="resourceType">The resource type.</param>
/// <param name="cancellationToken">The cancellation token</param>
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
internal static Task<string> DetermineApiVersion(AzureProfile profile, string providerNamespace, string resourceType, CancellationToken cancellationToken, bool? pre = null)
{
var cacheKey = ApiVersionCache.GetCacheKey(providerNamespace: providerNamespace, resourceType: resourceType);
var apiVersions = ApiVersionCache.Instance
.AddOrGetExisting(cacheKey: cacheKey, getFreshData: () => ApiVersionHelper.GetApiVersionsForResourceType(
profile: profile,
providerNamespace: providerNamespace,
resourceType: resourceType,
cancellationToken: cancellationToken));
apiVersions = apiVersions.CoalesceEnumerable().ToArray();
var apiVersionsToSelectFrom = apiVersions;
if (pre == null || pre == false)
{
apiVersionsToSelectFrom = apiVersions
.Where(apiVersion => apiVersion.IsDecimal(NumberStyles.AllowDecimalPoint) || apiVersion.IsDateTime("yyyy-mm-dd", DateTimeStyles.None))
.ToArray();
}
var selectedApiVersion = apiVersionsToSelectFrom.OrderByDescending(apiVersion => apiVersion).FirstOrDefault();
if (string.IsNullOrWhiteSpace(selectedApiVersion) && apiVersions.Any())
{
// fall back on pre-release APIs if they're the only ones available.
selectedApiVersion = apiVersions.OrderByDescending(apiVersion => apiVersion).FirstOrDefault();
}
var result = string.IsNullOrWhiteSpace(selectedApiVersion)
? Constants.DefaultApiVersion
: selectedApiVersion;
return Task.FromResult(result);
}
示例6: BaseSetup
public void BaseSetup()
{
if (AzureSession.DataStore != null && !(AzureSession.DataStore is MemoryDataStore))
{
AzureSession.DataStore = new MemoryDataStore();
}
currentProfile = new AzureProfile();
if (currentProfile.Context.Subscription == null)
{
var newGuid = Guid.NewGuid();
currentProfile.Subscriptions[newGuid] = new AzureSubscription { Id = newGuid, Name = "test", Environment = EnvironmentName.AzureCloud, Account = "test" };
currentProfile.Accounts["test"] = new AzureAccount
{
Id = "test",
Type = AzureAccount.AccountType.User,
Properties = new Dictionary<AzureAccount.Property, string>
{
{AzureAccount.Property.Subscriptions, newGuid.ToString()}
}
};
currentProfile.DefaultSubscription = currentProfile.Subscriptions[newGuid];
}
AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory();
}
示例7: ListWebHostingPlansTest
public void ListWebHostingPlansTest()
{
// Setup
var clientMock = new Mock<IWebsitesClient>();
clientMock.Setup(c => c.ListWebSpaces())
.Returns(new[] {new WebSpace {Name = "webspace1"}, new WebSpace {Name = "webspace2"}});
clientMock.Setup(c => c.ListWebHostingPlans())
.Returns(new List<WebHostingPlan>
{
new WebHostingPlan {Name = "Plan1", WebSpace = "webspace1"},
new WebHostingPlan { Name = "Plan2", WebSpace = "webspace2" }
});
// Test
var command = new GetAzureWebHostingPlanCommand
{
CommandRuntime = new MockCommandRuntime(),
WebsitesClient = clientMock.Object
};
currentProfile = new AzureProfile();
var subscription = new AzureSubscription{Id = new Guid(subscriptionId) };
subscription.Properties[AzureSubscription.Property.Default] = "True";
currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription;
command.ExecuteCmdlet();
var plans = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)command.CommandRuntime).OutputPipeline).Cast<WebHostingPlan>();
Assert.NotNull(plans);
Assert.Equal(2, plans.Count());
Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1")));
Assert.True(plans.Any(p => (p).Name.Equals("Plan2") && (p).WebSpace.Equals("webspace2")));
}
示例8: AzureSqlDatabaseAdapter
/// <summary>
/// Constructs a database adapter
/// </summary>
/// <param name="profile">The current azure profile</param>
/// <param name="subscription">The current azure subscription</param>
public AzureSqlDatabaseAdapter(AzureProfile Profile, AzureSubscription subscription)
{
this.Profile = Profile;
this._subscription = subscription;
Communicator = new AzureSqlDatabaseCommunicator(Profile, subscription);
ElasticPoolCommunicator = new AzureSqlElasticPoolCommunicator(Profile, subscription);
}
示例9: ClearAzureProfileClearsDefaultProfile
public void ClearAzureProfileClearsDefaultProfile()
{
ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand();
// Setup
var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
AzurePSCmdlet.CurrentProfile = profile;
ProfileClient client = new ProfileClient(profile);
client.AddOrSetAccount(azureAccount);
client.AddOrSetEnvironment(azureEnvironment);
client.AddOrSetSubscription(azureSubscription1);
client.Profile.Save();
cmdlt.CommandRuntime = commandRuntimeMock;
cmdlt.Force = new SwitchParameter(true);
// Act
cmdlt.InvokeBeginProcessing();
cmdlt.ExecuteCmdlet();
cmdlt.InvokeEndProcessing();
// Verify
client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
Assert.Equal(0, client.Profile.Subscriptions.Count);
Assert.Equal(0, client.Profile.Accounts.Count);
Assert.Equal(2, client.Profile.Environments.Count); //only default environments
}
示例10: ProcessShowWebsiteTest
public void ProcessShowWebsiteTest()
{
// Setup
var mockClient = new Mock<IWebsitesClient>();
mockClient.Setup(c => c.GetWebsite("website1", null))
.Returns(new Site
{
Name = "website1",
WebSpace = "webspace1",
HostNames = new[] {"website1.cloudapp.com"}
});
// Test
ShowAzureWebsiteCommand showAzureWebsiteCommand = new ShowAzureWebsiteCommand
{
CommandRuntime = new MockCommandRuntime(),
Name = "website1",
WebsitesClient = mockClient.Object
};
currentProfile = new AzureProfile();
var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) };
subscription.Properties[AzureSubscription.Property.Default] = "True";
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
// Show existing website
showAzureWebsiteCommand.ExecuteCmdlet();
}
示例11: GetSubscriptions
public List<AzureSubscription> GetSubscriptions(AzureProfile profile)
{
string subscriptions = string.Empty;
List<AzureSubscription> subscriptionsList = new List<AzureSubscription>();
if (Properties.ContainsKey(Property.Subscriptions))
{
subscriptions = Properties[Property.Subscriptions];
}
foreach (var subscription in subscriptions.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries))
{
try
{
Guid subscriptionId = new Guid(subscription);
Debug.Assert(profile.Subscriptions.ContainsKey(subscriptionId));
subscriptionsList.Add(profile.Subscriptions[subscriptionId]);
}
catch
{
// Skip
}
}
return subscriptionsList;
}
示例12: AddsAzureEnvironment
public void AddsAzureEnvironment()
{
var profile = new AzureProfile();
Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
{
CommandRuntime = commandRuntimeMock.Object,
Name = "Katal",
PublishSettingsFileUrl = "http://microsoft.com",
ServiceEndpoint = "endpoint.net",
ManagementPortalUrl = "management portal url",
StorageEndpoint = "endpoint.net",
GalleryEndpoint = "http://galleryendpoint.com",
Profile = profile
};
cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
ProfileClient client = new ProfileClient(profile);
AzureEnvironment env = client.GetEnvironmentOrDefault("KaTaL");
Assert.Equal(env.Name, cmdlet.Name);
Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ServiceManagement], cmdlet.ServiceEndpoint);
Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl], cmdlet.ManagementPortalUrl);
Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.Gallery], "http://galleryendpoint.com");
}
示例13: SwitchesSlots
public void SwitchesSlots()
{
// Setup
var mockClient = new Mock<IWebsitesClient>();
string slot1 = WebsiteSlotName.Production.ToString();
string slot2 = "staging";
mockClient.Setup(c => c.GetWebsiteSlots("website1"))
.Returns(new List<Site> {
new Site { Name = "website1", WebSpace = "webspace1" },
new Site { Name = "website1(staging)", WebSpace = "webspace1" }
});
mockClient.Setup(f => f.GetSlotName("website1")).Returns(slot1);
mockClient.Setup(f => f.GetSlotName("website1(staging)")).Returns(slot2);
mockClient.Setup(f => f.SwitchSlots("webspace1", "website1(staging)", slot1, slot2)).Verifiable();
mockClient.Setup(f => f.GetWebsiteNameFromFullName("website1")).Returns("website1");
// Test
SwitchAzureWebsiteSlotCommand switchAzureWebsiteCommand = new SwitchAzureWebsiteSlotCommand
{
CommandRuntime = new MockCommandRuntime(),
WebsitesClient = mockClient.Object,
Name = "website1",
Force = true
};
currentProfile = new AzureProfile();
var subscription = new AzureSubscription { Id = new Guid(base.subscriptionId) };
subscription.Properties[AzureSubscription.Property.Default] = "True";
currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription;
// Switch existing website
switchAzureWebsiteCommand.ExecuteCmdlet();
mockClient.Verify(c => c.SwitchSlots("webspace1", "website1", slot1, slot2), Times.Once());
}
示例14: Deserialize
public bool Deserialize(string contents, AzureProfile profile)
{
ProfileData data;
Debug.Assert(profile != null);
DeserializeErrors = new List<string>();
DataContractSerializer serializer = new DataContractSerializer(typeof(ProfileData));
using (MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(contents ?? "")))
{
data = (ProfileData)serializer.ReadObject(s);
}
if (data != null)
{
foreach (AzureEnvironmentData oldEnv in data.Environments)
{
profile.Environments[oldEnv.Name] = oldEnv.ToAzureEnvironment();
}
List<AzureEnvironment> envs = profile.Environments.Values.ToList();
foreach (AzureSubscriptionData oldSubscription in data.Subscriptions)
{
try
{
var newSubscription = oldSubscription.ToAzureSubscription(envs);
if (newSubscription.Account == null)
{
continue;
}
var newAccounts = oldSubscription.ToAzureAccounts();
foreach (var account in newAccounts)
{
if (profile.Accounts.ContainsKey(account.Id))
{
profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Tenants,
account.GetPropertyAsArray(AzureAccount.Property.Tenants));
profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Subscriptions,
account.GetPropertyAsArray(AzureAccount.Property.Subscriptions));
}
else
{
profile.Accounts[account.Id] = account;
}
}
profile.Subscriptions[newSubscription.Id] = newSubscription;
}
catch (Exception ex)
{
// Skip subscription if failed to load
DeserializeErrors.Add(ex.Message);
}
}
}
return DeserializeErrors.Count == 0;
}
示例15: AzureSqlDatabaseReplicationAdapter
/// <summary>
/// Constructs a database adapter
/// </summary>
/// <param name="profile">The current azure profile</param>
/// <param name="subscription">The current azure subscription</param>
public AzureSqlDatabaseReplicationAdapter(AzureProfile Profile, AzureSubscription subscription)
{
this.Profile = Profile;
this._subscription = subscription;
ReplicationCommunicator = new AzureSqlDatabaseReplicationCommunicator(Profile, subscription);
DatabaseCommunicator = new AzureSqlDatabaseCommunicator(Profile, subscription);
ServerCommunicator = new AzureSqlServerCommunicator(Profile, subscription);
}