public void WriteContentBytes(DemoBinaryContent content, byte[] data) { string filePath = PrepareContentFilePath(content); lock (this.demoDataLocker) { File.WriteAllBytes(filePath, data); } content.IsLoaded = true; }
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); }
string PrepareContentFilePath(DemoBinaryContent content) { string demoDataPath = GetDemoDataPath(); if (!Directory.Exists(demoDataPath)) { Directory.CreateDirectory(demoDataPath); } string fileName = GetBinaryContentFileName(content); return(Path.Combine(demoDataPath, fileName)); }
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 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 int GetFileSize(Item fileItem) { DemoItem item = fileItem as DemoItem; if (item.Content != null) { DemoBinaryContent content = item.Content as DemoBinaryContent; if (content.IsLoaded) { string filePath = PrepareContentFilePath(content); lock (this.demoDataLocker) { FileInfo file = new FileInfo(filePath); return((int)file.Length); } } return(SourceDataService.GetFileSize(fileItem)); } return(0); }
string GetBinaryContentFileName(DemoBinaryContent content) { return(content.Id.ToString() + ".tmp"); }