Esempio n. 1
0
        private static IEnumerable <TestCaseData> QueryStatementCases()
        {
            yield return(new TestCaseData(
                             TSql.QueryStatement("text"),
                             new SqlQueryCommand("text", new DbParameter[0], CommandType.Text)));

            yield return(new TestCaseData(
                             TSql.QueryStatement("text", parameters: null),
                             new SqlQueryCommand("text", new DbParameter[0], CommandType.Text)));

            yield return(new TestCaseData(
                             TSql.QueryStatement("text", new { }),
                             new SqlQueryCommand("text", new DbParameter[0], CommandType.Text)));

            yield return(new TestCaseData(
                             TSql.QueryStatement("text", new { Parameter = new SqlParameterValueStub() }),
                             new SqlQueryCommand("text", new[]
            {
                new SqlParameterValueStub().ToDbParameter("@Parameter")
            }, CommandType.Text)));

            yield return(new TestCaseData(
                             TSql.QueryStatement("text", new { Parameter1 = new SqlParameterValueStub(), Parameter2 = new SqlParameterValueStub() }),
                             new SqlQueryCommand("text", new[]
            {
                new SqlParameterValueStub().ToDbParameter("@Parameter1"),
                new SqlParameterValueStub().ToDbParameter("@Parameter2")
            }, CommandType.Text)));
        }
        private void DispatchCommands()
        {
            if (!_isLive || Interlocked.CompareExchange(ref _isDispatching, 1, 0) != 0)
            {
                return;
            }

            var candidates = Enumerable.Repeat(new { Id = default(Guid), CausationId = default(Guid) }, 0).ToList();

            using (var reader = _queryExecutor.ExecuteReader(TSql.QueryStatement(@"SELECT [Id], [CausationId] FROM [ApprovalProcess] WHERE [DispatchAcknowledged] = 0 AND ([Dispatched] IS NULL OR [Dispatched] < DATEADD(MINUTE, -5, GETDATE()))")))
            {
                candidates = reader.Cast <IDataRecord>()
                             .Select(record => new { Id = record.GetGuid(0), CausationId = record.GetGuid(1) })
                             .ToList();
            }

            foreach (var candidate in candidates)
            {
                var newCausationId = ApprovalProcessorConstants.DeterministicGuid.Create(candidate.CausationId);

                _bus.Publish(new MarkApprovalAccepted
                {
                    Id = candidate.Id,
                    ReferenceNumber = GuidEncoder.Encode(candidate.CausationId)
                }, context => context.SetHeader(Constants.CausationIdKey, newCausationId.ToString()));

                _queryExecutor.ExecuteNonQuery(TSql.NonQueryStatement(@"UPDATE [ApprovalProcess] SET [Dispatched] = GETDATE() WHERE [Id] = @P1", new { P1 = TSql.UniqueIdentifier(candidate.Id) }));
            }

            Interlocked.Exchange(ref _isDispatching, 0);
        }
        public string GetCheckpoint()
        {
            const string sql = @"SELECT [CheckpointToken] FROM [StoreCheckpoint] WHERE [StoreId] = @P1";

            using (var reader = _executer.ExecuteReader(TSql.QueryStatement(sql, new { P1 = TSql.NVarCharMax(_tenantId) })))
            {
                if (reader.IsClosed)
                {
                    return(null);
                }
                return(reader.Read() ? reader.GetString(0) : null);
            }
        }
        public IEnumerable <string> GetTenantIds()
        {
            using (var reader = _executer.ExecuteReader(TSql.QueryStatement(@"SELECT [StoreId] FROM [StoreCheckpoint]")))
            {
                if (reader.IsClosed)
                {
                    yield break;
                }

                while (reader.Read())
                {
                    yield return(reader.GetString(0));
                }
            }
        }
 public void QueryParameterCountLimitedTo2098()
 {
     Assert.Throws <ArgumentException>(() => TSql.QueryStatement("", ParameterCountLimitedExceeded.Instance));
 }