File size: 31,067 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Internal;
using System.Management.Automation.Runspaces;
using Microsoft.PowerShell.Commands;
namespace Microsoft.PowerShell.Commands.Internal.Format
{
/// <summary>
/// Base class defining the formatting context and the
/// formatting context manager (stack based)
/// </summary>
internal class InnerFormatShapeCommandBase : ImplementationCommandBase
{
/// <summary>
/// Constructor to set up the formatting context.
/// </summary>
internal InnerFormatShapeCommandBase()
{
contextManager.Push(FormattingContextState.none);
}
/// <summary>
/// Enum listing the possible states the context is in.
/// </summary>
internal enum FormattingContextState { none, document, group }
/// <summary>
/// Context manager: stack to keep track in which context
/// the formatter is.
/// </summary>
protected Stack<FormattingContextState> contextManager = new Stack<FormattingContextState>();
}
/// <summary>
/// Core inner implementation for format/xxx commands.
/// </summary>
internal class InnerFormatShapeCommand : InnerFormatShapeCommandBase
{
/// <summary>
/// Constructor to glue to the CRO.
/// </summary>
internal InnerFormatShapeCommand(FormatShape shape)
{
_shape = shape;
}
internal static int FormatEnumerationLimit()
{
object enumLimitVal = null;
try
{
// Win8: 192504
if (LocalPipeline.GetExecutionContextFromTLS() != null)
{
enumLimitVal = LocalPipeline.GetExecutionContextFromTLS()
.SessionState.PSVariable
.GetValue("global:" + InitialSessionState.FormatEnumerationLimit);
}
}
// Eat the following exceptions, enumerationLimit will use the default value
catch (ProviderNotFoundException)
{
}
catch (ProviderInvocationException)
{
}
// if $global:FormatEnumerationLimit is an int, overwrite the default value
return enumLimitVal is int ? (int)enumLimitVal : InitialSessionState.DefaultFormatEnumerationLimit;
}
internal override void BeginProcessing()
{
base.BeginProcessing();
// Get the Format Enumeration Limit.
_enumerationLimit = InnerFormatShapeCommand.FormatEnumerationLimit();
_expressionFactory = new PSPropertyExpressionFactory();
_formatObjectDeserializer = new FormatObjectDeserializer(this.TerminatingErrorContext);
}
/// <summary>
/// Execution entry point.
/// </summary>
internal override void ProcessRecord()
{
_typeInfoDataBase = this.OuterCmdlet().Context.FormatDBManager.GetTypeInfoDataBase();
PSObject so = this.ReadObject();
if (so == null || so == AutomationNull.Value)
return;
IEnumerable e = PSObjectHelper.GetEnumerable(so);
if (e == null)
{
ProcessObject(so);
return;
}
// we have an IEnumerable, we have to decide if to expand, if at all
EnumerableExpansion expansionState = this.GetExpansionState(so);
switch (expansionState)
{
case EnumerableExpansion.EnumOnly:
{
foreach (object obj in e)
{
ProcessObject(PSObjectHelper.AsPSObject(obj));
}
}
break;
case EnumerableExpansion.Both:
{
var objs = e.Cast<object>().ToArray();
ProcessCoreOutOfBand(so, objs.Length);
foreach (object obj in objs)
{
ProcessObject(PSObjectHelper.AsPSObject(obj));
}
}
break;
default:
{
// do not enumerate at all (CoreOnly)
ProcessObject(so);
}
break;
}
}
private EnumerableExpansion GetExpansionState(PSObject so)
{
// if the command line swtich has been specified, use this as an override
if (_parameters != null && _parameters.expansion.HasValue)
{
return _parameters.expansion.Value;
}
// check if we have an expansion entry in format.mshxml
var typeNames = so.InternalTypeNames;
return DisplayDataQuery.GetEnumerableExpansionFromType(
_expressionFactory, _typeInfoDataBase, typeNames);
}
private void ProcessCoreOutOfBand(PSObject so, int count)
{
// emit some description header
SendCommentOutOfBand(FormatAndOut_format_xxx.IEnum_Header);
// emit the object as out of band
ProcessOutOfBand(so, isProcessingError: false);
string msg;
// emit a comment to signal that the next N objects are from the IEnumerable
switch (count)
{
case 0:
{
msg = FormatAndOut_format_xxx.IEnum_NoObjects;
}
break;
case 1:
{
msg = FormatAndOut_format_xxx.IEnum_OneObject;
}
break;
default:
{
msg = StringUtil.Format(FormatAndOut_format_xxx.IEnum_ManyObjects, count);
}
break;
}
SendCommentOutOfBand(msg);
}
private void SendCommentOutOfBand(string msg)
{
FormatEntryData fed = OutOfBandFormatViewManager.GenerateOutOfBandObjectAsToString(PSObjectHelper.AsPSObject(msg));
if (fed != null)
{
this.WriteObject(fed);
}
}
/// <summary>
/// Execute formatting on a single object.
/// </summary>
/// <param name="so">Object to process.</param>
private void ProcessObject(PSObject so)
{
// we do protect against reentrancy, assuming
// no fancy multiplexing
if (_formatObjectDeserializer.IsFormatInfoData(so))
{
// we are already formatted...
this.WriteObject(so);
return;
}
// if objects have to be treated as out of band, just
// bail now
// this is the case of objects coming before the
// context manager is properly set
if (ProcessOutOfBandObjectOutsideDocumentSequence(so))
{
return;
}
// if we haven't started yet, need to do so
FormattingContextState ctx = contextManager.Peek();
if (ctx == FormattingContextState.none)
{
// initialize the view manager
_viewManager.Initialize(this.TerminatingErrorContext, _expressionFactory, _typeInfoDataBase, so, _shape, _parameters);
// add the start message to output queue
WriteFormatStartData(so);
// enter the document context
contextManager.Push(FormattingContextState.document);
}
// if we are here, we are either in the document document, or in a group
// since we have a view now, we check if objects should be treated as out of band
if (ProcessOutOfBandObjectInsideDocumentSequence(so))
{
return;
}
// check if we have to enter or exit a group
GroupTransition transition = ComputeGroupTransition(so);
if (transition == GroupTransition.enter)
{
// insert the group start marker
PushGroup(so);
this.WritePayloadObject(so);
}
else if (transition == GroupTransition.exit)
{
this.WritePayloadObject(so);
// insert the group end marker
PopGroup();
}
else if (transition == GroupTransition.startNew)
{
// Add newline before each group except first
WriteNewLineObject();
// double transition
PopGroup(); // exit the current one
PushGroup(so); // start a sibling group
this.WritePayloadObject(so);
}
else // none, we did not have any transitions, just push out the data
{
this.WritePayloadObject(so);
}
}
private void WriteNewLineObject()
{
FormatEntryData fed = new FormatEntryData();
fed.outOfBand = true;
ComplexViewEntry cve = new ComplexViewEntry();
FormatEntry fe = new FormatEntry();
cve.formatValueList.Add(fe);
// Formating system writes newline before each object
// so no need to add newline here like:
// fe.formatValueList.Add(new FormatNewLine());
fed.formatEntryInfo = cve;
this.WriteObject(fed);
}
private bool ShouldProcessOutOfBand
{
get
{
if (_shape == FormatShape.Undefined || _parameters == null)
{
return true;
}
return !_parameters.forceFormattingAlsoOnOutOfBand;
}
}
private bool ProcessOutOfBandObjectOutsideDocumentSequence(PSObject so)
{
if (!ShouldProcessOutOfBand)
{
return false;
}
if (so.InternalTypeNames.Count == 0)
{
return false;
}
List<ErrorRecord> errors;
var fed = OutOfBandFormatViewManager.GenerateOutOfBandData(this.TerminatingErrorContext, _expressionFactory,
_typeInfoDataBase, so, _enumerationLimit, false, out errors);
WriteErrorRecords(errors);
if (fed != null)
{
this.WriteObject(fed);
return true;
}
return false;
}
private bool ProcessOutOfBandObjectInsideDocumentSequence(PSObject so)
{
if (!ShouldProcessOutOfBand)
{
return false;
}
var typeNames = so.InternalTypeNames;
if (_viewManager.ViewGenerator.IsObjectApplicable(typeNames))
{
return false;
}
return ProcessOutOfBand(so, isProcessingError: false);
}
private bool ProcessOutOfBand(PSObject so, bool isProcessingError)
{
List<ErrorRecord> errors;
FormatEntryData fed = OutOfBandFormatViewManager.GenerateOutOfBandData(this.TerminatingErrorContext, _expressionFactory,
_typeInfoDataBase, so, _enumerationLimit, true, out errors);
if (!isProcessingError)
WriteErrorRecords(errors);
if (fed != null)
{
this.WriteObject(fed);
return true;
}
return false;
}
protected void WriteInternalErrorMessage(string message)
{
FormatEntryData fed = new FormatEntryData();
fed.outOfBand = true;
ComplexViewEntry cve = new ComplexViewEntry();
FormatEntry fe = new FormatEntry();
cve.formatValueList.Add(fe);
fe.formatValueList.Add(new FormatNewLine());
// get a field for the message
FormatTextField ftf = new FormatTextField();
ftf.text = message;
fe.formatValueList.Add(ftf);
fe.formatValueList.Add(new FormatNewLine());
fed.formatEntryInfo = cve;
this.WriteObject(fed);
}
private void WriteErrorRecords(List<ErrorRecord> errorRecordList)
{
if (errorRecordList == null)
return;
// NOTE: for the time being we directly process error records.
// This is should change if we hook up error pipelines; for the
// time being, this achieves partial results.
//
// see NTRAID#Windows OS Bug-932722-2004/10/21-kevinloo ("Output: SS: Swallowing exceptions")
foreach (ErrorRecord errorRecord in errorRecordList)
{
// we are recursing on formatting errors: isProcessingError == true
ProcessOutOfBand(PSObjectHelper.AsPSObject(errorRecord), true);
}
}
internal override void EndProcessing()
{
// need to pop all the contexts, in case the transmission sequence
// was interrupted
while (true)
{
FormattingContextState ctx = contextManager.Peek();
if (ctx == FormattingContextState.none)
{
break; // we emerged and we are done
}
else if (ctx == FormattingContextState.group)
{
PopGroup();
}
else if (ctx == FormattingContextState.document)
{
// inject the end format information
FormatEndData endFormat = new FormatEndData();
this.WriteObject(endFormat);
contextManager.Pop();
}
}
}
internal void SetCommandLineParameters(FormattingCommandLineParameters commandLineParameters)
{
Diagnostics.Assert(commandLineParameters != null, "the caller has to pass a valid instance");
_parameters = commandLineParameters;
}
/// <summary>
/// Group transitions:
/// none: stay in the same group
/// enter: start a new group
/// exit: exit from the current group.
/// </summary>
private enum GroupTransition { none, enter, exit, startNew }
/// <summary>
/// Compute the group transition, given an input object.
/// </summary>
/// <param name="so">Object received from the input pipeline.</param>
/// <returns>GroupTransition enumeration.</returns>
private GroupTransition ComputeGroupTransition(PSObject so)
{
// check if we have to start a group
FormattingContextState ctx = contextManager.Peek();
if (ctx == FormattingContextState.document)
{
// prime the grouping algorithm
_viewManager.ViewGenerator.UpdateGroupingKeyValue(so);
// need to start a group, but we are not in one
return GroupTransition.enter;
}
// check if we need to start another group and keep track
// of the current value for the grouping property
return _viewManager.ViewGenerator.UpdateGroupingKeyValue(so) ? GroupTransition.startNew : GroupTransition.none;
}
private void WriteFormatStartData(PSObject so)
{
FormatStartData startFormat = _viewManager.ViewGenerator.GenerateStartData(so);
this.WriteObject(startFormat);
}
/// <summary>
/// Write a payplad object by properly wrapping it into
/// a FormatEntry object.
/// </summary>
/// <param name="so">Object to process.</param>
private void WritePayloadObject(PSObject so)
{
Diagnostics.Assert(so != null, "object so cannot be null");
FormatEntryData fed = _viewManager.ViewGenerator.GeneratePayload(so, _enumerationLimit);
fed.writeStream = so.WriteStream;
this.WriteObject(fed);
List<ErrorRecord> errors = _viewManager.ViewGenerator.ErrorManager.DrainFailedResultList();
WriteErrorRecords(errors);
}
/// <summary>
/// Inject the start group information
/// and push group context on stack.
/// </summary>
/// <param name="firstObjectInGroup">current pipeline object
/// that is starting the group</param>
private void PushGroup(PSObject firstObjectInGroup)
{
GroupStartData startGroup = _viewManager.ViewGenerator.GenerateGroupStartData(firstObjectInGroup, _enumerationLimit);
this.WriteObject(startGroup);
contextManager.Push(FormattingContextState.group);
}
/// <summary>
/// Inject the end group information
/// and pop group context out of stack.
/// </summary>
private void PopGroup()
{
GroupEndData endGroup = _viewManager.ViewGenerator.GenerateGroupEndData();
this.WriteObject(endGroup);
contextManager.Pop();
}
/// <summary>
/// The formatting shape this formatter emits.
/// </summary>
private readonly FormatShape _shape;
#region expression factory
/// <exception cref="ParseException"></exception>
internal ScriptBlock CreateScriptBlock(string scriptText)
{
var scriptBlock = this.OuterCmdlet().InvokeCommand.NewScriptBlock(scriptText);
scriptBlock.DebuggerStepThrough = true;
return scriptBlock;
}
private PSPropertyExpressionFactory _expressionFactory;
#endregion
private FormatObjectDeserializer _formatObjectDeserializer;
private TypeInfoDataBase _typeInfoDataBase = null;
private FormattingCommandLineParameters _parameters = null;
private readonly FormatViewManager _viewManager = new FormatViewManager();
private int _enumerationLimit = InitialSessionState.DefaultFormatEnumerationLimit;
}
/// <summary>
/// </summary>
public class OuterFormatShapeCommandBase : FrontEndCommandBase
{
#region Command Line Switches
/// <summary>
/// Optional, non positional parameter to specify the
/// group by property.
/// </summary>
[Parameter]
public object GroupBy { get; set; } = null;
/// <summary>
/// Optional, non positional parameter.
/// </summary>
/// <value></value>
[Parameter]
public string View { get; set; } = null;
/// <summary>
/// Optional, non positional parameter.
/// </summary>
/// <value></value>
[Parameter]
public SwitchParameter ShowError
{
get
{
if (showErrorsAsMessages.HasValue)
return showErrorsAsMessages.Value;
return false;
}
set
{
showErrorsAsMessages = value;
}
}
internal bool? showErrorsAsMessages = null;
/// <summary>
/// Optional, non positional parameter.
/// </summary>
/// <value></value>
[Parameter]
public SwitchParameter DisplayError
{
get
{
if (showErrorsInFormattedOutput.HasValue)
return showErrorsInFormattedOutput.Value;
return false;
}
set
{
showErrorsInFormattedOutput = value;
}
}
internal bool? showErrorsInFormattedOutput = null;
/// <summary>
/// Optional, non positional parameter.
/// </summary>
/// <value></value>
[Parameter]
public SwitchParameter Force
{
get { return _forceFormattingAlsoOnOutOfBand; }
set { _forceFormattingAlsoOnOutOfBand = value; }
}
private bool _forceFormattingAlsoOnOutOfBand;
/// <summary>
/// Optional, non positional parameter.
/// </summary>
/// <value></value>
[Parameter]
[ValidateSet(EnumerableExpansionConversion.CoreOnlyString,
EnumerableExpansionConversion.EnumOnlyString,
EnumerableExpansionConversion.BothString, IgnoreCase = true)]
public string Expand { get; set; } = null;
internal EnumerableExpansion? expansion = null;
internal EnumerableExpansion? ProcessExpandParameter()
{
EnumerableExpansion? retVal = null;
if (string.IsNullOrEmpty(Expand))
{
return null;
}
EnumerableExpansion temp;
bool success = EnumerableExpansionConversion.Convert(Expand, out temp);
if (!success)
{
// this should never happen, since we use the [ValidateSet] attribute
// NOTE: this is an exception that should never be triggered
throw PSTraceSource.NewArgumentException("Expand", FormatAndOut_MshParameter.IllegalEnumerableExpansionValue);
}
retVal = temp;
return retVal;
}
internal MshParameter ProcessGroupByParameter()
{
if (GroupBy != null)
{
TerminatingErrorContext invocationContext =
new TerminatingErrorContext(this);
ParameterProcessor processor = new ParameterProcessor(new FormatGroupByParameterDefinition());
List<MshParameter> groupParameterList =
processor.ProcessParameters(new object[] { GroupBy },
invocationContext);
if (groupParameterList.Count != 0)
return groupParameterList[0];
}
return null;
}
#endregion
/// <summary>
/// </summary>
protected override void BeginProcessing()
{
InnerFormatShapeCommand innerFormatCommand =
(InnerFormatShapeCommand)this.implementation;
// read command line switches and pass them to the inner command
FormattingCommandLineParameters parameters = GetCommandLineParameters();
innerFormatCommand.SetCommandLineParameters(parameters);
// must call base class for further processing
base.BeginProcessing();
}
/// <summary>
/// It reads the command line switches and collects them into a
/// FormattingCommandLineParameters instance, ready to pass to the
/// inner format command.
/// </summary>
/// <returns>Parameters collected in unified manner.</returns>
internal virtual FormattingCommandLineParameters GetCommandLineParameters()
{
return null;
}
internal void ReportCannotSpecifyViewAndProperty()
{
string msg = StringUtil.Format(FormatAndOut_format_xxx.CannotSpecifyViewAndPropertyError);
ErrorRecord errorRecord = new ErrorRecord(
new InvalidDataException(),
"FormatCannotSpecifyViewAndProperty",
ErrorCategory.InvalidArgument,
null);
errorRecord.ErrorDetails = new ErrorDetails(msg);
this.ThrowTerminatingError(errorRecord);
}
}
/// <summary>
/// </summary>
public class OuterFormatTableAndListBase : OuterFormatShapeCommandBase
{
#region Command Line Switches
/// <summary>
/// Positional parameter for properties, property sets and table sets
/// specified on the command line.
/// The parameter is optional, since the defaults
/// will be determined using property sets, etc.
/// </summary>
[Parameter(Position = 0)]
[ValidateNotNullOrEmpty]
public object[] Property { get; set; }
/// <summary>
/// Optional parameter for excluding properties from formatting.
/// </summary>
[Parameter]
public string[] ExcludeProperty { get; set; }
#endregion
internal override FormattingCommandLineParameters GetCommandLineParameters()
{
FormattingCommandLineParameters parameters = new FormattingCommandLineParameters();
GetCommandLineProperties(parameters, false);
parameters.groupByParameter = this.ProcessGroupByParameter();
parameters.forceFormattingAlsoOnOutOfBand = this.Force;
if (this.showErrorsAsMessages.HasValue)
parameters.showErrorsAsMessages = this.showErrorsAsMessages;
if (this.showErrorsInFormattedOutput.HasValue)
parameters.showErrorsInFormattedOutput = this.showErrorsInFormattedOutput;
parameters.expansion = ProcessExpandParameter();
return parameters;
}
internal void GetCommandLineProperties(FormattingCommandLineParameters parameters, bool isTable)
{
// Check View conflicts first (before any auto-expansion)
if (!string.IsNullOrEmpty(this.View))
{
// View cannot be used with Property or ExcludeProperty
if ((Property is not null && Property.Length != 0) || (ExcludeProperty is not null && ExcludeProperty.Length != 0))
{
ReportCannotSpecifyViewAndProperty();
}
parameters.viewName = this.View;
}
if (Property != null)
{
CommandParameterDefinition def;
if (isTable)
def = new FormatTableParameterDefinition();
else
def = new FormatListParameterDefinition();
ParameterProcessor processor = new ParameterProcessor(def);
TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
parameters.mshParameterList = processor.ProcessParameters(Property, invocationContext);
}
if (ExcludeProperty is not null)
{
parameters.excludePropertyFilter = new PSPropertyExpressionFilter(ExcludeProperty);
// ExcludeProperty implies -Property * for better UX
if (Property is null || Property.Length == 0)
{
CommandParameterDefinition def = isTable
? new FormatTableParameterDefinition()
: new FormatListParameterDefinition();
ParameterProcessor processor = new ParameterProcessor(def);
TerminatingErrorContext invocationContext = new TerminatingErrorContext(this);
parameters.mshParameterList = processor.ProcessParameters(new object[] { "*" }, invocationContext);
}
}
}
}
/// <summary>
/// </summary>
public class OuterFormatTableBase : OuterFormatTableAndListBase
{
#region Command Line Switches
/// <summary>
/// Optional, non positional parameter.
/// </summary>
/// <value></value>
[Parameter]
public SwitchParameter AutoSize
{
get
{
if (_autosize.HasValue)
return _autosize.Value;
return false;
}
set
{
_autosize = value;
}
}
private bool? _autosize = null;
/// <summary>
/// Gets or sets if header is repeated per screen.
/// </summary>
[Parameter]
public SwitchParameter RepeatHeader { get; set; }
/// <summary>
/// Optional, non positional parameter.
/// </summary>
/// <value></value>
[Parameter]
public SwitchParameter HideTableHeaders
{
get
{
if (_hideHeaders.HasValue)
return _hideHeaders.Value;
return false;
}
set
{
_hideHeaders = value;
}
}
private bool? _hideHeaders = null;
/// <summary>
/// Optional, non positional parameter.
/// </summary>
/// <value></value>
[Parameter]
public SwitchParameter Wrap
{
get
{
if (_multiLine.HasValue)
return _multiLine.Value;
return false;
}
set
{
_multiLine = value;
}
}
private bool? _multiLine = null;
#endregion
internal override FormattingCommandLineParameters GetCommandLineParameters()
{
FormattingCommandLineParameters parameters = new FormattingCommandLineParameters();
GetCommandLineProperties(parameters, true);
parameters.forceFormattingAlsoOnOutOfBand = this.Force;
if (this.showErrorsAsMessages.HasValue)
parameters.showErrorsAsMessages = this.showErrorsAsMessages;
if (this.showErrorsInFormattedOutput.HasValue)
parameters.showErrorsInFormattedOutput = this.showErrorsInFormattedOutput;
parameters.expansion = ProcessExpandParameter();
if (_autosize.HasValue)
parameters.autosize = _autosize.Value;
if (RepeatHeader)
{
parameters.repeatHeader = true;
}
parameters.groupByParameter = this.ProcessGroupByParameter();
TableSpecificParameters tableParameters = new TableSpecificParameters();
parameters.shapeParameters = tableParameters;
if (_hideHeaders.HasValue)
{
tableParameters.hideHeaders = _hideHeaders.Value;
}
if (_multiLine.HasValue)
{
tableParameters.multiLine = _multiLine.Value;
}
return parameters;
}
}
}
|