/// <summary> /// Copy constructor /// </summary> internal InformationRecord(InformationRecord baseRecord) { this.MessageData = baseRecord.MessageData; this.Source = baseRecord.Source; this.TimeGenerated = baseRecord.TimeGenerated; this.Tags = baseRecord.Tags; this.User = baseRecord.User; this.Computer = baseRecord.Computer; this.ProcessId = baseRecord.ProcessId; this.NativeThreadId = baseRecord.NativeThreadId; this.ManagedThreadId = baseRecord.ManagedThreadId; }
private void ReadXml() { try { XmlReader xmlReader = XmlReader.Create(_streamReader, InternalDeserializer.XmlReaderSettingsForCliXml); Deserializer des = new Deserializer(xmlReader); while (!des.Done()) { string streamName; object obj = des.Deserialize(out streamName); //Decide the stream to which data belongs MinishellStream stream = MinishellStream.Unknown; if (streamName != null) { stream = StringToMinishellStreamConverter.ToMinishellStream(streamName); } if (stream == MinishellStream.Unknown) { stream = _isOutput ? MinishellStream.Output : MinishellStream.Error; } //Null is allowed only in output stream if (stream != MinishellStream.Output && obj == null) { continue; } if (stream == MinishellStream.Error) { if (obj is PSObject) { obj = ErrorRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj)); } else { string errorMessage = null; try { errorMessage = (string)LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture); } catch (PSInvalidCastException) { continue; } obj = new ErrorRecord(new RemoteException(errorMessage), "NativeCommandError", ErrorCategory.NotSpecified, errorMessage); } } else if (stream == MinishellStream.Information) { if (obj is PSObject) { obj = InformationRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj)); } else { string messageData = null; try { messageData = (string)LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture); } catch (PSInvalidCastException) { continue; } obj = new InformationRecord(messageData, null); } } else if (stream == MinishellStream.Debug || stream == MinishellStream.Verbose || stream == MinishellStream.Warning) { //Convert to string try { obj = LanguagePrimitives.ConvertTo(obj, typeof(string), CultureInfo.InvariantCulture); } catch (PSInvalidCastException) { continue; } } AddObjectToWriter(obj, stream); } } catch (XmlException originalException) { string template = NativeCP.CliXmlError; string message = string.Format( null, template, _isOutput ? MinishellStream.Output : MinishellStream.Error, _processPath, originalException.Message); XmlException newException = new XmlException( message, originalException); ErrorRecord error = new ErrorRecord( newException, "ProcessStreamReader_CliXmlError", ErrorCategory.SyntaxError, _processPath); AddObjectToWriter(error, MinishellStream.Error); } }
public override void WriteInformation(System.Management.Automation.InformationRecord record) { outStream.println(record.ToString()); outStream.flush(); }
/// <summary> /// /// See base class /// /// </summary> /// <param name="record"></param> public override void WriteInformation(InformationRecord record) { //We should write information to error stream only if redirected.) if (_parent.ErrorFormat == Serialization.DataFormat.XML) { _parent.ErrorSerializer.Serialize(record, "information"); } else { // Do nothing. The information stream is not visible by default } }
/// <summary> /// Send the specified information record to client. /// </summary> /// <param name="record">Information record.</param> internal void SendInformationRecordToClient(InformationRecord record) { SendDataAsync(RemotingEncoder.GeneratePowerShellInformational( record, _clientRunspacePoolId, _clientPowerShellId)); }
/// <summary> /// Default implementation - just discards it's arguments. /// </summary> /// <param name="informationRecord">Record to write.</param> public void WriteInformation(InformationRecord informationRecord) { ; }
/// <summary> /// Send the specified information record to client /// </summary> /// <param name="record">information record</param> internal void SendInformationRecordToClient(InformationRecord record) { SendDataAsync(RemotingEncoder.GeneratePowerShellInformational( record, _clientRunspacePoolId, _clientPowerShellId)); }
/// <summary> /// Display tagged object information /// </summary> internal void WriteInformation(InformationRecord record, bool overrideInquire = false) { ActionPreference preference = InformationPreference; if (overrideInquire && preference == ActionPreference.Inquire) preference = ActionPreference.Continue; if (preference != ActionPreference.Ignore) { if (InformationOutputPipe != null) { if (CBhost != null && CBhost.InternalUI != null && InformationOutputPipe.NullPipe) { // If redirecting to a null pipe, still write to // information buffers. CBhost.InternalUI.WriteInformationInfoBuffers(record); } // Add note property so that the information output is formatted correctly. PSObject informationWrap = PSObject.AsPSObject(record); if (informationWrap.Members["WriteInformationStream"] == null) { informationWrap.Properties.Add(new PSNoteProperty("WriteInformationStream", true)); } InformationOutputPipe.Add(informationWrap); } else { // // If no pipe, write directly to host. // if (null == Host || null == Host.UI) { Diagnostics.Assert(false, "No host in CommandBase.WriteVerbose()"); throw PSTraceSource.NewInvalidOperationException(); } CBhost.InternalUI.WriteInformationRecord(record); if ((record.Tags.Contains("PSHOST") && (!record.Tags.Contains("FORWARDED"))) || (preference == ActionPreference.Continue)) { HostInformationMessage hostOutput = record.MessageData as HostInformationMessage; if (hostOutput != null) { string message = hostOutput.Message; ConsoleColor? foregroundColor = null; ConsoleColor? backgroundColor = null; bool noNewLine = false; if (hostOutput.ForegroundColor.HasValue) { foregroundColor = hostOutput.ForegroundColor.Value; } if (hostOutput.BackgroundColor.HasValue) { backgroundColor = hostOutput.BackgroundColor.Value; } if (hostOutput.NoNewLine.HasValue) { noNewLine = hostOutput.NoNewLine.Value; } if (foregroundColor.HasValue || backgroundColor.HasValue) { // It is possible for either one or the other to be empty if run from a // non-interactive host, but only one was specified in Write-Host. // So fill them with defaults if they are empty. if (!foregroundColor.HasValue) { foregroundColor = ConsoleColor.Gray; } if (!backgroundColor.HasValue) { backgroundColor = ConsoleColor.Black; } if (noNewLine) { CBhost.InternalUI.Write(foregroundColor.Value, backgroundColor.Value, message); } else { CBhost.InternalUI.WriteLine(foregroundColor.Value, backgroundColor.Value, message); } } else { if (noNewLine) { CBhost.InternalUI.Write(message); } else { CBhost.InternalUI.WriteLine(message); } } } else { CBhost.InternalUI.WriteLine(record.ToString()); } } else { // Only transcribe informational messages here. Transcription of PSHost-targeted messages is done in the InternalUI.Write* methods. CBhost.InternalUI.TranscribeResult(StringUtil.Format(InternalHostUserInterfaceStrings.InformationFormatString, record.ToString())); } } } AppendInformationVarList(record); lastInformationContinueStatus = WriteHelper( null, null, preference, lastInformationContinueStatus, "InformationPreference", record.ToString()); }
/// <summary> /// Display tagged object information /// </summary> public void WriteInformation(InformationRecord informationRecord) { WriteInformation(informationRecord, false); }
/// <summary> /// Default implementation - just discards it's arguments /// </summary> /// <param name="informationRecord">Record to write.</param> public void WriteInformation(InformationRecord informationRecord) {; }
internal static InformationRecord FromPSObjectForRemoting(PSObject inputObject) { InformationRecord informationRecord = new InformationRecord(); informationRecord.MessageData = RemotingDecoder.GetPropertyValue<Object>(inputObject, "MessageData"); informationRecord.Source = RemotingDecoder.GetPropertyValue<string>(inputObject, "Source"); informationRecord.TimeGenerated = RemotingDecoder.GetPropertyValue<DateTime>(inputObject, "TimeGenerated"); informationRecord.Tags = new List<string>(); System.Collections.ArrayList tagsArrayList = RemotingDecoder.GetPropertyValue<System.Collections.ArrayList>(inputObject, "Tags"); foreach (string tag in tagsArrayList) { informationRecord.Tags.Add(tag); } informationRecord.User = RemotingDecoder.GetPropertyValue<string>(inputObject, "User"); informationRecord.Computer = RemotingDecoder.GetPropertyValue<string>(inputObject, "Computer"); informationRecord.ProcessId = RemotingDecoder.GetPropertyValue<uint>(inputObject, "ProcessId"); informationRecord.NativeThreadId = RemotingDecoder.GetPropertyValue<uint>(inputObject, "NativeThreadId"); informationRecord.ManagedThreadId = RemotingDecoder.GetPropertyValue<uint>(inputObject, "ManagedThreadId"); return informationRecord; }
} // WriteDebug internal void WriteInformation(InformationRecord record) { if (_command != null) { _command.WriteInformation(record); } } // WriteInformation