Exemplo n.º 1
0
        public Task <string> GetImageUrlAsync(ImageValue image, int width = 0, int height = 0, CancellationToken cancellationToken = default)
        {
            if (!image.HasValue)
            {
                throw new ArgumentException();
            }

            string url;

            switch (image.ValueType)
            {
            case ImageValueType.Id:
                if (width > 0 || height > 0)
                {
                    url = linkGenerator.GetPathByAction("Image", "File", new { fileId = image.Value, width, height });
                }
                else
                {
                    url = linkGenerator.GetPathByAction("Index", "File", new { fileId = image.Value });
                }
                break;

            case ImageValueType.Url:
                url = NormalizeUrl(image.Value);
                break;

            default:
                throw new InvalidOperationException();
            }

            return(Task.FromResult(url));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostAsync([FromQuery] string fileName, [FromQuery] string width = null, [FromQuery] string height = null)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(BadRequest());
            }

            var contentType = Request.ContentType;

            if (!contentType.StartsWith("image"))
            {
                return(BadRequest());
            }

            var file = await fileService.UploadFileAsync(Page, fileName, contentType, Request.Body);

            var modelValue = new ImageValue(file.Id);

            Field.SetModelValue(ContentContext.Content, modelValue);

            await SaveChangesAsync();

            if (width != null && height != null)
            {
                var fielUrl = await fileUrlGenerator.GetImageUrlAsync(modelValue, int.Parse(width), int.Parse(height));

                return(Ok(fielUrl));
            }

            return(await FormValueAsync());
        }
Exemplo n.º 3
0
        public void Equality_Equal_Null()
        {
            var value1 = new ImageValue(new Uri("http://test/test.jpg"));

            var result = value1.Equals((object)null);

            Assert.False(result);
        }
Exemplo n.º 4
0
        public void Implicit_String_ImageValue()
        {
            var value = new ImageValue(new Uri("http://test/test.jpg"));

            string result = value;

            Assert.Equal(value.ToString(), result);
        }
Exemplo n.º 5
0
 public override object ConvetValueFromData(object value)
 {
     if (!ImageValue.TryParse((string)value, out ImageValue imageValue))
     {
         throw new InvalidOperationException();
     }
     return(imageValue);
 }
Exemplo n.º 6
0
        public void Implicit_ImageValue_Guid()
        {
            var id = Guid.NewGuid();

            ImageValue result = id;

            Assert.Equal(id.ToString(), result.Value);
        }
Exemplo n.º 7
0
        public void Implicit_ImageValue_Uri()
        {
            var url = new Uri("http://test/test.jpg");

            ImageValue result = url;

            Assert.Equal(url.ToString(), result.Value);
        }
Exemplo n.º 8
0
        public void Implicit_ImageValue_String()
        {
            var value = "url(http://test/test.jpg)";

            ImageValue result = value;

            Assert.Equal(value, result.ToString());
        }
Exemplo n.º 9
0
        public void TryParse_Url()
        {
            var fileUrl = new Uri("http://test/test.jpg");
            var result  = ImageValue.TryParse($"Url({fileUrl})", out ImageValue value);

            Assert.Equal(ImageValueType.Url, value.ValueType);
            Assert.Equal(fileUrl.ToString(), value.Value);
            Assert.True(value.HasValue);
        }
Exemplo n.º 10
0
        public void Check_UrlValue()
        {
            var fileUrl = new Uri("http://test/test.jpg");
            var value   = new ImageValue(fileUrl);

            Assert.Equal(ImageValueType.Url, value.ValueType);
            Assert.Equal(fileUrl.ToString(), value.Value);
            Assert.True(value.HasValue);
        }
Exemplo n.º 11
0
        public void Check_IdValue()
        {
            var fileId = Guid.NewGuid();
            var value  = new ImageValue(fileId);

            Assert.Equal(ImageValueType.Id, value.ValueType);
            Assert.Equal(fileId.ToString(), value.Value);
            Assert.True(value.HasValue);
        }
Exemplo n.º 12
0
        public void Implicit_Guid_ImageValue()
        {
            var id    = Guid.NewGuid();
            var value = new ImageValue(id);

            Guid result = value;

            Assert.Equal(id, result);
        }
Exemplo n.º 13
0
        public void Implicit_Uri_ImageValue()
        {
            var url   = new Uri("http://test/test.jpg");
            var value = new ImageValue(url);

            Uri result = value;

            Assert.Equal(url, result);
        }
Exemplo n.º 14
0
        public Task <string> GetImageUrlAsync(ImageValue image, int width = 0, int height = 0, CancellationToken cancellationToken = default)
        {
            if (!image.HasValue)
            {
                throw new InvalidOperationException();
            }

            return(Task.FromResult(image.Value));
        }
