コード例 #1
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);
         }
     }
 }
コード例 #2
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());
        }
コード例 #3
0
        /// <summary>
        /// Generates an escher record including the any children contained under that record.
        /// An exception is thrown if the record could not be generated.
        /// </summary>
        /// <param name="data">The byte array containing the records</param>
        /// <param name="offset">The starting offset into the byte array</param>
        /// <returns>The generated escher record</returns>
        public virtual EscherRecord CreateRecord(byte[] data, int offset)
        {
            EscherRecord.EscherRecordHeader header = EscherRecord.EscherRecordHeader.ReadHeader(data, offset);

            // Options of 0x000F means container record
            // However, EscherTextboxRecord are containers of records for the
            //  host application, not of other Escher records, so treat them
            //  differently
            if ((header.Options & (short)0x000F) == (short)0x000F &&
                header.RecordId != EscherTextboxRecord.RECORD_ID)
            {
                EscherContainerRecord r = new EscherContainerRecord();
                r.RecordId = header.RecordId;
                r.Options  = header.Options;
                return(r);
            }
            if (header.RecordId >= EscherBlipRecord.RECORD_ID_START && header.RecordId <= EscherBlipRecord.RECORD_ID_END)
            {
                EscherBlipRecord r;
                if (header.RecordId == EscherBitmapBlip.RECORD_ID_DIB ||
                    header.RecordId == EscherBitmapBlip.RECORD_ID_JPEG ||
                    header.RecordId == EscherBitmapBlip.RECORD_ID_PNG)
                {
                    r = new EscherBitmapBlip();
                }
                else if (header.RecordId == EscherMetafileBlip.RECORD_ID_EMF ||
                         header.RecordId == EscherMetafileBlip.RECORD_ID_WMF ||
                         header.RecordId == EscherMetafileBlip.RECORD_ID_PICT)
                {
                    r = new EscherMetafileBlip();
                }
                else
                {
                    r = new EscherBlipRecord();
                }
                r.RecordId = header.RecordId;
                r.Options  = header.Options;
                return(r);
            }

            //ConstructorInfo recordConstructor = (ConstructorInfo) recordsMap[header.RecordId];
            ConstructorInfo recordConstructor = null;

            if (recordsMap.ContainsKey(header.RecordId))
            {
                recordConstructor = recordsMap[header.RecordId];
            }

            EscherRecord escherRecord = null;

            if (recordConstructor == null)
            {
                return(new UnknownEscherRecord());
            }

            try
            {
                escherRecord = (EscherRecord)recordConstructor.Invoke(new object[] { });
                //escherRecord = (EscherRecord)Activator.CreateInstance(recordConstructor);
            }
            catch (Exception)
            {
                return(new UnknownEscherRecord());
            }
            escherRecord.RecordId = header.RecordId;
            escherRecord.Options  = header.Options;
            return(escherRecord);
        }