Esempio n. 1
0
        /// <summary>
        /// Serializes to an existing byte array without serialization listener.
        /// This is done by delegating to Serialize(int, byte[], EscherSerializationListener).
        /// </summary>
        /// <param name="offset">the offset within the data byte array.</param>
        /// <param name="data"> the data array to Serialize to.</param>
        /// <param name="listener">a listener for begin and end serialization events.</param>
        /// <returns>The number of bytes written.</returns>
        public override int Serialize(int offset, byte[] data, EscherSerializationListener listener)
        {
            listener.BeforeRecordSerialize(offset, RecordId, this);

            LittleEndian.PutShort(data, offset, Options);
            LittleEndian.PutShort(data, offset + 2, RecordId);
            int remainingBytes = 0;

            for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext();)
            {
                EscherRecord r = (EscherRecord)iterator.Current;
                remainingBytes += r.RecordSize;
            }

            remainingBytes += _remainingLength;

            LittleEndian.PutInt(data, offset + 4, remainingBytes);
            int pos = offset + 8;

            for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext();)
            {
                EscherRecord r = (EscherRecord)iterator.Current;
                pos += r.Serialize(pos, data, listener);
            }

            listener.AfterRecordSerialize(pos, RecordId, pos - offset, this);
            return(pos - offset);
        }
Esempio n. 2
0
 /// <summary>
 /// Do any of our (top level) children have the
 /// given recordId?
 /// </summary>
 /// <param name="recordId">The record id.</param>
 /// <returns>
 ///     <c>true</c> if [has child of type] [the specified record id]; otherwise, <c>false</c>.
 /// </returns>
 public bool HasChildOfType(short recordId)
 {
     for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext();)
     {
         EscherRecord r = (EscherRecord)iterator.Current;
         if (r.RecordId == recordId)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
 /// <summary>
 /// Recursively find records with the specified record ID
 /// </summary>
 /// <param name="recordId"></param>
 /// <param name="out1">list to store found records</param>
 public void GetRecordsById(short recordId, ref ArrayList out1)
 {
     for (IEnumerator it = ChildRecords.GetEnumerator(); it.MoveNext();)
     {
         Object       er = it.Current;
         EscherRecord r  = (EscherRecord)er;
         if (r is EscherContainerRecord)
         {
             EscherContainerRecord c = (EscherContainerRecord)r;
             c.GetRecordsById(recordId, ref out1);
         }
         else if (r.RecordId == recordId)
         {
             out1.Add(er);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            String nl = Environment.NewLine;

            StringBuilder children = new StringBuilder();

            if (ChildRecords.Count > 0)
            {
                children.Append("  children: " + nl);

                int count = 0;
                for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext();)
                {
                    EscherRecord record = (EscherRecord)iterator.Current;
                    children.Append("    Child " + count + ":" + nl);

                    String childResult = (record).ToString();
                    childResult = childResult.Replace("\n", "\n    ");
                    children.Append("    ");
                    children.Append(childResult);
                    children.Append(nl);

                    //if (record is EscherContainerRecord)
                    //{
                    //    EscherContainerRecord ecr = (EscherContainerRecord)record;
                    //    children.Append(ecr.ToString());
                    //}
                    //else
                    //{
                    //    children.Append(record.ToString());
                    //}
                    count++;
                }
            }

            return
                (this.GetType().Name + " (" + RecordName + "):" + nl +
                 "  isContainer: " + IsContainerRecord + nl +
                 "  version: 0x" + HexDump.ToHex(Version) + nl +
                 "  instance: 0x" + HexDump.ToHex(Instance) + nl +
                 "  recordId: 0x" + HexDump.ToHex(RecordId) + nl +
                 "  numchildren: " + ChildRecords.Count + nl +
                 children.ToString());
        }
Esempio n. 5
0
        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override String ToString()
        {
            String nl = Environment.NewLine;

            StringBuilder children = new StringBuilder();

            if (ChildRecords.Count > 0)
            {
                children.Append("  children: " + nl);
                for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext();)
                {
                    EscherRecord record = (EscherRecord)iterator.Current;
                    children.Append(record.ToString());
                    children.Append(nl);
                }
            }

            String theDumpHex = "";

            try
            {
                if (_thedata.Length != 0)
                {
                    theDumpHex  = "  Extra Data(" + _thedata.Length + "):" + nl;
                    theDumpHex += HexDump.Dump(_thedata, 0, 0);
                }
            }
            catch (Exception)
            {
                theDumpHex = "Error!!";
            }

            return(this.GetType().Name + ":" + nl +
                   "  isContainer: " + IsContainerRecord + nl +
                   "  version: 0x" + HexDump.ToHex(Version) + nl +
                   "  instance: 0x" + HexDump.ToHex(Instance) + nl +
                   "  recordId: 0x" + HexDump.ToHex(RecordId) + nl +
                   "  numchildren: " + ChildRecords.Count + nl +
                   theDumpHex +
                   children.ToString());
        }
Esempio n. 6
0
        /// <summary>
        /// Toes the string.
        /// </summary>
        /// <param name="indent">The indent.</param>
        /// <returns></returns>
        public String ToString(String indent)
        {
            String nl = Environment.NewLine;

            StringBuilder children = new StringBuilder();

            if (ChildRecords.Count > 0)
            {
                children.Append("  children: " + nl);

                int count = 0;
                for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext();)
                {
                    String newIndent = indent + "   ";

                    EscherRecord record = (EscherRecord)iterator.Current;
                    children.Append(newIndent + "Child " + count + ":" + nl);

                    if (record is EscherContainerRecord)
                    {
                        EscherContainerRecord ecr = (EscherContainerRecord)record;
                        children.Append(ecr.ToString(newIndent));
                    }
                    else
                    {
                        children.Append(record.ToString());
                    }
                    count++;
                }
            }

            return
                (indent + this.GetType().Name + " (" + RecordName + "):" + nl +
                 indent + "  isContainer: " + IsContainerRecord + nl +
                 indent + "  options: 0x" + HexDump.ToHex(Options) + nl +
                 indent + "  recordId: 0x" + HexDump.ToHex(RecordId) + nl +
                 indent + "  numchildren: " + ChildRecords.Count + nl +
                 indent + children.ToString());
        }
        internal override int Serialize(BinaryWriter dataWriter)
        {
            dataWriter.Write(getOptions());
            dataWriter.Write(GetRecordId());
            int         num        = 0;
            IEnumerator enumerator = ChildRecords.GetEnumerator();

            while (enumerator.MoveNext())
            {
                EscherRecord escherRecord = (EscherRecord)enumerator.Current;
                num += escherRecord.RecordSize;
            }
            dataWriter.Write(num);
            int         num2        = 8;
            IEnumerator enumerator2 = ChildRecords.GetEnumerator();

            while (enumerator2.MoveNext())
            {
                EscherRecord escherRecord2 = (EscherRecord)enumerator2.Current;
                num2 += escherRecord2.Serialize(dataWriter);
            }
            return(num2);
        }