string PrepareContentFilePath(DemoBinaryContent content) { string demoDataPath = GetDemoDataPath(); if (!Directory.Exists(demoDataPath)) Directory.CreateDirectory(demoDataPath); string fileName = GetBinaryContentFileName(content); return Path.Combine(demoDataPath, fileName); }
string GetBinaryContentFileName(DemoBinaryContent content) { return content.Id.ToString() + ".tmp"; }
DemoBinaryContent CreateInitialBinaryContent(long id, byte[] data) { DemoBinaryContent content = new DemoBinaryContent(this); content.Id = id; if (data != null) content.Data = data; BinaryContentCache.Add(id, content); if (MaxBinaryContentId < id) MaxBinaryContentId = id; return content; }
public void WriteContentBytes(DemoBinaryContent content, byte[] data) { string filePath = PrepareContentFilePath(content); lock (this.demoDataLocker) { File.WriteAllBytes(filePath, data); } content.IsLoaded = true; }
public byte[] ReadContentBytes(DemoBinaryContent content) { if (content.IsLoaded) { string filePath = PrepareContentFilePath(content); lock (this.demoDataLocker) { return File.ReadAllBytes(filePath); } } byte[] data = SourceDataService.BinaryContentSet. Where(dbContent => dbContent.Id == content.Id). Select(dbContent => dbContent.Data). First(); WriteContentBytes(content, data); return data; }
public override BinaryContent CreateBinaryContent(byte[] data) { DemoBinaryContent content = new DemoBinaryContent(this); lock (this.binaryContentCacheLocker) { MaxBinaryContentId++; content.Id = MaxBinaryContentId; BinaryContentCache.Add(content.Id, content); } content.Data = data; return content; }