Esempio n. 1
0
 /// <summary>
 /// Stores the given timeout in memory
 /// </summary>
 public void Add(Timeout.Timeout newTimeout)
 {
     lock (listLock)
     {
         timeouts.Add(newTimeout);
     }
 }
		/// <summary>
		/// Adds the given timeout to the table specified by <see cref="TimeoutsTableName"/>
		/// </summary>
		public void Add(Timeout.Timeout newTimeout)
		{
			using (var connection = factory.OpenConnection())
			using (var command = connection.CreateCommand())
			{
				var parameters = new Dictionary<string, object>
					{
						{ "time_to_return", newTimeout.TimeToReturn },
						{ "correlation_id", newTimeout.CorrelationId },
						{ "saga_id", newTimeout.SagaId },
						{ "reply_to", newTimeout.ReplyTo }
					};

				if (newTimeout.CustomData != null)
				{
					parameters.Add("custom_data", newTimeout.CustomData);
				}

				foreach (var parameter in parameters)
				{
					command.AddParameter(parameter.Key, parameter.Value);
				}

				const string sql = @"INSERT INTO ""{0}"" ({1}) VALUES ({2})";

				var valueNames = string.Join(", ", parameters.Keys.Select(x => "\"" + x + "\""));
				var parameterNames = string.Join(", ", parameters.Keys.Select(x => "@" + x));

				command.CommandText = string.Format(sql, timeoutsTableName, valueNames, parameterNames);

				command.ExecuteNonQuery();
			}
		}
        /// <summary>
        /// Adds the timeout to the underlying collection of timeouts
        /// </summary>
        public void Add(Timeout.Timeout newTimeout)
        {
            var doc = new BsonDocument()
                .Add(CorrIdProperty, newTimeout.CorrelationId)
                .Add(SagaIdProperty, newTimeout.SagaId)
                .Add(TimeProperty, newTimeout.TimeToReturn)
                .Add(DataProperty, newTimeout.CustomData)
                .Add(ReplyToProperty, newTimeout.ReplyTo);

            collection.Insert(doc);
        }
        /// <summary>
        /// Stores the given timeout in memory
        /// </summary>
        public void Add(Timeout.Timeout newTimeout)
        {
            log.Debug("Adding timeout {0} -> {1}: {2}",
                      newTimeout.TimeToReturn,
                      newTimeout.ReplyTo,
                      newTimeout.CustomData);

            lock (listLock)
            {
                timeouts.Add(newTimeout);
            }
        }
Esempio n. 5
0
        public void Add(Timeout.Timeout newTimeout)
        {
            var collection = database.GetCollection(collectionName);

            collection.Insert(new
                                  {
                                      corr_id = newTimeout.CorrelationId,
                                      saga_id = newTimeout.SagaId,
                                      time = newTimeout.TimeToReturn,
                                      data = newTimeout.CustomData,
                                      reply_to = newTimeout.ReplyTo,
                                  });
        }
Esempio n. 6
0
 public void Add(Timeout.Timeout newTimeout)
 {
     using (var session = store.OpenSession())
     {
         session.Store(new RavenTimeout
                           {
                               SagaId = newTimeout.SagaId,
                               CorrelationId = newTimeout.CorrelationId,
                               Time = newTimeout.TimeToReturn,
                               Data = newTimeout.CustomData,
                               ReplyTo = newTimeout.ReplyTo,
                           });
         session.SaveChanges();
     }
 }
        /// <summary>
        /// Adds the given timeout to the table specified by <see cref="TimeoutsTableName"/>
        /// </summary>
        public void Add(Timeout.Timeout newTimeout)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    var parameters =
                        new List<Tuple<string, object>>
                            {
                                new Tuple<string, object>("time_to_return", newTimeout.TimeToReturn),
                                new Tuple<string, object>("correlation_id", newTimeout.CorrelationId),
                                new Tuple<string, object>("saga_id", newTimeout.SagaId),
                                new Tuple<string, object>("reply_to", newTimeout.ReplyTo)
                            };

                    if (newTimeout.CustomData != null)
                    {
                        parameters.Add(new Tuple<string, object>("custom_data", newTimeout.CustomData));
                    }

                    // generate sql with necessary columns including matching sql parameter names
                    command.CommandText =
                        string.Format(
                            @"insert into [{0}] ({1}) values ({2})",
                            timeoutsTableName,
                            string.Join(", ", parameters.Select(c => c.Item1)),
                            string.Join(", ", parameters.Select(c => "@" + c.Item1)));

                    // set parameters
                    foreach (var parameter in parameters)
                    {
                        command.Parameters.AddWithValue(parameter.Item1, parameter.Item2);
                    }

                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (SqlException ex)
                    {
                        // if we're violating PK, it's because we're inserting the same timeout again...
                        if (ex.Number != PrimaryKeyViolationNumber) throw;
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Adds the given timeout to the table specified by <see cref="TimeoutsTableName"/>
        /// </summary>
        public void Add(Timeout.Timeout newTimeout)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    var parameters =
                        new List<Tuple<string, object, SqlDbType>>
                            {
                                Tuple.Create("time_to_return", (object)newTimeout.TimeToReturn, SqlDbType.DateTime2),
                                Tuple.Create("correlation_id", (object)newTimeout.CorrelationId, SqlDbType.NVarChar),
                                Tuple.Create("saga_id", (object)newTimeout.SagaId, SqlDbType.UniqueIdentifier),
                                Tuple.Create("reply_to", (object)newTimeout.ReplyTo, SqlDbType.NVarChar),
                            };

                    if (newTimeout.CustomData != null)
                    {
                        parameters.Add(Tuple.Create("custom_data", (object)newTimeout.CustomData, SqlDbType.NVarChar));
                    }
                    // generate sql with necessary columns including matching sql parameter names
                    command.CommandText =
                        string.Format(
                            @"insert into [{0}] ({1}) values ({2})",
                            timeoutsTableName,
                            string.Join(", ", parameters.Select(c => c.Item1)),
                            string.Join(", ", parameters.Select(c => "@" + c.Item1)));

                    // set parameters
                    foreach (var parameter in parameters)
                    {
                        command.Parameters.Add(parameter.Item1, parameter.Item3).Value = parameter.Item2;
                    }

                    command.ExecuteNonQuery();
                }
            }
        }
Esempio n. 9
0
        void DeleteTimeout(Timeout.Timeout timeout, SqlConnection connection)
        {
            using (var command = connection.CreateCommand())
            {
                command.CommandText =
                    string.Format(
                        @"delete from [{0}]
                          where time_to_return = @time_to_return
                            and reply_to = @reply_to
                            and correlation_id = @correlation_id",
                        timeoutsTableName);

                command.Parameters.AddWithValue("time_to_return", timeout.TimeToReturn);
                command.Parameters.AddWithValue("correlation_id", timeout.CorrelationId);
                command.Parameters.AddWithValue("reply_to", timeout.ReplyTo);

                var executeNonQuery = command.ExecuteNonQuery();

                if (executeNonQuery == 0)
                {
                    throw new InvalidOperationException(string.Format("Stale state! Attempted to delete {0} from {1}, but it was already deleted!", timeout, timeoutsTableName));
                }
            }
        }