File size: 2,817 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Management.Automation;
using System.Management.Automation.Internal;

using Microsoft.PowerShell.Commands.Internal.Format;

namespace Microsoft.PowerShell.Commands
{
    /// <summary>
    /// Implementation for the out-lineoutput command
    /// it provides a wrapper for the OutCommandInner class,
    /// which is the general purpose output command.
    /// </summary>
    [Cmdlet(VerbsData.Out, "LineOutput")]
    public class OutLineOutputCommand : FrontEndCommandBase
    {
        /// <summary>
        /// Command line switch for ILineOutput communication channel.
        /// </summary>
        /// <value></value>
        [Parameter(Mandatory = true, Position = 0)]
        public object LineOutput
        {
            get { return _lineOutput; }

            set { _lineOutput = value; }
        }

        private object _lineOutput = null;

        /// <summary>
        /// Set inner command.
        /// </summary>
        public OutLineOutputCommand()
        {
            this.implementation = new OutCommandInner();
        }

        /// <summary>
        /// </summary>
        protected override void BeginProcessing()
        {
            if (_lineOutput == null)
            {
                ProcessNullLineOutput();
            }

            LineOutput lo = _lineOutput as LineOutput;
            if (lo == null)
            {
                ProcessWrongTypeLineOutput(_lineOutput);
            }

            ((OutCommandInner)this.implementation).LineOutput = lo;

            base.BeginProcessing();
        }

        private void ProcessNullLineOutput()
        {
            string msg = StringUtil.Format(FormatAndOut_out_xxx.OutLineOutput_NullLineOutputParameter);

            ErrorRecord errorRecord = new ErrorRecord(
                PSTraceSource.NewArgumentNullException("LineOutput"),
                "OutLineOutputNullLineOutputParameter",
                ErrorCategory.InvalidArgument,
                null);

            errorRecord.ErrorDetails = new ErrorDetails(msg);
            this.ThrowTerminatingError(errorRecord);
        }

        private void ProcessWrongTypeLineOutput(object obj)
        {
            string msg = StringUtil.Format(FormatAndOut_out_xxx.OutLineOutput_InvalidLineOutputParameterType,
                obj.GetType().FullName,
                typeof(LineOutput).FullName);

            ErrorRecord errorRecord = new ErrorRecord(
                new InvalidCastException(),
                "OutLineOutputInvalidLineOutputParameterType",
                ErrorCategory.InvalidArgument,
                null);

            errorRecord.ErrorDetails = new ErrorDetails(msg);
            this.ThrowTerminatingError(errorRecord);
        }
    }
}