Example #1
0
 internal ListControlEntryItem(ListControlItemDefinition definition)
 {
     if (definition.label != null)
     {
         this._label = definition.label.text;
     }
     FieldPropertyToken token = definition.formatTokenList[0] as FieldPropertyToken;
     if (token != null)
     {
         if (token.expression.isScriptBlock)
         {
             this._entry = new System.Management.Automation.DisplayEntry(token.expression.expressionValue, DisplayEntryValueType.ScriptBlock);
         }
         else
         {
             this._entry = new System.Management.Automation.DisplayEntry(token.expression.expressionValue, DisplayEntryValueType.Property);
         }
     }
 }
        /// <summary>
        /// Let the view prepare itself for RemoteObjects. This will add "ComputerName" to the 
        /// table columns.
        /// </summary>
        /// <param name="so"></param>
        internal override void PrepareForRemoteObjects(PSObject so)
        {
            Diagnostics.Assert(null != so, "so cannot be null");

            // make sure computername property exists.
            Diagnostics.Assert(null != so.Properties[RemotingConstants.ComputerNameNoteProperty],
                "PrepareForRemoteObjects cannot be called when the object does not contain ComputerName property.");

            if ((dataBaseInfo != null) && (dataBaseInfo.view != null) && (dataBaseInfo.view.mainControl != null))
            {
                _listBody = (ListControlBody)this.dataBaseInfo.view.mainControl.Copy();
                // build up the definition for computer name.
                ListControlItemDefinition cnListItemDefinition = new ListControlItemDefinition();
                cnListItemDefinition.label = new TextToken();
                cnListItemDefinition.label.text = RemotingConstants.ComputerNameNoteProperty;
                FieldPropertyToken fpt = new FieldPropertyToken();
                fpt.expression = new ExpressionToken(RemotingConstants.ComputerNameNoteProperty, false);
                cnListItemDefinition.formatTokenList.Add(fpt);


                _listBody.defaultEntryDefinition.itemDefinitionList.Add(cnListItemDefinition);
            }
        }
Example #3
0
        private void LoadListControlItemDefinitions(ListControlEntryDefinition lved, XmlNode bodyNode)
        {
            using (this.StackFrame(bodyNode))
            {
                int index = 0;

                foreach (XmlNode n in bodyNode.ChildNodes)
                {
                    if (MatchNodeName(n, XmlTags.ListItemNode))
                    {
                        index++;
                        ListControlItemDefinition lvid = LoadListControlItemDefinition(n);
                        if (lvid == null)
                        {
                            //Error at XPath {0} in file {1}: Invalid property entry.
                            this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.InvalidPropertyEntry, ComputeCurrentXPath(), FilePath));
                            lved.itemDefinitionList = null;
                            return; //fatal
                        }
                        lved.itemDefinitionList.Add(lvid);
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }

                // we must have at least a definition in th elist
                if (lved.itemDefinitionList.Count == 0)
                {
                    //Error at XPath {0} in file {1}: At least one list view item must be specified.
                    this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.NoListViewItem, ComputeCurrentXPath(), FilePath));
                    lved.itemDefinitionList = null;
                    return; //fatal
                }
            }
        }
Example #4
0
 private void LoadListControlItemDefinitionsFromObjectModel(ListControlEntryDefinition lved, List<ListControlEntryItem> listItems, int viewIndex, string typeName)
 {
     foreach (ListControlEntryItem item in listItems)
     {
         ListControlItemDefinition definition = new ListControlItemDefinition();
         if (item.DisplayEntry != null)
         {
             ExpressionToken token = this.LoadExpressionFromObjectModel(item.DisplayEntry, viewIndex, typeName);
             if (token == null)
             {
                 lved.itemDefinitionList = null;
                 return;
             }
             FieldPropertyToken token2 = new FieldPropertyToken {
                 expression = token
             };
             definition.formatTokenList.Add(token2);
         }
         if (!string.IsNullOrEmpty(item.Label))
         {
             TextToken token3 = new TextToken {
                 text = item.Label
             };
             definition.label = token3;
         }
         lved.itemDefinitionList.Add(definition);
     }
     if (lved.itemDefinitionList.Count == 0)
     {
         base.ReportErrorForLoadingFromObjectModel(StringUtil.Format(FormatAndOutXmlLoadingStrings.NoListViewItemInFormattingData, typeName, viewIndex), typeName);
         lved.itemDefinitionList = null;
     }
 }
