private static TranscriptionOption GetTranscriptOptionFromSettings(Dictionary<string, object> settings, TranscriptionOption currentTranscript) { TranscriptionOption transcript = null; object keyValue = null; if (settings.TryGetValue("EnableTranscripting", out keyValue)) { if (String.Equals(keyValue.ToString(), "1", StringComparison.OrdinalIgnoreCase)) { if (currentTranscript != null) { return currentTranscript; } transcript = new TranscriptionOption(); // Pull out the transcript path object outputDirectoryValue = null; if (settings.TryGetValue("OutputDirectory", out outputDirectoryValue)) { string outputDirectoryString = outputDirectoryValue as string; transcript.Path = GetTranscriptPath(outputDirectoryString, true); } else { transcript.Path = GetTranscriptPath(); } // Pull out the "enable invocation header" object enableInvocationHeaderValue = null; if (settings.TryGetValue("EnableInvocationHeader", out enableInvocationHeaderValue)) { if (String.Equals("1", enableInvocationHeaderValue.ToString(), StringComparison.OrdinalIgnoreCase)) { transcript.IncludeInvocationHeader = true; } } } } return transcript; }
/// <summary> /// Get Module Logging information from the registry. /// </summary> internal static TranscriptionOption GetSystemTranscriptOption(TranscriptionOption currentTranscript) { Dictionary<string, object> groupPolicySettings = Utils.GetGroupPolicySetting("Transcription", Utils.RegLocalMachineThenCurrentUser); if (groupPolicySettings != null) { // If we have an existing system transcript for this process, use that. // Otherwise, populate the static variable with the result of the group policy setting. // // This way, multiple runspaces opened by the same process will share the same transcript. lock (s_systemTranscriptLock) { if (systemTranscript == null) { systemTranscript = PSHostUserInterface.GetTranscriptOptionFromSettings(groupPolicySettings, currentTranscript); } } } return systemTranscript; }
private void LogTranscriptHeader(System.Management.Automation.Remoting.PSSenderInfo senderInfo, TranscriptionOption transcript) { string username = Environment.UserDomainName + "\\" + Environment.UserName; string runAsUser = username; if (senderInfo != null) { username = senderInfo.UserInfo.Identity.Name; } // Add bits from PSVersionTable StringBuilder psVersionInfo = new StringBuilder(); Hashtable versionInfo = PSVersionInfo.GetPSVersionTable(); foreach (string versionKey in versionInfo.Keys) { Object value = versionInfo[versionKey]; if (value != null) { var arrayValue = value as object[]; string valueString = arrayValue != null ? string.Join(", ", arrayValue) : value.ToString(); psVersionInfo.AppendLine(versionKey + ": " + valueString); } } // Transcribe the transcript header string format = InternalHostUserInterfaceStrings.TranscriptPrologue; string line = String.Format( Globalization.CultureInfo.InvariantCulture, format, DateTime.Now, username, runAsUser, Environment.MachineName, Environment.OSVersion.VersionString, String.Join(" ", Environment.GetCommandLineArgs()), System.Diagnostics.Process.GetCurrentProcess().Id, psVersionInfo.ToString().TrimEnd() ); lock (transcript.OutputToLog) { transcript.OutputToLog.Add(line); } TranscribeCommandComplete(null); }
private void LogTranscriptFooter(TranscriptionOption stoppedTranscript) { // Transcribe the transcript epilogue try { string message = String.Format( Globalization.CultureInfo.InvariantCulture, InternalHostUserInterfaceStrings.TranscriptEpilogue, DateTime.Now); lock (stoppedTranscript.OutputToLog) { stoppedTranscript.OutputToLog.Add(message); } TranscribeCommandComplete(null); } catch (Exception e) { // Ignoring errors when stopping transcription (i.e.: file in use, access denied) // since this is probably handling exactly that error. CommandProcessorBase.CheckForSevereException(e); } }
internal void StartTranscribing(string path, System.Management.Automation.Remoting.PSSenderInfo senderInfo, bool includeInvocationHeader) { TranscriptionOption transcript = new TranscriptionOption(); transcript.Path = path; transcript.IncludeInvocationHeader = includeInvocationHeader; TranscriptionData.Transcripts.Add(transcript); LogTranscriptHeader(senderInfo, transcript); }