protected virtual void OnMessageDelivered(InstagramMessageDto message) { InstagramImageViewModel image = _mappingEngine.Map <InstagramImageViewModel>(message); EventHandler <MessageEventArgs <InstagramImageViewModel> > handler = MessageDelivered; if (handler != null) { handler(this, new MessageEventArgs <InstagramImageViewModel>(this, image)); } }
public void ProcessImages(IEnumerable <Image> images, string printerName) { foreach (var image in images) { InstagramMessageDto imageDto = _mappingEngine.Map <InstagramMessageDto>(image); _imageService.SaveImage(new ImageViewModel(image.Data)); _imagePrinter.Print(imageDto.Data, printerName); //await _queueUtilizer.SendMessage(imageDto); } }
public void Print(Image image, string printerName) { InstagramMessageDto imageDto = _mappingEngine.Map <InstagramMessageDto>(image); var result = _patternVmProvider.GetPatterns(); var instaTemplate = result.SingleOrDefault(x => x.IsInstaPrinterTemplate); Action <byte[]> print = null; if (!string.IsNullOrEmpty(printerName)) { print = (data) => _imagePrinter.Print(data, printerName); } else { print = (data) => _imagePrinter.Print(data); } byte[] imageData = new byte[] { }; Size imageStreamSize; using (var stream = new MemoryStream(imageDto.Data)) { var img = DrawingImage.FromStream(stream); imageStreamSize = img.Size; } if (instaTemplate != null) { imageData = _imageUtils.ProcessImages(new List <byte[]> { imageDto.Data }, imageStreamSize, _mappingEngine.Map <EntityTemplate>(instaTemplate)); } else { //если раземер имени превышает допустимое значение то мы обрезаем его var imageName = imageDto.FullName.Length < 23 ? imageDto.FullName : (imageDto.UserName.Length < 23 ? imageDto.UserName : (imageDto.UserName.Substring(0, 20) + "...")); imageData = _imageUtils.GetCaptureForInstagramControl(imageDto.Data, imageName, DateTime.Now, imageDto.ProfilePictureData); } _imageService.SaveImage(new ImageViewModel(imageData)); print(imageData); }