Example #5
0
 private ListControlItemDefinition LoadListControlItemDefinition(System.Xml.XmlNode propertyEntryNode)
 {
     using (base.StackFrame(propertyEntryNode))
     {
         ViewEntryNodeMatch match = new ViewEntryNodeMatch(this);
         List<System.Xml.XmlNode> unprocessedNodes = new List<System.Xml.XmlNode>();
         if (!match.ProcessExpressionDirectives(propertyEntryNode, unprocessedNodes))
         {
             return null;
         }
         TextToken token = null;
         ExpressionToken token2 = null;
         bool flag = false;
         bool flag2 = false;
         foreach (System.Xml.XmlNode node in unprocessedNodes)
         {
             if (base.MatchNodeName(node, "ItemSelectionCondition"))
             {
                 if (flag2)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag2 = true;
                 token2 = this.LoadItemSelectionCondition(node);
                 if (token2 == null)
                 {
                     return null;
                 }
             }
             else if (base.MatchNodeNameWithAttributes(node, "Label"))
             {
                 if (flag)
                 {
                     base.ProcessDuplicateNode(node);
                     return null;
                 }
                 flag = true;
                 token = this.LoadLabel(node);
                 if (token == null)
                 {
                     return null;
                 }
             }
             else
             {
                 base.ProcessUnknownNode(node);
             }
         }
         ListControlItemDefinition definition = new ListControlItemDefinition {
             label = token,
             conditionToken = token2
         };
         if (match.TextToken != null)
         {
             definition.formatTokenList.Add(match.TextToken);
         }
         else
         {
             FieldPropertyToken item = new FieldPropertyToken {
                 expression = match.Expression
             };
             item.fieldFormattingDirective.formatString = match.FormatString;
             definition.formatTokenList.Add(item);
         }
         return definition;
     }
 }
Example #6
0
        /// <summary>
        /// Load ListItems into ListControlItemDefinition
        /// </summary>
        /// <param name="lved"></param>
        /// <param name="listItems"></param>
        /// <param name="viewIndex"></param>
        /// <param name="typeName"></param>
        private void LoadListControlItemDefinitionsFromObjectModel(ListControlEntryDefinition lved, List<ListControlEntryItem> listItems, int viewIndex, string typeName)
        {
            foreach (ListControlEntryItem listItem in listItems)
            {
                ListControlItemDefinition lvid = new ListControlItemDefinition();

                // Contains:
                //   DisplayEntry --- Expression  cardinality 0..1
                //   Label        --- Label       cardinality 0..1
                if (listItem.DisplayEntry != null)
                {
                    ExpressionToken expression = LoadExpressionFromObjectModel(listItem.DisplayEntry, viewIndex, typeName);
                    if (expression == null)
                    {
                        lved.itemDefinitionList = null;
                        return; // fatal
                    }
                    FieldPropertyToken fpt = new FieldPropertyToken();
                    fpt.expression = expression;
                    fpt.fieldFormattingDirective.formatString = listItem.FormatString;
                    lvid.formatTokenList.Add(fpt);
                }

                if (!String.IsNullOrEmpty(listItem.Label))
                {
                    TextToken tt = new TextToken();
                    tt.text = listItem.Label;
                    lvid.label = tt;
                }

                lved.itemDefinitionList.Add(lvid);
            }

            // we must have at least a definition in th elist
            if (lved.itemDefinitionList.Count == 0)
            {
                //Error: At least one list view item must be specified.
                this.ReportErrorForLoadingFromObjectModel(
                    StringUtil.Format(FormatAndOutXmlLoadingStrings.NoListViewItemInFormattingData, typeName, viewIndex), typeName);
                lved.itemDefinitionList = null;
                return; //fatal
            }
        }
