/// <summary> /// match the section of the screen definition against content of an actual /// screen. /// </summary> /// <param name="section"></param> /// <param name="Content"></param> /// <returns></returns> public static bool Match( this ISectionHeader section, IScreenLoc Start, ScreenContent Content, string DebugInfo) { bool isMatch = true; // match from screenDefn to the screenContent. foreach (var item in section.Items) { if (isMatch == false) { break; } isMatch = item.Match(Start, Content, DebugInfo); // BgnTemp if ((isMatch == false) && (DebugInfo == "DisplayMessages")) { isMatch = item.Match(Start, Content, DebugInfo); } // EndTemp } return(isMatch); }
/// <summary> /// recalc range as an absolute range. /// </summary> /// <param name="Start"></param> /// <returns></returns> public ScreenLocRange ToAbsolute(IScreenLoc Start) { var from = this.From.AbsoluteLoc(Start); var to = this.To.AbsoluteLoc(Start); return(new ScreenLocRange(from, to, this.RangeForm)); }
public static ScreenItemInstance FindItem( this IScreenItem item, IScreenLoc Start, IScreenLoc FindZeroLoc, ScreenContent Content) { ScreenItemInstance findItem = null; if (item.ItemType == ShowItemType.Section) { var sectionItem = item as IScreenSection; findItem = sectionItem.FindItem(Start, FindZeroLoc, Content); } else { // adjust screen loc of the item by start pos of the section it is contained in. var adjRow = Start.RowNum - 1; var adjCol = Start.ColNum - 1; var loc = new OneScreenLoc( item.ScreenLoc.RowNum + adjRow, item.ScreenLoc.ColNum + adjCol); var zeroLoc = loc.ToZeroRowCol(); var itemAtomic = item as IScreenAtomic; var range = new ScreenLocRange(zeroLoc, itemAtomic.Length, Content.ScreenDim); if (range.Contains(FindZeroLoc) == true) findItem = new ScreenItemInstance(item, range.From); } return findItem; }
public static Tuple<DataItem, DataItemReport> CaptureReport( this IScreenItem item, IScreenLoc Start, ScreenContent Content) { string captureText = null; DataItem dataItem = null; DataItemReport itemReport = null; ContentItemBase contentItem = null; // get the content item at the rowcol location. bool rc = true; IScreenAtomic atomicItem = null; // adjust screen loc of the item by start pos of the section it is contained in. var adjRow = Start.RowNum - 1; var adjCol = Start.ColNum - 1; var loc = new OneScreenLoc( item.ScreenLoc.RowNum + adjRow, item.ScreenLoc.ColNum + adjCol); var zeroLoc = loc.ToZeroRowCol(); if (item.ItemType != ShowItemType.Section) { rc = Content.FieldDict.TryGetValue(zeroLoc, out contentItem); atomicItem = item as IScreenAtomic; } if (rc == false) { } else if (item.ItemType == ShowItemType.Section) { var sectionItem = item as IScreenSection; itemReport = sectionItem.CaptureReport(Content); } else if (item.ItemType == ShowItemType.Field) { if ((contentItem is ContentField) == true) { var contentField = contentItem as ContentField; dataItem = new DataItem(item.ItemName, contentField.GetShowText(Content)); captureText = item.ItemName + "=" + contentField.GetShowText(Content); } } // match fixed literal else if (item.ItemType == ShowItemType.Literal) { if ((contentItem is ContentText) == true) { var contentText = contentItem as ContentText; var itemLit = item as IScreenLiteral; var ctValue = contentText.GetShowText(Content).TrimEndWhitespace(); } } return new Tuple<DataItem, DataItemReport>(dataItem, itemReport); }
public bool Contains(IScreenLoc RowCol) { bool contains = false; if ((RowCol.CompareTo(this.From) >= 0) && (RowCol.CompareTo(this.To) <= 0)) { contains = true; } return(contains); }
public ScreenLocRange(IScreenLoc From, int Length, ScreenDim Dim) { this.From = From; if (Length == 0) { this.To = From; } else { this.To = From.Advance(Length - 1, Dim); } }
public static ScreenItemInstance FindItem( this IScreenDefn Defn, IScreenLoc FindLoc, ScreenContent Content) { ScreenItemInstance found = null; ISectionHeader sectionHeader = Defn as ISectionHeader; var start = new OneScreenLoc(1, 1); found = sectionHeader.FindItem(start, FindLoc, Content); return(found); }
/// <summary> /// calc absolute location. /// </summary> /// <param name="Loc"></param> /// <param name="Start"></param> /// <returns></returns> public static IScreenLoc AbsoluteLoc(this IScreenLoc Loc, IScreenLoc Start) { var rowNum = Start.RowNum + Loc.RowNum; var colNum = Start.ColNum + Loc.ColNum; if (Loc.LocationFrame == LocationFrame.OneBased) { rowNum -= 1; colNum -= 1; } return(Loc.NewInstance(rowNum, colNum)); }
public static IScreenLoc ToOneBased(this IScreenLoc ScreenLoc) { if (ScreenLoc.LocationFrame == LocationFrame.ZeroBased) { int rowNum = ScreenLoc.RowNum + 1; int colNum = ScreenLoc.ColNum + 1; return(ScreenLoc.NewOneBased(rowNum, colNum)); } else { return(ScreenLoc); } }
public static DataItemReport CaptureReport(this IScreenSection section, ScreenContent Content) { var sb = new StringBuilder(); var sectionHeader = section as ISectionHeader; var sectionDim = section.CalcDim(); var itemReport = new DataItemReport(); IScreenLoc start = section.ScreenLoc; { start = start.NewInstance(start.RowNum, start.ColNum); } int repeatIx = 0; bool endOfRows = false; while (endOfRows == false) { if ((repeatIx > 0) && (repeatIx >= section.RepeatCount)) { break; } repeatIx += 1; // section is a subfile. subfile row can be blank. If blank consider as // the end of rows of the subfile. So no need to match. bool rowIsBlank = false; if (section.PurposeCode == ScreenPurposeCode.ReportDetail) { if (Content.RowIsBlank(start.RowNum) == true) { rowIsBlank = true; } } // a blank row. no more rows to match. if (rowIsBlank == true) { endOfRows = true; } if (endOfRows == false) { var report = sectionHeader.CaptureToReport(start, Content); var combo = DataItemReport.CombineVertically(itemReport, report); itemReport = combo; } start.RowNum += 1; } return(itemReport); }
public ScreenLocRange Extend(IScreenLoc loc) { var fromRow = this.From.RowNum; var from = this.From; var to = this.To; if (this.RangeForm == RangeForm.Linear) { if (loc.RowNum < from.RowNum) { from = loc; } else if ((loc.RowNum == from.RowNum) && (loc.ColNum < from.ColNum)) { from = loc; } if (loc.RowNum > to.RowNum) { to = loc; } else if ((loc.RowNum == to.RowNum) && (loc.ColNum > to.ColNum)) { to = loc; } } else if (this.RangeForm == RangeForm.Rectangular) { if (loc.RowNum < from.RowNum) { from = from.NewInstance(loc.RowNum, from.ColNum); } if (loc.ColNum < from.ColNum) { from = from.NewInstance(from.RowNum, loc.ColNum); } if (loc.RowNum > to.RowNum) { to = to.NewInstance(loc.RowNum, to.ColNum); } if (loc.ColNum > to.ColNum) { to = to.NewInstance(to.RowNum, loc.ColNum); } } return(new ScreenLocRange(from, to)); }
/// <summary> /// create a new RowCol from component parts. Either a ZeroRowCol or OneRowCol, /// depending on LocationFrame. /// </summary> /// <param name="frame"></param> /// <param name="RowNum"></param> /// <param name="ColNum"></param> /// <param name="Height"></param> /// <param name="Width"></param> /// <returns></returns> public static IScreenLoc Factory(LocationFrame frame, int RowNum, int ColNum) { IScreenLoc rc = null; if (frame == LocationFrame.OneBased) { rc = new OneScreenLoc(RowNum, ColNum); } else { rc = new ZeroScreenLoc(RowNum, ColNum); } return(rc); }
public static IScreenLoc ToScreenLoc(this XElement Elem, XNamespace Namespace) { IScreenLoc item = null; if (Elem != null) { int rowNum = Elem.Element(Namespace + "RowNum").IntOrDefault(0).Value; int colNum = Elem.Element(Namespace + "ColNum").IntOrDefault(0).Value; var frame = Elem.Element(Namespace + "Frame").StringOrDefault("").TryParseLocationFrame(LocationFrame.ZeroBased).Value; item = ScreenLocBase.Factory(frame, rowNum, colNum); } return(item); }
/// <summary> /// compare rowCol to 2nd RowCol value. Return -1 if 1st RowCol is less than /// 2nd RowCol. 0 if equal. 1 if 1st RowCol > 2nd RowCol. /// </summary> /// <param name="RowCol1"></param> /// <param name="RowCol2"></param> /// <returns></returns> public static int CompareTo(this IScreenLoc RowCol1, IScreenLoc RowCol2) { if (RowCol1.RowNum < RowCol2.RowNum) { return(-1); } else if (RowCol1.RowNum > RowCol2.RowNum) { return(1); } else { return(RowCol1.ColNum.CompareTo(RowCol2.ColNum)); } }
public static bool Match(this IScreenSection section, ScreenContent Content, string DebugInfo) { bool isMatch = true; var header = section as ISectionHeader; var sectionDim = section.CalcDim(); IScreenLoc start = section.ScreenLoc; { start = start.NewInstance(start.RowNum, start.ColNum); } int repeatIx = 0; bool endOfRows = false; while (isMatch == true) { if ((repeatIx > 0) && (repeatIx >= section.RepeatCount)) { break; } repeatIx += 1; // section is a subfile. subfile row can be blank. If blank consider as // the end of rows of the subfile. So no need to match. bool rowIsBlank = false; if (section.PurposeCode == ScreenPurposeCode.ReportDetail) { if (Content.RowIsBlank(start.RowNum) == true) { rowIsBlank = true; } } // a blank row. no more rows to match. if (rowIsBlank == true) { endOfRows = true; } if (endOfRows == false) { isMatch = header.Match(start, Content, DebugInfo); } start.RowNum += 1; } return(isMatch); }
public ScreenLocRange(IScreenLoc From, IScreenLoc To, RangeForm rangeForm = RangeForm.Rectangular) { // make sure from preceeds to. if (To.CompareTo(From) < 0) { this.From = To; this.To = From; } else { this.From = From; this.To = To; } this.RangeForm = rangeForm; }
public static ContentItemBase GetContentItem(this ScreenContent Content, IScreenLoc loc) { ContentItemBase foundItem = null; foreach (var contentItem in Content.ContentItems()) { var itemLoc = contentItem.RowCol as IScreenLoc; var range = new ScreenLocRange( itemLoc, contentItem.GetItemLength(Content), Content.ScreenDim); if (range.Contains(loc)) { foundItem = contentItem; break; } } return(foundItem); }
public static ScreenItemInstance FindItem( this ISectionHeader section, IScreenLoc Start, IScreenLoc FindLoc, ScreenContent Content) { ScreenItemInstance findItem = null; // find the screenitem located at the find location. foreach (var item in section.Items) { findItem = item.FindItem(Start, FindLoc, Content); if (findItem != null) { break; } } return(findItem); }
public static IScreenLoc Advance(this IScreenLoc Loc, int Length, ScreenDim Dim) { int col = Loc.ColNum + Length; int row = Loc.RowNum; // adjust to zero based. if (Loc.LocationFrame == LocationFrame.OneBased) { col -= 1; row -= 1; } // negative advance and column off the charts to the left. while (col < 0) { col += Dim.Width; row -= 1; if (row < 0) { row = Dim.Height - 1; } } // positive advance and column out of bounds to the right. while (col >= Dim.Width) { col -= Dim.Width; row += 1; if (row >= Dim.Height) { row = Dim.Height - 1; } } // back to one based. if (Loc.LocationFrame == LocationFrame.OneBased) { col += 1; row += 1; } return(Loc.NewInstance(row, col)); }
public static ScreenAtomic FindFieldItem( this IEnumerable <ScreenAtomic> List, IScreenLoc ScreenLoc, int Length) { ScreenAtomic found = null; var dim = new ScreenDim(24, 80); var range = new ScreenLocRange(ScreenLoc, Length, dim); foreach (var item in List) { if (item.ItemType == ShowItemType.Field) { if (item.ScreenLocRange.CompletelyContains(range) == true) { found = item; break; } } } return(found); }
public static bool CompareEqual(this IScreenLoc RowCol1, IScreenLoc RowCol2) { if ((RowCol1 == null) && (RowCol2 == null)) { return(true); } else if ((RowCol1 == null) || (RowCol2 == null)) { return(false); } else if (RowCol1.RowNum != RowCol2.RowNum) { return(false); } else if (RowCol1.ColNum != RowCol2.ColNum) { return(false); } else { return(true); } }
public static DataItemReport CaptureToReport( this ISectionHeader section, IScreenLoc Start, ScreenContent Content) { var report = new DataItemReport(); var row = new DataItemList(); // capture item data from each item of the section that is marked for capture. // ( by default, all ScreenField items are captured. ) foreach (var item in section.Items) { var rv = item.CaptureReport(Start, Content); var dataItem = rv.Item1; var itemReport = rv.Item2; if (dataItem != null) { report.Columns.Add(dataItem.ToColumnDefn()); row.Add(dataItem); } // this item is a section. The capture function returned a DataItemReport // contains the data of the report. Join that report with what has been // captured up to this point. if (itemReport != null) { var comboReport = DataItemReport.CombineHorizontally(report, itemReport); report = comboReport; } } if (row.Count > 0) { report.Rows.Add(row); } return(report); }
/// <summary> /// find the item within the screen section. /// </summary> /// <param name="section"></param> /// <param name="Start"></param> /// <param name="FindLoc"></param> /// <param name="Content"></param> /// <returns></returns> public static ScreenItemInstance FindItem( this IScreenSection section, IScreenLoc Start, IScreenLoc FindLoc, ScreenContent Content) { ScreenItemInstance foundItem = null; var header = section as ISectionHeader; var sectionDim = section.CalcDim(); var adjRow = Start.RowNum - 1; var adjCol = Start.ColNum - 1; var start = new OneScreenLoc( section.ScreenLoc.RowNum + adjRow, section.ScreenLoc.ColNum + adjCol); int repeatIx = 0; bool endOfRows = false; int loopCx = 0; while (foundItem == null) { if (section.PurposeCode != ScreenPurposeCode.ReportDetail) { if (loopCx > 0) { break; } } else { if (repeatIx >= section.GetRepeatCount()) { break; } repeatIx += 1; } loopCx += 1; // section is a subfile. subfile row can be blank. If blank consider as // the end of rows of the subfile. So no need to match. bool rowIsBlank = false; if (section.PurposeCode == ScreenPurposeCode.ReportDetail) { if (Content.RowIsBlank(start.RowNum) == true) { rowIsBlank = true; } } // a blank row. no more rows to match. if (rowIsBlank == true) { endOfRows = true; } if (endOfRows == false) { foundItem = header.FindItem(start, FindLoc, Content); if (foundItem != null) { foundItem.RepeatNum = repeatIx; break; } } start.RowNum += 1; } return(foundItem); }
/// <summary> /// return the value as text. Different from ToString in that ToString /// includes the class name. /// </summary> /// <param name="RowCol"></param> /// <returns></returns> public static string ToText(this IScreenLoc RowCol) { return(RowCol.RowNum + "/" + RowCol.ColNum); }
public ScreenItemInstance(IScreenItem item, IScreenLoc itemLoc) { this.Item = item; this.ItemLoc = itemLoc; this.RepeatNum = 0; }
public OneScreenLoc(IScreenLoc RowCol) : this(RowCol.RowNum, RowCol.ColNum) { }
public void Apply(IScreenLoc Value) { this.RowNum = Value.RowNum; this.ColNum = Value.ColNum; }
/// <summary> /// fill and make visible the hover window. /// Called by the DrawHoverBox method of ItemCanvas. /// </summary> /// <param name="Position"></param> /// <param name="CanvasRowCol"></param> /// <param name="MatchScreenDefn"></param> /// <param name="Content"></param> public void DrawHoverBox( Point Position, IScreenLoc CanvasRowCol, IScreenDefn MatchScreenDefn, ScreenContent Content) { // first remove any existing popup hover box. RemoveHoverBox(); // hovering on a screen with a screen defn. Find the item on the screen // which is being hovered over. string itemName = ""; string itemValue = ""; int itemRowNum = 0; ScreenItemInstance hoverItem = null; if ((MatchScreenDefn != null) && (CanvasRowCol != null)) { var foundItem = MatchScreenDefn.FindItem(CanvasRowCol, Content); if (foundItem != null) { hoverItem = foundItem; itemName = foundItem.GetItemName().EmptyIfNull(); itemValue = foundItem.GetValue(Content); itemRowNum = foundItem.RepeatNum; } } // capture the contents of the screen to a DataTable. EnhancedDataTable itemTable = null; Grid srcmbrGrid = null; object hoverData = null; string hoverXaml = null; string hoverCode = null; if ((MatchScreenDefn != null) && (hoverItem != null)) { itemTable = MatchScreenDefn.Capture(Content, hoverItem); { hoverXaml = FindHoverXaml(hoverItem.Item); hoverCode = FindHoverCode(hoverItem.Item); } if (hoverCode.IsNullOrEmpty( ) == false) { hoverData = CompileAndRunHoverCode(hoverCode, itemTable); } if ((MatchScreenDefn.ScreenName == "wrkmbrpdm") && (hoverData == null)) { // BgnTemp { if (itemTable.Rows.Count == 0) { var rep = Content.ToColumnReport("Content report"); rep.DebugPrint(); itemTable = MatchScreenDefn.Capture(Content, hoverItem); } } // EndTemp var srcmbr = itemTable.SelectedRow["MbrName"].ToString(); var srcfName = itemTable.SelectedRow["SrcfName"].ToString(); var srcfLib = itemTable.SelectedRow["SrcfLib"].ToString(); var sourceLines = SrcmbrScripts.GetSrcmbrLines(srcfName, srcfLib, srcmbr); hoverData = new { srcmbr, srcfName, srcfLib, sourceLines }; } } Grid grid = null; if (hoverData != null) { if (hoverXaml.IsNullOrEmpty( ) == false) { var sr = new StringReader(hoverXaml); var xr = XmlReader.Create(sr); var uiElem = XamlReader.Load(xr); grid = uiElem as Grid; grid.DataContext = hoverData; } else { var uiElem = hoverData.ToUIElement(); grid = uiElem as Grid; } } else { // create the controls that make up the hover control. ListBox lb = null; System.Windows.Controls.Canvas canvas = null; if (srcmbrGrid != null) { var rv = BuildSrcmbrHoverGrid(srcmbrGrid); grid = rv.Item1; } else { var rv = BuildFoundation(); grid = rv.Item1; lb = rv.Item2; canvas = rv.Item3; lb.Items.Add("field name:" + itemName); lb.Items.Add("RowCol:" + CanvasRowCol.ToText()); lb.Items.Add("Value:" + itemValue); lb.Items.Add("Row number:" + itemRowNum); } } ShowHoverBox(grid, Position); }
public static bool Match( this IScreenItem item, IScreenLoc Start, ScreenContent Content, string DebugInfo) { bool isMatch = true; ContentItemBase contentItem = null; // get the content item at the rowcol location. bool rc = true; IScreenAtomic atomicItem = null; // adjust screen loc of the item by start pos of the section it is contained in. var adjRow = Start.RowNum - 1; var adjCol = Start.ColNum - 1; var loc = new OneScreenLoc( item.ScreenLoc.RowNum + adjRow, item.ScreenLoc.ColNum + adjCol) ; var zeroLoc = loc.ToZeroRowCol(); // item is not a section. Get the field or literal located at the item loc. if (item.ItemType != ShowItemType.Section) { atomicItem = item as IScreenAtomic; } if ((rc == false) && ( 1 == 2)) { if ( item.IsOptional == false ) isMatch = false; } else if ((isMatch == true) && (item.ItemType == ShowItemType.Section)) { var sectionItem = item as IScreenSection; isMatch = sectionItem.Match(Content, DebugInfo); } else if ((isMatch == true) && (item.ItemType == ShowItemType.Field)) { var fieldItem = item as IScreenField; rc = Content.FieldDict.TryGetValue(zeroLoc, out contentItem); if (rc == false) isMatch = false; // can match a screen field to a literal, but only if the field is output // only. else if ((contentItem is ContentText) && (fieldItem.Usage != ShowUsage.Output)) isMatch = false; else if ((contentItem is ContentField) == false) isMatch = false; else { var contentField = contentItem as ContentField; if (contentField.LL_Length != atomicItem.Length) isMatch = false; } } // match screen literal to actual content on the screen. The content can be // either a field or a literal. But the content has to match one of the // values of the screen literal. else if ((isMatch == true) && (item.ItemType == ShowItemType.Literal)) { // screen literal has a dsply attr. advance .... if ( atomicItem.DsplyAttr.IsNullOrEmpty( ) == false ) { zeroLoc = zeroLoc.Advance(1) as ZeroRowCol; } var buf = Content.GetContentBytes_NonNull(zeroLoc, atomicItem.Length); var itemLit = item as IScreenLiteral; var contentText = buf.EbcdicBytesToString().TrimEndWhitespace(); // match the screen defn item to the screen content. isMatch = itemLit.MatchValue(contentText); // failed the match. But if the item content is blank. And this screen // item is optional then that is ok. if ((isMatch == false) && (item.IsOptional == true) && (contentText.Length == 0)) isMatch = true; } else if (isMatch == true) { throw new Exception("unrecognized screen item type"); } return isMatch; }
public ScreenLocRange(IScreenLoc RowCol, RangeForm RangeForm = RangeForm.Rectangular) { this.From = RowCol; this.To = RowCol; this.RangeForm = RangeForm; }