예제 #1
0
        public virtual async Task UpdateFieldById <TField>(TKey id,
                                                           Expression <Func <TEntity, TField> > memberExpression, TField value)
        {
            var entity = (await DbSet.FirstOrDefaultAsync(q => q.Id.Equals(id)))
                         ?? throw new KeyNotFoundException(
                                   $"there is no item in {typeof(TEntity).Name} with id : {id}");

            var memberName = LambdaExpressions.GetName(memberExpression);

            entity.GetType()
            .GetProperty(memberName)
            ?.SetValue(entity, value);
        }
예제 #2
0
        public virtual async Task UpdateFieldById <TField>(object[] ids,
                                                           Expression <Func <TEntity, TField> > memberExpression, TField value)
        {
            var entity = await DbSet.FindAsync(ids)
                         ?? throw new KeyNotFoundException(
                                   $"there is no item in {typeof(TEntity).Name} with id : {ids}");

            var memberName = LambdaExpressions.GetName(memberExpression);

            entity.GetType()
            .GetProperty(memberName)
            ?.SetValue(entity, value);
        }
예제 #3
0
        /// <inheritdoc />
        public virtual async Task UpdateField <TField>(Expression <Func <TEntity, bool> > filterExpression,
                                                       Expression <Func <TEntity, TField> > memberExpression,
                                                       TField value)
        {
            var entity = (await DbSet.FirstOrDefaultAsync(filterExpression))
                         ?? throw new KeyNotFoundException(
                                   $"there is no item in {typeof(TEntity).Name} with query : {filterExpression}");

            var memberName = LambdaExpressions.GetName(memberExpression);

            entity.GetType()
            .GetProperty(memberName)
            ?.SetValue(entity, value);
        }
        public virtual Result UpdateOne <TField>(TKey id,
                                                 Expression <Func <TEntity, TField> > memberExpression,
                                                 TField value)
        {
            var entity = base.DbSet.FirstOrDefault(q => q.Id.Equals(id));

            if (entity == null)
            {
                return(Result.Error($"there is no item in {typeof(TEntity).Name} with id : {id}"));
            }

            try
            {
                var memberName = LambdaExpressions.GetName(memberExpression);
                entity.GetType().GetProperty(memberName).SetValue(entity, value);
                var item = base.Context.SaveChanges();
                return(Result.Okay(Messages.ItemUpdated));
                //return Result.Okay($"{item} item successfully updated.");
            }
            catch (Exception ex)
            {
                return(Result.Exception(ex));
            }
        }
예제 #5
0
        public override IElement Evaluate(IElement[] Arguments, Variables Variables)
        {
            double xc, yc;
            double dr;
            long   N;
            int    dimx, dimy;
            int    i, c;
            int    Seed;

            i  = 0;
            c  = Arguments.Length;
            xc = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            yc = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            dr = Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            N  = (long)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            if (N <= 0)
            {
                throw new ScriptRuntimeException("N in calls to IfsFractal() must be a positive integer.", this);
            }

            if (!(Arguments[i].AssociatedObjectValue is Array Functions))
            {
                throw new ScriptRuntimeException("the fifth parameter to IfsFractal must be an array of homogenous 2D-transformations or lambda expressions.", this);
            }

            List <DoubleMatrix>      Matrices          = null;
            List <ILambdaExpression> LambdaExpressions = null;
            List <double>            Weights           = new List <double>();
            List <SKColor>           Colors            = new List <SKColor>();
            string FunctionsExpression = this.Arguments[i++].SubExpression;

            foreach (object f in Functions)
            {
                if (f is DoubleMatrix M)
                {
                    if (!(LambdaExpressions is null))
                    {
                        throw new ScriptRuntimeException("Cannot mix homogenous 2D-transforms with lambda expressions.", this);
                    }

                    if (Matrices is null)
                    {
                        Matrices = new List <DoubleMatrix>();
                    }

                    Matrices.Add(M);
                    Weights.Add(1);
                    Colors.Add(SKColors.Black);
                }
                else if (f is ILambdaExpression Lambda)
                {
                    if (!(Matrices is null))
                    {
                        throw new ScriptRuntimeException("Cannot mix homogenous 2D-transforms with lambda expressions.", this);
                    }

                    if (LambdaExpressions is null)
                    {
                        LambdaExpressions = new List <ILambdaExpression>();
                    }

                    LambdaExpressions.Add(Lambda);
                    Weights.Add(1);
                    Colors.Add(SKColors.Black);
                }
                else if (f is SKColor || f is string)
                {
                    if (Colors.Count == 0)
                    {
                        throw new ScriptRuntimeException("Color definitions can only be specified after each transformation.", this);
                    }

                    Colors[Colors.Count - 1] = Graph.ToColor(f);
                }
                else
                {
                    try
                    {
                        double d = Expression.ToDouble(f);

                        if (Weights.Count == 0)
                        {
                            throw new ScriptRuntimeException("Weight definitions can only be specified after each transformation.", this);
                        }

                        Weights[Weights.Count - 1] = d;
                    }
                    catch (Exception)
                    {
                        throw new ScriptRuntimeException("The fifth parameter to IfsFractal must be an array of homogenous 2D-transformations or lambda expressions, optionally followed by their corresponding weights and/or colors.", this);
                    }
                }
            }

            if (i < c)
            {
                dimx = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimx = 320;
            }

            if (i < c)
            {
                dimy = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                dimy = 200;
            }

            if (i < c)
            {
                Seed = (int)Expression.ToDouble(Arguments[i++].AssociatedObjectValue);
            }
            else
            {
                lock (gen)
                {
                    Seed = gen.Next();
                }

                Variables.ConsoleOut.WriteLine("Seed = " + Seed.ToString(), Variables);
            }

            if (i < c)
            {
                throw new ScriptRuntimeException("Parameter mismatch in call to IfsFractal(xc,yc,dr,N,Transforms[,dimx[,dimy[,Seed]]]).",
                                                 this);
            }

            if (dimx <= 0 || dimx > 5000 || dimy <= 0 || dimy > 5000)
            {
                throw new ScriptRuntimeException("Image size must be within 1x1 to 5000x5000", this);
            }

            if (!(Matrices is null))
            {
                return(CalcIfs(xc, yc, dr, N, Matrices.ToArray(), Weights.ToArray(), Colors.ToArray(),
                               dimx, dimy, Seed, this, this.FractalZoomScript,
                               new object[] { dimx, dimy, N, FunctionsExpression, Seed }));
            }