Exemple #1
0
        private async Task SendImageUsingReferenceAsync(List <string> objectIDs, ImageRef imageRef, int page = 1, string locationName = null, string batchID = null)
        {
            //Create an image object.
            MultiProductImage image = new MultiProductImage
            {
                ImageReference = imageRef.ImageReference,
                ObjectIDs      = objectIDs,
                //The type of display this image is meant for.
                //See Appendix A of the API reference for the full list.
                DisplayTypeName = "Chroma29",
                PageID          = page,
            };

            //Send the image as a local override image
            if (locationName != null)
            {
                image.LocationName = locationName;
            }

            //Use a user supplied batchID
            //For more information on how to use this feature see section 5.1 of the System Management documentation.
            if (batchID != null)
            {
                image.UserDefinedBatchID = batchID;
            }

            var response = await _client.PostApiAsync <MultiProductImage>("api/objects/imagetomultipleobjects", image);

            response.EnsureSuccessStatusCode();
        }
 private void ReplacePreviewImage(ImageRef newImage)
 {
     if (this.previewImage != null)
     {
         this.previewImage.Dispose();
     }
     this.previewImage = newImage;
 }
        public static void SaveImage(ImageRef imageRef, RenderOutputMethod renderOutput, string relativeDestPath, ImageFormat imageFormat)
        {
            Stream stream = renderOutput.CreateFile(relativeDestPath, ImageTypeMapper.ByImageFormat(imageFormat).mimeType);

            using (stream)
            {
                imageRef.image.Save(stream, imageFormat);
                stream.Close();
            }
        }
        private void previewPanel_Paint(object sender, PaintEventArgs e)
        {
            HandleUpdate();
            ImageRef imageRef = null;

            Monitor.Enter(this);
            try
            {
                if (previewImage != null)
                {
                    imageRef = (ImageRef)previewImage.Duplicate("LegendOptionsPanel.previewPanel_Paint");
                }
            }
            finally
            {
                Monitor.Exit(this);
            }

            if (imageRef != null)
            {
                try
                {
                    GDIBigLockedImage image;
                    Monitor.Enter(image = imageRef.image);
                    try
                    {
                        Image image2 = imageRef.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                        e.Graphics.DrawImage(image2,
                                             new Rectangle(new Point(0, 0), previewPanel.Size),
                                             new Rectangle(new Point(0, 0), previewPanel.Size),
                                             GraphicsUnit.Pixel);
                    }
                    finally
                    {
                        Monitor.Exit(image);
                    }
                }
                catch (Exception)
                {
                    D.Say(0, "Absorbing that disturbing bug wherein the mostRecentTile image is corrupt.");
                }

                imageRef.Dispose();
                return;
            }

            e.Graphics.DrawRectangle(new Pen(Color.Black),
                                     0,
                                     0,
                                     previewPanel.Size.Width - 1,
                                     previewPanel.Height - 1);
        }
Exemple #5
0
        public async Task <ImageRefResponse> SaveAsync(ImageRef imageRef)
        {
            try
            {
                await _imageRefRepository.AddAsync(imageRef);

                await _unitOfWork.CompleteAsync();

                return(new ImageRefResponse(imageRef));
            } catch (Exception ex) {
                return(new ImageRefResponse($"An error occurred when saving the ImageRef, exception: {ex.Message}"));
            }
        }
