Пример #1
0
 /// <summary>
 /// 赋值应用程序限流数据操作
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="reader"></param>
 /// <param name="prefix"></param>
 public static void SetApplicationLimitStoreSelectFields(ApplicationLimit limit, DbDataReader reader, string prefix)
 {
     limit.ID            = (Guid)reader[string.Format("{0}id", prefix)];
     limit.Name          = reader[string.Format("{0}name", prefix)].ToString();
     limit.Type          = reader[string.Format("{0}type", prefix)].ToString();
     limit.Configuration = reader[string.Format("{0}configuration", prefix)].ToString();
     limit.CreateTime    = (DateTime)reader[string.Format("{0}createtime", prefix)];
     limit.ModifyTime    = (DateTime)reader[string.Format("{0}modifytime", prefix)];
 }
Пример #2
0
        public ApplicationLimit QueryByNameSync(string name)
        {
            ApplicationLimit limit = null;

            DBTransactionHelper.SqlTransactionWork(DBTypes.SqlServer, true, false, _distributeConnectionFactory.CreateReadForDistributeCoordinator(), (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    CommandText = string.Format(@"SELECT {0} FROM [ApplicationLimit] WHERE name=@name;", StoreHelper.GetApplicationLockStoreSelectFields(string.Empty)),
                    Transaction = sqlTran
                })
                {
                    var parameter = new SqlParameter("@name", SqlDbType.VarChar, 150)
                    {
                        Value = name
                    };
                    command.Parameters.Add(parameter);
                    command.Prepare();
                    SqlDataReader reader = null;

                    using (reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            limit = new ApplicationLimit();
                            StoreHelper.SetApplicationLimitStoreSelectFields(limit, reader, string.Empty);
                        }
                        reader.Close();
                    }
                }
            });
            return(limit);
        }