public DocumentDbTests.Metadata.MyTrackedDoc Resolve(System.Data.Common.DbDataReader reader)
        {
            var id = reader.GetFieldValue <System.Guid>(0);

            if (_identityMap.TryGetValue(id, out var existing))
            {
                return(existing);
            }

            DocumentDbTests.Metadata.MyTrackedDoc document;
            document = _serializer.FromJson <DocumentDbTests.Metadata.MyTrackedDoc>(reader, 1);
            if (!reader.IsDBNull(2))
            {
                var correlationId = reader.GetFieldValue <string>(2);
                document.CorrelationId = correlationId;
            }
            if (!reader.IsDBNull(3))
            {
                var causationId = reader.GetFieldValue <string>(3);
                document.CausationId = causationId;
            }
            if (!reader.IsDBNull(4))
            {
                var lastModifiedBy = reader.GetFieldValue <string>(4);
                document.LastModifiedBy = lastModifiedBy;
            }
            _session.MarkAsDocumentLoaded(id, document);
            _identityMap[id] = document;
            StoreTracker(_session, document);
            return(document);
        }
Exemplo n.º 2
0
        public SignalProp getCurSigProp()
        {
            SignalProp   prop = null;
            String       sql  = " SELECT s.lampId, s.signalName, s.type, s.state, c.state as specState, direction, dir_to, s.ip FROM cursignal c LEFT JOIN signal s ON c.lampId=s.lampId AND c.type=1 ";
            MySqlCommand cmd  = new MySql.Data.MySqlClient.MySqlCommand(sql, myConn);

            System.Data.Common.DbDataReader reader = cmd.ExecuteReader();
            try
            {
                if (reader.Read())
                {
                    prop            = new SignalProp();
                    prop.SignalID   = reader.GetString(0).ToUpper();
                    prop.SignalName = DBStringToNormal(reader.GetString(1));
                    prop.Type       = reader.IsDBNull(2)? (byte)0 : (byte)reader.GetInt16(2);
                    prop.State      = reader.GetString(3);
                    prop.SpecState  = reader.IsDBNull(4) ? (byte)0 : (byte)reader.GetInt16(4);
                    prop.DirFrom    = reader.IsDBNull(5) ? (byte)0 : (byte)reader.GetInt16(5);
                    prop.DirTo      = reader.IsDBNull(6) ? (byte)0 : (byte)reader.GetInt16(6);
                    prop.Ip         = reader.GetString(7);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                reader.Close();
                Trace.TraceError("get cur signal prop " + e.StackTrace);
            }

            return(prop);
        }
Exemplo n.º 3
0
        public override void ApplyReaderDataToEvent(System.Data.Common.DbDataReader reader, Marten.Events.IEvent e)
        {
            if (!reader.IsDBNull(3))
            {
                var sequence = reader.GetFieldValue <long>(3);
                e.Sequence = sequence;
            }
            if (!reader.IsDBNull(4))
            {
                var id = reader.GetFieldValue <System.Guid>(4);
                e.Id = id;
            }
            var streamId = reader.GetFieldValue <System.Guid>(5);

            e.StreamId = streamId;
            if (!reader.IsDBNull(6))
            {
                var version = reader.GetFieldValue <long>(6);
                e.Version = version;
            }
            if (!reader.IsDBNull(7))
            {
                var timestamp = reader.GetFieldValue <System.DateTimeOffset>(7);
                e.Timestamp = timestamp;
            }
            if (!reader.IsDBNull(8))
            {
                var tenantId = reader.GetFieldValue <string>(8);
                e.TenantId = tenantId;
            }
            var isArchived = reader.GetFieldValue <bool>(9);

            e.IsArchived = isArchived;
        }
Exemplo n.º 4
0
 public static string SafeGetString(this System.Data.Common.DbDataReader reader, int colIndex)
 {
     if (!reader.IsDBNull(colIndex))
     {
         return(reader.GetString(colIndex));
     }
     return(string.Empty);
 }
Exemplo n.º 5
0
 public static T Gr <T>(this System.Data.Common.DbDataReader Dr, int I)
 {
     if (Dr.IsDBNull(I))
     {
         return(default(T));
     }
     return((T)Dr.GetValue(I));
 }
Exemplo n.º 6
0
 public static decimal GetDecValue(System.Data.Common.DbDataReader reader, int ordinal)
 {
     if (reader.IsDBNull(ordinal))
     {
         return(0);
     }
     else
     {
         return(reader.GetDecimal(ordinal));
     }
 }
Exemplo n.º 7
0
 public static int GetRefValue(System.Data.Common.DbDataReader reader, int ordinal)
 {
     if (reader.IsDBNull(ordinal))
     {
         return(0);
     }
     else
     {
         return(reader.GetInt32(ordinal));
     }
 }
 public DocumentDbTests.Metadata.MyTrackedDoc Resolve(System.Data.Common.DbDataReader reader)
 {
     DocumentDbTests.Metadata.MyTrackedDoc document;
     document = _serializer.FromJson <DocumentDbTests.Metadata.MyTrackedDoc>(reader, 0);
     if (!reader.IsDBNull(1))
     {
         var correlationId = reader.GetFieldValue <string>(1);
         document.CorrelationId = correlationId;
     }
     if (!reader.IsDBNull(2))
     {
         var causationId = reader.GetFieldValue <string>(2);
         document.CausationId = causationId;
     }
     if (!reader.IsDBNull(3))
     {
         var lastModifiedBy = reader.GetFieldValue <string>(3);
         document.LastModifiedBy = lastModifiedBy;
     }
     return(document);
 }
Exemplo n.º 9
0
        public List <SignalPos> getPosList()
        {
            // position// position
            List <SignalPos> posList = new List <SignalPos>();

            String       sql = "SELECT lampId, compass, dir, x, y  FROM signalPos";
            MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, myConn);

            System.Data.Common.DbDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                SignalPos pos = new SignalPos();
                pos.LampId  = reader.GetString(0).Trim().ToUpper(); //.Replace('-', '_')
                pos.Compass = reader.IsDBNull(1) ? 1 : reader.GetInt32(1);
                pos.Dir     = reader.IsDBNull(2) ? 1 : reader.GetInt32(2);
                pos.X       = reader.IsDBNull(3) ? 1 : reader.GetInt32(3);
                pos.Y       = reader.IsDBNull(4) ? 1 : reader.GetInt32(4);
                posList.Add(pos);
            }
            reader.Close();

            return(posList);
        }
