Пример #1
0
 /// <summary>
 /// Called when a prompt should be displayed for a specific
 /// input field.
 /// </summary>
 /// <param name="fieldDetails">The details of the field to be displayed.</param>
 protected override void ShowFieldPrompt(FieldDetails fieldDetails)
 {
     // For a simple prompt there won't be any field name.
     // In this case don't write anything
     if (!string.IsNullOrEmpty(fieldDetails.Name))
     {
         this.hostOutput.WriteOutput(
             fieldDetails.Name + ": ",
             false);
     }
 }
Пример #2
0
        protected override void ShowFieldPrompt(FieldDetails fieldDetails)
        {
            base.ShowFieldPrompt(fieldDetails);

            _languageServer.SendRequest <ShowInputPromptRequest, ShowInputPromptResponse>(
                "powerShell/showInputPrompt",
                new ShowInputPromptRequest
            {
                Name  = fieldDetails.Name,
                Label = fieldDetails.Label
            }).ContinueWith(HandlePromptResponse)
            .ConfigureAwait(false);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="promptCaption"></param>
        /// <param name="promptMessage"></param>
        /// <param name="fieldDescriptions"></param>
        /// <returns></returns>
        public override Dictionary <string, PSObject> Prompt(
            string promptCaption,
            string promptMessage,
            Collection <FieldDescription> fieldDescriptions)
        {
            FieldDetails[] fields =
                fieldDescriptions
                .Select(f => { return(FieldDetails.Create(f, this.Logger)); })
                .ToArray();

            CancellationTokenSource             cancellationToken = new CancellationTokenSource();
            Task <Dictionary <string, object> > promptTask        =
                this.CreateInputPromptHandler()
                .PromptForInputAsync(
                    promptCaption,
                    promptMessage,
                    fields,
                    cancellationToken.Token);

            // Run the prompt task and wait for it to return
            this.WaitForPromptCompletion(
                promptTask,
                "Prompt",
                cancellationToken);

            // Convert all values to PSObjects
            var psObjectDict = new Dictionary <string, PSObject>();

            // The result will be null if the prompt was cancelled
            if (promptTask.Result != null)
            {
                // Convert all values to PSObjects
                foreach (var keyValuePair in promptTask.Result)
                {
                    psObjectDict.Add(
                        keyValuePair.Key,
                        keyValuePair.Value != null
                            ? PSObject.AsPSObject(keyValuePair.Value)
                            : null);
                }
            }

            // Return the result
            return(psObjectDict);
        }
Пример #4
0
        private FieldDetails GetNextField()
        {
            FieldDetails nextField = this.currentField?.GetNextField();

            if (nextField == null)
            {
                this.currentFieldIndex++;

                // Have we shown all the prompts already?
                if (this.currentFieldIndex < this.Fields.Length)
                {
                    nextField = this.Fields[this.currentFieldIndex];
                }
            }

            this.currentField = nextField;
            return(nextField);
        }
Пример #5
0
 /// <summary>
 /// Called when a prompt should be displayed for a specific
 /// input field.
 /// </summary>
 /// <param name="fieldDetails">The details of the field to be displayed.</param>
 protected abstract void ShowFieldPrompt(FieldDetails fieldDetails);