protected ColumnDisplay[] GetSizes(GenericScore genScore, string[][] labels) { ColumnDisplay[] cols = null; if (!this.AutoSize) { cols = ColumnDisplay.GetSizes(genScore.Sizes); } else { // evaluate max size foreach column // warning: all columns do not have the same number of columns Dictionary <int, int> coldic = new Dictionary <int, int>(); foreach (string[] row in labels) { if (row == null) { continue; } for (int i = 0; i < row.Length; i++) { string cell = row[i]; int length = String.IsNullOrEmpty(cell) ? 0 : cell.Length; if (coldic.ContainsKey(i)) { coldic[i] = Math.Max(coldic[i], length); } else { coldic[i] = length; } } } cols = new ColumnDisplay[coldic.Count]; foreach (int key in coldic.Keys) { cols[key] = new ColumnDisplay(coldic[key], ColumnDisplay.Alignment.Left); } } return(cols); }
internal override BaseScore Clone(string id) { GenericScore copy = new GenericScore(); copy.Id = id; if (String.IsNullOrEmpty(id)) { copy.Id = Tools.GenerateId(); } copy.Name = this.Name; copy.Url = this.Url; copy.XPath = this.XPath; copy.XPathRow = this.XPathRow; copy.XPathCol = this.XPathCol; copy.Headers = this.Headers; copy.Sizes = this.Sizes; copy.Skip = this.Skip; copy.MaxLines = this.MaxLines; copy.Image = this.Image; copy.Element = this.Element; copy.Encoding = this.Encoding; copy.ParseOptions = this.ParseOptions; copy.Parent = this.Parent; copy.LiveConfig = this.LiveConfig; copy.Dictionary = this.Dictionary; if (this.Rules != null && this.Rules.Length > 0) { copy.Rules = new Rule[this.Rules.Length]; for (int i = 0; i < this.Rules.Length; i++) { copy.Rules[i] = this.Rules[i].Clone(); } } if (this.Range != null) { copy.Range = this.Range.Clone(); } return((BaseScore)copy); }
/// <summary> /// Constructor. /// </summary> /// <param name="scores"></param> /// <param name="center"></param> public LiveCenter(IEnumerable <BaseScore> scores, ScoreCenter center) { m_scores = scores; #if DEBUG Rule r = new Rule(); r.Column = 2; r.Operator = Operation.EqualTo; r.Action = RuleAction.ReplaceText; r.Value = "b,zz"; GenericScore sc = m_scores.First() as GenericScore; sc.Rules = new Rule[1]; sc.Rules[0] = r; #endif m_center = center; this.WorkerReportsProgress = false; this.WorkerSupportsCancellation = true; this.SleepTimer = m_center.Setup.LiveCheckDelay * 60000; }
private string[][] EvaluateRules(BaseScore score, string[][] labels) { GenericScore genScore = score as GenericScore; if (genScore == null) { return(null); } RuleEvaluator engine = new RuleEvaluator(genScore.Rules); ParsingOptions opt = genScore.GetParseOption(); bool reverseOrder = Tools.CheckParsingOption(opt, ParsingOptions.Reverse); bool wordWrap = Tools.CheckParsingOption(opt, ParsingOptions.WordWrap); int lineNumber = -1; // for all the rows IList <string[]> controls = new List <string[]>(); int totalLines = labels.Count(p => p != null && p[0] != ScoreCenterPlugin.C_HEADER); foreach (string[] row_ in labels) { // ignore empty lines if (row_ == null || row_.Length == 0) { continue; } lineNumber++; bool isHeader = (row_[0] == ScoreCenterPlugin.C_HEADER); string[] row = isHeader ? row_.Where(c => c != ScoreCenterPlugin.C_HEADER).ToArray() : row_; // Evaluate rule for full line if (!isHeader) { Rule rule = engine.CheckLine(row, lineNumber, totalLines); if (rule != null) { // skip lines and continue if (rule.Action == RuleAction.SkipLine) { continue; } } } #region For all columns for (int index = 0; index < row.Length; index++) { int colIndex = reverseOrder ? row.Length - index - 1 : index; // get cell string cell = row[colIndex]; #region Evaluate rule for the cell if (!isHeader) { IList <Rule> cellRules = engine.CheckCell(cell, colIndex); foreach (var cellRule in cellRules) { cell = RuleProcessor.Process(cell, cellRule); } } #endregion row[colIndex] = cell; } #endregion // create the control controls.Add(row); } return(controls.ToArray()); }
public override IList <T> Build(BaseScore score, string[][] labels, int startLine, int startColumn, int startX, int startY, int pnlWidth, int pnlHeight, CreateControlDelegate <T> createControl, out bool overRight, out bool overDown, out int lineNumber, out int colNumber) { lineNumber = -1; colNumber = -1; overRight = false; overDown = false; //Tools.LogMessage("X = {0}, Y = {1}, W = {2}, H = {3}", startX, startY, pnlWidth, pnlHeight); GenericScore genScore = score as GenericScore; if (genScore == null) { return(null); } int maxX = startX + pnlWidth; int maxY = startY + pnlHeight; int posX = startX; int posY = startY; int maxColumnSize = pnlWidth / m_charWidth; // Get Columns Sizes ColumnDisplay[] cols = GetSizes(genScore, labels); RuleEvaluator engine = new RuleEvaluator(genScore.Rules); ParsingOptions opt = genScore.GetParseOption(); bool reverseOrder = Tools.CheckParsingOption(opt, ParsingOptions.Reverse); bool wordWrap = Tools.CheckParsingOption(opt, ParsingOptions.WordWrap); // for all the rows IList <T> controls = new List <T>(); int totalLines = labels.Count(p => p != null && p[0] != ScoreCenterPlugin.C_HEADER); foreach (string[] row_ in labels) { // ignore empty lines if (row_ == null || row_.Length == 0) { continue; } lineNumber++; // ignore lines on previous page if (lineNumber < startLine) { continue; } // calculate X position posX = startX;// -startColumn; // ignore if outside and break to next row if (LimitToPage && posY > maxY) { overDown = true; break; } bool isHeader = (row_[0] == ScoreCenterPlugin.C_HEADER); string[] row = isHeader ? row_.Where(c => c != ScoreCenterPlugin.C_HEADER).ToArray() : row_; #region Evaluate rule for full line //bool isHeader = !String.IsNullOrEmpty(this.Score.Headers) && lineNumber == 0; Style lineStyle = (lineNumber % 2 == 0) ? m_defaultStyle : m_altStyle; bool merge = false; if (!isHeader) { Rule rule = engine.CheckLine(row, lineNumber, totalLines); if (rule != null) { // skip lines and continue if (rule.Action == RuleAction.SkipLine) { continue; } merge = rule.Action == RuleAction.MergeCells; lineStyle = FindStyle(rule.Format) ?? lineStyle; } } #endregion #region For all columns int nbLines = 1; int nbControls = 0; for (int index = startColumn; index < row.Length; index++) { int colIndex = reverseOrder ? row.Length - index - 1 : index; // get cell string cell = row[colIndex]; ColumnDisplay colSize = GetColumnSize(colIndex, cols, cell, merge); if (colSize.Size == 0) { continue; } // ignore controls outside area if (LimitToPage && posX > maxX) { overRight = true; continue; } // evaluate size of the control in pixel int maxChar = Math.Min(colSize.Size + 1, maxColumnSize); // wrap needed? if (wordWrap || AutoWrap) { int i = maxChar + 1; while (i < cell.Length) { cell = cell.Insert(i, Environment.NewLine); i += maxChar + 1; } } // count new lines int nb = Tools.CountLines(cell); nbLines = Math.Max(nbLines, nb); int length = m_charWidth * maxChar; int height = m_charHeight * nbLines; if (posX < startX) { // cell was on previous page // increase posX so that we can get to current page posX += length; continue; } #region Evaluate rule for the cell Style cellStyle = lineStyle; if (!isHeader) { IList <Rule> cellRules = engine.CheckCell(cell, colIndex); foreach (var cellRule in cellRules) { cell = RuleProcessor.Process(cell, cellRule); if (cellRule != null && cellRule.Action == RuleAction.FormatCell) { cellStyle = FindStyle(cellRule.Format) ?? lineStyle; } } } #endregion // create the control string[] aa = cell.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < aa.Length; i++) { T control = createControl(posX, posY + (i * m_charHeight), length, m_charHeight, colSize.Alignement, aa[i], m_fontName, m_fontSize, cellStyle, maxChar, colIndex); if (control != null) { controls.Add(control); nbControls++; } } // set X pos to the end of the control posX += Math.Min(length, pnlWidth - 1); } #endregion // set Y pos to the bottom of the control if (nbControls > 0 || isHeader) { posY += m_charHeight * nbLines; } } Tools.LogMessage("{0}: {1} controls created", score.Id, controls.Count); return(controls); }