예제 #1
0
        public async Task <ExecutionResult> GetActiveTargetAsync(IChannel channel)
        {
            if (AvailableProviders == null)
            {
                channel.Stderr($"Please call {GetCommandDisplayName("connect")} before getting the execution target.");
                return(AzureClientError.NotConnected.ToExecutionResult());
            }

            if (ActiveTarget == null)
            {
                channel.Stderr($"No execution target has been specified. To specify one, call {GetCommandDisplayName("target")} with the target ID.");
                channel.Stdout($"Available execution targets: {ValidExecutionTargetsDisplayText}");
                return(AzureClientError.NoTarget.ToExecutionResult());
            }

            var connectionResult = await RefreshConnectionAsync(channel);

            if (connectionResult.Status != ExecuteStatus.Ok)
            {
                return(connectionResult);
            }

            channel.Stdout($"Current execution target: {ActiveTarget.TargetId}");
            channel.Stdout($"Available execution targets: {ValidExecutionTargetsDisplayText}");

            return(AvailableTargets.First(target => target.Id == ActiveTarget.TargetId).ToExecutionResult());
        }
예제 #2
0
        public void AddAvailableTarget(TargetObject _target)
        {
            if (_target == null || !_target.IsValidAndReady)
            {
                return;
            }

            _target.Selectors.ResetStatus();
            AvailableTargets.Add(_target);
        }
예제 #3
0
        public void OnAddButtonClicked(IList selectedItems)
        {
            IEnumerable <TargetViewModel> targets =
                AvailableTargets.Where(t => selectedItems.Cast <TargetViewModel>().Select(item => item.DisplayName).Contains(t.DisplayName)).ToList();

            foreach (TargetViewModel target in targets)
            {
                SelectedTargets.Add(target);
                AvailableTargets.Remove(target);
            }
        }
예제 #4
0
        public async Task <ExecutionResult> SetActiveTargetAsync(IChannel channel, string targetId, CancellationToken?cancellationToken = default)
        {
            if (ActiveWorkspace == null || AvailableProviders == null)
            {
                channel?.Stderr($"Please call {GetCommandDisplayName("connect")} before setting an execution target.");
                return(AzureClientError.NotConnected.ToExecutionResult());
            }

            var connectionResult = await RefreshConnectionAsync(channel);

            if (connectionResult.Status != ExecuteStatus.Ok)
            {
                return(connectionResult);
            }

            // Validate that this target is valid in the workspace.
            var target = AvailableTargets.FirstOrDefault(t => targetId == t.TargetId);

            if (target == null)
            {
                channel?.Stderr($"Target {targetId} is not available in the current Azure Quantum workspace.");
                channel?.Stdout($"Available execution targets: {ValidExecutionTargetsDisplayText}");
                return(AzureClientError.InvalidTarget.ToExecutionResult());
            }

            // Validate that we know which package to load for this target.
            var executionTarget = AzureExecutionTarget.Create(target);

            if (executionTarget == null)
            {
                channel?.Stderr($"Target {targetId} does not support executing Q# jobs.");
                channel?.Stdout($"Available execution targets: {ValidExecutionTargetsDisplayText}");
                return(AzureClientError.InvalidTarget.ToExecutionResult());
            }

            // Set the active target and load the package.
            ActiveTarget = executionTarget;

            channel?.Stdout($"Loading package {ActiveTarget.PackageName} and dependencies...");
            await References.AddPackage(ActiveTarget.PackageName);

            channel?.Stdout($"Active target is now {ActiveTarget.TargetId}");

            return(AvailableTargets.First(target => target.TargetId == ActiveTarget.TargetId).ToExecutionResult());
        }
예제 #5
0
        private void UpdateAvailableTables()
        {
            if (string.IsNullOrEmpty(SelectedDatabase.DatabasePath))
            {
                return;
            }

            using (var dbHandler = new DatabaseHandler(SelectedDatabase.DatabasePath))
            {
                var tables = dbHandler.GetTables();
                var views  = dbHandler.GetViews();

                AvailableTargets.Clear();

                foreach (var table in tables)
                {
                    AvailableTargets.Add(table.Name);
                }
                foreach (var view in views)
                {
                    AvailableTargets.Add(view.Name);
                }
            }
        }
예제 #6
0
 public override void OnPanelVisible()
 {
     AvailableTargets.ReplaceAll(mainwindow.InstallationTargets.Where(x => x.Selectable));
     SelectedTarget = AvailableTargets.FirstOrDefault();
 }