Пример #1
0
 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;
     }
 }
Пример #2
0
        private bool LoadMainControlDependentData(List <XmlNode> unprocessedNodes, ViewDefinition view)
        {
            foreach (XmlNode n in unprocessedNodes)
            {
                bool outOfBandNodeFound      = false; // cardinality 0..1
                bool controlDefinitionsFound = false; // cardinality 0..1

                if (MatchNodeName(n, XmlTags.OutOfBandNode))
                {
                    if (outOfBandNodeFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return(false);
                    }

                    outOfBandNodeFound = true;
                    if (!this.ReadBooleanNode(n, out view.outOfBand))
                    {
                        return(false);
                    }
                    if (!(view.mainControl is ComplexControlBody) && !(view.mainControl is ListControlBody))
                    {
                        //Error at XPath {0} in file {1}: Out Of Band views can only have CustomControl or ListControl.
                        ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.InvalidControlForOutOfBandView, ComputeCurrentXPath(), FilePath));
                        return(false);
                    }
                }
                else if (MatchNodeName(n, XmlTags.ControlsNode))
                {
                    if (controlDefinitionsFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return(false);
                    }

                    controlDefinitionsFound = true;
                    LoadControlDefinitions(n, view.formatControlDefinitionHolder.controlDefinitionList);
                }
                else
                {
                    ProcessUnknownNode(n);
                }
            }
            return(true);
        }
Пример #3
0
        internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, int enumerationLimit, bool useToStringFallback, out List <ErrorRecord> errors)
        {
            ViewGenerator generator;

            errors = null;
            ConsolidatedString internalTypeNames = so.InternalTypeNames;
            ViewDefinition     view = DisplayDataQuery.GetOutOfBandView(expressionFactory, db, internalTypeNames);

            if (view != null)
            {
                if (view.mainControl is ComplexControlBody)
                {
                    generator = new ComplexViewGenerator();
                }
                else
                {
                    generator = new ListViewGenerator();
                }
                generator.Initialize(errorContext, expressionFactory, db, view, null);
            }
            else
            {
                if (DefaultScalarTypes.IsTypeInList(internalTypeNames) || IsPropertyLessObject(so))
                {
                    return(GenerateOutOfBandObjectAsToString(so));
                }
                if (!useToStringFallback)
                {
                    return(null);
                }
                if (new MshExpression("*").ResolveNames(so).Count <= 0)
                {
                    return(null);
                }
                generator = new ListViewGenerator();
                generator.Initialize(errorContext, expressionFactory, so, db, null);
            }
            FormatEntryData data = generator.GeneratePayload(so, enumerationLimit);

            data.outOfBand = true;
            data.SetStreamTypeFromPSObject(so);
            errors = generator.ErrorManager.DrainFailedResultList();
            return(data);
        }
Пример #4
0
        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();
        }
Пример #5
0
        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 CustomControl(ComplexControlBody body, ViewDefinition viewDefinition)
        {
            // viewDefinition can be null for nested controls
            if (viewDefinition != null)
            {
                OutOfBand = viewDefinition.outOfBand;
                GroupBy = PSControlGroupBy.Get(viewDefinition.groupBy);
            }

            Entries = new List<CustomControlEntry>();

            // Default entry
            var cce = new CustomControlEntry(body.defaultEntry);
            Entries.Add(cce);

            foreach (var entry in body.optionalEntryList)
            {
                cce = new CustomControlEntry(entry);
                Entries.Add(cce);
            }
        }
Пример #7
0
 private static void TraceHelper(ViewDefinition vd, bool isMatched)
 {
     if ((ActiveTracer.Options & PSTraceSourceOptions.WriteLine) != PSTraceSourceOptions.None)
     {
         foreach (TypeOrGroupReference reference in vd.appliesTo.referenceList)
         {
             StringBuilder builder    = new StringBuilder();
             TypeReference reference2 = reference as TypeReference;
             builder.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
             if (reference2 != null)
             {
                 builder.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  TYPE: {2}", new object[] { ControlBase.GetControlShapeName(vd.mainControl), vd.name, reference2.name });
             }
             else
             {
                 TypeGroupReference reference3 = reference as TypeGroupReference;
                 builder.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  GROUP: {2}", new object[] { ControlBase.GetControlShapeName(vd.mainControl), vd.name, reference3.name });
             }
             ActiveTracer.WriteLine(builder.ToString(), new object[0]);
         }
     }
 }
