Beispiel #1
0
        internal static DbCommand BuildIncomingStorageCommand(IEnumerable <Envelope> envelopes, DatabaseSettings settings)
        {
            var cmd     = settings.CreateEmptyCommand();
            var builder = new CommandBuilder(cmd);

            foreach (var envelope in envelopes)
            {
                envelope.EnsureData();

                var id       = builder.AddParameter(envelope.Id);
                var status   = builder.AddParameter(envelope.Status);
                var owner    = builder.AddParameter(envelope.OwnerId);
                var attempts = builder.AddParameter(envelope.Attempts);
                var time     = builder.AddParameter(envelope.ExecutionTime);
                var body     = builder.AddParameter(envelope.Serialize());


                builder.Append(
                    $"insert into {settings.SchemaName}.{IncomingTable} (id, status, owner_id, execution_time, attempts, body) values (@{id.ParameterName}, @{status.ParameterName}, @{owner.ParameterName}, @{time.ParameterName}, @{attempts.ParameterName}, @{body.ParameterName});");
            }

            builder.Apply();

            return(cmd);
        }
Beispiel #2
0
        public static DbCommand BuildOutgoingStorageCommand(Envelope[] envelopes, int ownerId,
                                                            DatabaseSettings settings)
        {
            var cmd     = settings.CreateEmptyCommand();
            var builder = new CommandBuilder(cmd);

            builder.AddNamedParameter("owner", ownerId).DbType = DbType.Int32;

            foreach (var envelope in envelopes)
            {
                var id          = builder.AddParameter(envelope.Id);
                var destination = builder.AddParameter(envelope.Destination.ToString());
                var deliverBy   = builder.AddParameter(envelope.DeliverBy);
                var body        = builder.AddParameter(envelope.Serialize());

                builder.Append(
                    $"insert into {settings.SchemaName}.{OutgoingTable} (id, owner_id, destination, deliver_by, body) values (@{id.ParameterName}, @owner, @{destination.ParameterName}, @{deliverBy.ParameterName}, @{body.ParameterName});");
            }

            builder.Apply();
            return(cmd);
        }