/// <summary>
 /// Parse parameter
 /// </summary>
 /// <param name="originalParameters">Original parameter</param>
 /// <returns>Return command parameters</returns>
 public static CommandParameters ParseParameters(object originalParameters)
 {
     if (originalParameters == null)
     {
         return(null);
     }
     if (originalParameters is CommandParameters commandParameters)
     {
         return(commandParameters);
     }
     commandParameters = new CommandParameters();
     if (originalParameters is IEnumerable <KeyValuePair <string, string> > stringParametersDict)
     {
         commandParameters.Add(stringParametersDict);
     }
     else if (originalParameters is IEnumerable <KeyValuePair <string, dynamic> > dynamicParametersDict)
     {
         commandParameters.Add(dynamicParametersDict);
     }
     else if (originalParameters is IEnumerable <KeyValuePair <string, object> > objectParametersDict)
     {
         commandParameters.Add(objectParametersDict);
     }
     else if (originalParameters is IEnumerable <KeyValuePair <string, IModifyValue> > modifyParametersDict)
     {
         commandParameters.Add(modifyParametersDict);
     }
     else
     {
         objectParametersDict = originalParameters.ObjectToDcitionary();
         commandParameters.Add(objectParametersDict);
     }
     return(commandParameters);
 }
Example #2
0
        public TopClause(int rowCountLimit, ICommandParameterFactory commandParameterFactory)
        {
            _rowCountLimit = rowCountLimit;

            var parameter = commandParameterFactory.Create("RowCountLimit", _rowCountLimit);

            CommandParameters.Add(parameter);
        }
Example #3
0
        private void GetParam(MethodInfo getServiceMethod, int position, Type parameterType)
        {
            var baseParserType = typeof(IParameterParser <>);
            var parserType     = baseParserType.MakeGenericType(parameterType);
            var parser         = getServiceMethod.Invoke(ServiceProvider, new object[] { parserType });

            if (parser != null)
            {
                try
                {
                    var defaultInstance =
                        parser.GetType().GetMethod("DefaultInstance")?.Invoke(parser, null);

                    var parserParams = new[] { CommandArgs[position], defaultInstance };
                    var result       = parser.GetType().GetMethod("TryGetValue")?.Invoke(parser, parserParams);
                    if (result != null && (bool)result)
                    {
                        var commandParameter =
                            new CommandParameter(position, parserParams[1]);
                        CommandParameters.Add(commandParameter);
                        return;
                    }
                } catch
                {
                    throw new ArgumentException("Wrong parser! WTF??");
                }
            }

            var extendParametrType = typeof(IRawParameterParser <>);

            parserType = extendParametrType.MakeGenericType(parameterType);
            parser     = getServiceMethod.Invoke(ServiceProvider, new object[] { parserType });
            if (parser != null)
            {
                try
                {
                    var defaultInstance =
                        parser.GetType().GetMethod("DefaultInstance")?.Invoke(parser, null);

                    var parserParams = new[] { Update, defaultInstance };
                    var result       = parser.GetType().GetMethod("TryGetValueByRawUpdate")?.Invoke(parser, parserParams);
                    if (result != null && (bool)result)
                    {
                        var commandParameter =
                            new CommandParameter(position, parserParams[1]);
                        CommandParameters.Add(commandParameter);
                    }
                } catch
                {
                    throw new ArgumentException("Wrong parser! WTF??");
                }
            }
        }
Example #4
0
        /// <summary>
        /// Get cmd parameters
        /// </summary>
        /// <returns></returns>
        public CommandParameters GetCommandParameters()
        {
            var parameters = new CommandParameters();
            var propertys  = EntityManager.GetFields(entityType);

            foreach (var property in propertys)
            {
                var value  = GetPropertyValue(property.PropertyName);
                var dbType = LookupDbType(property.DataType, property.PropertyName, false, out ITypeHandler handler);
                parameters.Add(property.PropertyName, value, dbType: dbType);
            }
            return(parameters);
        }
Example #5
0
        /// <summary>
        /// Get cmd parameters
        /// </summary>
        /// <returns></returns>
        public CommandParameters GetCommandParameters()
        {
            var parameters   = new CommandParameters();
            var entityConfig = EntityManager.GetEntityConfiguration(entityType);

            if (entityConfig == null)
            {
                return(parameters);
            }
            foreach (var fieldItem in entityConfig.AllFields)
            {
                var value  = GetValue(fieldItem.Key);
                var dbType = LookupDbType(fieldItem.Value.DataType, fieldItem.Key, false, out ITypeHandler handler);
                parameters.Add(fieldItem.Key, value, dbType: dbType);
            }
            return(parameters);
        }
Example #6
0
        /// <summary>
        /// Construct a new command message
        /// </summary>
        /// <param name="commandID">The command ID</param>
        /// <param name="parameters">The command parameters</param>
        public CommandMessage(string commandID, object parameters = null)
        {
            CommandID  = commandID;
            Parameters = new CommandParameters();

            if (parameters == null)
            {
                return;
            }

            foreach (var prop in parameters.GetType().GetProperties())
            {
                var name = prop.Name;
                var val  = prop.GetValue(parameters);
                Parameters.Add(name, val);
            }
        }
 public UpdateCommandBuilder AppendParameter(string key, object value)
 => this.Chain(() => CommandParameters.Add(key, value));