Ejemplo n.º 1
0
        public override async Task <ExecutionResult> RunAsync(string input, IChannel channel, CancellationToken cancellationToken)
        {
            var inputParameters = ParseInputParameters(input, firstParameterInferredName: ParameterNameTargetId);

            if (inputParameters.ContainsKey(ParameterNameTargetId))
            {
                string targetId = inputParameters.DecodeParameter <string>(ParameterNameTargetId);
                return(await AzureClient.SetActiveTargetAsync(channel, targetId));
            }

            return(await AzureClient.GetActiveTargetAsync(channel));
        }
Ejemplo n.º 2
0
 public override async Task <ExecutionResult> RunAsync(string input, IChannel channel, CancellationToken cancellationToken)
 {
     return(await AzureClient.GetQuotaListAsync(channel, cancellationToken));
 }
Ejemplo n.º 3
0
 public override async Task <ExecutionResult> RunAsync(string input, IChannel channel, CancellationToken cancellationToken)
 {
     return(await AzureClient.ExecuteJobAsync(channel, AzureSubmissionContext.Parse(input), cancellationToken));
 }
Ejemplo n.º 4
0
        public override async Task <ExecutionResult> RunAsync(string input, IChannel channel, CancellationToken cancellationToken)
        {
            var inputParameters = ParseInputParameters(input);

            if (!inputParameters.Any())
            {
                return(await AzureClient.GetConnectionStatusAsync(channel));
            }

            var resourceId        = inputParameters.DecodeParameter <string>(ParameterNameResourceId, defaultValue: string.Empty);
            var subscriptionId    = string.Empty;
            var resourceGroupName = string.Empty;
            var workspaceName     = string.Empty;

            if (string.IsNullOrEmpty(resourceId))
            {
                resourceId = inputParameters.Keys.FirstOrDefault(key => ResourceIdRegex.IsMatch(key)) ?? string.Empty;
            }

            var match = ResourceIdRegex.Match(resourceId);

            if (match.Success)
            {
                // match.Groups will be a GroupCollection containing four Group objects:
                // -> match.Groups[0]: The full resource ID for the Azure Quantum workspace
                // -> match.Groups[1]: The Azure subscription ID
                // -> match.Groups[2]: The Azure resource group name
                // -> match.Groups[3]: The Azure Quantum workspace name
                subscriptionId    = match.Groups[1].Value;
                resourceGroupName = match.Groups[2].Value;
                workspaceName     = match.Groups[3].Value;
            }
            else
            {
                // look for each of the parameters individually
                subscriptionId    = inputParameters.DecodeParameter <string>(ParameterNameSubscriptionId, defaultValue: string.Empty);
                resourceGroupName = inputParameters.DecodeParameter <string>(ParameterNameResourceGroupName, defaultValue: string.Empty);
                workspaceName     = inputParameters.DecodeParameter <string>(ParameterNameWorkspaceName, defaultValue: string.Empty);
            }

            if (string.IsNullOrWhiteSpace(subscriptionId) ||
                string.IsNullOrWhiteSpace(resourceGroupName) ||
                string.IsNullOrWhiteSpace(workspaceName))
            {
                channel.Stderr($"Please specify a valid {ParameterNameResourceId}, or specify a valid combination of " +
                               $"{ParameterNameSubscriptionId}, {ParameterNameResourceGroupName}, and {ParameterNameWorkspaceName}.");
                return(AzureClientError.WorkspaceNotFound.ToExecutionResult());
            }

            var storageAccountConnectionString = inputParameters.DecodeParameter <string>(ParameterNameStorageAccountConnectionString, defaultValue: string.Empty);
            var location           = inputParameters.DecodeParameter <string>(ParameterNameLocation, defaultValue: string.Empty);
            var refreshCredentials = inputParameters.DecodeParameter <bool>(ParameterNameRefresh, defaultValue: false);

            return(await AzureClient.ConnectAsync(
                       channel,
                       subscriptionId,
                       resourceGroupName,
                       workspaceName,
                       storageAccountConnectionString,
                       location,
                       refreshCredentials));
        }