Ejemplo n.º 1
0
        public async Task <QueryResult <CommonQueueConsumeEndpoint> > QueryByPage(string name, int page, int pageSize)
        {
            QueryResult <CommonQueueConsumeEndpoint> result = new QueryResult <CommonQueueConsumeEndpoint>();

            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _commonQueueConnectionFactory.CreateReadForCommonQueue(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                await using (SqlCommand commond = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran,
                    CommandText = string.Format(@"
		                           select @count= count(*) from [CommonQueueConsumeEndpoint] where [name] like @name
	
                                    select {0} from [CommonQueueConsumeEndpoint] where [name] like @name
                                    order by [sequence]
		                            offset (@pagesize * (@page - 1)) rows 
		                            fetch next @pagesize rows only;"        , StoreHelper.GetCommonQueueConsumeEndpointSelectFields(string.Empty))
                })
                {
                    var parameter = new SqlParameter("@page", SqlDbType.Int)
                    {
                        Value = page
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@pagesize", SqlDbType.Int)
                    {
                        Value = pageSize
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@name", SqlDbType.VarChar, 200)
                    {
                        Value = $"{name.ToSqlLike()}%"
                    };
                    commond.Parameters.Add(parameter);

                    parameter = new SqlParameter("@count", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.Output
                    };
                    commond.Parameters.Add(parameter);

                    await commond.PrepareAsync();

                    SqlDataReader reader = null;

                    await using (reader = await commond.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var endpoint = new CommonQueueConsumeEndpoint();
                            StoreHelper.SetCommonQueueConsumeEndpointSelectFields(endpoint, reader, string.Empty);
                            result.Results.Add(endpoint);
                        }

                        await reader.CloseAsync();

                        result.TotalCount  = (int)commond.Parameters["@count"].Value;
                        result.CurrentPage = page;
                    }
                }
            });

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <CommonMessageClientType> QueryByName(string name)
        {
            CommonMessageClientType type = null;

            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _commonQueueConnectionFactory.CreateReadForCommonQueue(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                await using (SqlCommand commond = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran,
                    CommandText = string.Format(@"select {0},{1} from [CommonMessageClientType] as t join [CommonQueueProductEndpoint] as e on t.endpointid=e.id where t.[name]=@name", StoreHelper.GetCommonQueueConsumeEndpointSelectFields("t"), StoreHelper.GetCommonQueueProductEndpointSelectFields("e"))
                })
                {
                    var parameter = new SqlParameter("@name", SqlDbType.VarChar, 150)
                    {
                        Value = name
                    };
                    commond.Parameters.Add(parameter);

                    await commond.PrepareAsync();

                    SqlDataReader reader = null;

                    await using (reader = await commond.ExecuteReaderAsync())
                    {
                        if (await reader.ReadAsync())
                        {
                            type = new CommonMessageClientType();
                            StoreHelper.SetCommonMessageClientTypeSelectFields(type, reader, "t");
                            type.Endpoint = new CommonQueueProductEndpoint();
                            StoreHelper.SetCommonQueueProductEndpointSelectFields(type.Endpoint, reader, "e");
                        }

                        await reader.CloseAsync();
                    }
                }
            });

            return(type);
        }
Ejemplo n.º 3
0
        public async Task <CommonQueueConsumeEndpoint> QueryByID(Guid id)
        {
            CommonQueueConsumeEndpoint endpoint = null;

            await DBTransactionHelper.SqlTransactionWorkAsync(DBTypes.SqlServer, true, false, _commonQueueConnectionFactory.CreateReadForCommonQueue(), async (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                await using (SqlCommand commond = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    Transaction = sqlTran,
                    CommandText = string.Format(@"select {0} from [CommonQueueConsumeEndpoint] where [id]=@id", StoreHelper.GetCommonQueueConsumeEndpointSelectFields(string.Empty))
                })
                {
                    var parameter = new SqlParameter("@id", SqlDbType.UniqueIdentifier)
                    {
                        Value = id
                    };
                    commond.Parameters.Add(parameter);

                    await commond.PrepareAsync();

                    SqlDataReader reader = null;

                    await using (reader = await commond.ExecuteReaderAsync())
                    {
                        if (await reader.ReadAsync())
                        {
                            endpoint = new CommonQueueConsumeEndpoint();
                            StoreHelper.SetCommonQueueConsumeEndpointSelectFields(endpoint, reader, string.Empty);
                        }

                        await reader.CloseAsync();
                    }
                }
            });

            return(endpoint);
        }