Пример #8
0
        internal static ViewDefinition GetOutOfBandView(MshExpressionFactory expressionFactory, TypeInfoDataBase db, Collection <string> typeNames)
        {
            TypeMatch match = new TypeMatch(expressionFactory, db, typeNames);

            foreach (ViewDefinition definition in db.viewDefinitionsSection.viewDefinitionList)
            {
                if (IsOutOfBandView(definition) && match.PerfectMatch(new TypeMatchItem(definition, definition.appliesTo)))
                {
                    return(definition);
                }
            }
            ViewDefinition bestMatch = match.BestMatch as ViewDefinition;

            if (bestMatch == null)
            {
                Collection <string> collection = Deserializer.MaskDeserializationPrefix(typeNames);
                if (collection != null)
                {
                    bestMatch = GetOutOfBandView(expressionFactory, db, collection);
                }
            }
            return(bestMatch);
        }
Пример #9
0
 private static void TraceHelper(ViewDefinition vd, bool isMatched)
 {
     if ((DisplayDataQuery.ActiveTracer.Options & PSTraceSourceOptions.WriteLine) == PSTraceSourceOptions.None)
     {
         return;
     }
     foreach (TypeOrGroupReference reference in vd.appliesTo.referenceList)
     {
         StringBuilder stringBuilder = new StringBuilder();
         TypeReference typeReference = reference as TypeReference;
         stringBuilder.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
         if (typeReference != null)
         {
             stringBuilder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, " {0} NAME: {1}  TYPE: {2}", (object)ControlBase.GetControlShapeName(vd.mainControl), (object)vd.name, (object)typeReference.name);
         }
         else
         {
             TypeGroupReference typeGroupReference = reference as TypeGroupReference;
             stringBuilder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, " {0} NAME: {1}  GROUP: {2}", (object)ControlBase.GetControlShapeName(vd.mainControl), (object)vd.name, (object)typeGroupReference.name);
         }
         DisplayDataQuery.ActiveTracer.WriteLine(stringBuilder.ToString(), new object[0]);
     }
 }
Пример #10
0
 private static void TraceHelper(ViewDefinition vd, bool isMatched)
 {
     if ((ActiveTracer.Options & PSTraceSourceOptions.WriteLine) != 0)
     {
         foreach (TypeOrGroupReference togr in vd.appliesTo.referenceList)
         {
             StringBuilder sb = new StringBuilder();
             TypeReference tr = togr as TypeReference;
             sb.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
             if (tr != null)
             {
                 sb.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  TYPE: {2}",
                                 ControlBase.GetControlShapeName(vd.mainControl), vd.name, tr.name);
             }
             else
             {
                 TypeGroupReference tgr = togr as TypeGroupReference;
                 sb.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  GROUP: {2}",
                                 ControlBase.GetControlShapeName(vd.mainControl), vd.name, tgr.name);
             }
             ActiveTracer.WriteLine(sb.ToString());
         }
     }
 }
Пример #11
0
        internal WideControl(WideControlBody widecontrolbody, ViewDefinition viewDefinition) : this()
        {
            OutOfBand = viewDefinition.outOfBand;
            GroupBy = PSControlGroupBy.Get(viewDefinition.groupBy);

            AutoSize = widecontrolbody.autosize.HasValue && widecontrolbody.autosize.Value;
            Columns = (uint)widecontrolbody.columns;

            Entries.Add(new WideControlEntryItem(widecontrolbody.defaultEntryDefinition));

            foreach (WideControlEntryDefinition definition in widecontrolbody.optionalEntryList)
            {
                Entries.Add(new WideControlEntryItem(definition));
            }
        }
Пример #12
0
 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;
     }
 }
Пример #13
0
        internal TableControl(TableControlBody tcb, ViewDefinition viewDefinition) : this()
        {
            this.OutOfBand = viewDefinition.outOfBand;
            this.GroupBy = PSControlGroupBy.Get(viewDefinition.groupBy);

            this.AutoSize = tcb.autosize.HasValue && tcb.autosize.Value;
            this.HideTableHeaders = tcb.header.hideHeader;

            TableControlRow row = new TableControlRow(tcb.defaultDefinition);

            Rows.Add(row);

            foreach (TableRowDefinition rd in tcb.optionalDefinitionList)
            {
                row = new TableControlRow(rd);

                Rows.Add(row);
            }

            foreach (TableColumnHeaderDefinition hd in tcb.header.columnHeaderDefinitionList)
            {
                TableControlColumnHeader header = new TableControlColumnHeader(hd);
                Headers.Add(header);
            }
        }
Пример #14
0
        private static ConsolidatedString CreateConsolidatedTypeName(ViewDefinition definition, Dictionary<string, List<string>> typeGroupMap)
        {
            // Create our "consolidated string" typename which is used as a dictionary key
            var reflist = definition.appliesTo.referenceList;
            var consolidatedTypeName = new ConsolidatedString(ConsolidatedString.Empty);

            foreach (TypeOrGroupReference item in reflist)
            {
                // If it's a TypeGroup, we need to look that up and add it's members
                if (item is TypeGroupReference)
                {
                    List<string> typesInGroup;
                    if (typeGroupMap.TryGetValue(item.name, out typesInGroup))
                    {
                        foreach (string typeName in typesInGroup)
                        {
                            consolidatedTypeName.Add(typeName);
                        }
                    }
                }
                else
                {
                    consolidatedTypeName.Add(item.name);
                }
            }
            return consolidatedTypeName;
        }
