protected override void OnGetCellData(Row row, Column column, CellData cellData) { base.OnGetCellData(row, column, cellData); IResultAttribute attribute = row.Item as IResultAttribute; if (attribute != null && column.DataField != null) { if (column == columnName) { cellData.Value = attribute.Name; } else if (column == columnValue) { cellData.Value = attribute.ValueAsString; } // Display attributes that have no corresponding column as grayed out if (!Result.Detectors.First().ColumnInHeader(Result.Name, attribute.Name)) { cellData.EvenStyle = new Style(cellData.EvenStyle, GrayedOutStyleDelta); cellData.OddStyle = new Style(cellData.OddStyle, GrayedOutStyleDelta); } } }
/// <summary> /// Adds the given <paramref name="attribute"/> to the <c>Result</c>. /// </summary> /// <param name="attribute">the attribute to add</param> public void AddAttribute(IResultAttribute attribute) { // TODO: if past end-of-input, do not add attribute, invalidate result Result.Attributes.Add(attribute); if (!attribute.Valid) { Result.Valid = false; } }
/// <summary> /// Trims the zero byte stuffing from the end of the header. /// This removes the zero byte stuffing from the data packet /// and removes the corresponding attribute. /// </summary> /// <param name="parser">the parser</param> public void TrimZeroByteStuffing(Mpeg4Parser parser) { if (ZeroByteStuffing > 0) { IResultAttribute zeroByteStuffingAttribute = FindAttributeByName(Enum.GetName(typeof(Attribute), Attribute.ZeroByteStuffing)); Debug.Assert(Attributes.Count > 0 && zeroByteStuffingAttribute != null); // Trim the zero byte stuffing DataPacket = parser.GetDataPacket(Offset, Length - ZeroByteStuffing); this.ZeroByteStuffing = 0; // Removes the corresponding attribute Attributes.Remove(zeroByteStuffingAttribute); } }
/// <summary> /// Returns whether any of the <paramref name="selectedRows"/> has /// an accompanying column. /// </summary> /// <param name="selectedRows">the selected rows</param> /// <returns><c>true</c> if any row has an accompanying column, <c>false</c> otherwise</returns> private bool HasAccompanyingColumn(RowSelectionList selectedRows) { if (!HasSelectedRows) { return(false); } foreach (Row row in selectedRows) { IResultAttribute resultAttribute = row.Item as IResultAttribute; if (resultAttribute != null && Result.Detectors.First().ColumnInHeader(Result.Name, resultAttribute.Name)) { return(true); } } return(false); }
/// <summary> /// Checks the attribute specified by <paramref name="attributeName"/> /// and invalidates the attribute if the specified <param name="condition"/> /// is <code>false</code>. /// Also invalidates the <c>Result</c> currently being parsed and containing /// the attribute if <param name="invalidateResult"/> is <code>true</code>. /// </summary> /// <remarks> /// The type of <typeref name="T"/> should be an enum. /// </remarks> /// <typeparam name="T">the attribute enumeration type</typeparam> /// <param name="attributeName">the name of the attribute to check</param> /// <param name="condition">the condition</param> /// <param name="invalidateResult">invalidates the <c>Result</c> if true (default)</param> /// <returns>condition</returns> public bool CheckAttribute <T>(T attributeName, bool condition, bool invalidateResult) { if (!condition) { string name = Enum.GetName(typeof(T), attributeName); IResultAttribute attribute = Result.FindAttributeByName(name); if (attribute == null) { throw new ArgumentException("No such attribute.", "attributeName"); } attribute.Valid = false; if (invalidateResult) { Result.Valid = false; } } return(condition); }
public void AddAttribute(IResultAttribute attribute) { _attributes.Add(attribute); }
protected override void OnGetCellData(Row row, Column column, CellData cellData) { base.OnGetCellData(row, column, cellData); if (column.Name == null) { return; } IResultNode result = row.Item as IResultNode; if (result == null) { return; } DefaultColumnIndex index; if (DefaultColumnExtensions.TryParse(column.Name, out index)) { switch (index) { case DefaultColumnIndex.Name: cellData.Value = result.Name; if (result.InputFile is IReferenceHeaderFile) { cellData.EvenStyle = new Style(cellData.EvenStyle) { ForeColor = Color.RoyalBlue, Font = new Font(cellData.EvenStyle.Font.FontFamily, cellData.EvenStyle.Font.SizeInPoints, FontStyle.Bold) }; cellData.OddStyle = new Style(cellData.OddStyle) { ForeColor = Color.RoyalBlue, Font = new Font(cellData.OddStyle.Font.FontFamily, cellData.OddStyle.Font.SizeInPoints, FontStyle.Bold) }; } break; case DefaultColumnIndex.Detector: cellData.Value = result.Detectors.First().Name; break; case DefaultColumnIndex.DetectorVersion: cellData.Value = _detectorFormatter.FormatVersion(result.Detectors.First()); break; case DefaultColumnIndex.Offset: cellData.Value = result.StartOffset; if (DisplayMode == DisplayMode.Hex) { cellData.Format = "{0:X}"; } break; case DefaultColumnIndex.Length: cellData.Value = result.Length; if (DisplayMode == DisplayMode.Hex) { cellData.Format = "{0:X}"; } break; case DefaultColumnIndex.EndOffset: cellData.Value = result.EndOffset; if (DisplayMode == DisplayMode.Hex) { cellData.Format = "{0:X}"; } break; case DefaultColumnIndex.File: IInputFile inputFile = result.InputFile; if (inputFile != null) { cellData.Value = (new FileInfo(inputFile.Name)).Name; cellData.ToolTip = inputFile.Name; cellData.AlwaysDisplayToolTip = true; } break; } } else { IResultAttribute attribute = result.FindAttributeByName(column.Name); if (attribute == null) { cellData.Value = string.Empty; } else { cellData.Value = attribute.ValueAsString; // Align the cell content depending its value. if ((attribute.Value.GetType() == typeof(string)) || (attribute.Value.GetType() == typeof(bool))) { cellData.EvenStyle = new Style(cellData.EvenStyle, _horzAlignmentNearStyleDelta); cellData.OddStyle = new Style(cellData.OddStyle, _horzAlignmentNearStyleDelta); } else { cellData.EvenStyle = new Style(cellData.EvenStyle, _horzAlignmentFarStyleDelta); cellData.OddStyle = new Style(cellData.OddStyle, _horzAlignmentFarStyleDelta); } } } }
public ResultAttributeVerification(IResultAttribute attribute, string description) { _attribute = attribute; _description = description; }
public void Attribute(IResultAttribute attribute) { AddLine(attribute.Name + ":" + attribute.ValueAsString); }
/// <summary> /// Compares results on the values of an attribute. /// </summary> /// <param name="x">the first result to compare</param> /// <param name="y">the second result to compare</param> /// <param name="attributeName">the name of the attribute to compare</param> private static int CompareResultsByAttributeValue(IResultNode x, IResultNode y, string attributeName) { if (x == y) { return(0); } IResultAttribute attributeX = x.FindAttributeByName(attributeName); IResultAttribute attributeY = y.FindAttributeByName(attributeName); if (attributeX == attributeY) { return(0); } if (attributeX == null || attributeY == null) { return((attributeX == null) ? -1 : 1); } // Compare by object value if appropriate types object valueX = attributeX.Value; object valueY = attributeY.Value; if (valueX is byte && valueY is byte) { return(((byte)valueX).CompareTo((byte)valueY)); } else if (valueX is short && valueY is short) { return(((short)valueX).CompareTo((short)valueY)); } else if (valueX is ushort && valueY is ushort) { return(((ushort)valueX).CompareTo((ushort)valueY)); } else if (valueX is int && valueY is int) { return(((int)valueX).CompareTo((int)valueY)); } else if (valueX is uint && valueY is uint) { return(((uint)valueX).CompareTo((uint)valueY)); } else if (valueX is long && valueY is long) { return(((long)valueX).CompareTo((long)valueY)); } else if (valueX is ulong && valueY is ulong) { return(((ulong)valueX).CompareTo((ulong)valueY)); } else if (valueX is bool && valueY is bool) { return(((bool)valueX).CompareTo((bool)valueY)); } else if (valueX is float && valueY is float) { return(((float)valueX).CompareTo((float)valueY)); } else if (valueX is double && valueY is double) { return(((double)valueX).CompareTo((double)valueY)); } else if (valueX is decimal && valueY is decimal) { return(((decimal)valueX).CompareTo((decimal)valueY)); } // Compare by string value string stringX = attributeX.ValueAsString; string stringY = attributeY.ValueAsString; if (stringX == stringY) { return(0); } else if (stringX == null || stringY == null) { return((stringX == null) ? -1 : 1); } else { return(stringX.CompareTo(stringY)); } }