2019-08-14 18:48:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-06-02 18:56:10 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-08-14 18:48:40 +00:00
|
|
|
|
using Tapeti.Config;
|
2017-02-15 21:05:01 +00:00
|
|
|
|
|
|
|
|
|
namespace Tapeti.Default
|
|
|
|
|
{
|
2019-08-15 09:26:55 +00:00
|
|
|
|
internal class MessageContext : IMessageContext
|
2017-02-15 21:05:01 +00:00
|
|
|
|
{
|
2019-08-14 18:48:40 +00:00
|
|
|
|
private readonly Dictionary<string, object> items = new Dictionary<string, object>();
|
|
|
|
|
|
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public ITapetiConfig Config { get; set; }
|
2017-02-15 21:05:01 +00:00
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
2017-02-15 21:05:01 +00:00
|
|
|
|
public string Queue { get; set; }
|
2017-07-07 08:59:12 +00:00
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string Exchange { get; set; }
|
2017-02-15 21:05:01 +00:00
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string RoutingKey { get; set; }
|
2017-07-07 08:59:12 +00:00
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public object Message { get; set; }
|
2017-07-07 08:59:12 +00:00
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public IMessageProperties Properties { get; set; }
|
2017-07-07 08:59:12 +00:00
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public IBinding Binding { get; set; }
|
2017-07-07 08:59:12 +00:00
|
|
|
|
|
2019-08-14 18:48:40 +00:00
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in items.Values)
|
|
|
|
|
(item as IDisposable)?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-06-02 18:56:10 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async ValueTask DisposeAsync()
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in items.Values)
|
|
|
|
|
{
|
|
|
|
|
if (item is IAsyncDisposable asyncDisposable)
|
|
|
|
|
await asyncDisposable.DisposeAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 18:48:40 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Store(string key, object value)
|
|
|
|
|
{
|
|
|
|
|
items.Add(key, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
2019-08-14 18:48:40 +00:00
|
|
|
|
public bool Get<T>(string key, out T value) where T : class
|
2017-07-07 08:59:12 +00:00
|
|
|
|
{
|
2019-08-14 18:48:40 +00:00
|
|
|
|
if (!items.TryGetValue(key, out var objectValue))
|
|
|
|
|
{
|
|
|
|
|
value = default(T);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value = (T)objectValue;
|
|
|
|
|
return true;
|
2017-02-15 21:05:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|