Exemplo n.º 1
0
        public IEnumerable <int> InsertRange(IEnumerable <DIn> entities)
        {
            var res = entities.Select(u => ObjectHelpers.MapTo <T>(u));

            _genericRepository.InsertRange(res).Wait();
            return(res.Select(u => u.Id));
        }
Exemplo n.º 2
0
        public Listener(Uri url, DynamicObject opts, Connection callback)
        {
            listener = new HttpListener();
            listener.Prefixes.Add(url.AbsoluteUri);
            listener.Start();
            Port = url.Port;
            Dispatcher dispatcher       = Dispatcher.CurrentDispatcher;
            var        acceptConnection = new Action <HttpListenerContext>((HttpListenerContext context) =>
            {
                var request  = new Request(context.Request);
                var response = new Response(context.Response);

                if (opts != null)
                {
                    var keepAlive = ObjectHelpers.GetProperty(opts, "keepAlive");
                    if (!(keepAlive is Undefined) && (bool)keepAlive == true)
                    {
                        context.Response.KeepAlive = true;
                    }
                }
                callback.Write(request, response);
            });

            acceptLoop = Task.Run(async() =>
            {
                while (listener.IsListening)
                {
                    var context = await listener.GetContextAsync();
                    dispatcher.Invoke(acceptConnection, context);
                }
            });
        }
Exemplo n.º 3
0
        public int Insert(DIn entity)
        {
            var res = ObjectHelpers.MapTo <T>(entity);

            _genericRepository.Insert(res).Wait();
            return(res.Id);
        }
Exemplo n.º 4
0
 public void Alert(string msg)
 {
     if (webPage.OnAlert != null)
     {
         ObjectHelpers.DynamicInvoke(webPage.OnAlert, msg);
     }
 }
Exemplo n.º 5
0
 public override bool Equals(object obj)
 {
     return(ObjectHelpers.Equals(this, obj,
                                 x => x.PropertyKey,
                                 x => x.Name,
                                 x => x._expectedTypes));
 }
Exemplo n.º 6
0
 public void Write(string data)
 {
     if (data != null && data.Length > 0)
     {
         ObjectHelpers.DynamicInvoke(callback, data);
     }
 }
Exemplo n.º 7
0
 public void Write(params dynamic[] data)
 {
     foreach (var cb in callbacks)
     {
         ObjectHelpers.DynamicInvoke(cb, data);
     }
 }
Exemplo n.º 8
0
        public virtual async Task <HttpResponseMessage> ResultAsync(CancellationToken token)
        {
            HttpResponseMessage response = null;

            using (_tokenSource = ObjectHelpers.GetCancellationTokenSource(token))
            {
                Settings.Token = _tokenSource.Token;

                try
                {
                    response = await RecursiveResultAsync(Settings.Token);
                }
                catch (OperationCanceledException)
                {
                    if (!Settings.SuppressCancellationErrors)
                    {
                        throw;
                    }
                }
            }

            Reset();

            return(response);
        }
Exemplo n.º 9
0
 public void ConsoleMessage(string msg, int line, string source)
 {
     if (webPage.OnConsoleMessage != null)
     {
         ObjectHelpers.DynamicInvoke(webPage.OnConsoleMessage, msg, line, source);
     }
 }
 public IQueryable <PermissionDTO> GetPermissionsOfRole(string roleName)
 {
     if (!RolesRepository.CheckRoleExists(roleName))
     {
         return(null);
     }
     return(PermissionsRepository.GetPermissionsOfRole(roleName).Select(x => ObjectHelpers.MapTo <PermissionDTO>(x)));
 }
Exemplo n.º 11
0
 string ValueToStrings()
 {
     if (value != null && value.GetType().IsPrimitive)
     {
         return(value.ToString());
     }
     return(ObjectHelpers.IdentityToString(value));
 }
Exemplo n.º 12
0
 public override bool Equals(object obj)
 {
     return(ObjectHelpers.Equals(this, obj,
                                 x => x.cbSize,
                                 x => x.classGuid,
                                 x => x.devInst,
                                 x => x.reserved));
 }
Exemplo n.º 13
0
 public bool Confirm(string msg)
 {
     if (webPage.OnConfirm != null)
     {
         return((bool)ObjectHelpers.DynamicInvoke(webPage.OnConfirm, msg));
     }
     return(false);
 }