Example #7
0
        private ListControlItemDefinition LoadListControlItemDefinition(XmlNode propertyEntryNode)
        {
            using (this.StackFrame(propertyEntryNode))
            {
                // process Mshexpression, format string and text token
                ViewEntryNodeMatch match            = new ViewEntryNodeMatch(this);
                List <XmlNode>     unprocessedNodes = new List <XmlNode>();
                if (!match.ProcessExpressionDirectives(propertyEntryNode, unprocessedNodes))
                {
                    return(null); // fatal error
                }

                // process the remaining nodes
                TextToken       labelToken     = null;
                ExpressionToken condition      = null;
                bool            labelNodeFound = false;                  // cardinality 0..1
                bool            itemSelectionConditionNodeFound = false; // cardinality 0..1

                foreach (XmlNode n in unprocessedNodes)
                {
                    if (MatchNodeName(n, XmlTags.ItemSelectionConditionNode))
                    {
                        if (itemSelectionConditionNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return(null); // fatal error
                        }
                        itemSelectionConditionNodeFound = true;
                        condition = LoadItemSelectionCondition(n);
                        if (condition == null)
                        {
                            return(null); // fatal error
                        }
                    }
                    else if (MatchNodeNameWithAttributes(n, XmlTags.LabelNode))
                    {
                        if (labelNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return(null); // fatal error
                        }
                        labelNodeFound = true;
                        labelToken     = LoadLabel(n);
                        if (labelToken == null)
                        {
                            return(null); // fatal error
                        }
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }

                // finally build the item to return
                ListControlItemDefinition lvid = new ListControlItemDefinition();

                // add the label
                lvid.label = labelToken;

                // add condition
                lvid.conditionToken = condition;

                // add either the text token or the MshExpression with optional format string
                if (match.TextToken != null)
                {
                    lvid.formatTokenList.Add(match.TextToken);
                }
                else
                {
                    FieldPropertyToken fpt = new FieldPropertyToken();
                    fpt.expression = match.Expression;
                    fpt.fieldFormattingDirective.formatString = match.FormatString;
                    lvid.formatTokenList.Add(fpt);
                }
                return(lvid);
            }
        }
Example #8
0
 internal override void PrepareForRemoteObjects(PSObject so)
 {
     PSPropertyInfo local1 = so.Properties[RemotingConstants.ComputerNameNoteProperty];
     if (((base.dataBaseInfo != null) && (base.dataBaseInfo.view != null)) && (base.dataBaseInfo.view.mainControl != null))
     {
         this.listBody = (ListControlBody) base.dataBaseInfo.view.mainControl.Copy();
         ListControlItemDefinition item = new ListControlItemDefinition {
             label = new TextToken()
         };
         item.label.text = RemotingConstants.ComputerNameNoteProperty;
         FieldPropertyToken token = new FieldPropertyToken {
             expression = new ExpressionToken(RemotingConstants.ComputerNameNoteProperty, false)
         };
         item.formatTokenList.Add(token);
         this.listBody.defaultEntryDefinition.itemDefinitionList.Add(item);
     }
 }
        private ListControlItemDefinition LoadListControlItemDefinition(XmlNode propertyEntryNode)
        {
            using (this.StackFrame(propertyEntryNode))
            {
                // process Mshexpression, format string and text token
                ViewEntryNodeMatch match = new ViewEntryNodeMatch(this);
                List<XmlNode> unprocessedNodes = new List<XmlNode>();
                if (!match.ProcessExpressionDirectives(propertyEntryNode, unprocessedNodes))
                {
                    return null; // fatal error
                }

                // process the remaining nodes
                TextToken labelToken = null;
                ExpressionToken condition = null;
                bool labelNodeFound = false; // cardinality 0..1
                bool itemSelectionConditionNodeFound = false; // cardinality 0..1

                foreach (XmlNode n in unprocessedNodes)
                {
                    if (MatchNodeName(n, XmlTags.ItemSelectionConditionNode))
                    {
                        if (itemSelectionConditionNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return null; // fatal error
                        }
                        itemSelectionConditionNodeFound = true;
                        condition = LoadItemSelectionCondition(n);
                        if (condition == null)
                        {
                            return null; // fatal error
                        }
                    }
                    else if (MatchNodeNameWithAttributes(n, XmlTags.LabelNode))
                    {
                        if (labelNodeFound)
                        {
                            this.ProcessDuplicateNode(n);
                            return null; // fatal error
                        }
                        labelNodeFound = true;
                        labelToken = LoadLabel(n);
                        if (labelToken == null)
                        {
                            return null; // fatal error
                        }
                    }
                    else
                    {
                        this.ProcessUnknownNode(n);
                    }
                }

                // finally build the item to return
                ListControlItemDefinition lvid = new ListControlItemDefinition();

                // add the label
                lvid.label = labelToken;

                // add condition
                lvid.conditionToken = condition;

                // add either the text token or the MshExpression with optional format string
                if (match.TextToken != null)
                {
                    lvid.formatTokenList.Add(match.TextToken);
                }
                else
                {
                    FieldPropertyToken fpt = new FieldPropertyToken();
                    fpt.expression = match.Expression;
                    fpt.fieldFormattingDirective.formatString = match.FormatString;
                    lvid.formatTokenList.Add(fpt);
                }
                return lvid;
            }
        }
        internal ListControlEntryItem(ListControlItemDefinition definition)
        {
            if (definition.label != null)
            {
                Label = definition.label.text;
            }
            FieldPropertyToken fpt = definition.formatTokenList[0] as FieldPropertyToken;
            if (fpt != null)
            {
                if (fpt.fieldFormattingDirective.formatString != null)
                {
                    FormatString = fpt.fieldFormattingDirective.formatString;
                }

                DisplayEntry = new DisplayEntry(fpt.expression);
                if (definition.conditionToken != null)
                {
                    ItemSelectionCondition = new DisplayEntry(definition.conditionToken);
                }
            }
        }