/// <summary> /// Return conents of Memory Mapped locaton as bytes[] /// </summary> /// <param name="mmLocation"></param> /// <returns></returns> public static byte[] MMRecordContentBytes(String mmLocation) { byte[] mmrResourceBytes = new byte[0] { }; if (mmfRepo.ContainsKey(mmLocation)) { MMRecord mmr = mmfRepo[mmLocation]; using (MemoryMappedViewStream mmfstr = mmr.ResourceMMFile.CreateViewStream()) { BinaryReader mmfreader = new BinaryReader(mmfstr); mmrResourceBytes = mmfreader.ReadBytes((int)mmr.ResourceSize); } } else { Console.WriteLine("Unable to find {0}. Valid value?", mmLocation); } return(mmrResourceBytes); }
/// <summary> /// Dumps Meta and contents of the Memory record /// </summary> /// <param name="mmLocation"></param> public static void DumpMMRecord(String mmLocation) { if (mmfRepo.ContainsKey(mmLocation)) { MMRecord mmr = mmfRepo[mmLocation]; Console.WriteLine("Location: {0}", mmLocation); Console.WriteLine("Type : {0}", mmr.ResourceType); Console.WriteLine("Size : {0}", mmr.ResourceSize); Console.WriteLine("Content : "); using (MemoryMappedViewStream mmstream = mmr.ResourceMMFile.CreateViewStream()) { mmstream.Seek(0, SeekOrigin.Begin); BinaryReader mmfreader = new BinaryReader(mmstream); byte[] mmrResourceBytes = mmfreader.ReadBytes((int)mmr.ResourceSize); //Console.WriteLine("MMRecord bytes: {0}", Encoding.Default.GetString(mmrResourceBytes)); Console.WriteLine("MMRecord bytes: {0}", Encoding.UTF8.GetString(mmrResourceBytes)); } } else { Console.WriteLine("Unable to dump {0}. Valid value?", mmLocation); } }