public static JArray ToJson(this IDataReader dataReader)
        {
            JArray jArray = new JArray();

            try
            {
                while (dataReader.Read())
                {
                    JObject jObject = new JObject();
                    for (int i = 0; i < dataReader.FieldCount; i++)
                    {
                        try
                        {
                            string strKey = dataReader.GetName(i);
                            if (dataReader[i] != DBNull.Value)
                            {
                                object obj = Convert.ChangeType(dataReader[i], dataReader.GetFieldType(i));
                                jObject.Add(strKey, JToken.FromObject(obj));
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                    jArray.Add(jObject);
                }
            }
            catch (Exception ex)
            {
                TaosException.ThrowExceptionForRC(-10001, "ToJson Error", ex);
            }
            return(jArray);
        }
Beispiel #2
0
        /// <summary>
        ///     Throws an exception with a specific Taos error code value.
        /// </summary>
        /// <param name="rc">The Taos error code corresponding to the desired exception.</param>
        /// <param name="db">A handle to database connection.</param>
        /// <remarks>
        ///     No exception is thrown for non-error result codes.
        /// </remarks>
        public static void ThrowExceptionForRC(string _commandText, TaosErrorResult taosError)
        {
            var te = new TaosException(taosError);

            te.Data.Add("commandText", _commandText);
            throw te;
        }
Beispiel #3
0
        public static void ThrowExceptionForRC(int code, string message, Exception ex)
        {
            var te = new TaosException(new TaosErrorResult()
            {
                Code = code, Error = message
            }, ex);

            throw te;
        }
Beispiel #4
0
        public static void ThrowExceptionForRC(IntPtr _taos)
        {
            var te = new TaosException(new TaosErrorResult()
            {
                Code = TDengine.ErrorNo(_taos), Error = TDengine.Error(_taos)
            });

            throw te;
        }
        public static List <T> ToObject <T>(this IDataReader dataReader)
        {
            List <T> jArray = new List <T>();

            try
            {
                var t    = typeof(T);
                var pots = t.GetProperties();
                while (dataReader.Read())
                {
                    T jObject = Activator.CreateInstance <T>();
                    for (int i = 0; i < dataReader.FieldCount; i++)
                    {
                        try
                        {
                            string strKey = dataReader.GetName(i);
                            if (dataReader[i] != DBNull.Value)
                            {
                                var pr = from p in pots where   p.Name == strKey && p.CanWrite select p;
                                if (pr.Any())
                                {
                                    var pi = pr.FirstOrDefault();
                                    pi.SetValue(jObject, Convert.ChangeType(dataReader[i], pi.PropertyType));
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                    jArray.Add(jObject);
                }
            }
            catch (Exception ex)
            {
                TaosException.ThrowExceptionForRC(-10002, $"ToObject<{nameof(T)}>  Error", ex);
            }
            return(jArray);
        }