public static MemoryStream ReadAsMemoryStream(string filePath) { try { byte[] buffer = ReadAsArray(filePath); if (buffer == null) { LogSystem.Error("Err ReadFileAsMemoryStream failed:{0}\n", filePath); return(null); } return(new MemoryStream(buffer)); } catch (Exception e) { LogSystem.Error("Exception:{0}\n", e.Message); Helper.LogCallStack(); return(null); } }
public static byte[] ReadAsArray(string filePath) { byte[] buffer = null; try { if (OnReadAsArray != null) { buffer = OnReadAsArray(filePath); } else { LogSystem.Error("ReadFileByEngine handler have not register: {0}", filePath); } } catch (Exception e) { LogSystem.Error("Exception:{0}\n", e.Message); Helper.LogCallStack(); return(null); } return(buffer); }
public bool LoadFromBinary(string file) { long t1 = TimeUtility.GetElapsedTimeUs(); bool result = true; BinaryTable table = new BinaryTable(); table.Load(HomePath.GetAbsolutePath(file)); long t2 = TimeUtility.GetElapsedTimeUs(); long t3 = TimeUtility.GetElapsedTimeUs(); for (int index = 0; index < table.Records.Count; ++index) { try { TData data = new TData(); bool ret = data.ReadFromBinary(table, index); if (ret && !m_DataContainer.ContainsKey(data.GetId())) { m_DataContainer.Add(data.GetId(), data); } else { string info = string.Format("DataTempalteMgr.CollectDataFromBinary collectData Row:{0} failed in {1}!", index, file); LogSystem.Error(info); Helper.LogCallStack(true); result = false; } } catch (System.Exception ex) { LogSystem.Error("CollectData failed. file:{0} rowIndex:{1}\nException:{2}\n{3}", file, index, ex.Message, ex.StackTrace); } } long t4 = TimeUtility.GetElapsedTimeUs(); LogSystem.Info("binary load {0} parse {1}, file {2}", t2 - t1, t4 - t3, file); return(result); }