Пример #15
0
 private static bool IsOutOfBandView(ViewDefinition vd)
 {
     return (vd.mainControl is ComplexControlBody || vd.mainControl is ListControlBody) && vd.outOfBand;
 }
Пример #16
0
        private ViewDefinition LoadView(XmlNode viewNode, int index)
        {
            using (this.StackFrame(viewNode, index))
            {
                // load the common data
                ViewDefinition view             = new ViewDefinition();
                List <XmlNode> unprocessedNodes = new List <XmlNode>();
                bool           success          = LoadCommonViewData(viewNode, view, unprocessedNodes);

                if (!success)
                {
                    //Error at XPath {0} in file {1}: View cannot be loaded.
                    this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.ViewNotLoaded, ComputeCurrentXPath(), FilePath));
                    return(null); // fatal error
                }

                // add the main control constituting the view
                // only one control can exist, and it can be
                // of the various types: Table, List, etc.

                string[] controlNodeTags = new string[]
                {
                    XmlTags.TableControlNode,
                    XmlTags.ListControlNode,
                    XmlTags.WideControlNode,
                    XmlTags.ComplexControlNode
                };

                List <XmlNode> secondPassUnprocessedNodes = new List <XmlNode>();

                bool mainControlFound = false; // cardinality 1
                foreach (XmlNode n in unprocessedNodes)
                {
                    if (MatchNodeName(n, XmlTags.TableControlNode))
                    {
                        if (mainControlFound)
                        {
                            ProcessDuplicateNode(n);
                            return(null);
                        }
                        mainControlFound = true;
                        view.mainControl = LoadTableControl(n);
                    }
                    else if (MatchNodeName(n, XmlTags.ListControlNode))
                    {
                        if (mainControlFound)
                        {
                            ProcessDuplicateNode(n);
                            return(null);
                        }
                        mainControlFound = true;
                        view.mainControl = LoadListControl(n);
                    }

                    else if (MatchNodeName(n, XmlTags.WideControlNode))
                    {
                        if (mainControlFound)
                        {
                            ProcessDuplicateNode(n);
                            return(null);
                        }
                        mainControlFound = true;
                        view.mainControl = LoadWideControl(n);
                    }
                    else if (MatchNodeName(n, XmlTags.ComplexControlNode))
                    {
                        if (mainControlFound)
                        {
                            ProcessDuplicateNode(n);
                            return(null);
                        }
                        mainControlFound = true;
                        view.mainControl = LoadComplexControl(n);
                    }
                    else
                    {
                        secondPassUnprocessedNodes.Add(n);
                    }
                } // foreach

                if (view.mainControl == null)
                {
                    this.ReportMissingNodes(controlNodeTags);
                    return(null); // fatal
                }

                if (!LoadMainControlDependentData(secondPassUnprocessedNodes, view))
                {
                    return(null); // fatal
                }

                if (view.outOfBand && (view.groupBy != null))
                {
                    // we cannot have grouping and out of band at the same time
                    //Error at XPath {0} in file {1}: An Out Of Band view cannot have GroupBy.
                    this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.OutOfBandGroupByConflict, ComputeCurrentXPath(), FilePath));
                    return(null); // fatal
                }

                return(view);
            }
        }
Пример #17
0
        private static ViewDefinition GetView(PSPropertyExpressionFactory expressionFactory, TypeInfoDataBase db, System.Type mainControlType, Collection <string> typeNames, string viewName)
        {
            TypeMatch match = new TypeMatch(expressionFactory, db, typeNames);

            foreach (ViewDefinition vd in db.viewDefinitionsSection.viewDefinitionList)
            {
                if (vd == null || mainControlType != vd.mainControl.GetType())
                {
                    ActiveTracer.WriteLine(
                        "NOT MATCH {0}  NAME: {1}",
                        ControlBase.GetControlShapeName(vd.mainControl), (vd != null ? vd.name : string.Empty));
                    continue;
                }
                if (IsOutOfBandView(vd))
                {
                    ActiveTracer.WriteLine(
                        "NOT MATCH OutOfBand {0}  NAME: {1}",
                        ControlBase.GetControlShapeName(vd.mainControl), vd.name);
                    continue;
                }
                if (vd.appliesTo == null)
                {
                    ActiveTracer.WriteLine(
                        "NOT MATCH {0}  NAME: {1}  No applicable types",
                        ControlBase.GetControlShapeName(vd.mainControl), vd.name);
                    continue;
                }
                // first make sure we match on name:
                // if not, we do not try a match at all
                if (viewName != null && !string.Equals(vd.name, viewName, StringComparison.OrdinalIgnoreCase))
                {
                    ActiveTracer.WriteLine(
                        "NOT MATCH {0}  NAME: {1}",
                        ControlBase.GetControlShapeName(vd.mainControl), vd.name);
                    continue;
                }

                // check if we have a perfect match
                // if so, we are done
                try
                {
                    TypeMatch.SetTracer(ActiveTracer);
                    if (match.PerfectMatch(new TypeMatchItem(vd, vd.appliesTo)))
                    {
                        TraceHelper(vd, true);
                        return(vd);
                    }
                }
                finally
                {
                    TypeMatch.ResetTracer();
                }
                TraceHelper(vd, false);
            }

            // this is the best match we had
            ViewDefinition result = GetBestMatch(match);

            // we were unable to find a best match so far..try
            // to get rid of Deserialization prefix and see if a
            // match can be found.
            if (result == null)
            {
                Collection <string> typesWithoutPrefix = Deserializer.MaskDeserializationPrefix(typeNames);
                if (typesWithoutPrefix != null)
                {
                    result = GetView(expressionFactory, db, mainControlType, typesWithoutPrefix, viewName);
                }
            }

            return(result);
        }
