internal void GetCommandLineProperties(FormattingCommandLineParameters parameters, bool isTable) { 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 (!string.IsNullOrEmpty(this.View)) { // we have a view command line switch if (parameters.mshParameterList.Count != 0) { ReportCannotSpecifyViewAndProperty(); } parameters.viewName = this.View; } }
internal void GetCommandLineProperties(FormattingCommandLineParameters parameters, bool isTable) { if (this.props != null) { CommandParameterDefinition definition; if (isTable) { definition = new FormatTableParameterDefinition(); } else { definition = new FormatListParameterDefinition(); } ParameterProcessor processor = new ParameterProcessor(definition); TerminatingErrorContext invocationContext = new TerminatingErrorContext(this); parameters.mshParameterList = processor.ProcessParameters(this.props, invocationContext); } if (!string.IsNullOrEmpty(base.View)) { if (parameters.mshParameterList.Count != 0) { base.ReportCannotSpecifyViewAndProperty(); } parameters.viewName = base.View; } }
internal override FormattingCommandLineParameters GetCommandLineParameters() { FormattingCommandLineParameters parameters = new FormattingCommandLineParameters(); if (this.props != null) { ParameterProcessor processor = new ParameterProcessor(new FormatObjectParameterDefinition()); TerminatingErrorContext invocationContext = new TerminatingErrorContext(this); parameters.mshParameterList = processor.ProcessParameters(this.props, invocationContext); } if (!string.IsNullOrEmpty(base.View)) { if (parameters.mshParameterList.Count != 0) { base.ReportCannotSpecifyViewAndProperty(); } parameters.viewName = base.View; } parameters.groupByParameter = base.ProcessGroupByParameter(); parameters.forceFormattingAlsoOnOutOfBand = (bool) base.Force; if (this.showErrorsAsMessages.HasValue) { parameters.showErrorsAsMessages = base.showErrorsAsMessages; } if (this.showErrorsInFormattedOutput.HasValue) { parameters.showErrorsInFormattedOutput = base.showErrorsInFormattedOutput; } parameters.expansion = base.ProcessExpandParameter(); ComplexSpecificParameters parameters2 = new ComplexSpecificParameters { maxDepth = this.depth }; parameters.shapeParameters = parameters2; return parameters; }
internal override FormattingCommandLineParameters GetCommandLineParameters() { FormattingCommandLineParameters parameters = new FormattingCommandLineParameters(); base.GetCommandLineProperties(parameters, true); parameters.forceFormattingAlsoOnOutOfBand = (bool) base.Force; if (this.showErrorsAsMessages.HasValue) { parameters.showErrorsAsMessages = base.showErrorsAsMessages; } if (this.showErrorsInFormattedOutput.HasValue) { parameters.showErrorsInFormattedOutput = base.showErrorsInFormattedOutput; } parameters.expansion = base.ProcessExpandParameter(); if (this.autosize.HasValue) { parameters.autosize = new bool?(this.autosize.Value); } parameters.groupByParameter = base.ProcessGroupByParameter(); TableSpecificParameters parameters2 = new TableSpecificParameters(); parameters.shapeParameters = parameters2; if (this.hideHeaders.HasValue) { parameters2.hideHeaders = new bool?(this.hideHeaders.Value); } if (this.multiLine.HasValue) { parameters2.multiLine = new bool?(this.multiLine.Value); } return parameters; }
internal ComplexViewEntry GenerateView(PSObject so, FormattingCommandLineParameters inputParameters) { this.complexSpecificParameters = (ComplexSpecificParameters)inputParameters.shapeParameters; int maxDepth = this.complexSpecificParameters.maxDepth; TraversalInfo level = new TraversalInfo(0, maxDepth); List <MshParameter> parameterList = null; if (inputParameters != null) { parameterList = inputParameters.mshParameterList; } ComplexViewEntry entry = new ComplexViewEntry(); if (TreatAsScalarType(so.InternalTypeNames)) { FormatEntry item = new FormatEntry(); entry.formatValueList.Add(item); this.DisplayRawObject(so, item.formatValueList); return(entry); } IEnumerable e = PSObjectHelper.GetEnumerable(so); if (e != null) { FormatEntry entry3 = new FormatEntry(); entry.formatValueList.Add(entry3); this.DisplayEnumeration(e, level, entry3.formatValueList); return(entry); } this.DisplayObject(so, level, parameterList, entry.formatValueList); return(entry); }
internal override FormattingCommandLineParameters GetCommandLineParameters() { FormattingCommandLineParameters parameters = new FormattingCommandLineParameters(); base.GetCommandLineProperties(parameters, true); parameters.forceFormattingAlsoOnOutOfBand = (bool)base.Force; if (this.showErrorsAsMessages.HasValue) { parameters.showErrorsAsMessages = base.showErrorsAsMessages; } if (this.showErrorsInFormattedOutput.HasValue) { parameters.showErrorsInFormattedOutput = base.showErrorsInFormattedOutput; } parameters.expansion = base.ProcessExpandParameter(); if (this.autosize.HasValue) { parameters.autosize = new bool?(this.autosize.Value); } parameters.groupByParameter = base.ProcessGroupByParameter(); TableSpecificParameters parameters2 = new TableSpecificParameters(); parameters.shapeParameters = parameters2; if (this.hideHeaders.HasValue) { parameters2.hideHeaders = new bool?(this.hideHeaders.Value); } if (this.multiLine.HasValue) { parameters2.multiLine = new bool?(this.multiLine.Value); } return(parameters); }
private static ViewGenerator SelectViewGeneratorFromViewDefinition( TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters parameters) { ViewGenerator viewGenerator = null; if (view.mainControl is TableControlBody) { viewGenerator = new TableViewGenerator(); } else if (view.mainControl is ListControlBody) { viewGenerator = new ListViewGenerator(); } else if (view.mainControl is WideControlBody) { viewGenerator = new WideViewGenerator(); } else if (view.mainControl is ComplexControlBody) { viewGenerator = new ComplexViewGenerator(); } Diagnostics.Assert(viewGenerator != null, "viewGenerator != null"); viewGenerator.Initialize(errorContext, expressionFactory, db, view, parameters); return(viewGenerator); }
protected override void BeginProcessing() { InnerFormatShapeCommand implementation = (InnerFormatShapeCommand) base.implementation; FormattingCommandLineParameters commandLineParameters = this.GetCommandLineParameters(); implementation.SetCommandLineParameters(commandLineParameters); base.BeginProcessing(); }
internal virtual void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters formatParameters) { this.errorContext = terminatingErrorContext; this.expressionFactory = mshExpressionFactory; this.parameters = formatParameters; this.dataBaseInfo.db = db; this.InitializeHelper(); }
internal override void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters) { base.Initialize(terminatingErrorContext, mshExpressionFactory, db, view, formatParameters); if ((null != this.dataBaseInfo) && (null != this.dataBaseInfo.view)) { _tableBody = (TableControlBody)this.dataBaseInfo.view.mainControl; } }
private static ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so, TerminatingErrorContext errorContext, PSPropertyExpressionFactory expressionFactory, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { // use some heuristics to determine the shape if none is specified if (shape == FormatShape.Undefined && parameters == null) { // check first if we have a known shape for a type var typeNames = so.InternalTypeNames; shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, typeNames); if (shape == FormatShape.Undefined) { // check if we can have a table: // we want to get the # of properties we are going to display List <PSPropertyExpression> expressionList = PSObjectHelper.GetDefaultPropertySet(so); if (expressionList.Count == 0) { // we failed to get anything from a property set // we just get the first properties out of the first object foreach (MshResolvedExpressionParameterAssociation mrepa in AssociationManager.ExpandAll(so)) { expressionList.Add(mrepa.ResolvedExpression); } } // decide what shape we want for the given number of properties shape = DisplayDataQuery.GetShapeFromPropertyCount(db, expressionList.Count); } } ViewGenerator viewGenerator = null; if (shape == FormatShape.Table) { viewGenerator = new TableViewGenerator(); } else if (shape == FormatShape.List) { viewGenerator = new ListViewGenerator(); } else if (shape == FormatShape.Wide) { viewGenerator = new WideViewGenerator(); } else if (shape == FormatShape.Complex) { viewGenerator = new ComplexViewGenerator(); } Diagnostics.Assert(viewGenerator != null, "viewGenerator != null"); viewGenerator.Initialize(errorContext, expressionFactory, so, db, parameters); return(viewGenerator); }
internal virtual void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters) { this.errorContext = terminatingErrorContext; this.expressionFactory = mshExpressionFactory; this.parameters = formatParameters; this.dataBaseInfo.db = db; this.dataBaseInfo.view = view; this.dataBaseInfo.applicableTypes = DisplayDataQuery.GetAllApplicableTypes(db, view.appliesTo); this.InitializeHelper(); }
internal override void Initialize(TerminatingErrorContext errorContext, PSPropertyExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); if ((this.dataBaseInfo != null) && (this.dataBaseInfo.view != null)) { _tableBody = (TableControlBody)this.dataBaseInfo.view.mainControl; } List <MshParameter> rawMshParameterList = null; if (parameters != null) { rawMshParameterList = parameters.mshParameterList; } // check if we received properties from the command line if (rawMshParameterList != null && rawMshParameterList.Count > 0) { this.activeAssociationList = AssociationManager.ExpandTableParameters(rawMshParameterList, so); return; } // we did not get any properties: // try to get properties from the default property set of the object this.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, this.expressionFactory); if (this.activeAssociationList.Count > 0) { // we got a valid set of properties from the default property set..add computername for // remoteobjects (if available) if (PSObjectHelper.ShouldShowComputerNameProperty(so)) { activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, new PSPropertyExpression(RemotingConstants.ComputerNameNoteProperty))); } return; } // we failed to get anything from the default property set this.activeAssociationList = AssociationManager.ExpandAll(so); if (this.activeAssociationList.Count > 0) { // Remove PSComputerName and PSShowComputerName from the display as needed. AssociationManager.HandleComputerNameProperties(so, activeAssociationList); FilterActiveAssociationList(); return; } // we were unable to retrieve any properties, so we leave an empty list this.activeAssociationList = new List <MshResolvedExpressionParameterAssociation>(); }
internal override void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); if ((null != this.dataBaseInfo) && (null != this.dataBaseInfo.view)) { _listBody = (ListControlBody)this.dataBaseInfo.view.mainControl; } this.inputParameters = parameters; SetUpActiveProperties(so); }
internal override void Initialize(TerminatingErrorContext errorContext, PSPropertyExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); if ((null != this.dataBaseInfo) && (null != this.dataBaseInfo.view)) { _listBody = (ListControlBody)this.dataBaseInfo.view.mainControl; } this.inputParameters = parameters; SetUpActiveProperties(so); }
/// <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(); }
internal virtual void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters formatParameters) { errorContext = terminatingErrorContext; expressionFactory = mshExpressionFactory; parameters = formatParameters; dataBaseInfo.db = db; InitializeHelper(); }
internal override void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); if ((null != this.dataBaseInfo) && (null != this.dataBaseInfo.view)) { _tableBody = (TableControlBody)this.dataBaseInfo.view.mainControl; } List<MshParameter> rawMshParameterList = null; if (parameters != null) rawMshParameterList = parameters.mshParameterList; // check if we received properties from the command line if (rawMshParameterList != null && rawMshParameterList.Count > 0) { this.activeAssociationList = AssociationManager.ExpandTableParameters(rawMshParameterList, so); return; } // we did not get any properties: //try to get properties from the default property set of the object this.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, this.expressionFactory); if (this.activeAssociationList.Count > 0) { // we got a valid set of properties from the default property set..add computername for // remoteobjects (if available) if (PSObjectHelper.ShouldShowComputerNameProperty(so)) { activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, new MshExpression(RemotingConstants.ComputerNameNoteProperty))); } return; } // we failed to get anything from the default property set this.activeAssociationList = AssociationManager.ExpandAll(so); if (this.activeAssociationList.Count > 0) { // Remove PSComputerName and PSShowComputerName from the display as needed. AssociationManager.HandleComputerNameProperties(so, activeAssociationList); FilterActiveAssociationList(); return; } // we were unable to retrieve any properties, so we leave an empty list this.activeAssociationList = new List<MshResolvedExpressionParameterAssociation>(); }
internal override FormattingCommandLineParameters GetCommandLineParameters() { FormattingCommandLineParameters parameters = new FormattingCommandLineParameters(); if (this.prop != null) { ParameterProcessor processor = new ParameterProcessor(new FormatWideParameterDefinition()); TerminatingErrorContext invocationContext = new TerminatingErrorContext(this); parameters.mshParameterList = processor.ProcessParameters(new object[] { this.prop }, invocationContext); } if (!string.IsNullOrEmpty(base.View)) { if (parameters.mshParameterList.Count != 0) { base.ReportCannotSpecifyViewAndProperty(); } parameters.viewName = base.View; } if ((this.autosize.HasValue && this.column.HasValue) && this.autosize.Value) { string message = StringUtil.Format(FormatAndOut_format_xxx.CannotSpecifyAutosizeAndColumnsError, new object[0]); ErrorRecord errorRecord = new ErrorRecord(new InvalidDataException(), "FormatCannotSpecifyAutosizeAndColumns", ErrorCategory.InvalidArgument, null) { ErrorDetails = new ErrorDetails(message) }; base.ThrowTerminatingError(errorRecord); } parameters.groupByParameter = base.ProcessGroupByParameter(); parameters.forceFormattingAlsoOnOutOfBand = (bool) base.Force; if (this.showErrorsAsMessages.HasValue) { parameters.showErrorsAsMessages = base.showErrorsAsMessages; } if (this.showErrorsInFormattedOutput.HasValue) { parameters.showErrorsInFormattedOutput = base.showErrorsInFormattedOutput; } parameters.expansion = base.ProcessExpandParameter(); if (this.autosize.HasValue) { parameters.autosize = new bool?(this.autosize.Value); } WideSpecificParameters parameters2 = new WideSpecificParameters(); parameters.shapeParameters = parameters2; if (this.column.HasValue) { parameters2.columns = new int?(this.column.Value); } return parameters; }
/// <summary> /// given an object, generate a tree-like view /// of the object /// </summary> /// <param name="so">object to process</param> /// <param name="inputParameters">parameters from the command line</param> /// <returns>complex view entry to send to the output command</returns> internal ComplexViewEntry GenerateView(PSObject so, FormattingCommandLineParameters inputParameters) { _complexSpecificParameters = (ComplexSpecificParameters)inputParameters.shapeParameters; int maxDepth = _complexSpecificParameters.maxDepth; TraversalInfo level = new TraversalInfo(0, maxDepth); List <MshParameter> mshParameterList = null; if (inputParameters != null) { mshParameterList = inputParameters.mshParameterList; } // create a top level entry as root of the tree ComplexViewEntry cve = new ComplexViewEntry(); var typeNames = so.InternalTypeNames; if (TreatAsScalarType(typeNames)) { FormatEntry fe = new FormatEntry(); cve.formatValueList.Add(fe); DisplayRawObject(so, fe.formatValueList); } else { // check if the top level object is an enumeration IEnumerable e = PSObjectHelper.GetEnumerable(so); if (e != null) { // let's start the traversal with an enumeration FormatEntry fe = new FormatEntry(); cve.formatValueList.Add(fe); DisplayEnumeration(e, level, fe.formatValueList); } else { // let's start the traversal with a traversal on properties DisplayObject(so, level, mshParameterList, cve.formatValueList); } } return(cve); }
internal override FormattingCommandLineParameters GetCommandLineParameters() { FormattingCommandLineParameters parameters = new FormattingCommandLineParameters(); this.GetCommandLineProperties(parameters, false); parameters.groupByParameter = base.ProcessGroupByParameter(); parameters.forceFormattingAlsoOnOutOfBand = (bool) base.Force; if (this.showErrorsAsMessages.HasValue) { parameters.showErrorsAsMessages = base.showErrorsAsMessages; } if (this.showErrorsInFormattedOutput.HasValue) { parameters.showErrorsInFormattedOutput = base.showErrorsInFormattedOutput; } parameters.expansion = base.ProcessExpandParameter(); return parameters; }
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); }
internal override FormattingCommandLineParameters GetCommandLineParameters() { FormattingCommandLineParameters parameters = new FormattingCommandLineParameters(); this.GetCommandLineProperties(parameters, false); parameters.groupByParameter = base.ProcessGroupByParameter(); parameters.forceFormattingAlsoOnOutOfBand = (bool)base.Force; if (this.showErrorsAsMessages.HasValue) { parameters.showErrorsAsMessages = base.showErrorsAsMessages; } if (this.showErrorsInFormattedOutput.HasValue) { parameters.showErrorsInFormattedOutput = base.showErrorsInFormattedOutput; } parameters.expansion = base.ProcessExpandParameter(); return(parameters); }
internal virtual void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters) { Diagnostics.Assert(mshExpressionFactory != null, "mshExpressionFactory cannot be null"); Diagnostics.Assert(db != null, "db cannot be null"); Diagnostics.Assert(view != null, "view cannot be null"); errorContext = terminatingErrorContext; expressionFactory = mshExpressionFactory; parameters = formatParameters; dataBaseInfo.db = db; dataBaseInfo.view = view; dataBaseInfo.applicableTypes = DisplayDataQuery.GetAllApplicableTypes(db, view.appliesTo); InitializeHelper(); }
internal virtual void Initialize(TerminatingErrorContext terminatingErrorContext, PSPropertyExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters) { Diagnostics.Assert(mshExpressionFactory != null, "mshExpressionFactory cannot be null"); Diagnostics.Assert(db != null, "db cannot be null"); Diagnostics.Assert(view != null, "view cannot be null"); errorContext = terminatingErrorContext; expressionFactory = mshExpressionFactory; parameters = formatParameters; dataBaseInfo.db = db; dataBaseInfo.view = view; dataBaseInfo.applicableTypes = DisplayDataQuery.GetAllApplicableTypes(db, view.appliesTo); InitializeHelper(); }
internal override FormattingCommandLineParameters GetCommandLineParameters() { FormattingCommandLineParameters parameters = new FormattingCommandLineParameters(); if (_props != null) { ParameterProcessor processor = new ParameterProcessor(new FormatObjectParameterDefinition()); TerminatingErrorContext invocationContext = new TerminatingErrorContext(this); parameters.mshParameterList = processor.ProcessParameters(_props, invocationContext); } if (!string.IsNullOrEmpty(this.View)) { // we have a view command line switch if (parameters.mshParameterList.Count != 0) { ReportCannotSpecifyViewAndProperty(); } parameters.viewName = this.View; } 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(); ComplexSpecificParameters csp = new ComplexSpecificParameters(); csp.maxDepth = _depth; parameters.shapeParameters = csp; return parameters; }
internal void GetCommandLineProperties(FormattingCommandLineParameters parameters, bool isTable) { 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 (!string.IsNullOrEmpty(this.View)) { // we have a view command line switch if (parameters.mshParameterList.Count != 0) { ReportCannotSpecifyViewAndProperty(); } parameters.viewName = this.View; } }
internal void SetCommandLineParameters(FormattingCommandLineParameters commandLineParameters) { this.parameters = commandLineParameters; }
internal void SetCommandLineParameters(FormattingCommandLineParameters commandLineParameters) { Diagnostics.Assert(commandLineParameters != null, "the caller has to pass a valid instance"); _parameters = commandLineParameters; }
private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromViewDefinition(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters parameters) { Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null; if (view.mainControl is TableControlBody) { generator = new TableViewGenerator(); } else if (view.mainControl is ListControlBody) { generator = new ListViewGenerator(); } else if (view.mainControl is WideControlBody) { generator = new WideViewGenerator(); } else if (view.mainControl is ComplexControlBody) { generator = new ComplexViewGenerator(); } generator.Initialize(errorContext, expressionFactory, db, view, parameters); return generator; }
internal override void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters) { base.Initialize(terminatingErrorContext, mshExpressionFactory, db, view, formatParameters); if ((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null)) { this.listBody = (ListControlBody) base.dataBaseInfo.view.mainControl; } }
internal void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, FormatShape shape, FormattingCommandLineParameters parameters) { ViewDefinition view = null; try { DisplayDataQuery.SetTracer(formatViewBindingTracer); ConsolidatedString internalTypeNames = so.InternalTypeNames; if (shape == FormatShape.Undefined) { using (formatViewBindingTracer.TraceScope("FINDING VIEW TYPE: {0}", new object[] { PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); PrepareViewForRemoteObjects(this.ViewGenerator, so); } else { formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null); PrepareViewForRemoteObjects(this.ViewGenerator, so); } } else if ((parameters != null) && (parameters.mshParameterList.Count > 0)) { this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); } else { if ((parameters != null) && !string.IsNullOrEmpty(parameters.viewName)) { using (formatViewBindingTracer.TraceScope("FINDING VIEW NAME: {0} TYPE: {1}", new object[] { parameters.viewName, PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, parameters.viewName); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); return; } formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape); } using (formatViewBindingTracer.TraceScope("FINDING VIEW {0} TYPE: {1}", new object[] { shape, PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); PrepareViewForRemoteObjects(this.ViewGenerator, so); } else { formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); PrepareViewForRemoteObjects(this.ViewGenerator, so); } } } finally { DisplayDataQuery.ResetTracer(); } }
internal virtual void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters) { this.errorContext = terminatingErrorContext; this.expressionFactory = mshExpressionFactory; this.parameters = formatParameters; this.dataBaseInfo.db = db; this.dataBaseInfo.view = view; this.dataBaseInfo.applicableTypes = DisplayDataQuery.GetAllApplicableTypes(db, view.appliesTo); this.InitializeHelper(); }
internal void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, FormatShape shape, FormattingCommandLineParameters parameters) { ViewDefinition view = null; const string findViewType = "FINDING VIEW TYPE: {0}"; const string findViewShapeType = "FINDING VIEW {0} TYPE: {1}"; const string findViewNameType = "FINDING VIEW NAME: {0} TYPE: {1}"; const string viewFound = "An applicable view has been found"; const string viewNotFound = "No applicable view has been found"; try { DisplayDataQuery.SetTracer(s_formatViewBindingTracer); // shape not specified: we need to select one var typeNames = so.InternalTypeNames; if (shape == FormatShape.Undefined) { using (s_formatViewBindingTracer.TraceScope(findViewType, PSObjectTypeName(so))) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, null); } if (view != null) { // we got a matching view from the database // use this and we are done _viewGenerator = SelectViewGeneratorFromViewDefinition( errorContext, expressionFactory, db, view, parameters); s_formatViewBindingTracer.WriteLine(viewFound); PrepareViewForRemoteObjects(ViewGenerator, so); return; } s_formatViewBindingTracer.WriteLine(viewNotFound); // we did not get any default view (and shape), we need to force one // we just select properties out of the object itself, since they were not // specified on the command line _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null); PrepareViewForRemoteObjects(ViewGenerator, so); return; } // we have a predefined shape: did the user specify properties on the command line? if (parameters != null && parameters.mshParameterList.Count > 0) { _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); return; } // predefined shape: did the user specify the name of a view? if (parameters != null && !string.IsNullOrEmpty(parameters.viewName)) { using (s_formatViewBindingTracer.TraceScope(findViewNameType, parameters.viewName, PSObjectTypeName(so))) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, parameters.viewName); } if (view != null) { _viewGenerator = SelectViewGeneratorFromViewDefinition( errorContext, expressionFactory, db, view, parameters); s_formatViewBindingTracer.WriteLine(viewFound); return; } s_formatViewBindingTracer.WriteLine(viewNotFound); // illegal input, we have to terminate ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape); } // predefined shape: do we have a default view in format.ps1xml? using (s_formatViewBindingTracer.TraceScope(findViewShapeType, shape, PSObjectTypeName(so))) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, null); } if (view != null) { _viewGenerator = SelectViewGeneratorFromViewDefinition( errorContext, expressionFactory, db, view, parameters); s_formatViewBindingTracer.WriteLine(viewFound); PrepareViewForRemoteObjects(ViewGenerator, so); return; } s_formatViewBindingTracer.WriteLine(viewNotFound); // we just select properties out of the object itself _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); PrepareViewForRemoteObjects(ViewGenerator, so); } finally { DisplayDataQuery.ResetTracer(); } }
private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so, TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { if ((shape == FormatShape.Undefined) && (parameters == null)) { ConsolidatedString internalTypeNames = so.InternalTypeNames; shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, internalTypeNames); if (shape == FormatShape.Undefined) { List<MshExpression> defaultPropertySet = PSObjectHelper.GetDefaultPropertySet(so); if (defaultPropertySet.Count == 0) { foreach (MshResolvedExpressionParameterAssociation association in AssociationManager.ExpandAll(so)) { defaultPropertySet.Add(association.ResolvedExpression); } } shape = DisplayDataQuery.GetShapeFromPropertyCount(db, defaultPropertySet.Count); } } Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null; if (shape == FormatShape.Table) { generator = new TableViewGenerator(); } else if (shape == FormatShape.List) { generator = new ListViewGenerator(); } else if (shape == FormatShape.Wide) { generator = new WideViewGenerator(); } else if (shape == FormatShape.Complex) { generator = new ComplexViewGenerator(); } generator.Initialize(errorContext, expressionFactory, so, db, parameters); return generator; }
internal ComplexViewEntry GenerateView(PSObject so, FormattingCommandLineParameters inputParameters) { this.complexSpecificParameters = (ComplexSpecificParameters) inputParameters.shapeParameters; int maxDepth = this.complexSpecificParameters.maxDepth; TraversalInfo level = new TraversalInfo(0, maxDepth); List<MshParameter> parameterList = null; if (inputParameters != null) { parameterList = inputParameters.mshParameterList; } ComplexViewEntry entry = new ComplexViewEntry(); if (TreatAsScalarType(so.InternalTypeNames)) { FormatEntry item = new FormatEntry(); entry.formatValueList.Add(item); this.DisplayRawObject(so, item.formatValueList); return entry; } IEnumerable e = PSObjectHelper.GetEnumerable(so); if (e != null) { FormatEntry entry3 = new FormatEntry(); entry.formatValueList.Add(entry3); this.DisplayEnumeration(e, level, entry3.formatValueList); return entry; } this.DisplayObject(so, level, parameterList, entry.formatValueList); return entry; }
private static ViewGenerator SelectViewGeneratorFromViewDefinition( TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters parameters) { ViewGenerator viewGenerator = null; if (view.mainControl is TableControlBody) { viewGenerator = new TableViewGenerator(); } else if (view.mainControl is ListControlBody) { viewGenerator = new ListViewGenerator(); } else if (view.mainControl is WideControlBody) { viewGenerator = new WideViewGenerator(); } else if (view.mainControl is ComplexControlBody) { viewGenerator = new ComplexViewGenerator(); } Diagnostics.Assert(viewGenerator != null, "viewGenerator != null"); viewGenerator.Initialize(errorContext, expressionFactory, db, view, parameters); return viewGenerator; }
internal override void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); if ((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null)) { this.tableBody = (TableControlBody)base.dataBaseInfo.view.mainControl; } List <MshParameter> mshParameterList = null; if (parameters != null) { mshParameterList = parameters.mshParameterList; } if ((mshParameterList != null) && (mshParameterList.Count > 0)) { base.activeAssociationList = AssociationManager.ExpandTableParameters(mshParameterList, so); } else { base.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, base.expressionFactory); if (base.activeAssociationList.Count > 0) { if (PSObjectHelper.ShouldShowComputerNameProperty(so)) { base.activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, new MshExpression(RemotingConstants.ComputerNameNoteProperty))); } } else { base.activeAssociationList = AssociationManager.ExpandAll(so); if (base.activeAssociationList.Count > 0) { AssociationManager.HandleComputerNameProperties(so, base.activeAssociationList); this.FilterActiveAssociationList(); } else { base.activeAssociationList = new List <MshResolvedExpressionParameterAssociation>(); } } } }
internal override FormattingCommandLineParameters GetCommandLineParameters() { FormattingCommandLineParameters parameters = new FormattingCommandLineParameters(); if (_prop != null) { ParameterProcessor processor = new ParameterProcessor(new FormatWideParameterDefinition()); TerminatingErrorContext invocationContext = new TerminatingErrorContext(this); parameters.mshParameterList = processor.ProcessParameters(new object[] { _prop }, invocationContext); } if (!string.IsNullOrEmpty(this.View)) { // we have a view command line switch if (parameters.mshParameterList.Count != 0) { ReportCannotSpecifyViewAndProperty(); } parameters.viewName = this.View; } // we cannot specify -column and -autosize, they are mutually exclusive if (_autosize.HasValue && _column.HasValue) { if (_autosize.Value) { // the user specified -autosize:true AND a column number string msg = StringUtil.Format(FormatAndOut_format_xxx.CannotSpecifyAutosizeAndColumnsError); ErrorRecord errorRecord = new ErrorRecord( new InvalidDataException(), "FormatCannotSpecifyAutosizeAndColumns", ErrorCategory.InvalidArgument, null); errorRecord.ErrorDetails = new ErrorDetails(msg); this.ThrowTerminatingError(errorRecord); } } 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(); if (_autosize.HasValue) parameters.autosize = _autosize.Value; WideSpecificParameters wideSpecific = new WideSpecificParameters(); parameters.shapeParameters = wideSpecific; if (_column.HasValue) { wideSpecific.columns = _column.Value; } return parameters; }
internal override void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); if ((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null)) { this.listBody = (ListControlBody)base.dataBaseInfo.view.mainControl; } base.inputParameters = parameters; this.SetUpActiveProperties(so); }
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; 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; }
internal void SetCommandLineParameters(FormattingCommandLineParameters commandLineParameters) { Diagnostics.Assert(commandLineParameters != null, "the caller has to pass a valid instance"); _parameters = commandLineParameters; }
internal void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, FormatShape shape, FormattingCommandLineParameters parameters) { ViewDefinition view = null; try { DisplayDataQuery.SetTracer(formatViewBindingTracer); ConsolidatedString internalTypeNames = so.InternalTypeNames; if (shape == FormatShape.Undefined) { using (formatViewBindingTracer.TraceScope("FINDING VIEW TYPE: {0}", new object[] { PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); PrepareViewForRemoteObjects(this.ViewGenerator, so); } else { formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null); PrepareViewForRemoteObjects(this.ViewGenerator, so); } } else if ((parameters != null) && (parameters.mshParameterList.Count > 0)) { this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); } else { if ((parameters != null) && !string.IsNullOrEmpty(parameters.viewName)) { using (formatViewBindingTracer.TraceScope("FINDING VIEW NAME: {0} TYPE: {1}", new object[] { parameters.viewName, PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, parameters.viewName); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); return; } formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape); } using (formatViewBindingTracer.TraceScope("FINDING VIEW {0} TYPE: {1}", new object[] { shape, PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); PrepareViewForRemoteObjects(this.ViewGenerator, so); } else { formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); PrepareViewForRemoteObjects(this.ViewGenerator, so); } } } finally { DisplayDataQuery.ResetTracer(); } }
internal override void Initialize(TerminatingErrorContext terminatingErrorContext, MshExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters) { base.Initialize(terminatingErrorContext, mshExpressionFactory, db, view, formatParameters); if ((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null)) { this.tableBody = (TableControlBody)base.dataBaseInfo.view.mainControl; } }
private static ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so, TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { // use some heuristics to determine the shape if none is specified if (shape == FormatShape.Undefined && parameters == null) { // check first if we have a known shape for a type var typeNames = so.InternalTypeNames; shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, typeNames); if (shape == FormatShape.Undefined) { // check if we can have a table: // we want to get the # of properties we are going to display List<MshExpression> expressionList = PSObjectHelper.GetDefaultPropertySet(so); if (expressionList.Count == 0) { // we failed to get anything from a property set // we just get the first properties out of the first object foreach (MshResolvedExpressionParameterAssociation mrepa in AssociationManager.ExpandAll(so)) { expressionList.Add(mrepa.ResolvedExpression); } } // decide what shape we want for the given number of properties shape = DisplayDataQuery.GetShapeFromPropertyCount(db, expressionList.Count); } } ViewGenerator viewGenerator = null; if (shape == FormatShape.Table) { viewGenerator = new TableViewGenerator(); } else if (shape == FormatShape.List) { viewGenerator = new ListViewGenerator(); } else if (shape == FormatShape.Wide) { viewGenerator = new WideViewGenerator(); } else if (shape == FormatShape.Complex) { viewGenerator = new ComplexViewGenerator(); } Diagnostics.Assert(viewGenerator != null, "viewGenerator != null"); viewGenerator.Initialize(errorContext, expressionFactory, so, db, parameters); return viewGenerator; }
private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so, TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { if ((shape == FormatShape.Undefined) && (parameters == null)) { ConsolidatedString internalTypeNames = so.InternalTypeNames; shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, internalTypeNames); if (shape == FormatShape.Undefined) { List <MshExpression> defaultPropertySet = PSObjectHelper.GetDefaultPropertySet(so); if (defaultPropertySet.Count == 0) { foreach (MshResolvedExpressionParameterAssociation association in AssociationManager.ExpandAll(so)) { defaultPropertySet.Add(association.ResolvedExpression); } } shape = DisplayDataQuery.GetShapeFromPropertyCount(db, defaultPropertySet.Count); } } Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null; if (shape == FormatShape.Table) { generator = new TableViewGenerator(); } else if (shape == FormatShape.List) { generator = new ListViewGenerator(); } else if (shape == FormatShape.Wide) { generator = new WideViewGenerator(); } else if (shape == FormatShape.Complex) { generator = new ComplexViewGenerator(); } generator.Initialize(errorContext, expressionFactory, so, db, parameters); return(generator); }
internal override void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); this.inputParameters = parameters; }
internal void SetCommandLineParameters(FormattingCommandLineParameters commandLineParameters) { this.parameters = commandLineParameters; }
internal void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, FormatShape shape, FormattingCommandLineParameters parameters) { ViewDefinition view = null; const string findViewType = "FINDING VIEW TYPE: {0}"; const string findViewShapeType = "FINDING VIEW {0} TYPE: {1}"; const string findViewNameType = "FINDING VIEW NAME: {0} TYPE: {1}"; const string viewFound = "An applicable view has been found"; const string viewNotFound = "No applicable view has been found"; try { DisplayDataQuery.SetTracer(s_formatViewBindingTracer); // shape not specified: we need to select one var typeNames = so.InternalTypeNames; if (shape == FormatShape.Undefined) { using (s_formatViewBindingTracer.TraceScope(findViewType, PSObjectTypeName(so))) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, null); } if (view != null) { // we got a matching view from the database // use this and we are done _viewGenerator = SelectViewGeneratorFromViewDefinition( errorContext, expressionFactory, db, view, parameters); s_formatViewBindingTracer.WriteLine(viewFound); PrepareViewForRemoteObjects(ViewGenerator, so); return; } s_formatViewBindingTracer.WriteLine(viewNotFound); // we did not get any default view (and shape), we need to force one // we just select properties out of the object itself, since they were not // specified on the command line _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null); PrepareViewForRemoteObjects(ViewGenerator, so); return; } // we have a predefined shape: did the user specify properties on the command line? if (parameters != null && parameters.mshParameterList.Count > 0) { _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); return; } // predefined shape: did the user specify the name of a view? if (parameters != null && !string.IsNullOrEmpty(parameters.viewName)) { using (s_formatViewBindingTracer.TraceScope(findViewNameType, parameters.viewName, PSObjectTypeName(so))) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, parameters.viewName); } if (view != null) { _viewGenerator = SelectViewGeneratorFromViewDefinition( errorContext, expressionFactory, db, view, parameters); s_formatViewBindingTracer.WriteLine(viewFound); return; } s_formatViewBindingTracer.WriteLine(viewNotFound); // illegal input, we have to terminate ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape); } // predefined shape: do we have a default view in format.ps1xml? using (s_formatViewBindingTracer.TraceScope(findViewShapeType, shape, PSObjectTypeName(so))) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, typeNames, null); } if (view != null) { _viewGenerator = SelectViewGeneratorFromViewDefinition( errorContext, expressionFactory, db, view, parameters); s_formatViewBindingTracer.WriteLine(viewFound); PrepareViewForRemoteObjects(ViewGenerator, so); return; } s_formatViewBindingTracer.WriteLine(viewNotFound); // we just select properties out of the object itself _viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); PrepareViewForRemoteObjects(ViewGenerator, so); } finally { DisplayDataQuery.ResetTracer(); } }
internal override void Initialize(TerminatingErrorContext terminatingErrorContext, PSPropertyExpressionFactory mshExpressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters formatParameters) { base.Initialize(terminatingErrorContext, mshExpressionFactory, db, view, formatParameters); if ((null != this.dataBaseInfo) && (null != this.dataBaseInfo.view)) { _listBody = (ListControlBody)this.dataBaseInfo.view.mainControl; } }
private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromViewDefinition(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, ViewDefinition view, FormattingCommandLineParameters parameters) { Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null; if (view.mainControl is TableControlBody) { generator = new TableViewGenerator(); } else if (view.mainControl is ListControlBody) { generator = new ListViewGenerator(); } else if (view.mainControl is WideControlBody) { generator = new WideViewGenerator(); } else if (view.mainControl is ComplexControlBody) { generator = new ComplexViewGenerator(); } generator.Initialize(errorContext, expressionFactory, db, view, parameters); return(generator); }
/// <summary> /// given an object, generate a tree-like view /// of the object /// </summary> /// <param name="so">object to process</param> /// <param name="inputParameters">parameters from the command line</param> /// <returns>complex view entry to send to the output command</returns> internal ComplexViewEntry GenerateView(PSObject so, FormattingCommandLineParameters inputParameters) { _complexSpecificParameters = (ComplexSpecificParameters)inputParameters.shapeParameters; int maxDepth = _complexSpecificParameters.maxDepth; TraversalInfo level = new TraversalInfo(0, maxDepth); List<MshParameter> mshParameterList = null; if (inputParameters != null) mshParameterList = inputParameters.mshParameterList; // create a top level entry as root of the tree ComplexViewEntry cve = new ComplexViewEntry(); var typeNames = so.InternalTypeNames; if (TreatAsScalarType(typeNames)) { FormatEntry fe = new FormatEntry(); cve.formatValueList.Add(fe); DisplayRawObject(so, fe.formatValueList); } else { // check if the top level object is an enumeration IEnumerable e = PSObjectHelper.GetEnumerable(so); if (e != null) { // let's start the traversal with an enumeration FormatEntry fe = new FormatEntry(); cve.formatValueList.Add(fe); DisplayEnumeration(e, level, fe.formatValueList); } else { // let's start the traversal with a traversal on properties DisplayObject(so, level, mshParameterList, cve.formatValueList); } } return cve; }
internal override void Initialize(TerminatingErrorContext errorContext, PSPropertyExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); this.inputParameters = parameters; }
internal override void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, PSObject so, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { base.Initialize(errorContext, expressionFactory, so, db, parameters); if ((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null)) { this.tableBody = (TableControlBody) base.dataBaseInfo.view.mainControl; } List<MshParameter> mshParameterList = null; if (parameters != null) { mshParameterList = parameters.mshParameterList; } if ((mshParameterList != null) && (mshParameterList.Count > 0)) { base.activeAssociationList = AssociationManager.ExpandTableParameters(mshParameterList, so); } else { base.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, base.expressionFactory); if (base.activeAssociationList.Count > 0) { if (PSObjectHelper.ShouldShowComputerNameProperty(so)) { base.activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, new MshExpression(RemotingConstants.ComputerNameNoteProperty))); } } else { base.activeAssociationList = AssociationManager.ExpandAll(so); if (base.activeAssociationList.Count > 0) { AssociationManager.HandleComputerNameProperties(so, base.activeAssociationList); this.FilterActiveAssociationList(); } else { base.activeAssociationList = new List<MshResolvedExpressionParameterAssociation>(); } } } }