private FrameToken LoadFrameDefinition(System.Xml.XmlNode frameNode, int index) { using (base.StackFrame(frameNode, index)) { bool flag = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; bool flag5 = false; FrameToken token = new FrameToken(); foreach (System.Xml.XmlNode node in frameNode.ChildNodes) { bool flag6; if (base.MatchNodeName(node, "LeftIndent")) { if (flag2) { base.ProcessDuplicateNode(node); return null; } flag2 = true; token.frameInfoDefinition.leftIndentation = this.LoadPositiveOrZeroIntegerValue(node, out flag6); if (!flag6) { return null; } } else if (base.MatchNodeName(node, "RightIndent")) { if (flag3) { base.ProcessDuplicateNode(node); return null; } flag3 = true; token.frameInfoDefinition.rightIndentation = this.LoadPositiveOrZeroIntegerValue(node, out flag6); if (!flag6) { return null; } } else if (base.MatchNodeName(node, "FirstLineIndent")) { if (flag4) { base.ProcessDuplicateAlternateNode(node, "FirstLineIndent", "FirstLineHanging"); return null; } flag4 = true; token.frameInfoDefinition.firstLine = this.LoadPositiveOrZeroIntegerValue(node, out flag6); if (!flag6) { return null; } } else if (base.MatchNodeName(node, "FirstLineHanging")) { if (flag5) { base.ProcessDuplicateAlternateNode(node, "FirstLineIndent", "FirstLineHanging"); return null; } flag5 = true; token.frameInfoDefinition.firstLine = this.LoadPositiveOrZeroIntegerValue(node, out flag6); if (!flag6) { return null; } token.frameInfoDefinition.firstLine = -token.frameInfoDefinition.firstLine; } else if (base.MatchNodeName(node, "CustomItem")) { if (flag) { base.ProcessDuplicateNode(node); return null; } flag = true; token.itemDefinition.formatTokenList = this.LoadComplexControlTokenListDefinitions(node); } else { base.ProcessUnknownNode(node); } } if (flag5 && flag4) { base.ProcessDuplicateAlternateNode("FirstLineIndent", "FirstLineHanging"); return null; } if (token.itemDefinition.formatTokenList == null) { base.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.MissingNode, new object[] { base.ComputeCurrentXPath(), base.FilePath, "CustomItem" })); return null; } return token; } }
private void ExecuteFormatTokenList(TraversalInfo level, PSObject so, List <FormatToken> formatTokenList, List <FormatValue> formatValueList) { if (so == null) { throw PSTraceSource.NewArgumentNullException("so"); } // guard against infinite loop if (level.Level == level.MaxDepth) { return; } FormatEntry fe = new FormatEntry(); formatValueList.Add(fe); #region foreach loop foreach (FormatToken t in formatTokenList) { TextToken tt = t as TextToken; if (tt != null) { FormatTextField ftf = new FormatTextField(); ftf.text = _db.displayResourceManagerCache.GetTextTokenString(tt); fe.formatValueList.Add(ftf); continue; } var newline = t as NewLineToken; if (newline != null) { for (int i = 0; i < newline.count; i++) { fe.formatValueList.Add(new FormatNewLine()); } continue; } FrameToken ft = t as FrameToken; if (ft != null) { // instantiate a new entry and attach a frame info object FormatEntry feFrame = new FormatEntry(); feFrame.frameInfo = new FrameInfo(); // add the frame info feFrame.frameInfo.firstLine = ft.frameInfoDefinition.firstLine; feFrame.frameInfo.leftIndentation = ft.frameInfoDefinition.leftIndentation; feFrame.frameInfo.rightIndentation = ft.frameInfoDefinition.rightIndentation; // execute the list inside the frame ExecuteFormatTokenList(level, so, ft.itemDefinition.formatTokenList, feFrame.formatValueList); // add the frame computation results to the current format entry fe.formatValueList.Add(feFrame); continue; } #region CompoundPropertyToken CompoundPropertyToken cpt = t as CompoundPropertyToken; if (cpt != null) { if (!EvaluateDisplayCondition(so, cpt.conditionToken)) { // token not active, skip it continue; } // get the property from the object object val = null; // if no expression was specified, just use the // object itself if (cpt.expression == null || string.IsNullOrEmpty(cpt.expression.expressionValue)) { val = so; } else { PSPropertyExpression ex = _expressionFactory.CreateFromExpressionToken(cpt.expression, _loadingInfo); List <PSPropertyExpressionResult> resultList = ex.GetValues(so); if (resultList.Count > 0) { val = resultList[0].Result; if (resultList[0].Exception != null) { _errorManager.LogPSPropertyExpressionFailedResult(resultList[0], so); } } } // if the token is has a formatting string, it's a leaf node, // do the formatting and we will be done if (cpt.control == null || cpt.control is FieldControlBody) { // Since it is a leaf node we just consider it an empty string and go // on with formatting if (val == null) { val = string.Empty; } FieldFormattingDirective fieldFormattingDirective = null; StringFormatError formatErrorObject = null; if (cpt.control != null) { fieldFormattingDirective = ((FieldControlBody)cpt.control).fieldFormattingDirective; if (fieldFormattingDirective != null && _errorManager.DisplayFormatErrorString) { formatErrorObject = new StringFormatError(); } } IEnumerable e = PSObjectHelper.GetEnumerable(val); FormatPropertyField fpf = new FormatPropertyField(); if (cpt.enumerateCollection && e != null) { foreach (object x in e) { if (x == null) { // nothing to process continue; } fpf = new FormatPropertyField(); fpf.propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, x, _enumerationLimit, formatErrorObject, _expressionFactory); fe.formatValueList.Add(fpf); } } else { fpf = new FormatPropertyField(); fpf.propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, val, _enumerationLimit, formatErrorObject, _expressionFactory); fe.formatValueList.Add(fpf); } if (formatErrorObject != null && formatErrorObject.exception != null) { _errorManager.LogStringFormatError(formatErrorObject); fpf.propertyValue = _errorManager.FormatErrorString; } } else { // An empty result that is not a leaf node should not be expanded if (val == null) { continue; } IEnumerable e = PSObjectHelper.GetEnumerable(val); if (cpt.enumerateCollection && e != null) { foreach (object x in e) { if (x == null) { // nothing to process continue; } // proceed with the recursion ExecuteFormatControl(level.NextLevel, cpt.control, PSObject.AsPSObject(x), fe.formatValueList); } } else { // proceed with the recursion ExecuteFormatControl(level.NextLevel, cpt.control, PSObjectHelper.AsPSObject(val), fe.formatValueList); } } } #endregion CompoundPropertyToken } #endregion foreach loop }
private FormatToken LoadFormatTokenFromObjectModel(CustomItemBase item, int viewIndex, string typeName) { var newline = item as CustomItemNewline; if (newline != null) { return new NewLineToken { count = newline.Count }; } var text = item as CustomItemText; if (text != null) { return new TextToken { text = text.Text }; } var expr = item as CustomItemExpression; if (expr != null) { var cpt = new CompoundPropertyToken { enumerateCollection = expr.EnumerateCollection }; if (expr.ItemSelectionCondition != null) { cpt.conditionToken = LoadExpressionFromObjectModel(expr.ItemSelectionCondition, viewIndex, typeName); } if (expr.Expression != null) { cpt.expression = LoadExpressionFromObjectModel(expr.Expression, viewIndex, typeName); } if (expr.CustomControl != null) { cpt.control = LoadCustomControlFromObjectModel(expr.CustomControl, viewIndex, typeName); } return cpt; } var frame = (CustomItemFrame)item; var frameToken = new FrameToken { frameInfoDefinition = { leftIndentation = (int) frame.LeftIndent, rightIndentation = (int) frame.RightIndent, firstLine = frame.FirstLineHanging != 0 ? -(int) frame.FirstLineHanging : (int) frame.FirstLineIndent } }; foreach (var i in frame.CustomItems) { frameToken.itemDefinition.formatTokenList.Add(LoadFormatTokenFromObjectModel(i, viewIndex, typeName)); } return frameToken; }
private FrameToken LoadFrameDefinition(XmlNode frameNode, int index) { using (this.StackFrame(frameNode, index)) { bool itemNodeFound = false; // cardinality 1 bool leftIndentFound = false; // cardinality 0..1 bool rightIndentFound = false; // cardinality 0..1 // mutually exclusive bool firstLineIndentFound = false; // cardinality 0..1 bool firstLineHangingFound = false; // cardinality 0..1 bool success; // scratch variable FrameToken frame = new FrameToken(); foreach (XmlNode n in frameNode.ChildNodes) { if (MatchNodeName(n, XmlTags.LeftIndentNode)) { if (leftIndentFound) { this.ProcessDuplicateNode(n); return(null); //fatal } leftIndentFound = true; // optional section frame.frameInfoDefinition.leftIndentation = LoadPositiveOrZeroIntegerValue(n, out success); if (!success) { return(null); } } else if (MatchNodeName(n, XmlTags.RightIndentNode)) { if (rightIndentFound) { this.ProcessDuplicateNode(n); return(null); //fatal } rightIndentFound = true; // optional section frame.frameInfoDefinition.rightIndentation = LoadPositiveOrZeroIntegerValue(n, out success); if (!success) { return(null); } } else if (MatchNodeName(n, XmlTags.FirstLineIndentNode)) { if (firstLineIndentFound) { this.ProcessDuplicateAlternateNode(n, XmlTags.FirstLineIndentNode, XmlTags.FirstLineHangingNode); return(null); } firstLineIndentFound = true; frame.frameInfoDefinition.firstLine = LoadPositiveOrZeroIntegerValue(n, out success); if (!success) { return(null); } } else if (MatchNodeName(n, XmlTags.FirstLineHangingNode)) { if (firstLineHangingFound) { this.ProcessDuplicateAlternateNode(n, XmlTags.FirstLineIndentNode, XmlTags.FirstLineHangingNode); return(null); } firstLineHangingFound = true; frame.frameInfoDefinition.firstLine = LoadPositiveOrZeroIntegerValue(n, out success); if (!success) { return(null); } // hanging is codified as negative frame.frameInfoDefinition.firstLine = -frame.frameInfoDefinition.firstLine; } else if (MatchNodeName(n, XmlTags.ComplexItemNode)) { if (itemNodeFound) { this.ProcessDuplicateNode(n); return(null); //fatal } itemNodeFound = true; frame.itemDefinition.formatTokenList = LoadComplexControlTokenListDefinitions(n); } else { this.ProcessUnknownNode(n); } } if (firstLineHangingFound && firstLineIndentFound) { this.ProcessDuplicateAlternateNode(XmlTags.FirstLineIndentNode, XmlTags.FirstLineHangingNode); return(null); // fatal error } if (frame.itemDefinition.formatTokenList == null) { //MissingNode=Error at XPath {0} in file {1}: Missing Node {2}. this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.MissingNode, ComputeCurrentXPath(), FilePath, XmlTags.ComplexItemNode)); return(null); } return(frame); } }
private List <FormatToken> LoadComplexControlTokenListDefinitions(XmlNode bodyNode) { using (this.StackFrame(bodyNode)) { List <FormatToken> formatTokenList = new List <FormatToken>(); int compoundPropertyIndex = 0; int newLineIndex = 0; int textIndex = 0; int frameIndex = 0; foreach (XmlNode n in bodyNode.ChildNodes) { if (MatchNodeName(n, XmlTags.ExpressionBindingNode)) { CompoundPropertyToken cpt = LoadCompoundProperty(n, compoundPropertyIndex++); if (cpt == null) { //Error at XPath {0} in file {1}: {2} failed to load. this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.LoadTagFailed, ComputeCurrentXPath(), FilePath, XmlTags.ExpressionBindingNode)); return(null); } formatTokenList.Add(cpt); } else if (MatchNodeName(n, XmlTags.NewLineNode)) { NewLineToken nlt = LoadNewLine(n, newLineIndex++); if (nlt == null) { //Error at XPath {0} in file {1}: {2} failed to load. this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.LoadTagFailed, ComputeCurrentXPath(), FilePath, XmlTags.NewLineNode)); return(null); } formatTokenList.Add(nlt); } else if (MatchNodeNameWithAttributes(n, XmlTags.TextNode)) { TextToken tt = LoadText(n, textIndex++); if (tt == null) { //Error at XPath {0} in file {1}: {2} failed to load. this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.LoadTagFailed, ComputeCurrentXPath(), FilePath, XmlTags.TextNode)); return(null); } formatTokenList.Add(tt); } else if (MatchNodeName(n, XmlTags.FrameNode)) { FrameToken frame = LoadFrameDefinition(n, frameIndex++); if (frame == null) { //Error at XPath {0} in file {1}: {2} failed to load. this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.LoadTagFailed, ComputeCurrentXPath(), FilePath, XmlTags.FrameNode)); return(null); } formatTokenList.Add(frame); } else { this.ProcessUnknownNode(n); } } if (formatTokenList.Count == 0) { //Error at XPath {0} in file {1}: Empty custom control token list. this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.EmptyCustomControlList, ComputeCurrentXPath(), FilePath)); return(null); } return(formatTokenList); } }
private void ExecuteFormatTokenList(TraversalInfo level, PSObject so, List <FormatToken> formatTokenList, List <FormatValue> formatValueList) { if (so == null) { throw PSTraceSource.NewArgumentNullException("so"); } if (level.Level != level.MaxDepth) { FormatEntry item = new FormatEntry(); formatValueList.Add(item); foreach (FormatToken token in formatTokenList) { TextToken tt = token as TextToken; if (tt != null) { FormatTextField field = new FormatTextField { text = this.db.displayResourceManagerCache.GetTextTokenString(tt) }; item.formatValueList.Add(field); } else if (token is NewLineToken) { item.formatValueList.Add(new FormatNewLine()); } else { FrameToken token3 = token as FrameToken; if (token3 != null) { FormatEntry entry2 = new FormatEntry { frameInfo = new FrameInfo() }; entry2.frameInfo.firstLine = token3.frameInfoDefinition.firstLine; entry2.frameInfo.leftIndentation = token3.frameInfoDefinition.leftIndentation; entry2.frameInfo.rightIndentation = token3.frameInfoDefinition.rightIndentation; this.ExecuteFormatTokenList(level, so, token3.itemDefinition.formatTokenList, entry2.formatValueList); item.formatValueList.Add(entry2); } else { CompoundPropertyToken token4 = token as CompoundPropertyToken; if ((token4 != null) && this.EvaluateDisplayCondition(so, token4.conditionToken)) { object result = null; if ((token4.expression == null) || string.IsNullOrEmpty(token4.expression.expressionValue)) { result = so; } else { List <MshExpressionResult> values = this.expressionFactory.CreateFromExpressionToken(token4.expression, this.loadingInfo).GetValues(so); if (values.Count > 0) { result = values[0].Result; if (values[0].Exception != null) { this.errorManager.LogMshExpressionFailedResult(values[0], so); } } } if ((token4.control == null) || (token4.control is FieldControlBody)) { if (result == null) { result = ""; } FieldFormattingDirective fieldFormattingDirective = null; StringFormatError formatErrorObject = null; if (token4.control != null) { fieldFormattingDirective = ((FieldControlBody)token4.control).fieldFormattingDirective; if ((fieldFormattingDirective != null) && this.errorManager.DisplayFormatErrorString) { formatErrorObject = new StringFormatError(); } } IEnumerable enumerable = PSObjectHelper.GetEnumerable(result); FormatPropertyField field2 = new FormatPropertyField(); if (token4.enumerateCollection && (enumerable != null)) { foreach (object obj3 in enumerable) { if (obj3 != null) { field2 = new FormatPropertyField { propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, obj3, this.enumerationLimit, formatErrorObject, this.expressionFactory) }; item.formatValueList.Add(field2); } } } else { field2 = new FormatPropertyField { propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, result, this.enumerationLimit, formatErrorObject, this.expressionFactory) }; item.formatValueList.Add(field2); } if ((formatErrorObject != null) && (formatErrorObject.exception != null)) { this.errorManager.LogStringFormatError(formatErrorObject); field2.propertyValue = this.errorManager.FormatErrorString; } } else if (result != null) { IEnumerable enumerable2 = PSObjectHelper.GetEnumerable(result); if (token4.enumerateCollection && (enumerable2 != null)) { foreach (object obj4 in enumerable2) { if (obj4 != null) { this.ExecuteFormatControl(level.NextLevel, token4.control, PSObject.AsPSObject(obj4), item.formatValueList); } } } else { this.ExecuteFormatControl(level.NextLevel, token4.control, PSObjectHelper.AsPSObject(result), item.formatValueList); } } } } } } } }
private FrameToken LoadFrameDefinition(XmlNode frameNode, int index) { using (this.StackFrame(frameNode, index)) { bool itemNodeFound = false; // cardinality 1 bool leftIndentFound = false; // cardinality 0..1 bool rightIndentFound = false; // cardinality 0..1 // mutually exclusive bool firstLineIndentFound = false; // cardinality 0..1 bool firstLineHangingFound = false; // cardinality 0..1 bool success; // scratch variable FrameToken frame = new FrameToken(); foreach (XmlNode n in frameNode.ChildNodes) { if (MatchNodeName(n, XmlTags.LeftIndentNode)) { if (leftIndentFound) { this.ProcessDuplicateNode(n); return null; //fatal } leftIndentFound = true; // optional section frame.frameInfoDefinition.leftIndentation = LoadPositiveOrZeroIntegerValue(n, out success); if (!success) return null; } else if (MatchNodeName(n, XmlTags.RightIndentNode)) { if (rightIndentFound) { this.ProcessDuplicateNode(n); return null; //fatal } rightIndentFound = true; // optional section frame.frameInfoDefinition.rightIndentation = LoadPositiveOrZeroIntegerValue(n, out success); if (!success) return null; } else if (MatchNodeName(n, XmlTags.FirstLineIndentNode)) { if (firstLineIndentFound) { this.ProcessDuplicateAlternateNode(n, XmlTags.FirstLineIndentNode, XmlTags.FirstLineHangingNode); return null; } firstLineIndentFound = true; frame.frameInfoDefinition.firstLine = LoadPositiveOrZeroIntegerValue(n, out success); if (!success) return null; } else if (MatchNodeName(n, XmlTags.FirstLineHangingNode)) { if (firstLineHangingFound) { this.ProcessDuplicateAlternateNode(n, XmlTags.FirstLineIndentNode, XmlTags.FirstLineHangingNode); return null; } firstLineHangingFound = true; frame.frameInfoDefinition.firstLine = LoadPositiveOrZeroIntegerValue(n, out success); if (!success) return null; // hanging is codified as negative frame.frameInfoDefinition.firstLine = -frame.frameInfoDefinition.firstLine; } else if (MatchNodeName(n, XmlTags.ComplexItemNode)) { if (itemNodeFound) { this.ProcessDuplicateNode(n); return null; //fatal } itemNodeFound = true; frame.itemDefinition.formatTokenList = LoadComplexControlTokenListDefinitions(n); } else { this.ProcessUnknownNode(n); } } if (firstLineHangingFound && firstLineIndentFound) { this.ProcessDuplicateAlternateNode(XmlTags.FirstLineIndentNode, XmlTags.FirstLineHangingNode); return null; // fatal error } if (frame.itemDefinition.formatTokenList == null) { //MissingNode=Error at XPath {0} in file {1}: Missing Node {2}. this.ReportError(StringUtil.Format(FormatAndOutXmlLoadingStrings.MissingNode, ComputeCurrentXPath(), FilePath, XmlTags.ComplexItemNode)); return null; } return frame; } }