示例#1
0
        /// <summary>
        ///     Executes the command against the connection. reads and Creates Typed objects from the result.
        ///
        /// </summary>
        /// <typeparam name="TType">The type of the t type.</typeparam>
        /// <param name="queryConditions">The query conditions.</param>
        /// <param name="logic">The logic.</param>
        /// <returns>IEnumerable&lt;TType&gt;.</returns>
        public IEnumerable <TType> ExecuteReader <TType>(MKCommandParameterCollection queryConditions, MKQueryLogicOperators logic)
        {
            var propList = string.Join(",", MKResponseParser.GetMkPropList <TType>());
            var rows     = ExecuteReader(propList, queryConditions, logic);

            var result = MKResponseParser.GetList <TType>(rows);

            return(result);
        }
示例#2
0
        /// <summary>
        ///     Excutes CommandText for read
        /// </summary>
        /// <param name="propList">
        ///     Optional:CSV of properies. limits number of Fileds that will be returned in result. it can
        ///     increase performance.
        /// </param>
        /// <param name="queryConditions">
        ///     Optional: Limits rows by condition on fields. Default logic is AND. You can change it in
        ///     Logic argument of this method
        /// </param>
        /// <param name="logic">The logic.</param>
        /// <returns>A collection of string in raw format of API result.</returns>
        public IEnumerable <string> ExecuteReader(string propList = null,
                                                  MKCommandParameterCollection queryConditions = null, MKQueryLogicOperators logic = MKQueryLogicOperators.And)
        {
            verifyConnection();

            if (!string.IsNullOrEmpty(propList))
            {
                Parameters.Add(".proplist", propList);
            }
            //*******************************************

            if (CommandText.Contains(@"/where/"))
            {
                if (queryConditions == null)
                {
                    queryConditions = new MKCommandParameterCollection();
                }
                queryConditions.AddRange(getCommandTextQueries(CommandText));
            }

            if (queryConditions != null)
            {
                foreach (var q in queryConditions)
                {
                    q.Name = "?" + q.Name;
                    Parameters.Add(q);
                }
                if (queryConditions.Count > 1)
                {
                    switch (logic)
                    {
                    case MKQueryLogicOperators.And:
                        Parameters.Add("?#", "&");
                        break;

                    case MKQueryLogicOperators.Or:
                        Parameters.Add("?#", "|");

                        break;
                    }
                }
            }

            sendCommand();
            var res = Connection.Read();

            checkResponse(res);
            return(res);
        }
示例#3
0
        /// <summary>
        ///     Gets the command text queries.
        /// </summary>
        /// <param name="commandText">The command text.</param>
        /// <returns>MKCommandParameterCollection.</returns>
        private MKCommandParameterCollection getCommandTextQueries(string commandText)
        {
            var query      = new MKCommandParameterCollection();
            var idx        = commandText.IndexOf(@"/where/");
            var parameters = commandText.Substring(idx, commandText.Length - idx)
                             .Replace(@"/where/", "")
                             .Split('=', ',');

            CommandText = commandText.Substring(0, idx);
            for (var i = 0; i < parameters.Length; i += 2)
            {
                query.Add(parameters[i], parameters[i + 1]);
            }

            return(query);
        }
示例#4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MKCommand" /> class.
 /// </summary>
 public MKCommand()
 {
     Parameters = new MKCommandParameterCollection();
 }