//
// Copyright (c) 2009 Microsoft Corporation. All rights reserved.
//
// DISCLAIMER OF WARRANTY: The software is licensed “as-is.” You
// bear the risk of using it. Microsoft gives no express warranties,
// guarantees or conditions. You may have additional consumer rights
// under your local laws which this agreement cannot change. To the extent
// permitted under your local laws, Microsoft excludes the implied warranties
// of merchantability, fitness for a particular purpose and non-infringement.
namespace Microsoft.Samples.PowerShell.Host
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Management.Automation;
using System.Management.Automation.Host;
///
/// A sample implementation of the PSHostUserInterface abstract class for console
/// applications. Few members are actually implemented. Those that aren't throw a
/// NotImplementedException.
///
internal class MyHostUserInterface : PSHostUserInterface
{
///
/// An instance of the PSRawUserInterface object.
///
private MyRawUserInterface myRawUi = new MyRawUserInterface();
///
/// Gets an instance of the PSRawUserInterface object for this host
/// application.
///
public override PSHostRawUserInterface RawUI
{
get { return this.myRawUi; }
}
///
/// Prompts the user for input.
///
/// The caption or title of the prompt.
/// The text of the prompt.
/// A collection of FieldDescription objects that
/// describe each field of the prompt.
/// Throws a NotImplementedException exception.
public override Dictionary Prompt(string caption, string message, System.Collections.ObjectModel.Collection descriptions)
{
throw new NotImplementedException("The method or operation is not implemented.");
}
///
/// Provides a set of choices that enable the user to choose a single option from a set of options.
///
/// Text that proceeds (a title) the choices.
/// A message that describes the choice.
/// A collection of ChoiceDescription objects that describes
/// each choice.
/// The index of the label in the Choices parameter
/// collection. To indicate no default choice, set to -1.
/// Throws a NotImplementedException exception.
public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection choices, int defaultChoice)
{
throw new NotImplementedException("The method or operation is not implemented.");
}
///
/// Prompts the user for credentials with a specified prompt window caption,
/// prompt message, user name, and target name.
///
/// The caption for the message window.
/// The text of the message.
/// The user name whose credential is to be prompted for.
/// The name of the target for which the credential is collected.
/// Throws a NotImplementedException exception.
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName)
{
throw new NotImplementedException("The method or operation is not implemented.");
}
///
/// Prompts the user for credentials by using a specified prompt window caption,
/// prompt message, user name and target name, credential types allowed to be
/// returned, and UI behavior options.
///
/// The caption for the message window.
/// The text of the message.
/// The user name whose credential is to be prompted for.
/// The name of the target for which the credential is collected.
/// A PSCredentialTypes constant that
/// identifies the type of credentials that can be returned.
/// A PSCredentialUIOptions constant that identifies the UI
/// behavior when it gathers the credentials.
/// Throws a NotImplementedException exception.
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options)
{
throw new NotImplementedException("The method or operation is not implemented.");
}
///
/// Reads characters that are entered by the user until a newline
/// (carriage return) is encountered.
///
/// The characters that are entered by the user.
public override string ReadLine()
{
return Console.ReadLine();
}
///
/// Reads characters entered by the user until a newline (carriage return)
/// is encountered and returns the characters as a secure string.
///
/// Throws a NotImplemented exception.
public override System.Security.SecureString ReadLineAsSecureString()
{
throw new NotImplementedException("The method or operation is not implemented.");
}
///
/// Writes a new line character (carriage return) to the output display
/// of the host.
///
/// The characters to be written.
public override void Write(string value)
{
System.Console.Write(value);
}
///
/// Writes characters to the output display of the host with possible
/// foreground and background colors. This implementation ignores the colors.
///
/// The color of the characters.
/// The backgound color to use.
/// The characters to be written.
public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
{
// Just ignore the colors.
System.Console.Write(value);
}
///
/// Writes a debug message to the output display of the host.
///
/// The debug message that is displayed.
public override void WriteDebugLine(string message)
{
Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "DEBUG: {0}", message));
}
///
/// Writes an error message to the output display of the host.
///
/// The error message that is displayed.
public override void WriteErrorLine(string value)
{
Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "ERROR: {0}", value));
}
///
/// Writes a newline character (carriage return)
/// to the output display of the host.
///
public override void WriteLine()
{
System.Console.WriteLine();
}
///
/// Writes a line of characters to the output display of the host
/// and appends a newline character(carriage return).
///
/// The line to be written.
public override void WriteLine(string value)
{
System.Console.WriteLine(value);
}
///
/// Writes a line of characters to the output display of the host
/// with foreground and background colors and appends a newline (carriage return).
///
/// The forground color of the display.
/// The background color of the display.
/// The line to be written.
public override void WriteLine(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
{
// Write to the output stream, ignore the colors
System.Console.WriteLine(value);
}
///
/// Writes a progress report to the output display of the host.
///
/// Unique identifier of the source of the record.
/// A ProgressReport object.
public override void WriteProgress(long sourceId, ProgressRecord record)
{
// Do nothing.
}
///
/// Writes a verbose message to the output display of the host.
///
/// The verbose message that is displayed.
public override void WriteVerboseLine(string message)
{
Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "VERBOSE: {0}", message));
}
///
/// Writes a warning message to the output display of the host.
///
/// The warning message that is displayed.
public override void WriteWarningLine(string message)
{
Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "WARNING: {0}", message));
}
}
}