Example #1
0
        /// <summary></summary>
        /// <param name="ui"></param>
        /// <param name="activity"></param>
        /// <param name="text"></param>
        public CmdletProgress(PSHostUserInterface ui, string activity, string statusDescription)
        {
            this.sourceId = Environment.TickCount;
            this.ui       = ui;
            this.progress = new ProgressRecord(Math.Abs(activity.GetHashCode()), activity, statusDescription);

            ui.WriteProgress(sourceId, progress);
        }         // ctor
        public override void WriteProgress(long sourceId, ProgressRecord record)
        {
            SendToSubscribers(s => s.WriteProgress(sourceId, record));

            if (externalUI != null)
            {
                externalUI.WriteProgress(sourceId, record);
            }
        }
        public override void WriteProgress(long sourceId, ProgressRecord record)
        {
            if (externalUI == null)
            {
                throw new InvalidOperationException();
            }

            SendToSubscribers(s => s.WriteProgress(sourceId, record));

            externalUI.WriteProgress(sourceId, record);
        }
Example #4
0
        public static PowerShell WithStreamsOutput(this PowerShell ps, PSHostUserInterface psui)
        {
            ps.Streams.Information.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <InformationRecord>)sender)[args.Index];
                psui.WriteInformation(data);
            };
            ps.Streams.Progress.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <ProgressRecord>)sender)[args.Index];
                psui.WriteProgress(data.ActivityId, data);
            };
            ps.Streams.Debug.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <DebugRecord>)sender)[args.Index];
                psui.WriteDebugLine(data.Message);
            };
            ps.Streams.Verbose.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <VerboseRecord>)sender)[args.Index];
                psui.WriteVerboseLine(data.Message);
            };
            ps.Streams.Warning.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <WarningRecord>)sender)[args.Index];
                psui.WriteWarningLine(data.Message);
            };
            ps.Streams.Error.DataAdded += (sender, args) =>
            {
                var data = ((PSDataCollection <ErrorRecord>)sender)[args.Index];
                psui.WriteErrorLine(data.ErrorDetails?.Message ?? "Error Occured:");
                psui.WriteErrorLine("    Id: " + data.FullyQualifiedErrorId);
                psui.WriteErrorLine("    Category: " + data.CategoryInfo.Category);
                psui.WriteErrorLine("    Exception:");
                psui.WriteErrorLine(data.Exception.Print(2));

                if (!string.IsNullOrWhiteSpace(data.ErrorDetails?.RecommendedAction))
                {
                    psui.WriteErrorLine("    Recommendation" + data.ErrorDetails?.RecommendedAction);
                }
            };
            return(ps);
        }
Example #5
0
 public override void WriteProgress(long sourceId, ProgressRecord record)
 {
     _ui.WriteProgress(sourceId, record);
 }
Example #6
0
        }         // ctor

        public void Dispose()
        {
            progress.RecordType = ProgressRecordType.Completed;
            ui.WriteProgress(sourceId, progress);
        }         // proc Dispose