Ejemplo n.º 1
0
        public async Task UploadAsync(string fileName, Stream content)
        {
            await connection.Start();

            var template = new OperationsTemplate(connection);
            var hash     = GetFileNameHash(fileName);
            FileHandleStatus result;
            var fileRecord = await dbContext.Files.Where(i => i.FileName == hash).FirstOrDefaultAsync();

            var length = content.Length;

            if (fileRecord != null)
            {
                if (await template.CheckFileExists(fileRecord.FileId))
                {
                    result = await template.UpdateFileByStream(fileRecord.FileId, hash, content);
                }
                else
                {
                    result = await template.SaveFileByStream(hash, content);
                }
                fileRecord.ContentType      = string.IsNullOrEmpty(result.ContentType) ? "application/octet-stream" : result.ContentType;
                fileRecord.FileSize         = length;
                fileRecord.LastModified     = DateTime.Now;
                fileRecord.FileName         = hash;
                fileRecord.OriginalFileName = fileName;
                dbContext.Files.Update(fileRecord);
            }
            else
            {
                result = await template.SaveFileByStream(hash, content);

                await dbContext.Files.AddAsync(new FileRecord
                {
                    ContentType      = string.IsNullOrEmpty(result.ContentType) ? "application/octet-stream" : result.ContentType,
                    FileSize         = length,
                    LastModified     = DateTime.Now,
                    FileName         = hash,
                    FileId           = result.FileId,
                    OriginalFileName = fileName
                });
            }
        }
Ejemplo n.º 2
0
 public void OneTimeSetUp()
 {
     Manager = new MasterConnection("localhost")
     {
         EnableLookupVolumeCache = true
     };
     Manager.Start().GetAwaiter().GetResult();
     Connection    = Manager.GetConnection();
     MasterWrapper = new MasterWrapper(Manager.GetConnection());
     Template      = new OperationsTemplate(Manager);
     VolumeWrapper = new VolumeWrapper(Manager.GetConnection());
 }