Пример #1
0
    public void WriteContentBytes(DemoBinaryContent content, byte[] data)
    {
        string filePath = PrepareContentFilePath(content);

        lock (this.demoDataLocker) {
            File.WriteAllBytes(filePath, data);
        }
        content.IsLoaded = true;
    }
Пример #2
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);
    }
Пример #3
0
    string PrepareContentFilePath(DemoBinaryContent content)
    {
        string demoDataPath = GetDemoDataPath();

        if (!Directory.Exists(demoDataPath))
        {
            Directory.CreateDirectory(demoDataPath);
        }

        string fileName = GetBinaryContentFileName(content);

        return(Path.Combine(demoDataPath, fileName));
    }
Пример #4
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);
    }
Пример #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 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);
    }
Пример #7
0
 string GetBinaryContentFileName(DemoBinaryContent content)
 {
     return(content.Id.ToString() + ".tmp");
 }