本文整理汇总了C#中Microsoft.WindowsAzure.SubscriptionCloudCredentials类的典型用法代码示例。如果您正苦于以下问题:C# SubscriptionCloudCredentials类的具体用法?C# SubscriptionCloudCredentials怎么用?C# SubscriptionCloudCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SubscriptionCloudCredentials类属于Microsoft.WindowsAzure命名空间,在下文中一共展示了SubscriptionCloudCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConfiguration
public XDocument GetConfiguration(SubscriptionCloudCredentials credentials, string serviceName, DeploymentSlot slot)
{
using (var client = CloudContext.Clients.CreateComputeManagementClient(credentials))
{
try
{
var response = client.Deployments.GetBySlot(serviceName, slot);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new Exception(string.Format("Getting deployment by slot returned HTTP Status Code: {0}",
response.StatusCode));
}
return string.IsNullOrEmpty(response.Configuration)
? null
: XDocument.Parse(response.Configuration);
}
catch (CloudException cloudException)
{
Log.VerboseFormat("Getting deployments for service '{0}', slot {1}, returned:\n{2}", serviceName, slot.ToString(), cloudException.Message);
return null;
}
}
}
示例2: OnExecute
protected override async Task OnExecute(SubscriptionCloudCredentials credentials)
{
using (var client = CloudContext.Clients.CreateCloudServiceManagementClient(credentials))
{
await Console.WriteInfoLine(String.Format(
CultureInfo.CurrentCulture,
Strings.Scheduler_CsNewCommand_CreatingService,
Name));
if (!WhatIf)
{
await client.CloudServices.CreateAsync(
Name,
new CloudServiceCreateParameters()
{
Description = Description,
Email = Email,
GeoRegion = GeoRegion,
Label = Label
});
}
await Console.WriteInfoLine(String.Format(
CultureInfo.CurrentCulture,
Strings.Scheduler_CsNewCommand_CreatedService,
Name));
}
}
示例3: GetMetricValue
static double GetMetricValue(SubscriptionCloudCredentials cred,
MetricsClient metricsClient,
string webSiteResourceId,
string metricName)
{
double requestCount = 0;
var metricValueResult = metricsClient.MetricValues.List(
webSiteResourceId,
new List<string> { metricName },
"",
TimeSpan.FromHours(1),
DateTime.UtcNow - TimeSpan.FromDays(1),
DateTime.UtcNow
);
var values = metricValueResult.MetricValueSetCollection;
foreach (var value in values.Value)
{
foreach (var total in value.MetricValues)
{
if (total.Total.HasValue)
requestCount += total.Total.Value;
}
}
return requestCount;
}
示例4: Upload
public Uri Upload(SubscriptionCloudCredentials credentials, string storageAccountName, string packageFile, string uploadedFileName)
{
var cloudStorage =
new CloudStorageAccount(new StorageCredentials(storageAccountName, GetStorageAccountPrimaryKey(credentials, storageAccountName)), true);
var blobClient = cloudStorage.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(OctopusPackagesContainerName);
container.CreateIfNotExists();
var permission = container.GetPermissions();
permission.PublicAccess = BlobContainerPublicAccessType.Off;
container.SetPermissions(permission);
var fileInfo = new FileInfo(packageFile);
var packageBlob = GetUniqueBlobName(uploadedFileName, fileInfo, container);
if (packageBlob.Exists())
{
Log.VerboseFormat("A blob named {0} already exists with the same length, so it will be used instead of uploading the new package.",
packageBlob.Name);
return packageBlob.Uri;
}
UploadBlobInChunks(fileInfo, packageBlob, blobClient);
Log.Info("Package upload complete");
return packageBlob.Uri;
}
示例5: OnExecute
protected override async Task OnExecute(SubscriptionCloudCredentials credentials)
{
using (var client = CloudContext.Clients.CreateSchedulerManagementClient(credentials))
{
await Console.WriteInfoLine(Strings.Scheduler_ColDeleteCommand_DeletingCollection, CloudService, Name);
await client.JobCollections.DeleteAsync(CloudService, Name);
}
}
示例6: GetSingleCollection
private async Task GetSingleCollection(SubscriptionCloudCredentials credentials)
{
using (var client = CloudContext.Clients.CreateSchedulerManagementClient(credentials))
{
await Console.WriteInfoLine(Strings.Scheduler_CollectionsCommand_GettingCollection, Name, CloudService);
var response = await client.JobCollections.GetAsync(CloudService, Name);
await Console.WriteObject(response);
}
}
示例7: OnExecute
protected override Task OnExecute(SubscriptionCloudCredentials credentials)
{
if (String.IsNullOrEmpty(Name))
{
return GetAllCollections(credentials);
}
else
{
return GetSingleCollection(credentials);
}
}
示例8: GetStorageAccountPrimaryKey
static string GetStorageAccountPrimaryKey(SubscriptionCloudCredentials credentials, string storageAccountName)
{
using (var cloudClient = CloudContext.Clients.CreateStorageManagementClient(credentials))
{
var getKeysResponse = cloudClient.StorageAccounts.GetKeys(storageAccountName);
if (getKeysResponse.StatusCode != HttpStatusCode.OK)
throw new Exception(string.Format("GetKeys for storage-account {0} returned HTTP status-code {1}", storageAccountName, getKeysResponse.StatusCode));
return getKeysResponse.PrimaryKey;
}
}
示例9: OnExecute
protected override async Task OnExecute(SubscriptionCloudCredentials credentials)
{
using (var client = CloudContext.Clients.CreateCloudServiceManagementClient(credentials))
{
await Console.WriteInfoLine(Strings.Scheduler_CsListCommand_ListingAvailableServices);
var response = await client.CloudServices.ListAsync();
await Console.WriteTable(response, r => new
{
r.Name,
r.Label,
r.Description,
r.GeoRegion
});
}
}
示例10: OnExecute
protected override async Task OnExecute(SubscriptionCloudCredentials credentials)
{
// Get the datacenter
var dc = GetDatacenter(Datacenter ?? 0, required: true);
// Find the server
var server = dc.FindResource(ResourceTypes.SqlDb, Database.ToString());
if (server == null)
{
await Console.WriteErrorLine(
Strings.Db_DatabaseCommandBase_NoDatabaseInDatacenter,
Datacenter.Value,
ResourceTypes.SqlDb,
Database.ToString());
return;
}
var connStr = new SqlConnectionStringBuilder(server.Value);
string serverName = Utils.GetServerName(connStr.DataSource);
// Get the secret value
var secrets = await GetEnvironmentSecretStore(Session.CurrentEnvironment);
string secretName = "sqldb." + serverName + ":admin";
// Connect to Azure
using (var sql = CloudContext.Clients.CreateSqlManagementClient(credentials))
{
await Console.WriteInfoLine(Strings.Db_ApplyAdminPasswordCommand_ApplyingPassword, secretName, serverName);
if (!WhatIf)
{
var secret = await secrets.Read(new SecretName(secretName), "nucmd db applyadminpassword");
if (secret == null)
{
await Console.WriteErrorLine(Strings.Db_ApplyAdminPasswordCommand_NoPasswordInStore, serverName);
return;
}
await sql.Servers.ChangeAdministratorPasswordAsync(
serverName, new ServerChangeAdministratorPasswordParameters()
{
NewPassword = secret.Value
},
CancellationToken.None);
}
await Console.WriteInfoLine(Strings.Db_ApplyAdminPasswordCommand_AppliedPassword);
}
}
示例11: OnExecute
protected override async Task OnExecute(SubscriptionCloudCredentials credentials)
{
using (var client = CloudContext.Clients.CreateCloudServiceManagementClient(credentials))
{
await Console.WriteInfoLine(String.Format(
CultureInfo.CurrentCulture,
Strings.Scheduler_CsDeleteCommand_DeletingService,
Name));
if (!WhatIf)
{
await client.CloudServices.DeleteAsync(Name);
}
await Console.WriteInfoLine(String.Format(
CultureInfo.CurrentCulture,
Strings.Scheduler_CsDeleteCommand_DeletedService,
Name));
}
}
示例12: OnExecute
protected override async Task OnExecute(SubscriptionCloudCredentials credentials)
{
if((MaxRecurrenceFrequency.HasValue && !MinRecurrenceInterval.HasValue) ||
(MinRecurrenceInterval.HasValue && !MaxRecurrenceFrequency.HasValue)) {
await Console.WriteErrorLine(Strings.Scheduler_ColNewCommand_MaxRecurrenceIncomplete);
}
else {
JobCollectionMaxRecurrence maxRecurrence = null;
if(MaxRecurrenceFrequency != null) {
maxRecurrence = new JobCollectionMaxRecurrence()
{
Frequency = MaxRecurrenceFrequency.Value,
Interval = MinRecurrenceInterval.Value
};
}
using (var client = CloudContext.Clients.CreateSchedulerManagementClient(credentials))
{
await Console.WriteInfoLine(Strings.Scheduler_ColNewCommand_CreatingCollection, Name, CloudService);
if (!WhatIf)
{
await client.JobCollections.CreateAsync(
CloudService,
Name,
new JobCollectionCreateParameters()
{
Label = Label,
IntrinsicSettings = new JobCollectionIntrinsicSettings()
{
Plan = Plan,
Quota = new JobCollectionQuota()
{
MaxJobCount = MaxJobCount,
MaxJobOccurrence = MaxJobOccurrence,
MaxRecurrence = maxRecurrence
}
}
},
CancellationToken.None);
}
await Console.WriteInfoLine(Strings.Scheduler_ColNewCommand_CreatedCollection, Name, CloudService);
}
}
}
示例13: GetAllCollections
private async Task GetAllCollections(SubscriptionCloudCredentials credentials)
{
using (var client = CloudContext.Clients.CreateCloudServiceManagementClient(credentials))
{
await Console.WriteInfoLine(Strings.Scheduler_CollectionsCommand_ListingCollections, CloudService);
var response = await client.CloudServices.GetAsync(CloudService);
await Console.WriteTable(response.Resources.Where(r =>
String.Equals(r.ResourceProviderNamespace, "scheduler", StringComparison.OrdinalIgnoreCase) &&
String.Equals(r.Type, "jobcollections", StringComparison.OrdinalIgnoreCase)),
r => new
{
r.Name,
r.State,
r.SubState,
r.Plan,
r.OutputItems
});
}
}
示例14: OnExecute
protected override async Task OnExecute(SubscriptionCloudCredentials credentials)
{
if (ServiceUri == null)
{
await Console.WriteErrorLine(Strings.ParameterRequired, "SerivceUri");
}
else
{
using (var client = CloudContext.Clients.CreateSchedulerClient(credentials, CloudService, Collection))
{
var job = await client.Jobs.GetAsync(InstanceName, CancellationToken.None);
if (job == null)
{
await Console.WriteErrorLine(Strings.Scheduler_RefreshJobCommand_NoSuchJob, InstanceName);
}
else if (job.Job.Action.Type == JobActionType.StorageQueue || job.Job.Action.Request == null)
{
await Console.WriteErrorLine(Strings.Scheduler_RefreshJobCommand_NotAWorkServiceJob, InstanceName);
}
else
{
Uri old = job.Job.Action.Request.Uri;
job.Job.Action.Request.Uri = new Uri(ServiceUri, "work/invocations");
await Console.WriteInfoLine(
Strings.Scheduler_RefreshJobCommand_UpdatingUrl,
InstanceName,
old.AbsoluteUri,
job.Job.Action.Request.Uri.AbsoluteUri);
if (!WhatIf)
{
await client.Jobs.CreateOrUpdateAsync(InstanceName, new JobCreateOrUpdateParameters()
{
StartTime = job.Job.StartTime,
Action = job.Job.Action,
Recurrence = job.Job.Recurrence
}, CancellationToken.None);
}
}
}
}
}
示例15: OnExecute
protected override async Task OnExecute(SubscriptionCloudCredentials credentials)
{
using (var client = CloudContext.Clients.CreateSchedulerClient(credentials, CloudService, Collection))
{
await Console.WriteInfoLine(Strings.Scheduler_JobsCommand_ListingJobs, CloudService, Collection);
if (String.IsNullOrEmpty(Id))
{
var jobs = await client.Jobs.ListAsync(new JobListParameters(), CancellationToken.None);
await Console.WriteTable(jobs, r => new
{
r.Id,
r.State,
r.Status
});
}
else
{
var job = await client.Jobs.GetAsync(Id, CancellationToken.None);
await Console.WriteObject(job.Job);
}
}
}