/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using Dbg = System.Management.Automation.Diagnostics;
using System.Runtime.Serialization;
using System.Collections.Generic;
namespace System.Management.Automation
{
///
///
/// Defines a data structure used to represent informational context destined for the host or user.
///
///
///
///
/// InformationRecords are passed to ,
/// which, according to host or user preference, forwards that information on to the host for rendering to the user.
///
///
///
[DataContract()]
public class InformationRecord
{
///
///
/// Initializes a new instance of the InformationRecord class.
///
///
/// The object to be transmitted to the host.
/// The source of the message (i.e.: script path, function name, etc.)
public InformationRecord(Object messageData, string source)
{
this.MessageData = messageData;
this.Source = source;
this.TimeGenerated = DateTime.Now;
this.Tags = new List();
if (Platform.IsWindows)
{
this.User = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
}
else
{
this.User = Platform.NonWindowsGetUserName();
}
// Porting note: PsUtils.GetHostName() already handles platform specifics
this.Computer = PsUtils.GetHostName();
this.ProcessId = (uint)System.Diagnostics.Process.GetCurrentProcess().Id;
this.NativeThreadId = PsUtils.GetNativeThreadId();
this.ManagedThreadId = (uint)System.Threading.Thread.CurrentThread.ManagedThreadId;
}
///
/// Added to enable ClrFacade.GetUninitializedObject to instantiate an uninitialized version of this class.
///
internal InformationRecord() { }
///
/// Copy constructor
///
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;
}
// Some of these setters are internal, while others are public.
// The ones that are public are left that way because systems that proxy
// the events may need to alter them (i.e.: workflow). The ones that remain internal
// are that way because they are fundamental properties of the record itself.
///
/// The message data for this informational record
///
[DataMember]
public Object MessageData { get; internal set; }
///
/// The source of this informational record (script path, function name, etc.)
///
[DataMember]
public string Source { get; set; }
///
/// The time this informational record was generated.
///
[DataMember]
public DateTime TimeGenerated { get; set; }
///
/// The tags assocaited with this informational record (if any)
///
[DataMember]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public List Tags { get; internal set; }
///
/// The user that generated this informational record
///
[DataMember]
public string User { get; set; }
///
/// The computer that generated this informational record
///
[DataMember]
public string Computer { get; set; }
///
/// The process that generated this informational record
///
[DataMember]
public uint ProcessId { get; set; }
///
/// The native thread that generated this informational record
///
public uint NativeThreadId { get; set; }
///
/// The managed thread that generated this informational record
///
[DataMember]
public uint ManagedThreadId { get; set; }
///
/// Converts an InformationRecord to a string-based representation.
///
///
public override string ToString()
{
if (MessageData != null)
{
return MessageData.ToString();
}
else
{
return base.ToString();
}
}
internal static InformationRecord FromPSObjectForRemoting(PSObject inputObject)
{
InformationRecord informationRecord = new InformationRecord();
informationRecord.MessageData = RemotingDecoder.GetPropertyValue