public async Task GetAllFiles(IoCType ioCType) { this.SetTestContext(ioCType); var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images", "image.jpg"); byte[] fileBytes = default(byte[]); #if NET461 fileBytes = File.ReadAllBytes(filePath); #else fileBytes = await File.ReadAllBytesAsync(filePath); #endif var file = new ImageBlob { FileName = "image.jpg", Data = fileBytes }; var fileSaved = await this.imageBlobCollection.UploadAsync(file); Assert.True(fileSaved != ObjectId.Empty); var files = await this.imageBlobCollection.GetFilesAllAsync(); Assert.NotNull(files); Assert.True(files.Any()); }
public void ImageLoadStart(ImageBlob result) { if (OnImageLoadStart != null) { OnImageLoadStart(result); } }
public async Task <IActionResult> Upload(List <IFormFile> files, CancellationToken cancellationToken) { var photos = new List <Photo>(); foreach (var formFile in files) { using (var openReadStream = formFile.OpenReadStream()) { var data = new byte[formFile.Length]; openReadStream.Read(data, 0, data.Length); var thumbnailData = ImageTools.ResizeTo(data, this.settings.Value.Thumbnail); var(width, height) = ImageTools.GetSize(data); var fullSizeBlob = new ImageBlob { Content = data, Id = Guid.NewGuid() }; var thumbnailBlob = new ImageBlob { Content = thumbnailData, Id = Guid.NewGuid() }; await ImageStore.SaveImageBlobAsync(fullSizeBlob, cancellationToken); await ImageStore.SaveImageBlobAsync(thumbnailBlob, cancellationToken); var photo = Repository.StorePhoto(formFile.FileName, fullSizeBlob.Id, thumbnailBlob.Id, formFile.ContentType, width, height); photos.Add(photo); } } await this.UnitOfWork.SaveChanges(cancellationToken); return(RedirectToAction("Index", "Tag", new { fileIds = photos.Select(_ => _.Id).ToList() })); }
public async Task <bool> DeleteImageAsync(string container, string fileName) { CloudBlobContainer Container; CloudBlockBlob ImageBlob; if (this.blobContainers.Find(itm => itm == container) != null) { if (fileName != null && fileName.Length > 0) { Container = this.blobClient.GetContainerReference(container); ImageBlob = Container.GetBlockBlobReference(fileName); try { ImageBlob.DeleteIfExists(); } catch (Exception error) { this.sMsgError.Add(error.Message); return(false); } return(true); } } return(false); }
private void ReadImageBlob(Tag tag, uint followingOffset) { int id = this.sdtr.ReadUI16(); #if DEBUG this.Log("char id=" + id); #endif byte[] data = this.sdtr.ReadByteBlock((int)(followingOffset - this.sdtr.Offset)); ImageBlob image = new ImageBlob() { DataFormat = tag, FormattedBytes = data }; if (tag == Tag.DefineBits) { if (jpegTable == null) { throw new SWFModellerException(SWFModellerError.SWFParsing, "DefineBits tag without a JPEGTables tag is illegal.", swf.Context); } image.JPEGTable = jpegTable; } this.characterUnmarshaller.Add(id, image); this.swf.AddCharacter(CID_PREFIX + id, image); }
private bool UploadImg(ImageFile File) { CloudBlobContainer Container; CloudBlockBlob ImageBlob; if (this.blobContainers.Find(itm => itm == File.Container) != null) { if (File.FileName != null && File.FileName.Length > 0) { Container = this.blobClient.GetContainerReference(File.Container); ImageBlob = Container.GetBlockBlobReference(File.FileName); if (File.ContentType != null && File.ContentType.Length > 0) { ImageBlob.Properties.ContentType = File.ContentType; } try { ImageBlob.UploadFromByteArray(File.FileData, 0, File.FileSize - 1); } catch (Exception error) { this.sMsgError.Add(error.Message); return(false); } return(true); } } return(false); }
private void WriteImage(IImage image) { if (characterMarshal.HasMarshalled(image)) { /* Been there, done that. */ return; } ImageBlob blob = image as ImageBlob; if (blob == null) { throw new SWFModellerException(SWFModellerError.Internal, "Can't write " + image.ToString()); } switch (blob.DataFormat) { case Tag.DefineBitsJPEG2: case Tag.DefineBitsLossless: case Tag.DefineBitsLossless2: WriteBuffer blobBuffer = OpenTag(blob.DataFormat); blobBuffer.WriteUI16((uint)characterMarshal.GetIDFor(image)); blobBuffer.WriteBytes(blob.FormattedBytes); CloseTag(); break; case Tag.DefineBits: if (blob.JPEGTable != null) { if (writtenJPEGTable != null && writtenJPEGTable != blob.JPEGTable) { /* ISSUE 16 */ throw new SWFModellerException(SWFModellerError.UnimplementedFeature, "Can't process multiple JPEG encoding tables yet."); } WriteBuffer tables = OpenTag(Tag.JPEGTables); tables.WriteBytes(blob.JPEGTable.TableData); CloseTag(); writtenJPEGTable = blob.JPEGTable; } WriteBuffer bits = OpenTag(Tag.DefineBits); bits.WriteUI16((uint)characterMarshal.GetIDFor(image)); bits.WriteBytes(blob.FormattedBytes); CloseTag(); break; default: throw new SWFModellerException(SWFModellerError.Internal, "Can't write image format " + blob.DataFormat.ToString());; } }
static void Main(string[] args) { var employees = new Employee[] { new Employee { Name = "Micheal Scott", JobTitle = "Branch Manager" }, new Employee { Name = "Pam Beesly", JobTitle = "Office Administrator" }, new Employee { Name = "Jim Halpert", JobTitle = "Salesman" }, new Employee { Name = "Dwight Schrute", JobTitle = "Salesman" }, new Employee { Name = "Andy Bernard", JobTitle = "Salesman" }, }; var image = new ImageBlob("jpeg", File.ReadAllBytes("Image.jpeg")); var data = new Dictionary <string, object>() { { "employees", employees }, { "image", image }, }; var context = new TemplateContext(data); using (var stream = File.OpenRead("EmployeesTemplate.odt")) { var odt = OdfDocument.LoadFrom(stream); var template = new OdtTemplate(odt); var result = template.Render(context); var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var outputFile = Path.Combine(desktopDir, "generated.odt"); result.Save(outputFile); Console.WriteLine("All done, checkout the generated document: {0}", outputFile); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
public async Task <bool> Post(ImageBlob imageBlob) { if (imageBlob == null || imageBlob.CanvasData == null) { return(false); } // add the blob to blob storage/table storage var storedImageBlob = await imageBlobRepository.AddBlob(imageBlob); if (storedImageBlob != null) { BlobHub.SendFromWebApi(storedImageBlob); } return(false); }
public void UpdateAdvertisement(NewAdvertisement item) { db.BeginTransaction(); int id = item.AdvertisementId; Advertisement ad = new Advertisement(); ad.Id = id; ad.SellingType = item.SellingType; ad.EmployeeId = item.EmployeeId; ad.CategoryId = item.CategoryId; ad.Expiry = item.Expiry; ad.PostedOn = item.PostedOn; ad.Status = "Active"; ad.DisplayPhone = item.DisplayPhone; var update = db.Update("Advertisement", "Id", ad); if (update > 0) { db.Delete <Report>("WHERE AdvertisementId = @0", id); db.Delete <AdminMessage>("WHERE AdvertisementId = @0", id); Images img; db.Delete <Images>("WHERE AdvertisementId = @0", id); if (item.Images.Count > 0) { foreach (var image in item.Images) { img = new Images(); img.AdvertisementId = id; ImageBlob imageBlob = new ImageBlob(_configuration); img.Image = imageBlob.ImageUploading(image).Result; db.Insert("Images", "Id", true, img); } } else { img = new Images(); img.AdvertisementId = id; db.Insert("Images", "Id", true, img); } foreach (var field in item.Fields) { db.Update <AdvertisementDetails>($"SET Value = '{field.Value}' WHERE AdvertisementId = {id} and FieldName Like '%{field.Key}'"); } } db.CompleteTransaction(); }
/// <summary> /// POST: /Admin /// updates existing inventory product in inventory or creates a new one /// </summary> /// <returns> reloads Admin page </returns> public async Task <IActionResult> OnPost() { Product query = await _inv.GetOneByIdAsync(Product.ID); Product.ID = 0; if (Image != null) { // do all the blob stuff // 1. make a filepath var filePath = Path.GetTempFileName(); // 2. open stream using (var stream = new FileStream(filePath, FileMode.Create)) { await Image.CopyToAsync(stream); } // 3. get container and blob var container = await ImageBlob.GetContainer("products"); CloudBlob blob = await ImageBlob.GetBlob(Image.FileName, container.Name); // 4. upload image ImageBlob.UploadFile(container, Image.FileName, filePath); Product.Image = blob.Uri.ToString(); } if (query == null || query.ID == 0) { await _inv.CreateAsync(Product); } else { query.Sku = Product.Sku; query.Name = Product.Name; query.Price = Product.Price; query.QtyAvail = Product.QtyAvail; query.Description = Product.Description; query.Meaty = Product.Meaty; query.Category = Product.Category; query.Image = Product.Image; await _inv.UpdateAsync(query); } CurrentInventory = await _inv.GetAllAsync(); return(RedirectToPage("../Admin/Index")); }
public void CreateNewAdvertisement(NewAdvertisement item) { db.BeginTransaction(); Console.WriteLine(item.Images); Advertisement ad = new Advertisement(); ad.SellingType = item.SellingType; ad.EmployeeId = item.EmployeeId; ad.CategoryId = item.CategoryId; ad.Expiry = item.Expiry; ad.PostedOn = item.PostedOn; ad.Status = "Active"; ad.DisplayPhone = item.DisplayPhone; int id = Convert.ToInt32(db.Insert("Advertisement", "Id", true, ad)); Images img; if (item.Images.Count > 0) { foreach (var image in item.Images) { img = new Images(); img.AdvertisementId = id; ImageBlob imageBlob = new ImageBlob(_configuration); img.Image = imageBlob.ImageUploading(image).Result; db.Insert("Images", "Id", true, img); } } else { img = new Images(); img.AdvertisementId = id; db.Insert("Images", "Id", true, img); } AdvertisementDetails adDetails; foreach (var field in item.Fields) { adDetails = new AdvertisementDetails(); adDetails.AdvertisementId = id; adDetails.FieldName = field.Key; adDetails.Value = field.Value; db.Insert("AdvertisementDetails", "Id", true, adDetails); } db.CompleteTransaction(); }
public async Task <IActionResult> OnPost() { Post query = await _post.GetOnePost(ID.GetValueOrDefault()); if (query == null) { query = new Post(); query.UserID = Post.UserID; } query.Caption = (Post.Caption != null) ? Post.Caption : query.Caption; if (Image != null) { // do all the blob stuff // 1. make a filepath var filePath = Path.GetTempFileName(); // 2. open stream using (var stream = new FileStream(filePath, FileMode.Create)) { await Image.CopyToAsync(stream); } // 3. get container and blob var container = await ImageBlob.GetContainer("userpics"); CloudBlob blob = await ImageBlob.GetBlob(Image.FileName, container.Name); // 4. upload image ImageBlob.UploadFile(container, Image.FileName, filePath); query.Photo = blob.Uri.ToString(); } if (query.ID == 0) { await _post.MakePost(query); } else { await _post.EditPost(query); } return(RedirectToPage("../Index")); }
public void Render() { var media = new MediaBuilder(this.Session).WithInData(this.GetResourceBytes("Domain.Tests.Resources.EmbeddedTemplate.odt")).Build(); var templateType = new TemplateTypes(this.Session).OpenDocumentType; var template = new TemplateBuilder(this.Session).WithMedia(media).WithTemplateType(templateType).WithArguments("logo, people").Build(); this.Session.Derive(); var people = new People(this.Session).Extent(); var image = new ImageBlob("jpeg", this.GetResourceBytes("Domain.Tests.Resources.logo.png")); var data = new Dictionary <string, object>() { { "logo", image }, { "people", people }, }; var watch = System.Diagnostics.Stopwatch.StartNew(); var result = template.Render(data); watch.Stop(); var run1 = watch.ElapsedMilliseconds; File.WriteAllBytes("Embedded.odt", result); Assert.NotNull(result); Assert.NotEmpty(result); watch = System.Diagnostics.Stopwatch.StartNew(); result = template.Render(data); watch.Stop(); var run2 = watch.ElapsedMilliseconds; Assert.NotNull(result); Assert.NotEmpty(result); // Reuse should make it at least 5 times faster Assert.True(run2 < run1 / 5); }
IEnumerator GrabImages(FileType fileType, string[] filePaths) { for (int i = 0; i < filePaths.Length; i++) { string tempPath = _PathPrefix + filePaths[i]; string title = Path.GetFileNameWithoutExtension(tempPath); int index = i + 1; ImageBlob imageBlob = new ImageBlob(title, index, filePaths[i]); Instance.ImageLoadStart(imageBlob); Texture2D tex = new Texture2D(4, 4, TextureFormat.DXT1, false); WWW www = new WWW(tempPath); yield return(www); www.LoadImageIntoTexture(tex); DetailedImage image = new DetailedImage(); image.Texture2D = tex; image.Title = title; switch (fileType) { case FileType.Details: DetailTextures[i] = image; break; case FileType.Radiograph: RadiographTextures[i] = image; break; case FileType.Movement: MovementTextures[i] = image; break; case FileType.Simulation: SimulationTextures[i] = image; break; } } }
public async Task <ImageBlob> AddBlob(ImageBlob imageBlobToStore) { BlobStorageResult blobStorageResult = await StoreImageInBlobStorage(imageBlobToStore); if (!blobStorageResult.StoredOk) { return(null); } else { CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable imageBlobsTable = tableClient.GetTableReference("ImageBlobs"); var tableExists = await imageBlobsTable.ExistsAsync(); if (!tableExists) { await imageBlobsTable.CreateIfNotExistsAsync(); } ImageBlobEntity imageBlobEntity = new ImageBlobEntity( imageBlobToStore.UserId, imageBlobToStore.UserName, Guid.NewGuid(), blobStorageResult.BlobUrl, imageBlobToStore.Title, imageBlobToStore.CreatedOn ); TableOperation insertOperation = TableOperation.Insert(imageBlobEntity); imageBlobsTable.Execute(insertOperation); return(ProjectToImageBlobs(new List <ImageBlobEntity>() { imageBlobEntity }).First()); } }
private static object TranslateContent(object content) { if (content is Image) { using (MemoryStream stream = new MemoryStream()) { ((Image)content).Save(stream, ImageFormat.Bmp); content = new ImageBlob(stream.ToArray()); } } if (!(content is ImageRef) && !(content is ImageBlob)) { return(content); } Image image2 = new Image { Stretch = Stretch.None, HorizontalAlignment = HorizontalAlignment.Left }; if (content is ImageRef) { image2.Source = new BitmapImage(((ImageRef)content).Uri); return(image2); } BitmapImage image3 = new BitmapImage(); image3.BeginInit(); MemoryStream stream2 = new MemoryStream(((ImageBlob)content).Data) { Position = 0L }; image3.StreamSource = stream2; image3.EndInit(); image2.Source = image3; return(image2); }
private async Task <BlobStorageResult> StoreImageInBlobStorage(ImageBlob imageBlobToStore) { CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("images"); bool created = container.CreateIfNotExists(); container.SetPermissionsAsync( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); var blockBlob = container.GetBlockBlobReference(string.Format(@"{0}.image/png", Guid.NewGuid().ToString())); string marker = "data:image/png;base64,"; string dataWithoutJpegMarker = imageBlobToStore.CanvasData.Replace(marker, String.Empty); byte[] filebytes = Convert.FromBase64String(dataWithoutJpegMarker); blockBlob.UploadFromByteArray(filebytes, 0, filebytes.Length); return(new BlobStorageResult(true, blockBlob.Uri.ToString())); }
public OdfImageBlobValue(OdfDocument document, ImageBlob blob) { _document = document; _value = blob; }
//Called from Web Api controller, so must use GlobalHost context resolution public static void SendFromWebApi(ImageBlob imageBlob) { var hubContext = GlobalHost.ConnectionManager.GetHubContext <BlobHub>(); hubContext.Clients.All.latestBlobMessage(imageBlob); }
public void Send(ImageBlob latestBlob) { Clients.All.latestBlobMessage(latestBlob); }
private void ARDirectoryManager_OnImageLoadStart(ImageBlob obj) { //image.fillAmount = obj.Index / _filesToLoad; _targetRatio = obj.Index / _filesToLoad; label.text = string.Format("Loading {0}", obj.Path); }