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 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(); } }