Exemplo n.º 14
0
 public string Prompt(string msg, string defaultVal)
 {
     if (webPage.OnPrompt != null)
     {
         return((string)ObjectHelpers.DynamicInvoke(webPage.OnPrompt, msg, defaultVal));
     }
     return(null);
 }
Exemplo n.º 15
0
 public dynamic CallPhantom(dynamic data)
 {
     if (webPage.OnCallback != null)
     {
         return(ObjectHelpers.DynamicInvoke(webPage.OnCallback, data));
     }
     return(null);
 }
Exemplo n.º 16
0
 public override int GetHashCode()
 {
     return(ObjectHelpers.GetHashCode(this,
                                      x => x.cbSize,
                                      x => x.classGuid,
                                      x => x.devInst,
                                      x => x.reserved));
 }
Exemplo n.º 17
0
        public void Update(int menuItemId, MenuItemRequestDTO entity)
        {
            MenuItem oldItem = menuItemRepository.Get(menuItemId);
            MenuItem newItem = mapper.Map <MenuItemRequestDTO, MenuItem>(entity);

            newItem.Id = menuItemId;
            ObjectHelpers.UpdateObjects(oldItem, newItem);
            menuItemRepository.Update(oldItem);
        }
Exemplo n.º 18
0
            // See also e.g. Remotion.Linq.Clauses.ExpressionTreeVisitors.FormattingExpressionTreeVisitor
            // for another example of this technique.

            protected override Expression VisitConstantExpression(ConstantExpression expression)
            {
                if (expression.Value.IsProxy())
                {
                    return(Expression.Parameter(expression.Type, ObjectHelpers.IdentityToString(expression.Value)));
                }

                return(base.VisitConstantExpression(expression));
            }
Exemplo n.º 19
0
        public static Object Cholesky(Double[,] matrix)
        {
            var chol = new CholeskyDecomposition(matrix);

            return(ObjectHelpers.CreateObject(
                       "l", chol.L,
                       "spd", chol.IsSpd
                       ));
        }
Exemplo n.º 20
0
        public void Update(int branchId, BranchRequestDTO entity)
        {
            Branch oldBranch = branchRepository.Get(branchId);
            Branch newBranch = ObjectHelpers.MapTo <Branch>(entity);

            newBranch.Id = branchId;
            ObjectHelpers.UpdateObjects(oldBranch, newBranch);
            branchRepository.Update(oldBranch);
        }
Exemplo n.º 21
0
        public void UpdateAddressOfBranch(int branchId, AddressRequestDTO newAddressDTO)
        {
            var currentAddress = addressRepository.GetAddressOfBranch(branchId);
            var newAddress     = ObjectHelpers.MapTo <Address>(newAddressDTO);

            newAddress.BranchId = branchId;
            newAddress.District = newAddressDTO.District.ToEnum <Districts>();
            ObjectHelpers.UpdateObjects(currentAddress, newAddress);
            addressRepository.Update(currentAddress);
        }
Exemplo n.º 22
0
        public IActionResult GetEnumValues([FromQuery] string EnumName)
        {
            var res = ObjectHelpers.GetEnumOptions(EnumName);

            if (res == null)
            {
                return(NotFound());
            }
            return(Ok(res));
        }
Exemplo n.º 23
0
        public static Object Qr(Double[,] matrix)
        {
            var qr = QRDecomposition.Create(matrix);

            return(ObjectHelpers.CreateObject(
                       "q", qr.Q,
                       "r", qr.R,
                       "full", qr.HasFullRank
                       ));
        }
Exemplo n.º 24
0
        public static Object Eigen(Double[,] matrix)
        {
            var ev = new Eigenvalues(matrix);

            return(ObjectHelpers.CreateObject(
                       "real", Helpers.ToMatrix(ev.RealEigenvalues),
                       "imag", Helpers.ToMatrix(ev.ImagEigenvalues),
                       "vec", ev.Eigenvectors
                       ));
        }
Exemplo n.º 25
0
        public static Object Givens(Double[,] matrix)
        {
            var qr = new GivensDecomposition(matrix);

            return(ObjectHelpers.CreateObject(
                       "q", qr.Q,
                       "r", qr.R,
                       "full", qr.HasFullRank
                       ));
        }