Пример #18
0
 private bool LoadMainControlDependentData(List<System.Xml.XmlNode> unprocessedNodes, ViewDefinition view)
 {
     foreach (System.Xml.XmlNode node in unprocessedNodes)
     {
         bool flag = false;
         bool flag2 = false;
         if (base.MatchNodeName(node, "OutOfBand"))
         {
             if (flag)
             {
                 base.ProcessDuplicateNode(node);
                 return false;
             }
             flag = true;
             if (!this.ReadBooleanNode(node, out view.outOfBand))
             {
                 return false;
             }
             if (!(view.mainControl is ComplexControlBody) && !(view.mainControl is ListControlBody))
             {
                 base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.InvalidControlForOutOfBandView, base.ComputeCurrentXPath(), base.FilePath));
                 return false;
             }
         }
         else if (base.MatchNodeName(node, "Controls"))
         {
             if (flag2)
             {
                 base.ProcessDuplicateNode(node);
                 return false;
             }
             flag2 = true;
             this.LoadControlDefinitions(node, view.formatControlDefinitionHolder.controlDefinitionList);
         }
         else
         {
             base.ProcessUnknownNode(node);
         }
     }
     return true;
 }
Пример #19
0
 private ViewDefinition LoadViewFromObjectModle(string typeName, FormatViewDefinition formatView, int viewIndex)
 {
     TypeReference reference = new TypeReference {
         name = typeName
     };
     AppliesTo to = new AppliesTo {
         referenceList = { reference }
     };
     ViewDefinition definition = new ViewDefinition {
         appliesTo = to,
         name = formatView.Name
     };
     PSControl control = formatView.Control;
     if (control is TableControl)
     {
         TableControl table = control as TableControl;
         definition.mainControl = this.LoadTableControlFromObjectModel(table, viewIndex, typeName);
     }
     else if (control is ListControl)
     {
         ListControl list = control as ListControl;
         definition.mainControl = this.LoadListControlFromObjectModel(list, viewIndex, typeName);
     }
     else if (control is WideControl)
     {
         WideControl wide = control as WideControl;
         definition.mainControl = this.LoadWideControlFromObjectModel(wide, viewIndex, typeName);
     }
     if (definition.mainControl == null)
     {
         return null;
     }
     return definition;
 }
Пример #20
0
        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();
            }
        }
Пример #21
0
 private static bool IsOutOfBandView(ViewDefinition vd)
 {
     return((vd.mainControl is ComplexControlBody || vd.mainControl is ListControlBody) && vd.outOfBand);
 }
Пример #22
0
 private static void TraceHelper(ViewDefinition vd, bool isMatched)
 {
     if ((ActiveTracer.Options & PSTraceSourceOptions.WriteLine) != PSTraceSourceOptions.None)
     {
         foreach (TypeOrGroupReference reference in vd.appliesTo.referenceList)
         {
             StringBuilder builder = new StringBuilder();
             TypeReference reference2 = reference as TypeReference;
             builder.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
             if (reference2 != null)
             {
                 builder.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  TYPE: {2}", new object[] { ControlBase.GetControlShapeName(vd.mainControl), vd.name, reference2.name });
             }
             else
             {
                 TypeGroupReference reference3 = reference as TypeGroupReference;
                 builder.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  GROUP: {2}", new object[] { ControlBase.GetControlShapeName(vd.mainControl), vd.name, reference3.name });
             }
             ActiveTracer.WriteLine(builder.ToString(), new object[0]);
         }
     }
 }
Пример #23
0
 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();
 }
Пример #24
0
 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;
     }
 }
