示例#1
0
        string PrepareContentFilePath(DemoBinaryContent content)
        {
            string demoDataPath = GetDemoDataPath();
                if (!Directory.Exists(demoDataPath))
                     Directory.CreateDirectory(demoDataPath);

                string fileName = GetBinaryContentFileName(content);
                return Path.Combine(demoDataPath, fileName);
        }
示例#2
0
 string GetBinaryContentFileName(DemoBinaryContent content)
 {
     return content.Id.ToString() + ".tmp";
 }
示例#3
0
 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;
 }
示例#4
0
 public void WriteContentBytes(DemoBinaryContent content, byte[] data)
 {
     string filePath = PrepareContentFilePath(content);
         lock (this.demoDataLocker)
         {
              File.WriteAllBytes(filePath, data);
         }
         content.IsLoaded = true;
 }
示例#5
0
 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;
 }
示例#6
0
 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;
 }