Exemplo n.º 10
0
        public List <SignalProp> getSignalList()
        {
            List <SignalProp> list = new List <SignalProp>();

            String       sql = " SELECT lampId, signalName, type, ip  FROM signal WHERE type IN (1, 4, 5) ";
            MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, myConn);

            System.Data.Common.DbDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                SignalProp prop = new SignalProp();

                prop.SignalID   = reader.GetString(0).Trim().ToUpper(); //.Replace('-', '_')
                prop.SignalName = DBStringToNormal(reader.GetString(1).Trim());
                prop.Type       = reader.IsDBNull(2) ? (byte)1 : (byte)reader.GetInt32(2);
                prop.Ip         = reader.IsDBNull(3) ? "" : reader.GetString(3).Trim();

                list.Add(prop);
            }
            reader.Close();

            return(list);
        }
Exemplo n.º 11
0
        private static void QueryEmployee(Oracle.DataAccess.Client.OracleConnection conn)
        {
            string sql = "Select Emp_Id, Emp_No, Emp_Name, Mng_Id from Employee";

            // Tạo một đối tượng Command.
            Oracle.DataAccess.Client.OracleCommand cmd = new Oracle.DataAccess.Client.OracleCommand();

            // Liên hợp Command với Connection.
            cmd.Connection  = conn;
            cmd.CommandText = sql;


            using (System.Data.Common.DbDataReader reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        // Chỉ số (index) của cột Emp_ID trong câu lệnh SQL.
                        int empIdIndex = reader.GetOrdinal("Emp_Id"); // 0


                        long empId = Convert.ToInt64(reader.GetValue(0));

                        // Chỉ số của cột Emp_No là 1.
                        string empNo        = reader.GetString(1);
                        int    empNameIndex = reader.GetOrdinal("Emp_Name");// 2
                        string empName      = reader.GetString(empNameIndex);


                        int mngIdIndex = reader.GetOrdinal("Mng_Id");

                        long?mngId = null;

                        if (!reader.IsDBNull(mngIdIndex))
                        {
                            mngId = Convert.ToInt64(reader.GetValue(mngIdIndex));
                        }
                        Console.WriteLine("--------------------");
                        Console.WriteLine("empIdIndex:" + empIdIndex);
                        Console.WriteLine("EmpId:" + empId);
                        Console.WriteLine("EmpNo:" + empNo);
                        Console.WriteLine("EmpName:" + empName);
                        Console.WriteLine("MngId:" + mngId);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public static string GetReaderValueString(System.Data.Common.DbDataReader reader, string name)
        {
            var ordinal = reader.GetOrdinal(name);

            if (reader.IsDBNull(ordinal))
            {
                return(null);
            }
            try
            {
                return(reader.GetString(ordinal));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(null);
        }
Exemplo n.º 13
0
 private static Domain.IncomeGroupLimitGroup loadIncomeGroup(System.Data.Common.DbDataReader reader)
 {
     Domain.IncomeGroupLimitGroup income = new Domain.IncomeGroupLimitGroup();
     income.Limitation = new List <Domain.IncomeGroupLimit>();
     Domain.IncomeGroupLimit limit = null;
     while (reader.Read())
     {
         var currentId = reader.GetGuid(0);
         if (income.Id != currentId)
         {
             income.Id            = currentId;
             income.CompanyId     = reader.GetGuid(1);
             income.IncomeGroupId = reader.IsDBNull(2) ? (Guid?)null : reader.GetGuid(2);
             income.Remark        = reader.GetString(3);
             income.Limitation    = new List <Domain.IncomeGroupLimit>();
         }
         var currlimitId = reader.GetGuid(4);
         if (!income.Limitation.Any(it => it.Id == currlimitId))
         {
             limit               = new Domain.IncomeGroupLimit();
             limit.Id            = currlimitId;
             limit.IncomeId      = reader.GetGuid(5);
             limit.Type          = (Common.Enums.PeriodType)reader.GetByte(6);
             limit.Price         = reader.GetInt32(7);
             limit.Airlines      = reader.GetString(12);
             limit.IsOwnerPolicy = reader.GetBoolean(13);
             limit.Period        = new List <Domain.IncomeGroupPeriod>();
             income.Limitation.Add(limit);
         }
         Domain.IncomeGroupPeriod period = new Domain.IncomeGroupPeriod();
         period.DeductId    = reader.GetGuid(8);
         period.StartPeriod = reader.GetDecimal(9);
         period.EndPeriod   = reader.GetDecimal(10);
         period.Period      = reader.GetDecimal(11);
         limit.Period.Add(period);
     }
     return(income);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Gets an int column.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="ordinal"></param>
 /// <returns></returns>
 public static Int32?GetNInt32(this System.Data.Common.DbDataReader reader, int ordinal)
 {
     return(reader.IsDBNull(ordinal) ? (int?)null : reader.GetInt32(ordinal));
 }
Exemplo n.º 15
0
        /// <summary>
        /// Gets an int column. Slower then GetOrdinal + GetInt32
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Int32?GetNInt32(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (int?)null : reader.GetInt32(ordinal));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets a byte array column.
        /// Use this for small byte array only, such as timestamps
        ///
        /// Slower then GetOrdinal + GetByteArray(ordinal)
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name">The name of the column</param>
        /// <returns></returns>
        public static byte[]? GetByteArray(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? null : (byte[])reader.GetValue(ordinal));
        }
Exemplo n.º 17
0
 /// <summary>
 /// Gets a byte array column.
 /// Use this for small byte array only, such as timestamps
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="ordinal"></param>
 /// <returns></returns>
 public static byte[]? GetByteArray(this System.Data.Common.DbDataReader reader, int ordinal)
 {
     return(reader.IsDBNull(ordinal) ? null : (byte[])reader.GetValue(ordinal));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Gets a decimal column.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="ordinal"></param>
 /// <returns></returns>
 public static decimal?GetNDecimal(this System.Data.Common.DbDataReader reader, int ordinal)
 {
     return(reader.IsDBNull(ordinal) ? (decimal?)null : reader.GetDecimal(ordinal));
 }
Exemplo n.º 19
0
        /// <summary>
        /// Gets a datetime column. Slower then GetOrdinal + GetDateTime
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static DateTime?GetNDateTime(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (DateTime?)null : reader.GetDateTime(ordinal));
        }
Exemplo n.º 20
0
 /// <summary>
 /// Gets a float column.
 /// </summary>
 /// <param name="reader">The db reader</param>
 /// <param name="ordinal">The column number</param>
 /// <returns></returns>
 public static float?GetNFloat(this System.Data.Common.DbDataReader reader, int ordinal)
 {
     return(reader.IsDBNull(ordinal) ? (float?)null : reader.GetFloat(ordinal));
 }
Exemplo n.º 21
0
        /// <summary>
        /// Gets a float column. Slower then GetOrdinal + GetFloat
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static float?GetNFloat(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (float?)null : reader.GetFloat(ordinal));
        }
Exemplo n.º 22
0
 /// <summary>
 /// Gets a bool column.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="ordinal">The column number</param>
 /// <returns></returns>
 public static bool?GetNBoolean(this System.Data.Common.DbDataReader reader, int ordinal)
 {
     return(reader.IsDBNull(ordinal) ? (bool?)null : reader.GetBoolean(ordinal));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Gets a datetime column.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="ordinal"></param>
 /// <returns></returns>
 public static DateTime?GetNDateTime(this System.Data.Common.DbDataReader reader, int ordinal)
 {
     return(reader.IsDBNull(ordinal) ? (DateTime?)null : reader.GetDateTime(ordinal));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Gets a string column. Slower then GetOrdinal + GetString
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string?GetNString(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? null : reader.GetString(ordinal));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Generate CSV formatted output for the given reader.
        /// </summary>
        public string Generate(System.Data.Common.DbDataReader reader)
        {
            var builder = new StringBuilder();

            var schema   = reader.GetSchemaTable();
            var colcount = reader.FieldCount;
            var nullable = new bool[colcount];
            var datatype = new Type[colcount];
            var typename = new string[colcount];

            for (int c = 0; c < colcount; c++)
            {
                nullable[c] = true;
                datatype[c] = reader.GetFieldType(c);
                typename[c] = reader.GetDataTypeName(c);

                if (c == 0)
                {
                    if (this.Settings.AddLineNumbers)
                    {
                        if (this.Settings.QuotedStrings)
                        {
                            builder.Append(this.Settings.StringQuote);
                        }
                        builder.Append("Line");
                        if (this.Settings.QuotedStrings)
                        {
                            builder.Append(this.Settings.StringQuote);
                        }
                        builder.Append(this.Settings.FieldSeparator);
                    }
                }
                else
                {
                    builder.Append(this.Settings.FieldSeparator);
                }
                if (this.Settings.QuotedStrings)
                {
                    builder.Append(this.Settings.StringQuote);
                }
                builder.Append(reader.GetName(c));
                if (this.Settings.QuotedStrings)
                {
                    builder.Append(this.Settings.StringQuote);
                }
            }

            builder.Append(this.Settings.LineSeparator);

            var lineNumber = 0;

            while (reader.Read())
            {
                lineNumber++;

                for (int c = 0; c < colcount; c++)
                {
                    if (c == 0)
                    {
                        if (this.Settings.AddLineNumbers)
                        {
                            builder.Append(lineNumber);
                            builder.Append(this.Settings.FieldSeparator);
                        }
                    }
                    else
                    {
                        builder.Append(this.Settings.FieldSeparator);
                    }

                    if (nullable[c] && reader.IsDBNull(c))
                    {
                    }
                    else
                    {
                        if (datatype[c] == typeof(String))
                        {
                            if (this.Settings.QuotedStrings)
                            {
                                builder.Append(this.Settings.StringQuote);
                            }
                            builder.Append(ToCsvableString(reader.GetString(c)));
                            if (this.Settings.QuotedStrings)
                            {
                                builder.Append(this.Settings.StringQuote);
                            }
                        }
                        else if (datatype[c] == typeof(DateTime))
                        {
                            builder.Append(reader.GetDateTime(c).ToString(this.Settings.DateTimeFormat, this.Settings.FormatProvider));
                        }
                        else if (datatype[c] == typeof(Boolean))
                        {
                            builder.Append(reader.GetBoolean(c) ? this.Settings.BooleanTrue : this.Settings.BooleanFalse);
                        }
                        else
                        {
                            builder.AppendFormat(this.Settings.FormatProvider, "{0}", reader.GetValue(c));
                        }
                    }
                }

                builder.Append(this.Settings.LineSeparator);
            }

            return(builder.ToString());
        }
Exemplo n.º 26
0
        /// <summary>
        /// Gets a decimal column. Slower then GetOrdinal + GetDecimal
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static decimal?GetNDecimal(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (decimal?)null : reader.GetDecimal(ordinal));
        }
Exemplo n.º 27
0
 private String GetString(System.Data.Common.DbDataReader RS, String FiledName)
 {
     return(RS.IsDBNull(RS.GetOrdinal(FiledName)) ? "" : RS[FiledName].ToString());
 }
Exemplo n.º 28
0
 /// <summary>
 /// Gets a string column.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="ordinal"></param>
 /// <returns></returns>
 public static string?GetNString(this System.Data.Common.DbDataReader reader, int ordinal)
 {
     return(reader.IsDBNull(ordinal) ? null : reader.GetString(ordinal));
 }
Exemplo n.º 29
0
        /// <summary>
        /// Gets a bool column. Slower then GetOrdinal + GetBool
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool?GetNBoolean(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (bool?)null : reader.GetBoolean(ordinal));
        }
Exemplo n.º 30
0
        private int GetInt(System.Data.Common.DbDataReader RS, String FiledName)
        {
            int FieldID = RS.GetOrdinal(FiledName);

            return(RS.IsDBNull(FieldID) ? 0 : RS.GetInt32(FieldID));
        }