Esempio n. 1
0
 public override Stream OpenRead()
 {
     if (!LoadFromDisk)
     {
         return(new NonSeekableMemoryStream(SqlBlobModelRepository.Get(ID).Blob));
     }
     return(FileHelper.GetOrCreateFileBlob(FilePath, ID));
 }
Esempio n. 2
0
        public override Blob CreateBlob(Uri id, string extension)
        {
            var sqlBlobModel = new SqlBlobModel
            {
                BlobId = Blob.NewBlobIdentifier(id, extension)
            };

            SqlBlobModelRepository.Save(sqlBlobModel);
            return(GetBlob(sqlBlobModel.BlobId));
        }
Esempio n. 3
0
        internal static Stream GetOrCreateFileBlob(string filePath, Uri id)
        {
            if (File.Exists(filePath))
            {
                return(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read));
            }
            var bytes         = SqlBlobModelRepository.Get(id).Blob;
            var directoryInfo = new DirectoryInfo(Path.GetDirectoryName(filePath));

            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }

            File.WriteAllBytes(filePath, bytes);
            return(new MemoryStream(bytes));
        }
Esempio n. 4
0
        public override void Write(Stream stream)
        {
            SqlBlobModel blobModel;

            if ((blobModel = SqlBlobModelRepository.Get(ID)) == null)
            {
                blobModel = new SqlBlobModel
                {
                    BlobId = ID
                };
            }
            var sqlBlobModel = blobModel;

            using (var memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                sqlBlobModel.Blob = memoryStream.ToArray();
            }
            SqlBlobModelRepository.Save(sqlBlobModel);
        }
Esempio n. 5
0
 public override void Delete(Uri id)
 {
     SqlBlobModelRepository.Delete(id);
     FileHelper.Delete(id, this.Path);
 }