public async Task <UploadResult> UploadBinaryAsync(byte[] source, string fileName) { Stopwatch stopwatch = new Stopwatch(); Stopwatch stopwatch2 = new Stopwatch(); // Console.WriteLine("try get info stream"); Stream infoSource = new MemoryStream(source); // Console.WriteLine("try get upload stream"); Stream uploadSource = new MemoryStream(source); Image image = new Image(); try { stopwatch.Restart(); imageProcessor.LoadInfoFromStream(infoSource, ref image); stopwatch.Stop(); Logger.LogInformation($"Core.LoadInfoFromStream used {stopwatch.Elapsed.Milliseconds}ms. "); } catch (NotSupportedException) { return(new UploadResult { Status = "invalid file format" }); } image.BlobName = image.MD5.ToString("X") + image.Format; stopwatch2.Start(); stopwatch.Restart(); var id = dbManager.GetIdByMD5(image.MD5); string status = "ok"; if (id == null) { // Console.WriteLine("Created: " + image.MD5); image = dbManager.Create(image); dbManager.SaveChanges(); } else { image.Id = id; stopwatch.Stop(); Logger.LogInformation($"Core.dbManager used {stopwatch.Elapsed.Milliseconds}ms. "); status = "duplicate"; return(new UploadResult { Status = status, Id = image.Id, UploadType = "image" }); } Task <Uri> uploadTask = storage.UploadAsync(uploadSource, image.BlobName); Uri uri = await uploadTask; stopwatch2.Stop(); Logger.LogInformation($"Core.UploadAsync used {stopwatch2.Elapsed.Milliseconds}ms. "); return(new UploadResult { Status = status, Id = image.Id, UploadType = "image" }); }
public void Create(T item) { idbManager.Create(item); }