Exemple #6
0
        private async Task SendImageBatchUsingReferenceAsync(ImageRef imageRef)
        {
            //A batch API endpoint can be used to send multiple requests together. This cuts down on excess HTTP traffic.

            //  Create the products we are going to assign the image to
            var products = new List <Product>();

            for (int i = 0; i < 100; i++)
            {
                products.Add(await AddProduct());
            }

            //Create the content body for the batch request
            var batchID = "batch_" + Guid.NewGuid();
            MultipartContent content = new MultipartContent("mixed", batchID);

            foreach (Product product in products)
            {
                //  Create the request for each image send that the batch is going to contain.
                MultiProductImage image = new MultiProductImage
                {
                    ImageReference = imageRef.ImageReference,
                    ObjectIDs      = new List <string> {
                        product.ObjectID
                    },
                    //The type of display this image is meant for.
                    //See Appendix A of the API reference for the full list.
                    DisplayTypeName = "Chroma29",
                    PageID          = 1,
                    //Send the image as a local override image
                    LocationName = existingLocation1.Name,
                    //Use a user supplied batchID
                    //For more information on how to use this feature see section 5.1 of the System Management documentation.
                    UserDefinedBatchID = batchID
                };

                //Create a message to send an image.
                //Create the different parts of the multipart content
                HttpMessageContent sendImageContent = new HttpMessageContent(new HttpRequestMessage(HttpMethod.Post, $"{ApiServer}/API/api/objects/imagetomultipleobjects"));
                sendImageContent.HttpRequestMessage.Content = new ObjectContent <MultiProductImage>(image, new JsonMediaTypeFormatter());
                content.Add(sendImageContent);
            }

            //  Now send all the image assigns as a single batch request.
            await SendBatchAndCheckReturnResponsesSuccessAsync(content);
        }
 public ItemInstance(Item i)
 {
     item        = i;
     CurrentName = i.DefaultName;
     if (!string.IsNullOrWhiteSpace(i.Icon))
     {
         CurrentIconPath = new ImageRef {
             Path = Editor.MainViewModel.AbsolutePath(MainViewModel.GetMainViewModelStatic().Location, i.Icon)
         };
     }
     else
     {
         CurrentIconPath = new ImageRef {
             Path = ""
         };
     }
     foreach (var property in i.ItemProperties)
     {
         var baseVar = property.BaseVariable;
         var wrapper = new VariableWrapper(baseVar);
         if (!property.UseDefaultValue)
         {
             if (baseVar.IsDateTime)
             {
                 wrapper.CurrentDateTimeValue = Convert.ToDateTime(property.Value);
             }
             else if (baseVar.IsNumber)
             {
                 wrapper.CurrentNumberValue = Convert.ToInt32(property.Value);
             }
             else if (baseVar.IsString)
             {
                 wrapper.CurrentStringValue = Convert.ToString(property.Value);
             }
             this.Properties.Add(property.Name, wrapper);
         }
         else
         {
             wrapper.CurrentDateTimeValue = baseVar.DefaultDateTime;
             wrapper.CurrentNumberValue   = baseVar.DefaultNumber;
             wrapper.CurrentStringValue   = baseVar.DefaultString;
             this.Properties.Add(property.Name, wrapper);
         }
     }
     this.CanBeDropped = i.Removable;
 }
Exemple #8
0
        public void CompositeImageInto(GDIBigLockedImage baseImage)
        {
            Present present = this.FetchClippedImage();

            if (present is ImageRef)
            {
                ImageRef imageRef = (ImageRef)present;
                baseImage.DrawImageOntoThis(imageRef.image, new Rectangle(0, 0, baseImage.Width, baseImage.Height), new Rectangle(0, 0, imageRef.image.Width, imageRef.image.Height));
            }
            else
            {
                if (present is PresentFailureCode)
                {
                    throw new NonredundantRenderComplaint(string.Format("{0}: {1}", this.applier.DescribeSourceForComplaint(), ((PresentFailureCode)present).exception.Message));
                }
            }
            present.Dispose();
        }
Exemple #9
0
        public override bool DoWork(ITileWorkFeedback feedback)
        {
            if (!this.needThisTile())
            {
                return(false);
            }
            D.Sayf(10, "SingleSourcing {0} {1}", new object[]
            {
                this.applier.source.GetSourceMapDisplayName(),
                this.address
            });
            Present present = this.FetchClippedImage();

            if (present is ImageRef)
            {
                ImageRef image = (ImageRef)present;
                feedback.PostImageResult(image, this.applier.layer, this.applier.source.GetSourceMapDisplayName(), this.address);
            }
            present.Dispose();
            return(true);
        }
Exemple #10
0
        public async Task <ImageRefResponse> UpdateAsync(int id, ImageRef imageRef)
        {
            var existingImageRef = await _imageRefRepository.FindByIdAsync(id);

            if (existingImageRef == null)
            {
                return(new ImageRefResponse("Genre not found."));
            }

            existingImageRef.URI          = imageRef.URI;
            existingImageRef.DateModified = DateTime.Now;

            try
            {
                _imageRefRepository.Update(existingImageRef);
                await _unitOfWork.CompleteAsync();

                return(new ImageRefResponse(existingImageRef));
            }
            catch (Exception ex)
            {
                return(new ImageRefResponse($"An error occurred when updating the image ref, exception: {ex.Message}"));
            }
        }
Exemple #11
0
 public ImageRefResponse(ImageRef imageRef) : this(true, string.Empty, imageRef)
 {
 }
Exemple #12
0
 private ImageRefResponse(bool success, string message, ImageRef imageRef) : base(success, message)
 {
     ImageRef = imageRef;
 }
 public void Update(ImageRef imageRef)
 {
     _context.ImageRefs.Update(imageRef);
 }
 public async Task AddAsync(ImageRef imageRef)
 {
     await _context.ImageRefs.AddAsync(imageRef);
 }
 public ImageAddedToProduct(Guid productId, AttributeRef varianterAttr, ImageRef image)
 {
     ProductId     = productId;
     VarianterAttr = varianterAttr;
     Image         = image;
 }