Пример #25
0
        private static ViewDefinition GetView(
            MshExpressionFactory expressionFactory,
            TypeInfoDataBase db,
            Type mainControlType,
            Collection <string> typeNames,
            string viewName)
        {
            TypeMatch match = new TypeMatch(expressionFactory, db, typeNames);

            foreach (ViewDefinition viewDefinition in db.viewDefinitionsSection.viewDefinitionList)
            {
                if (viewDefinition == null || mainControlType != viewDefinition.mainControl.GetType())
                {
                    DisplayDataQuery.ActiveTracer.WriteLine("NOT MATCH {0}  NAME: {1}", (object)ControlBase.GetControlShapeName(viewDefinition.mainControl), viewDefinition != null ? (object)viewDefinition.name : (object)string.Empty);
                }
                else if (DisplayDataQuery.IsOutOfBandView(viewDefinition))
                {
                    DisplayDataQuery.ActiveTracer.WriteLine("NOT MATCH OutOfBand {0}  NAME: {1}", (object)ControlBase.GetControlShapeName(viewDefinition.mainControl), (object)viewDefinition.name);
                }
                else if (viewDefinition.appliesTo == null)
                {
                    DisplayDataQuery.ActiveTracer.WriteLine("NOT MATCH {0}  NAME: {1}  No applicable types", (object)ControlBase.GetControlShapeName(viewDefinition.mainControl), (object)viewDefinition.name);
                }
                else
                {
                    if (viewName != null)
                    {
                        if (!string.Equals(viewDefinition.name, viewName, StringComparison.OrdinalIgnoreCase))
                        {
                            DisplayDataQuery.ActiveTracer.WriteLine("NOT MATCH {0}  NAME: {1}", (object)ControlBase.GetControlShapeName(viewDefinition.mainControl), (object)viewDefinition.name);
                            continue;
                        }
                    }
                    try
                    {
                        TypeMatch.SetTracer(DisplayDataQuery.ActiveTracer);
                        if (match.PerfectMatch(new TypeMatchItem((object)viewDefinition, viewDefinition.appliesTo)))
                        {
                            DisplayDataQuery.TraceHelper(viewDefinition, true);
                            return(viewDefinition);
                        }
                    }
                    finally
                    {
                        TypeMatch.ResetTracer();
                    }
                    DisplayDataQuery.TraceHelper(viewDefinition, false);
                }
            }
            ViewDefinition viewDefinition1 = DisplayDataQuery.GetBestMatch(match);

            if (viewDefinition1 == null)
            {
                Collection <string> typeNames1 = Deserializer.MaskDeserializationPrefix(typeNames);
                if (typeNames1 != null)
                {
                    viewDefinition1 = DisplayDataQuery.GetView(expressionFactory, db, mainControlType, typeNames1, viewName);
                }
            }
            return(viewDefinition1);
        }
Пример #26
0
        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();
            }
        }
Пример #27
0
        private bool LoadCommonViewData(XmlNode viewNode, ViewDefinition view, List <XmlNode> unprocessedNodes)
        {
            if (viewNode == null)
            {
                throw PSTraceSource.NewArgumentNullException("viewNode");
            }

            if (view == null)
            {
                throw PSTraceSource.NewArgumentNullException("view");
            }

            // set loading information
            view.loadingInfo       = this.LoadingInfo;
            view.loadingInfo.xPath = this.ComputeCurrentXPath();

            // start the loading process
            bool nameNodeFound      = false;        // cardinality 1
            bool appliesToNodeFound = false;        // cardinality 1
            bool groupByFound       = false;        // cardinality 0..1

            foreach (XmlNode n in viewNode.ChildNodes)
            {
                if (MatchNodeName(n, XmlTags.NameNode))
                {
                    if (nameNodeFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return(false);
                    }

                    nameNodeFound = true;
                    view.name     = GetMandatoryInnerText(n);
                    if (view.name == null)
                    {
                        return(false);
                    }
                }
                else if (MatchNodeName(n, XmlTags.ViewSelectedByNode))
                {
                    if (appliesToNodeFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return(false);
                    }

                    appliesToNodeFound = true;

                    // if null, we invalidate the view
                    view.appliesTo = LoadAppliesToSection(n, false);
                    if (view.appliesTo == null)
                    {
                        return(false);
                    }
                }
                else if (MatchNodeName(n, XmlTags.GroupByNode))
                {
                    if (groupByFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return(false);
                    }

                    groupByFound = true;
                    view.groupBy = LoadGroupBySection(n);
                    if (view.groupBy == null)
                    {
                        return(false);
                    }
                }
                else
                {
                    // save for further processing
                    unprocessedNodes.Add(n);
                }
            } // for

            if (!nameNodeFound)
            {
                this.ReportMissingNode(XmlTags.NameNode);
                return(false);
            }

            if (!appliesToNodeFound)
            {
                this.ReportMissingNode(XmlTags.ViewSelectedByNode);
                return(false);
            }

            return(true);
        }