Exemplo n.º 26
0
        public static Expression <Func <IFields, TDestiny> > GetMemberInit <TDestiny>(IFields fields, bool useXmlAttributes = true)
            where TDestiny : new()
        {
            var typeOfDestiny = typeof(TDestiny);
            var props         = ObjectHelpers.LoadProperties(typeOfDestiny, p => p.CanWrite, useXmlAttributes);

            var typeOfFields  = typeof(IFields);
            var methodField   = typeOfFields.GetMethod("Item");
            var propertyValue = typeof(IField).GetProperty("Value");

            var count       = fields.Count;
            var paramSource = Expression.Parameter(typeOfFields, "fields");
            var bindings    = new List <MemberBinding>(count);

            for (var i = 0; i < count; ++i)
            {
                var          field = fields.Item(i);
                PropertyInfo propertyInfo;

                if (!props.TryGetValue(field.Name, out propertyInfo))
                {
                    continue;
                }

                MemberBinding binding;
                var           value = Expression.Property(
                    Expression.Call(paramSource, methodField, Expression.Constant(i, ObjectHelpers.TypeOfObject)), propertyValue);

                if (propertyInfo.PropertyType.Name == "Boolean" && field.Type == BoFieldTypes.db_Alpha && field.Size == 1)
                {
                    binding = Expression.Bind(
                        propertyInfo,
                        Expression.Equal(Expression.Convert(value, ObjectHelpers.TypeOfString), Expression.Constant("Y")));
                    //binding = Expression.Bind(propertyInfo, Expression.Condition(
                    //	Expression.Equal(
                    //		Expression.Convert(value, typeOfString),
                    //		Expression.Constant("Y")),
                    //	Expression.Constant(true),
                    //	Expression.Constant(false)));
                }
                else
                {
                    binding = Expression.Bind(propertyInfo, Expression.Convert(value, propertyInfo.PropertyType));
                }

                bindings.Add(binding);
            }

            var lambda = Expression.Lambda <Func <IFields, TDestiny> >(
                Expression.MemberInit(Expression.New(typeOfDestiny), bindings),
                new[] { paramSource });

            return(lambda);
        }
Exemplo n.º 27
0
        public static Object Householder(Double[,] matrix)
        {
            var qr = new HouseholderDecomposition(matrix);

            return(ObjectHelpers.CreateObject(
                       "q", qr.Q,
                       "r", qr.R,
                       "h", qr.H,
                       "full", qr.HasFullRank
                       ));
        }
Exemplo n.º 28
0
        public static Object Lu(Double[,] matrix)
        {
            var lu = new LUDecomposition(matrix);

            return(ObjectHelpers.CreateObject(
                       "l", lu.L,
                       "u", lu.U,
                       "pivot", lu.Pivot,
                       "singular", !lu.IsNonSingular
                       ));
        }
Exemplo n.º 29
0
        public static void FromObject <TSource>(UserDataSources destiny, TSource source, bool useXmlAttributes = true)
            where TSource : class
        {
            if (destiny == null)
            {
                throw new ArgumentNullException("destiny");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var props = ObjectHelpers.LoadProperties(source.GetType(), p => p.CanRead, useXmlAttributes);

            for (var index = 0; index < destiny.Count; ++index)
            {
                var          item = destiny.Item(index);
                PropertyInfo propertyInfo;

                if (!props.TryGetValue(item.UID, out propertyInfo))
                {
                    continue;
                }

                var value = propertyInfo.GetValue(source, null);

                if (value == null)
                {
                    item.Value = String.Empty;
                }
                else
                {
                    bool nullable;
                    var  type = ObjectHelpers.GetSpecificType(propertyInfo.PropertyType, out nullable);

                    if (nullable && value.Equals(null))
                    {
                        item.Value = String.Empty;
                    }
                    else if (type == ObjectHelpers.TypeOfBoolean)
                    {
                        item.Value = value.Equals(true) ? "Y" : "N";
                    }
                    else
                    {
                        var convertible = value as IConvertible;

                        item.Value = convertible != null
                                                        ? convertible.ToString(CultureInfo.InvariantCulture)
                                                        : value.ToString();
                    }
                }
            }
        }
Exemplo n.º 30
0
        public static Object Svd(Double[,] matrix)
        {
            var svd = new SingularValueDecomposition(matrix);

            return(ObjectHelpers.CreateObject(
                       "condition", svd.Condition,
                       "s", svd.S,
                       "v", svd.V,
                       "u", svd.U,
                       "singular", svd.SingularValues
                       ));
        }