Exemple #1
0
        protected override void BeginProcessing()
        {
            InternalHost host = base.Host as InternalHost;

            if (host != null)
            {
                ConsoleHost externalHost = host.ExternalHost as ConsoleHost;
                if (externalHost != null)
                {
                    if (!externalHost.IsTranscribing)
                    {
                        if (!this.isFilenameSet)
                        {
                            object variableValue = base.GetVariableValue("global:TRANSCRIPT", null);
                            if (variableValue != null)
                            {
                                this.outFilename = (string)variableValue;
                            }
                            else
                            {
                                this.outFilename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), StringUtil.Format("PowerShell_transcript.{0:yyyyMMddHHmmss}.txt", DateTime.Now));
                            }
                        }
                        try
                        {
                            string str = this.ResolveFilePath(this.Path, this.isLiteralPath);
                            if (base.ShouldProcess(this.Path))
                            {
                                if (File.Exists(str))
                                {
                                    if (this.NoClobber && !this.Append)
                                    {
                                        string      str1 = StringUtil.Format(TranscriptStrings.TranscriptFileExistsNoClobber, str, "NoClobber");
                                        Exception   unauthorizedAccessException = new UnauthorizedAccessException(str1);
                                        ErrorRecord errorRecord = new ErrorRecord(unauthorizedAccessException, "NoClobber", ErrorCategory.ResourceExists, str);
                                        base.ThrowTerminatingError(errorRecord);
                                    }
                                    FileInfo fileInfo = new FileInfo(str);
                                    if ((fileInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                                    {
                                        if (!this.Force)
                                        {
                                            object[] objArray = new object[1];
                                            objArray[0] = str;
                                            Exception exception = PSTraceSource.NewArgumentException(str, "TranscriptStrings", "TranscriptFileReadOnly", objArray);
                                            base.ThrowTerminatingError(new ErrorRecord(exception, "FileReadOnly", ErrorCategory.InvalidArgument, str));
                                        }
                                        else
                                        {
                                            FileInfo attributes = fileInfo;
                                            attributes.Attributes = attributes.Attributes & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Directory | FileAttributes.Archive | FileAttributes.Device | FileAttributes.Normal | FileAttributes.Temporary | FileAttributes.SparseFile | FileAttributes.ReparsePoint | FileAttributes.Compressed | FileAttributes.Offline | FileAttributes.NotContentIndexed | FileAttributes.Encrypted
#if !MONO
                                                                                             | FileAttributes.IntegrityStream | FileAttributes.NoScrubData
#endif
                                                                                             );
                                        }
                                    }
                                }
                                externalHost.StartTranscribing(str, this.Append);
                                base.WriteObject(StringUtil.Format(TranscriptStrings.TranscriptionStarted, this.Path));
                            }
                        }
                        catch (Exception exception2)
                        {
                            Exception   exception1   = exception2;
                            string      str2         = "CannotStartTranscription";
                            ErrorRecord errorRecord1 = new ErrorRecord(PSTraceSource.NewInvalidOperationException(exception1, "TranscriptStrings", str2, new object[0]), str2, ErrorCategory.InvalidOperation, null);
                            base.ThrowTerminatingError(errorRecord1);
                        }
                        return;
                    }
                    else
                    {
                        throw new InvalidOperationException(TranscriptStrings.TranscriptionInProgress);
                    }
                }
                else
                {
                    throw new PSNotSupportedException(StringUtil.Format(TranscriptStrings.HostDoesNotSupportTranscript, new object[0]));
                }
            }
            else
            {
                throw new PSNotSupportedException(StringUtil.Format(TranscriptStrings.HostDoesNotSupportTranscript, new object[0]));
            }
        }