Exemplo n.º 15
0
        public void TryParse_Id()
        {
            var fileId = Guid.NewGuid();
            var result = ImageValue.TryParse($"Id({fileId})", out ImageValue value);

            Assert.Equal(ImageValueType.Id, value.ValueType);
            Assert.Equal(fileId.ToString(), value.Value);
            Assert.True(value.HasValue);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initialize a new instance of the ViewDrawButton class.
        /// </summary>
        /// <param name="paletteDisabled">Palette source for the disabled state.</param>
        /// <param name="paletteNormal">Palette source for the normal state.</param>
        /// <param name="paletteTracking">Palette source for the tracking state.</param>
        /// <param name="palettePressed">Palette source for the pressed state.</param>
        /// <param name="paletteCheckedNormal">Palette source for the normal checked state.</param>
        /// <param name="paletteCheckedTracking">Palette source for the tracking checked state.</param>
        /// <param name="paletteCheckedPressed">Palette source for the pressed checked state.</param>
        /// <param name="paletteMetric">Palette source for metric values.</param>
        /// <param name="imageValue"></param>
        /// <param name="commandLinkTextValues"></param>
        /// <param name="orientation">Visual orientation of the content.</param>
        /// <param name="useMnemonic">Use mnemonics.</param>
        public ViewDrawCommandLinkButton(IPaletteTriple paletteDisabled,
                                         IPaletteTriple paletteNormal,
                                         IPaletteTriple paletteTracking,
                                         IPaletteTriple palettePressed,
                                         IPaletteTriple paletteCheckedNormal,
                                         IPaletteTriple paletteCheckedTracking,
                                         IPaletteTriple paletteCheckedPressed,
                                         IPaletteMetric paletteMetric,
                                         ImageValue imageValue, CommandLinkTextValues commandLinkTextValues,
                                         VisualOrientation orientation,
                                         bool useMnemonic)
        {
            // Remember the source information
            _paletteDisabled        = paletteDisabled;
            _paletteNormal          = paletteNormal;
            _paletteTracking        = paletteTracking;
            _palettePressed         = palettePressed;
            _paletteCheckedNormal   = paletteCheckedNormal;
            _paletteCheckedTracking = paletteCheckedTracking;
            _paletteCheckedPressed  = paletteCheckedPressed;
            CurrentPalette          = _paletteNormal;

            // Default to not being checked
            Checked      = false;
            AllowUncheck = true;

            // Create the drop down view
            _drawImageContent = new ViewDrawContent(_paletteNormal.PaletteContent, imageValue, orientation);
            _drawImage        = new ViewLayoutCenter(paletteMetric, PaletteMetricPadding.BarPaddingOnly,
                                                     orientation, _drawImageContent);

            // Our view contains background and border with content inside
            _drawContent = new ViewDrawContent(_paletteNormal.PaletteContent, commandLinkTextValues, orientation)
            {
                // Pass the mnemonic default to the content view
                UseMnemonic = useMnemonic
            };

            // Use a docker layout to organize the contents of the canvas
            LayoutDocker = new ViewLayoutDocker
            {
                { _drawContent, ViewDockStyle.Left },
                { _drawImage, ViewDockStyle.Left }
            };
            LayoutDocker.Tag = this;


            _drawCanvas = new ViewDrawCanvas(_paletteNormal.PaletteBack, _paletteNormal.PaletteBorder, paletteMetric,
                                             PaletteMetricPadding.BarPaddingTabs, orientation)
            {
                // Place the content inside the canvas
                LayoutDocker
            };

            // Place the canvas inside ourself
            Add(_drawCanvas);
        }
Exemplo n.º 17
0
 public ImageDisplayInformation([NotNull] string name, [NotNull] ImageValue image, [CanBeNull] TransformValue transform)
 {
     Name          = name;
     Content       = image;
     Transform     = transform;
     layer         = 0;
     displayMatrix = Matrix4x4.identity;
     status        = ImageStatus.Unavailable;
 }
Exemplo n.º 18
0
        public void Equality_Equal_Url()
        {
            var url    = new Uri("http://test/test.jpg");
            var value1 = new ImageValue(url);
            var value2 = new ImageValue(url);

            var result = value1.Equals(value2);

            Assert.True(result);
        }
Exemplo n.º 19
0
        public void Equality_Equal_Id()
        {
            var id     = Guid.NewGuid();
            var value1 = new ImageValue(id);
            var value2 = new ImageValue(id);

            var result = value1.Equals(value2);

            Assert.True(result);
        }
Exemplo n.º 20
0
        public void SetModelValue()
        {
            var content = new TestContent {
                Image = "url(http://test/test.jpg)"
            };

            ImageValue newValue = "url(http://test/test2.jpg)";

            field.SetModelValue(content, newValue);

            Assert.Equal(newValue, content.Image);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initialize a new instance of the ViewDrawButton class.
 /// </summary>
 /// <param name="paletteDisabled">Palette source for the disabled state.</param>
 /// <param name="paletteNormal">Palette source for the normal state.</param>
 /// <param name="paletteTracking">Palette source for the tracking state.</param>
 /// <param name="palettePressed">Palette source for the pressed state.</param>
 /// <param name="paletteMetric">Palette source for metric values.</param>
 /// <param name="imageValue"></param>
 /// <param name="commandLinkTextValues"></param>
 /// <param name="orientation">Visual orientation of the content.</param>
 /// <param name="useMnemonic">Use mnemonics.</param>
 public ViewDrawCommandLinkButton(IPaletteTriple paletteDisabled,
                                  IPaletteTriple paletteNormal,
                                  IPaletteTriple paletteTracking,
                                  IPaletteTriple palettePressed,
                                  IPaletteMetric paletteMetric,
                                  ImageValue imageValue, CommandLinkTextValues commandLinkTextValues,
                                  VisualOrientation orientation,
                                  bool useMnemonic)
     : this(paletteDisabled, paletteNormal, paletteTracking, palettePressed,
            paletteNormal, paletteTracking, palettePressed, paletteMetric,
            imageValue, commandLinkTextValues, orientation, useMnemonic)
 {
 }
Exemplo n.º 22
0
        /// <summary>
        /// Compares this object to another <see cref="DesignImage"/>.
        /// </summary>
        public int CompareTo(DesignImage other)
        {
            int delta = ImageSource == null ? -1 : ImageSource.CompareTo(other.ImageSource);

            if (delta == 0)
            {
                delta = ImageValue == null ? -1 : ImageValue.CompareTo(other.ImageValue);
            }
            if (delta == 0)
            {
                delta = MimeType == null ? -1 : MimeType.CompareTo(other.MimeType);
            }
            return(delta);
        }
Exemplo n.º 23
0
        public override object ParseValue(string strValue)
        {
            if (string.IsNullOrEmpty(strValue))
            {
                return(null);
            }

            if (!ImageValue.TryParse(strValue, out ImageValue value))
            {
                throw new InvalidOperationException();
            }

            return(value);
        }
Exemplo n.º 24
0
        private void AddImage(ref ImageValue currentImage, ref string currentName, ref TransformValue currentTransform, List <ImageDisplayInformation> images, PluginExecuteContext context)
        {
            if (string.IsNullOrEmpty(currentName))
            {
                throw new MissingMemberException($"Unable to create show command: missing image name for {currentImage.ConvertToString(context.Language)}");
            }
            // ReSharper disable once AccessToModifiedClosure
            var name  = currentName;
            var image = currentImage;

            images.RemoveAll(e => e.Name == name || e.Content.EqualsWith(image, context.Language));
            images.Add(new ImageDisplayInformation(currentName, currentImage, currentTransform == null ? null : (TransformValue)_defaultTransform.AddWith(currentTransform)));
            currentName      = null;
            currentImage     = null;
            currentTransform = null;
        }
Exemplo n.º 25
0
        public IEnumerable <Attribute> Fetch(string path, DateTime lastWriteTime)
        {
            using (var reader = Execute(path, lastWriteTime))
            {
                while (reader.Read())
                {
                    var name      = reader.GetString(0);
                    var source    = reader.GetInt32(1);
                    var type      = reader.GetInt32(2);
                    var valueSize = reader.GetInt64(4);

                    // parse value
                    BaseValue value = null;
                    switch ((AttributeType)type)
                    {
                    case AttributeType.Int:
                        value = new IntValue(reader.GetInt32(3));
                        break;

                    case AttributeType.Double:
                        value = new RealValue(reader.GetDouble(3));
                        break;

                    case AttributeType.String:
                        value = new StringValue(reader.GetString(3));
                        break;

                    case AttributeType.DateTime:
                        value = new DateTimeValue(reader.GetDateTime(3));
                        break;

                    case AttributeType.Image:
                        var buffer = new byte[valueSize];
                        var length = reader.GetBytes(3, 0, buffer, 0, buffer.Length);
                        Trace.Assert(buffer.Length == length);
                        value = new ImageValue(buffer);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    // return the attribute
                    yield return(new Attribute(name, value, (AttributeSource)source));
                }
            }
        }
        private Paragraph ProcessImageType(ImageValue item, Book fictionBook)
        {
            var paragraph = new Paragraph();

            var path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Books\\" + fictionBook.FolderPath + "\\" + item.Href.Replace("#", "") + ".png");


            var container = new InlineUIContainer();

            container.Child = new Image()
            {
                Source = new BitmapImage(new Uri(path)), Stretch = Stretch.Uniform, HorizontalAlignment = HorizontalAlignment.Center
            };

            paragraph.Inlines.Add(container);

            return(paragraph);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Cache entity thumbnail.
        /// </summary>
        /// <remarks>
        /// This operation encodes <paramref name="decodedImage"/> as JPEG and saves the encoded data
        /// in attribute storage using the <see cref="IAttributeStorage.StoreThumbnail"/> method.
        /// </remarks>
        /// <param name="entity">Metadata of the image</param>
        /// <param name="decodedImage">Decoded image in BMP format</param>
        private void SaveThumbnail(IEntity entity, byte[] decodedImage)
        {
            using (var output = new MemoryStream())
                using (var input = new MemoryStream(decodedImage))
                {
                    MagicImageProcessor.ProcessImage(input, output, new ProcessImageSettings
                    {
                        Interpolation = InterpolationSettings.Linear,
                        SaveFormat    = FileFormat.Jpeg,
                        JpegQuality   = SavedThumbnailQuality
                    });

                    // update entity thumbnail
                    var value     = new ImageValue(output.ToArray());
                    var newEntity = entity.SetAttribute(new Attribute(
                                                            ExifAttributeReaderFactory.Thumbnail,
                                                            value, AttributeSource.Metadata));
                    _storage.StoreThumbnail(newEntity);
                }
        }
Exemplo n.º 28
0
        public async Task <IActionResult> UrlAsync([FromQuery] string url, [FromQuery] string width = null, [FromQuery] string height = null)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(BadRequest());
            }

            using (var client = new HttpClient())
            {
                var response = await client.GetAsync(url);

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(BadRequest());
                }

                var contentType = response.Content.Headers.ContentType.MediaType;
                if (!contentType.StartsWith("image"))
                {
                    return(BadRequest());
                }

                var file = await fileService.UploadFileAsync(Page, url, contentType, await response.Content.ReadAsStreamAsync());

                var modelValue = new ImageValue(file.Id);
                Field.SetModelValue(ContentContext.Content, modelValue);

                await SaveChangesAsync();

                if (width != null && height != null)
                {
                    var fielUrl = await fileUrlGenerator.GetImageUrlAsync(modelValue, int.Parse(width), int.Parse(height));

                    return(Ok(fielUrl));
                }
            }

            return(await FormValueAsync());
        }
Exemplo n.º 29
0
        private void SaveThumbnail(IEntity entity, SKBitmap thumbnail)
        {
            using (var dataStrem = new MemoryStream())
                using (var outputStream = new SKManagedWStream(dataStrem))
                {
                    var isEncoded = SKPixmap.Encode(
                        outputStream,
                        thumbnail,
                        SKEncodedImageFormat.Jpeg,
                        SavedThumbnailQuaity);
                    if (!isEncoded)
                    {
                        return;
                    }

                    var value     = new ImageValue(dataStrem.ToArray());
                    var newEntity = entity.SetAttribute(new Attribute(
                                                            ExifAttributeReaderFactory.Thumbnail,
                                                            value, AttributeSource.Metadata));
                    _storage.StoreThumbnail(newEntity);
                }
        }
Exemplo n.º 30
0
        public void ImageValue_GivenAnImageFieldValueToImageValueConstructorExpectPropertiesToBeSetted()
        {
            // Arrange
            var sharePointFieldValue = new ImageFieldValue()
            {
                ImageUrl = NewImageUrl, Hyperlink = NewHyperlink, OpenHyperlinkInNewWindow = NewOpenHyperlinkInNewWindow, Alignment = NewAlignment, AlternateText = NewAlternateText, BorderWidth = NewBorderWidth, Height = NewHeight, Width = NewWidth, HorizontalSpacing = NewHorizontalSpacing, VerticalSpacing = NewVerticalSpacing
            };

            // Act
            var imageValue = new ImageValue(sharePointFieldValue);

            // Assert
            Assert.AreEqual(NewImageUrl, imageValue.ImageUrl);
            Assert.AreEqual(NewHyperlink, imageValue.Hyperlink);
            Assert.AreEqual(NewOpenHyperlinkInNewWindow, imageValue.OpenHyperlinkInNewWindow);
            Assert.AreEqual(NewAlignment, imageValue.Alignment);
            Assert.AreEqual(NewAlternateText, imageValue.AlternateText);
            Assert.AreEqual(NewBorderWidth, imageValue.BorderWidth);
            Assert.AreEqual(NewHeight, imageValue.Height);
            Assert.AreEqual(NewWidth, imageValue.Width);
            Assert.AreEqual(NewHorizontalSpacing, imageValue.HorizontalSpacing);
            Assert.AreEqual(NewVerticalSpacing, imageValue.VerticalSpacing);
        }