public MockResult(IResultNode parent, IDataReader dataReader, long offset, long length, string name)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (length <= 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            _name       = name;
            _attributes = new List <IResultAttribute>();
            _dataPacket = dataReader.GetDataPacket(offset, length);
            _detector   = parent.Detectors.First();
            Offset      = offset;

            parent.AddChild(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds one or more <paramref name="results"/> in the location
        /// specified by <paramref name="row"/> and <paramref name="dropLocation"/>
        /// of this tree.
        /// </summary>
        /// <param name="row">the target row</param>
        /// <param name="dropLocation">the relative drop location</param>
        /// <param name="results">the dropped results</param>
        public void AddResults(Row row, RowDropLocation dropLocation, IResultNode[] results)
        {
            if (!IsWorkpad || row == null || results == null || results.Length == 0)
            {
                return;
            }

            int childIndex;

            // Determine child index (where to Add or Insert)
            if (dropLocation == RowDropLocation.AboveRow || dropLocation == RowDropLocation.BelowRow)
            {
                childIndex = row.ChildIndex;

                if (dropLocation == RowDropLocation.BelowRow)
                {
                    childIndex++;
                }

                row = row.ParentRow;
            }
            else
            {
                childIndex = row.NumChildren;
            }

            IResultNode rowResult = row.Item as IResultNode;

            if (rowResult != null)
            {
                // Copy/Move drop results to their new location
                foreach (IResultNode r in results)
                {
                    IResultNode result = r;

                    // Copy from old location
                    if (result.Parent != null)
                    {
                        result = result.DeepCopy();
                    }

                    // Add/Insert at new location
                    if (childIndex >= rowResult.Children.Count)
                    {
                        rowResult.AddChild(result);
                    }
                    else
                    {
                        rowResult.InsertChild(childIndex, result);
                    }

                    childIndex++;
                }
            }

            row.UpdateChildren(false, true);
        }
        /// <summary>
        /// Creates a deep copy of <paramref name="result"/> and its children.
        /// </summary>
        /// <param name="result">the result to copy</param>
        /// <return>the deep copy</return>
        public static IResultNode DeepCopy(this IResultNode result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            IResultNode resultCopy = result.ShallowCopy();

            // Create copies of children
            foreach (IResultNode childResult in result.Children)
            {
                resultCopy.AddChild(childResult.DeepCopy());
            }
            return(resultCopy);
        }
        private long TrimResult()
        {
            if (_lastHeader == null)
            {
                return(0L);
            }

            // Trim zero byte stuffing from last header (if any)
            string zeroByteStuffingName      = Enum.GetName(typeof(NalUnitParser.Attribute), NalUnitParser.Attribute.TrailingZeroBytes);
            var    zeroByteStuffingAttribute = _lastHeader.FindAttributeByName(zeroByteStuffingName);

            if (zeroByteStuffingAttribute == null)
            {
                return(0L);
            }

            uint byteCount = (uint)zeroByteStuffingAttribute.Value;

            // Rebuild the last header, omitting the zero byte stuffing attribute
            var resultNodeBuilder = new ResultNodeBuilder
            {
                Name       = _lastHeader.Name,
                Metadata   = _lastHeader,
                DataPacket = _lastHeader.GetSubPacket(0, (_lastHeader.Length - byteCount))
            };

            foreach (IResultAttribute attribute in _lastHeader.Attributes.Where(a => a.Name != zeroByteStuffingName))
            {
                resultNodeBuilder.AddAttribute(attribute);
            }

            // Replace the last header with the new (trimmed) header
            IResultNode parent = _lastHeader.Parent;

            parent.RemoveChild(_lastHeader);
            parent.AddChild(resultNodeBuilder.Build());

            // Compensate end offset for zero byte trimming
            return(-byteCount);
        }