/// <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 List <object> 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);
         }
     }
 }
Example #2
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)
        {
            short options  = LittleEndian.GetShort(data, offset);
            short recordId = LittleEndian.GetShort(data, offset + 2);

            // int remainingBytes = LittleEndian.getInt( data, offset + 4 );
            // 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 (IsContainer(options, recordId))
            {
                EscherContainerRecord r = new EscherContainerRecord();
                r.RecordId = recordId;
                r.Options  = options;
                return(r);
            }
            if (recordId >= EscherBlipRecord.RECORD_ID_START && recordId <= EscherBlipRecord.RECORD_ID_END)
            {
                EscherBlipRecord r;
                if (recordId == EscherBitmapBlip.RECORD_ID_DIB ||
                    recordId == EscherBitmapBlip.RECORD_ID_JPEG ||
                    recordId == EscherBitmapBlip.RECORD_ID_PNG)
                {
                    r = new EscherBitmapBlip();
                }
                else if (recordId == EscherMetafileBlip.RECORD_ID_EMF ||
                         recordId == EscherMetafileBlip.RECORD_ID_WMF ||
                         recordId == EscherMetafileBlip.RECORD_ID_PICT)
                {
                    r = new EscherMetafileBlip();
                }
                else
                {
                    r = new EscherBlipRecord();
                }
                r.RecordId = recordId;
                r.Options  = options;
                return(r);
            }

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

            if (recordsMap.ContainsKey(recordId))
            {
                recordConstructor = recordsMap[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 = recordId;
            escherRecord.Options  = options;
            return(escherRecord);
        }