Пример #28
0
 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;
 }
Пример #29
0
        /// <summary>
        /// Load the view into a ViewDefinition
        /// </summary>
        /// <param name="typeNames">the TypeName tag under SelectedBy tag</param>
        /// <param name="formatView"></param>
        /// <param name="viewIndex"></param>
        /// <returns></returns>
        private ViewDefinition LoadViewFromObjectModel(List<string> typeNames, FormatViewDefinition formatView, int viewIndex)
        {
            // Get AppliesTo information
            AppliesTo appliesTo = new AppliesTo();
            foreach (var typename in typeNames)
            {
                TypeReference tr = new TypeReference { name = typename };
                appliesTo.referenceList.Add(tr);
            }

            // Set AppliesTo and Name in the view
            ViewDefinition view = new ViewDefinition();
            view.appliesTo = appliesTo;
            view.name = formatView.Name;

            var firstTypeName = typeNames[0];
            PSControl control = formatView.Control;
            if (control is TableControl)
            {
                var tableControl = control as TableControl;
                view.mainControl = LoadTableControlFromObjectModel(tableControl, viewIndex, firstTypeName);
            }
            else if (control is ListControl)
            {
                var listControl = control as ListControl;
                view.mainControl = LoadListControlFromObjectModel(listControl, viewIndex, firstTypeName);
            }
            else if (control is WideControl)
            {
                var wideControl = control as WideControl;
                view.mainControl = LoadWideControlFromObjectModel(wideControl, viewIndex, firstTypeName);
            }
            else
            {
                view.mainControl = LoadCustomControlFromObjectModel((CustomControl)control, viewIndex, firstTypeName);
            }

            // Check if the PSControl is successfully loaded
            if (view.mainControl == null)
            {
                return null;
            }

            view.outOfBand = control.OutOfBand;

            if (control.GroupBy != null)
            {
                view.groupBy = new GroupBy
                {
                    startGroup = new StartGroup
                    {
                        expression = LoadExpressionFromObjectModel(control.GroupBy.Expression, viewIndex, firstTypeName)
                    }
                };
                if (control.GroupBy.Label != null)
                {
                    view.groupBy.startGroup.labelTextToken = new TextToken { text = control.GroupBy.Label };
                }
                if (control.GroupBy.CustomControl != null)
                {
                    view.groupBy.startGroup.control = LoadCustomControlFromObjectModel(control.GroupBy.CustomControl, viewIndex, firstTypeName);
                }
            }

            return view;
        }
Пример #30
0
 private static void TraceHelper(ViewDefinition vd, bool isMatched)
 {
     if ((ActiveTracer.Options & PSTraceSourceOptions.WriteLine) != 0)
     {
         foreach (TypeOrGroupReference togr in vd.appliesTo.referenceList)
         {
             StringBuilder sb = new StringBuilder();
             TypeReference tr = togr as TypeReference;
             sb.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
             if (tr != null)
             {
                 sb.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  TYPE: {2}",
                     ControlBase.GetControlShapeName(vd.mainControl), vd.name, tr.name);
             }
             else
             {
                 TypeGroupReference tgr = togr as TypeGroupReference;
                 sb.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1}  GROUP: {2}",
                     ControlBase.GetControlShapeName(vd.mainControl), vd.name, tgr.name);
             }
             ActiveTracer.WriteLine(sb.ToString());
         }
     }
 }
Пример #31
0
 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);
 }
Пример #32
0
 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();
 }
Пример #33
0
        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;
        }
Пример #34
0
 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;
     }
 }
Пример #35
0
 private ViewDefinition LoadView(System.Xml.XmlNode viewNode, int index)
 {
     using (base.StackFrame(viewNode, index))
     {
         ViewDefinition view = new ViewDefinition();
         List<System.Xml.XmlNode> unprocessedNodes = new List<System.Xml.XmlNode>();
         if (!this.LoadCommonViewData(viewNode, view, unprocessedNodes))
         {
             base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.ViewNotLoaded, base.ComputeCurrentXPath(), base.FilePath));
             return null;
         }
         string[] names = new string[] { "TableControl", "ListControl", "WideControl", "CustomControl" };
         List<System.Xml.XmlNode> list2 = new List<System.Xml.XmlNode>();
         bool flag2 = false;
         foreach (System.Xml.XmlNode node in unprocessedNodes)
         {
             if (base.MatchNodeName(node, "TableControl"))
             {
                 if (flag2)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag2 = true;
                 view.mainControl = this.LoadTableControl(node);
             }
             else if (base.MatchNodeName(node, "ListControl"))
             {
                 if (flag2)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag2 = true;
                 view.mainControl = this.LoadListControl(node);
             }
             else if (base.MatchNodeName(node, "WideControl"))
             {
                 if (flag2)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag2 = true;
                 view.mainControl = this.LoadWideControl(node);
             }
             else if (base.MatchNodeName(node, "CustomControl"))
             {
                 if (flag2)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag2 = true;
                 view.mainControl = this.LoadComplexControl(node);
             }
             else
             {
                 list2.Add(node);
             }
         }
         if (view.mainControl == null)
         {
             base.ReportMissingNodes(names);
             return null;
         }
         if (!this.LoadMainControlDependentData(list2, view))
         {
             return null;
         }
         if (view.outOfBand && (view.groupBy != null))
         {
             base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.OutOfBandGroupByConflict, base.ComputeCurrentXPath(), base.FilePath));
             return null;
         }
         return view;
     }
 }
