/// <summary> /// Writes an output message of the given type</summary> /// <param name="type">Message type (Error, Warning or Info)</param> /// <param name="message">Message</param> public void Write(OutputMessageType type, string message) { m_uiDispatcher.BeginInvokeIfRequired(() => { m_viewModel.OutputItems.Add(new OutputItemVm(DateTime.Now, type, message)); }); }
internal OutputMessage(OutputMessageType type, string name, string text, params string[] arguments) { Type = type; Name = name ?? throw new ArgumentNullException(nameof(name)); _arguments = arguments ?? throw new ArgumentNullException(nameof(arguments)); Text = text; }
/// <summary> /// Displays message to the user in a RichTextBox Control</summary> /// <param name="messageType">Message type, which modifies display of message</param> /// <param name="message">Text message to display</param> /// <param name="textBox">RichTextBox in which to display message</param> protected override void OutputMessage(OutputMessageType messageType, string message, RichTextBox textBox) { Color c; string messageTypeText; Font font; switch (messageType) { case OutputMessageType.Error: c = Color.Red; messageTypeText = "Danger!"; font = s_errorFont; break; case OutputMessageType.Warning: c = Color.Orange; messageTypeText = "Careful."; font = s_warningFont; break; default: c = Color.Beige; messageTypeText = "<Yawn>"; font = Font; break; } textBox.SelectionFont = font; textBox.SelectionColor = c; textBox.AppendText(messageTypeText + ": " + message); }
public static OutputMessageType ReadAndDisplayInteractiveCommandProcessOutput(StreamReader standardError) { int lastChr = 0; string output = ""; OutputMessageType messageType = OutputMessageType.None; while ((messageType == OutputMessageType.None || standardError.Peek() != -1) && (lastChr = standardError.Read()) > 0) { string outputChr = null; outputChr += standardError.CurrentEncoding.GetString(new byte[] { (byte)lastChr }); output += outputChr; if (messageType == OutputMessageType.None) { if (output.Contains("Password for")) { messageType = OutputMessageType.RequestInputPassword; } else if (output.Contains("(R)eject, accept (t)emporarily or accept (p)ermanently?")) { messageType = OutputMessageType.RequestAcceptCertificateFullOptions; } else if (output.Contains("(R)eject or accept (t)emporarily?")) { messageType = OutputMessageType.RequestAcceptCertificateNoPermanentOption; } } Console.Write(outputChr); } return(messageType); }
/// <summary> /// Appends the desired message to the text box (using AppendText) and optionally sets the font /// and font color to be used for this text. Can alter the message or take other actions /// depending on the content of the message.</summary> /// <param name="messageType">Type of message</param> /// <param name="message">Text intended to be read by the user</param> /// <param name="textBox">Ccontrol used to display text to the user</param> protected virtual void OutputMessage(OutputMessageType messageType, string message, RichTextBox textBox) { Color c; string messageTypeText; switch (messageType) { case OutputMessageType.Error: c = Color.Red; messageTypeText = "Error".Localize("Label for error message"); break; case OutputMessageType.Warning: c = Color.Orange; messageTypeText = "Warning".Localize("Label for warning message"); break; default: c = textBox.ForeColor; messageTypeText = "Info".Localize("Label for informative message"); break; } textBox.SelectionColor = c; textBox.AppendText(messageTypeText + ": " + message); }
private void ShowError(string messageId, string message, OutputMessageType messageType) { messageId = messageId.Replace(Environment.NewLine, string.Empty);// remove newlines to ease persistence if (!m_suppressedMessages.Contains(messageId)) { // lazily create error dialog if (m_errorDialog == null) { m_errorDialog = new ErrorDialog(); m_errorDialog.StartPosition = FormStartPosition.CenterScreen; m_errorDialog.SuppressMessageClicked += errorDialog_SuppressMessageClicked; m_errorDialog.FormClosed += errorDialog_FormClosed; } if (messageType == OutputMessageType.Error) { m_errorDialog.Text = "Error!".Localize(); } else if (messageType == OutputMessageType.Warning) { m_errorDialog.Text = "Warning".Localize(); } else if (messageType == OutputMessageType.Info) { m_errorDialog.Text = "Info".Localize(); } m_errorDialog.MessageId = messageId; m_errorDialog.Message = message; m_errorDialog.Visible = false; //Just in case a second error message comes through, because... m_errorDialog.Show(m_owner); //if Visible is true, Show() crashes. Should this be the modal ShowDialog(m_owner)? } }
/// <summary> /// Writes an output message of the given type</summary> /// <param name="type">Message type</param> /// <param name="message">Message</param> public void Write(OutputMessageType type, string message) { if (type == OutputMessageType.Error || type == OutputMessageType.Warning) { ShowError(message, message); } }
/// <summary> /// Writes an output message of the given type</summary> /// <param name="type">Message type</param> /// <param name="message">Message</param> public void Write(OutputMessageType type, string message) { if (type == OutputMessageType.Error || type == OutputMessageType.Warning) { ShowError(message, message, type); } }
internal OutputMessage(OutputMessageType type, string name, string text, params string[] arguments) { if (name == null) throw new ArgumentNullException("name"); if (arguments == null) throw new ArgumentNullException("arguments"); _type = type; _name = name; _arguments = arguments; _text = text; }
/// <summary> /// Writes an output message of the given type using all available IOutputWriters</summary> /// <param name="type">Message type</param> /// <param name="message">Message</param> public static void Write(OutputMessageType type, string message) { Write(type, 0, message); if (type == OutputMessageType.Error) ErrorCount++; else if (type == OutputMessageType.Warning) WarningCount++; }
/// <summary> /// Writes a message of the given type, ending in a new line character sequence (if necessary), using all /// available IOutputWriters</summary> /// <param name="type">Message type</param> /// <param name="message">Message</param> public static void WriteLine(OutputMessageType type, string message) { // don't add redundant newline character unless needed if (!message.EndsWith(Environment.NewLine)) { message += Environment.NewLine; } Write(type, message); }
/// <summary> /// Writes an output message of the given type using all available IOutputWriters</summary> /// <param name="type">Message type</param> /// <param name="message">Message</param> public static void Write(OutputMessageType type, string message) { Write(type, 0, message); if (type == OutputMessageType.Error) { ErrorCount++; } else if (type == OutputMessageType.Warning) { WarningCount++; } }
public void SendOutputMessage(string message, OutputMessageType Type = OutputMessageType.Guild) { for (int i = 0; i < Ranks.Count; i++) { for (int j = 0; j < Ranks[i].Members.Count; j++) { PlayerObject player = (PlayerObject)Ranks[i].Members[j].Player; if (player != null) { player.ReceiveOutputMessage(message, Type); } } } }
//Message Methods public void AddOutput(string msg, OutputMessageType type = OutputMessageType.info) { //Create message add to list of other outputs GameObject curMsgGO = Instantiate(messagePrefab); curMsgGO.transform.SetParent(messageHolder.transform); //Setup the message text and apearence OutputMessageIdentity curMsg = curMsgGO.GetComponent <OutputMessageIdentity>(); curMsg.SetupMessage(msg, type); messages.Add(curMsgGO); }
internal OutputMessage(OutputMessageType type, string name, string text, params string[] arguments) { if (name == null) { throw new ArgumentNullException("name"); } if (arguments == null) { throw new ArgumentNullException("arguments"); } _type = type; _name = name; _arguments = arguments; _text = text; }
/// <summary> /// Writes an output message of the given type</summary> /// <param name="type">Message type</param> /// <param name="message">Message</param> public void Write(OutputMessageType type, string message) { switch (type) { case OutputMessageType.Error: Console.Error.Write("Error".Localize() + ": " + message); break; case OutputMessageType.Warning: Console.Error.Write("Warning".Localize() + ": " + message); break; default: Console.Write(message); break; } }
internal OutputMessage(OutputMessageType type, string name, string text, params string[] arguments) { if (name == null) { throw new ArgumentNullException("name"); } if (arguments == null) { throw new ArgumentNullException("arguments"); } this.type = type; this.name = name; this.arguments = arguments; this.text = text; }
/// <summary> /// Writes an output message of the given type and id, using all available IOutputWriters</summary> /// <param name="type">Message type</param> /// <param name="id">A numeric identifier for the message; is only used with TraceSource</param> /// <param name="message">Message</param> public static void Write(OutputMessageType type, int id, string message) { switch (type) { case OutputMessageType.Error: s_atfOutputTracer.TraceEvent(TraceEventType.Error, id, message); break; case OutputMessageType.Warning: s_atfOutputTracer.TraceEvent(TraceEventType.Warning, id, message); break; case OutputMessageType.Info: s_atfOutputTracer.TraceEvent(TraceEventType.Information, id, message); break; } foreach (IOutputWriter writer in s_outputWriters) writer.Write(type, message); }
public void SearchForPassword() { // Prepare const string stdError = "Password for "; using (MemoryStream strReader = new MemoryStream(Encoding.ASCII.GetBytes(stdError))) { using (StreamReader reader = new StreamReader(strReader)) { // Act OutputMessageType type = CommandRunner.ReadAndDisplayInteractiveCommandProcessOutput( reader ); // Assert Assert.Equal(OutputMessageType.RequestInputPassword, type); } } }
public void SearchForRequestAcceptCertificateNoPermanentOption() { // Prepare const string stdError = "(R)eject or accept (t)emporarily?"; using (MemoryStream strReader = new MemoryStream(Encoding.ASCII.GetBytes(stdError))) { using (StreamReader reader = new StreamReader(strReader)) { // Act OutputMessageType type = CommandRunner.ReadAndDisplayInteractiveCommandProcessOutput( reader ); // Assert Assert.Equal(OutputMessageType.RequestAcceptCertificateNoPermanentOption, type); } } }
public void SetType(ProtoCore.OutputMessage.MessageType type) { switch (type) { case ProtoCore.OutputMessage.MessageType.Error: Type = OutputMessageType.Error; break; case ProtoCore.OutputMessage.MessageType.Warning: Type = OutputMessageType.Warning; break; case ProtoCore.OutputMessage.MessageType.Info: Type = OutputMessageType.Info; break; default: Type = OutputMessageType.Invalid; break; } }
/// <summary> /// Writes an output message of the given type and id, using all available IOutputWriters</summary> /// <param name="type">Message type</param> /// <param name="id">A numeric identifier for the message; is only used with TraceSource</param> /// <param name="message">Message</param> public static void Write(OutputMessageType type, int id, string message) { switch (type) { case OutputMessageType.Error: s_atfOutputTracer.TraceEvent(TraceEventType.Error, id, message); break; case OutputMessageType.Warning: s_atfOutputTracer.TraceEvent(TraceEventType.Warning, id, message); break; case OutputMessageType.Info: s_atfOutputTracer.TraceEvent(TraceEventType.Information, id, message); break; } foreach (IOutputWriter writer in s_outputWriters) { writer.Write(type, message); } }
public void SetupMessage(string msg, OutputMessageType type) { //set text uiHandle.text = msg; //set color if (type == OutputMessageType.warning) { uiHandle.color = Color.yellow; } else if (type == OutputMessageType.error) { uiHandle.color = Color.red; } else { uiHandle.color = Color.green; } //reset scale gameObject.transform.localScale = Vector3.one; }
private void ShowError(string messageId, string message, OutputMessageType messageType) { messageId = messageId.Replace(Environment.NewLine, string.Empty);// remove newlines to ease persistence if (!m_suppressedMessages.Contains(messageId)) { // Check for illegal cross-thread operation. m_owner may not be a Control and the InvokeIfRequired // extension method will handle that. (m_owner as Control).InvokeIfRequired(() => { // lazily create error dialog if (m_errorDialog == null) { m_errorDialog = new ErrorDialog(); m_errorDialog.StartPosition = FormStartPosition.CenterScreen; m_errorDialog.SuppressMessageClicked += errorDialog_SuppressMessageClicked; m_errorDialog.FormClosed += errorDialog_FormClosed; } if (messageType == OutputMessageType.Error) { m_errorDialog.Text = "Error!".Localize(); } else if (messageType == OutputMessageType.Warning) { m_errorDialog.Text = "Warning".Localize(); } else if (messageType == OutputMessageType.Info) { m_errorDialog.Text = "Info".Localize(); } m_errorDialog.MessageId = messageId; m_errorDialog.Message = message; m_errorDialog.Visible = false; //Just in case a second error message comes through, because... m_errorDialog.Show(m_owner); //if Visible is true, Show() crashes. }); } }
public void SetType(OutputMessageType type) { switch (type) { case OutputMessageType.PossibleError: Type = OutputMessageType.PossibleError; break; case OutputMessageType.PossibleWarning: Type = OutputMessageType.PossibleWarning; break; case OutputMessageType.Error: Type = OutputMessageType.Error; break; case OutputMessageType.Warning: Type = OutputMessageType.Warning; break; default: Type = OutputMessageType.Invalid; break; } }
/// <summary> /// Displays message to the user in a text control</summary> /// <param name="messageType">Message type, which modifies display of message</param> /// <param name="message">Text message to display</param> public void OutputMessage(OutputMessageType messageType, string message) { if (m_textBox.InvokeRequired) { // we must do this asynchronously in case the owning thread is blocking on this thread m_textBox.BeginInvoke(new Action <OutputMessageType, string>(OutputMessage), messageType, message); return; } if (m_textBox.IsDisposed) { return; } // for performance reasons, clear output if there is too much text if (m_textBox.TextLength > 1048576) { m_textBox.Text = string.Empty; } OutputMessage(messageType, message, m_textBox); m_textBox.ScrollToCaret(); }
private void OnWriteBuildOutput(string newLine, OutputMessageType messageType) { BrushConverter bc = new BrushConverter(); TextRange tr = new TextRange(tbOutput.Document.ContentEnd, tbOutput.Document.ContentEnd) { Text = newLine + Environment.NewLine }; string color = ""; switch (messageType) { case OutputMessageType.Information: color = "Black"; break; case OutputMessageType.Warning: color = "Yellow"; break; case OutputMessageType.Error: color = "Red"; break; } tr.ApplyPropertyValue(TextElement.ForegroundProperty, bc.ConvertFromString(color)); tbOutput.ScrollToEnd(); }
/// <summary> /// Formats and writes an output message of the given type</summary> /// <param name="writer">Output writer</param> /// <param name="type">Message type (Error, Warning or Info)</param> /// <param name="formatString">Message format string</param> /// <param name="args">Message arguments</param> /// <remarks>Use writer formatting when possible to help writers correctly classify /// output messages. For example, a writer that presents a dialog to the user can /// suppress messages of a given class, even though they may differ in specifics such /// as file name, exception message, etc.</remarks> public static void Write(this IOutputWriter writer, OutputMessageType type, string formatString, params object[] args) { writer.Write(type, string.Format(formatString, args)); }
public void OutputMessage(string message, OutputMessageType type = OutputMessageType.Normal) { OutputMessages.Add(new OutPutMessage { Message = message, ExpireTime = CMain.Time + 5000, Type = type }); if (OutputMessages.Count > 10) OutputMessages.RemoveAt(0); }
/// <summary> /// Writes an output message of the given type</summary> /// <param name="type">Message type</param> /// <param name="message">Message</param> public void Write(OutputMessageType type, string message) { OutputMessage(type, message); }
public int RunGitSvnInteractiveCommand(string arguments, string password) { ProcessStartInfo startInfo = new ProcessStartInfo { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, FileName = "git", Arguments = arguments }; using (ManualResetEventSlim exitedEvent = new ManualResetEventSlim(false)) { using (Process commandProcess = new Process()) { int exitCode = -1; try { commandProcess.StartInfo = startInfo; commandProcess.EnableRaisingEvents = true; commandProcess.Exited += (s, e) => { Log($"Process '{startInfo.FileName} {startInfo.Arguments}' exited"); exitedEvent.Set(); }; commandProcess.Start(); OutputMessageType messageType = OutputMessageType.None; do { // Stop if we want to cancel. this._cancelToken.ThrowIfCancellationRequested(); messageType = ReadAndDisplayInteractiveCommandProcessOutput(commandProcess.StandardError); if (messageType == OutputMessageType.RequestInputPassword) { if (password == null) { password = string.Empty; while (true) { var key = System.Console.ReadKey(true); this._cancelToken.ThrowIfCancellationRequested(); if (key.Key == ConsoleKey.Enter) { break; } password += key.KeyChar; } } commandProcess.StandardInput.WriteLine(password); } else if (messageType == OutputMessageType.RequestAcceptCertificateFullOptions) { Console.WriteLine("p"); commandProcess.StandardInput.WriteLine("p"); } else if (messageType == OutputMessageType.RequestAcceptCertificateNoPermanentOption) { Console.WriteLine("t"); commandProcess.StandardInput.WriteLine("t"); } commandProcess.StandardInput.Flush(); } while(messageType != OutputMessageType.None); exitedEvent.Wait(this._cancelToken); commandProcess.WaitForExit(); } catch (Win32Exception) { throw new MigrateException($"Command git does not exit. Did you install it or add it to the Environment path?"); } catch (OperationCanceledException) { Log("CTRL+C Received"); commandProcess.Kill(true); commandProcess.WaitForExit(); throw; } finally { exitCode = commandProcess.ExitCode; commandProcess.Close(); } return(exitCode); } } }
private void ShowError(string messageId, string message, OutputMessageType messageType) { messageId = messageId.Replace(Environment.NewLine, string.Empty);// remove newlines to ease persistence if (!m_suppressedMessages.Contains(messageId)) { // lazily create error dialog if (m_errorDialog == null) { m_errorDialog = new ErrorDialog(); m_errorDialog.StartPosition = FormStartPosition.CenterScreen; m_errorDialog.SuppressMessageClicked += errorDialog_SuppressMessageClicked; m_errorDialog.FormClosed += errorDialog_FormClosed; } if (messageType == OutputMessageType.Error) m_errorDialog.Text = "Error!".Localize(); else if (messageType == OutputMessageType.Warning) m_errorDialog.Text = "Warning".Localize(); else if (messageType == OutputMessageType.Info) m_errorDialog.Text = "Info".Localize(); m_errorDialog.MessageId = messageId; m_errorDialog.Message = message; m_errorDialog.Visible = false; //Just in case a second error message comes through, because... m_errorDialog.Show(m_owner); //if Visible is true, Show() crashes. Should this be the modal ShowDialog(m_owner)? } }
private void ShowError(string messageId, string message, OutputMessageType messageType) { messageId = messageId.Replace(Environment.NewLine, string.Empty);// remove newlines to ease persistence if (!m_suppressedMessages.Contains(messageId)) { // Check for illegal cross-thread operation. m_owner may not be a Control and the InvokeIfRequired // extension method will handle that. (m_owner as Control).InvokeIfRequired(() => { // lazily create error dialog if (m_errorDialog == null) { m_errorDialog = new ErrorDialog(); m_errorDialog.StartPosition = FormStartPosition.CenterScreen; m_errorDialog.SuppressMessageClicked += errorDialog_SuppressMessageClicked; m_errorDialog.FormClosed += errorDialog_FormClosed; } if (messageType == OutputMessageType.Error) m_errorDialog.Text = "Error!".Localize(); else if (messageType == OutputMessageType.Warning) m_errorDialog.Text = "Warning".Localize(); else if (messageType == OutputMessageType.Info) m_errorDialog.Text = "Info".Localize(); m_errorDialog.MessageId = messageId; m_errorDialog.Message = message; m_errorDialog.Visible = false; //Just in case a second error message comes through, because... m_errorDialog.Show(m_owner); //if Visible is true, Show() crashes. }); } }
/// <summary> /// Formats and writes an output message of the given type</summary> /// <param name="type">Message type</param> /// <param name="formatString">Message format string</param> /// <param name="args">Message arguments</param> /// <remarks>Use writer formatting when possible to help writers correctly classify /// output messages. For example, a writer that presents a dialog to the user can /// suppress messages of a given class, even though they may differ in specifics such /// as file name, exception message, etc.</remarks> public void Write(OutputMessageType type, string formatString, params object[] args) { string message = string.Format(formatString, args); Write(type, message); }
/// <summary> /// Writes a message of the given type, ending in a new line character sequence (if necessary), using all /// available IOutputWriters</summary> /// <param name="type">Message type</param> /// <param name="message">Message</param> public static void WriteLine(OutputMessageType type, string message) { // don't add redundant newline character unless needed if (!message.EndsWith(Environment.NewLine)) message += Environment.NewLine; Write(type, message); }
/// <summary> /// Displays message to the user in a text control</summary> /// <param name="messageType">Message type, which modifies display of message</param> /// <param name="message">Text message to display</param> public void OutputMessage(OutputMessageType messageType, string message) { if (m_textBox.InvokeRequired) { // we must do this asynchronously in case the owning thread is blocking on this thread m_textBox.BeginInvoke(new Action<OutputMessageType,string>(OutputMessage), messageType, message); return; } if (m_textBox.IsDisposed) return; // for performance reasons, clear output if there is too much text if (m_textBox.TextLength > 1048576) m_textBox.Text = string.Empty; OutputMessage(messageType, message, m_textBox); m_textBox.ScrollToCaret(); }
public int RunGitSvnInteractiveCommand(string arguments, string password) { Process commandProcess = new Process { StartInfo = { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, FileName = "git", Arguments = arguments } }; int exitCode = -1; try { commandProcess.Start(); OutputMessageType messageType = OutputMessageType.None; do { messageType = ReadAndDisplayCommandProcessOutput(commandProcess); if (messageType == OutputMessageType.RequestInputPassword) { if (string.IsNullOrEmpty(password)) { while (true) { var key = System.Console.ReadKey(true); if (key.Key == ConsoleKey.Enter) { break; } password += key.KeyChar; } } commandProcess.StandardInput.WriteLine(password); } else if (messageType == OutputMessageType.RequestAcceptCertificateFullOptions) { Console.WriteLine("p"); commandProcess.StandardInput.WriteLine("p"); } else if (messageType == OutputMessageType.RequestAcceptCertificateNoPermanentOption) { Console.WriteLine("t"); commandProcess.StandardInput.WriteLine("t"); } commandProcess.StandardInput.Flush(); } while (messageType != OutputMessageType.None); commandProcess.WaitForExit(); } catch (Win32Exception) { throw new MigrateException($"Command git does not exit. Did you install it or add it to the Environment path?"); } finally { exitCode = commandProcess.ExitCode; commandProcess.Close(); } return(exitCode); }
public OutputItemVm(DateTime time, OutputMessageType messageType, string message) { Time = time; MessageType = messageType; Message = message.Replace(System.Environment.NewLine, string.Empty); ; }
protected override void ReadPacket(BinaryReader reader) { Message = reader.ReadString(); Type = (OutputMessageType)reader.ReadByte(); }
/// <summary> /// Constructor</summary> /// <param name="time"></param> /// <param name="messageType"></param> /// <param name="message"></param> public OutputItemVm(DateTime time, OutputMessageType messageType, string message) { Time = time; MessageType = messageType; Message = message.Replace(Environment.NewLine, string.Empty); }