public static Action <Foo> CompileUntyped(TransformationBase transformation)
    {
        var transformType       = transformation.GetType();
        var genericType         = transformType.GetGenericArguments().First();
        var fooParam            = Expression.Parameter(typeof(Foo), "f");
        var valueGetter         = typeof(Foo).GetProperty("Value").GetGetMethod();
        var valueSetter         = typeof(Foo).GetProperty("Value").GetSetMethod();
        var transformFuncMember = transformType.GetProperty("Transform").GetGetMethod();
        //Equivalent to f => f.Value = transformation.Transform((T)f.Value)
        //Where T is the generic type parameter of the Transformation, and f is of type Foo
        var expression = Expression.Lambda <Action <Foo> >(
            Expression.Call(
                fooParam,
                valueSetter,
                Expression.Invoke(
                    Expression.Property(
                        Expression.Constant(transformation, transformType),
                        transformFuncMember
                        ),
                    Expression.Convert(
                        Expression.Property(fooParam, valueGetter),
                        genericType
                        )
                    )
                ), fooParam
            );

        return(expression.Compile());
    }
        public void Chain_WithTwoNormalTransformations_CreatesChainedTransformation()
        {
            var first = new TransformationBase();
            var second = new TransformationBase();

            var chained = first.Chain(second);

            Assert.That(chained is ChainedTransformation);
        }
 public static Action <Foo> Compile(TransformationBase transformation)
 {
     return(new Action <Foo>(f =>
     {
         dynamic d = f.Value;
         dynamic t = transformation;
         f.Value = t.Transform(d);
     }));
 }
    public static Action <Foo> CompileReflection(TransformationBase transformation)
    {
        var f = transformation
                .GetType()
                .GetProperty("Transform")
                .GetGetMethod()
                .Invoke(transformation, null) as Delegate;

        return(foo => foo.Value = f.DynamicInvoke(foo.Value));
    }
        public void ToCloudinary_WithTwoTransformations_CombinesThem()
        {
            var first = new Transformation(20, 40) { Angle = new Angle(40)};
            var second = new TransformationBase
                             {
                                 Effect = "sepia"
                             };

            var chained = new ChainedTransformation(first, second);

            Assert.AreEqual("w_20,h_40,a_40/e_sepia", chained.ToCloudinary());
        }
        public void Chain_WithSeconArgumentChained_ReUsesExistsing()
        {
            var first = new TransformationBase();
            var second = new TransformationBase();

            var chained = new ChainedTransformation(first, second);

            var third = new TransformationBase();

            var combined = third.Chain(chained);

            Assert.That(combined == chained);
        }
        public void Chain_OnChainedTransformation_ReUsesExisting()
        {
            var first = new TransformationBase();
            var second = new TransformationBase();

            ChainedTransformation chained = new ChainedTransformation(first, second);

            var third = new TransformationBase();

            var combined = chained.Chain(third);

            Assert.That(combined == chained);
            Assert.That(chained.InnerTransformations.Count() == 3);
        }
        public void GetFormat_WithTwoTransformations_ReturnsFirstFormat()
        {
            var first = new TransformationBase()
                            {
                                Format = "gif"
                            };

            var second = new Transformation(20, 30)
                             {
                                 Format = "png"
                             };

            var chained = new ChainedTransformation(first, second);

            Assert.That(chained.GetFormat() == "gif");
        }
        public void CloudinaryImage_WithChainedTransformation_Chains()
        {
            var first = new Transformation(35, 99)
                            {
                                Radius = 4,
                                Format = "png"
                            };
            var second = new TransformationBase()
                             {
                                 Angle = new Angle(45)
                             };

            var chained = new ChainedTransformation(first, second);

            string url = Url.CloudinaryImage("chained", chained).ToString();

            Assert.AreEqual("http://res.cloudinary.com/test/image/upload/w_35,h_99,r_4/a_45/chained.png", url);
        }
        public static void LoadImageAsync(
            this MvxCachedImageView imageView,
            string bundleResourceName,
            string url,
            TransformationBase transformationBase = null)
        {
            if (string.IsNullOrEmpty(url))
            {
                imageView.SetImageDrawable(null);

                if (!string.IsNullOrEmpty(bundleResourceName))
                {
                    var loadTask = ImageService.Instance
                                   .LoadCompiledResource(bundleResourceName);

                    if (transformationBase != null)
                    {
                        loadTask = loadTask.Transform(transformationBase);
                    }

                    loadTask.IntoAsync(imageView);
                }

                return;
            }

            var expr = ImageService.Instance.LoadUrl(url);

            if (!string.IsNullOrEmpty(bundleResourceName))
            {
                expr = expr.LoadingPlaceholder(bundleResourceName, ImageSource.CompiledResource)
                       .ErrorPlaceholder(bundleResourceName, ImageSource.CompiledResource);
            }

            if (transformationBase != null)
            {
                expr = expr.Transform(transformationBase);
            }

            expr.IntoAsync(imageView);
        }
Exemple #11
0
 public void InitChildren(IEnumerable <object> elements)
 {
     Transform = elements.FirstOrDefault(o => o is TransformationBase) as TransformationBase;
 }