Пример #36
0
        private bool LoadMainControlDependentData(List<XmlNode> unprocessedNodes, ViewDefinition view)
        {
            foreach (XmlNode n in unprocessedNodes)
            {
                bool outOfBandNodeFound = false; // cardinality 0..1
                bool controlDefinitionsFound = false; // cardinality 0..1

                if (MatchNodeName(n, XmlTags.OutOfBandNode))
                {
                    if (outOfBandNodeFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return false;
                    }

                    outOfBandNodeFound = true;
                    if (!this.ReadBooleanNode(n, out view.outOfBand))
                    {
                        return false;
                    }
                    if (!(view.mainControl is ComplexControlBody) && !(view.mainControl is ListControlBody))
                    {
                        //Error at XPath {0} in file {1}: Out Of Band views can only have CustomControl or ListControl.
                        ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.InvalidControlForOutOfBandView, ComputeCurrentXPath(), FilePath));
                        return false;
                    }
                }
                else if (MatchNodeName(n, XmlTags.ControlsNode))
                {
                    if (controlDefinitionsFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return false;
                    }

                    controlDefinitionsFound = true;
                    LoadControlDefinitions(n, view.formatControlDefinitionHolder.controlDefinitionList);
                }
                else
                {
                    ProcessUnknownNode(n);
                }
            }
            return true;
        }
Пример #37
0
 private bool LoadCommonViewData(System.Xml.XmlNode viewNode, ViewDefinition view, List<System.Xml.XmlNode> unprocessedNodes)
 {
     if (viewNode == null)
     {
         throw PSTraceSource.NewArgumentNullException("viewNode");
     }
     if (view == null)
     {
         throw PSTraceSource.NewArgumentNullException("view");
     }
     view.loadingInfo = base.LoadingInfo;
     view.loadingInfo.xPath = base.ComputeCurrentXPath();
     bool flag = false;
     bool flag2 = false;
     bool flag3 = false;
     foreach (System.Xml.XmlNode node in viewNode.ChildNodes)
     {
         if (base.MatchNodeName(node, "Name"))
         {
             if (flag)
             {
                 base.ProcessDuplicateNode(node);
                 return false;
             }
             flag = true;
             view.name = base.GetMandatoryInnerText(node);
             if (view.name == null)
             {
                 return false;
             }
         }
         else if (base.MatchNodeName(node, "ViewSelectedBy"))
         {
             if (flag2)
             {
                 base.ProcessDuplicateNode(node);
                 return false;
             }
             flag2 = true;
             view.appliesTo = this.LoadAppliesToSection(node, false);
             if (view.appliesTo == null)
             {
                 return false;
             }
         }
         else if (base.MatchNodeName(node, "GroupBy"))
         {
             if (flag3)
             {
                 base.ProcessDuplicateNode(node);
                 return false;
             }
             flag3 = true;
             view.groupBy = this.LoadGroupBySection(node);
             if (view.groupBy == null)
             {
                 return false;
             }
         }
         else
         {
             unprocessedNodes.Add(node);
         }
     }
     if (!flag)
     {
         base.ReportMissingNode("Name");
         return false;
     }
     if (!flag2)
     {
         base.ReportMissingNode("ViewSelectedBy");
         return false;
     }
     return true;
 }
Пример #38
0
        private bool LoadCommonViewData(XmlNode viewNode, ViewDefinition view, List<XmlNode> unprocessedNodes)
        {
            if (viewNode == null)
                throw PSTraceSource.NewArgumentNullException("viewNode");

            if (view == null)
                throw PSTraceSource.NewArgumentNullException("view");

            // set loading information
            view.loadingInfo = this.LoadingInfo;
            view.loadingInfo.xPath = this.ComputeCurrentXPath();

            // start the loading process
            bool nameNodeFound = false;             // cardinality 1
            bool appliesToNodeFound = false;        // cardinality 1
            bool groupByFound = false;              // cardinality 0..1

            foreach (XmlNode n in viewNode.ChildNodes)
            {
                if (MatchNodeName(n, XmlTags.NameNode))
                {
                    if (nameNodeFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return false;
                    }

                    nameNodeFound = true;
                    view.name = GetMandatoryInnerText(n);
                    if (view.name == null)
                    {
                        return false;
                    }
                }
                else if (MatchNodeName(n, XmlTags.ViewSelectedByNode))
                {
                    if (appliesToNodeFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return false;
                    }

                    appliesToNodeFound = true;

                    // if null, we invalidate the view
                    view.appliesTo = LoadAppliesToSection(n, false);
                    if (view.appliesTo == null)
                    {
                        return false;
                    }
                }
                else if (MatchNodeName(n, XmlTags.GroupByNode))
                {
                    if (groupByFound)
                    {
                        this.ProcessDuplicateNode(n);
                        return false;
                    }

                    groupByFound = true;
                    view.groupBy = LoadGroupBySection(n);
                    if (view.groupBy == null)
                    {
                        return false;
                    }
                }
                else
                {
                    // save for further processing 
                    unprocessedNodes.Add(n);
                }
            } // for

            if (!nameNodeFound)
            {
                this.ReportMissingNode(XmlTags.NameNode);
                return false;
            }

            if (!appliesToNodeFound)
            {
                this.ReportMissingNode(XmlTags.ViewSelectedByNode);
                return false;
            }

            return true;
        }
Пример #39
0
        private ViewDefinition LoadView(XmlNode viewNode, int index)
        {
            using (this.StackFrame(viewNode, index))
            {
                // load the common data
                ViewDefinition view = new ViewDefinition();
                List<XmlNode> unprocessedNodes = new List<XmlNode>();
                bool success = LoadCommonViewData(viewNode, view, unprocessedNodes);

                if (!success)
                {
                    //Error at XPath {0} in file {1}: View cannot be loaded.
                    this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.ViewNotLoaded, ComputeCurrentXPath(), FilePath));
                    return null; // fatal error
                }

                // add the main control constituting the view
                // only one control can exist, and it can be
                // of the various types: Table, List, etc.

                string[] controlNodeTags = new string[]
                {
                    XmlTags.TableControlNode,
                    XmlTags.ListControlNode,
                    XmlTags.WideControlNode,
                    XmlTags.ComplexControlNode
                };

                List<XmlNode> secondPassUnprocessedNodes = new List<XmlNode>();

                bool mainControlFound = false; // cardinality 1
                foreach (XmlNode n in unprocessedNodes)
                {
                    if (MatchNodeName(n, XmlTags.TableControlNode))
                    {
                        if (mainControlFound)
                        {
                            ProcessDuplicateNode(n);
                            return null;
                        }
                        mainControlFound = true;
                        view.mainControl = LoadTableControl(n);
                    }
                    else if (MatchNodeName(n, XmlTags.ListControlNode))
                    {
                        if (mainControlFound)
                        {
                            ProcessDuplicateNode(n);
                            return null;
                        }
                        mainControlFound = true;
                        view.mainControl = LoadListControl(n);
                    }

                    else if (MatchNodeName(n, XmlTags.WideControlNode))
                    {
                        if (mainControlFound)
                        {
                            ProcessDuplicateNode(n);
                            return null;
                        }
                        mainControlFound = true;
                        view.mainControl = LoadWideControl(n);
                    }
                    else if (MatchNodeName(n, XmlTags.ComplexControlNode))
                    {
                        if (mainControlFound)
                        {
                            ProcessDuplicateNode(n);
                            return null;
                        }
                        mainControlFound = true;
                        view.mainControl = LoadComplexControl(n);
                    }
                    else
                    {
                        secondPassUnprocessedNodes.Add(n);
                    }
                } // foreach

                if (view.mainControl == null)
                {
                    this.ReportMissingNodes(controlNodeTags);
                    return null; // fatal
                }

                if (!LoadMainControlDependentData(secondPassUnprocessedNodes, view))
                {
                    return null; // fatal
                }

                if (view.outOfBand && (view.groupBy != null))
                {
                    // we cannot have grouping and out of band at the same time
                    //Error at XPath {0} in file {1}: An Out Of Band view cannot have GroupBy.
                    this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.OutOfBandGroupByConflict, ComputeCurrentXPath(), FilePath));
                    return null; // fatal
                }

                return view;
            }
        }
Пример #40
0
        /// <summary>To go from internal representation to external - for Get-FormatData</summary>
        internal ListControl(ListControlBody listcontrolbody, ViewDefinition viewDefinition)
            : this()
        {
            this.GroupBy = PSControlGroupBy.Get(viewDefinition.groupBy);
            this.OutOfBand = viewDefinition.outOfBand;

            Entries.Add(new ListControlEntry(listcontrolbody.defaultEntryDefinition));

            foreach (ListControlEntryDefinition lced in listcontrolbody.optionalEntryList)
            {
                Entries.Add(new ListControlEntry(lced));
            }
        }