本文整理汇总了C#中IMessageContext类的典型用法代码示例。如果您正苦于以下问题:C# IMessageContext类的具体用法?C# IMessageContext怎么用?C# IMessageContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMessageContext类属于命名空间,在下文中一共展示了IMessageContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMessage
/// <summary>
/// Get a validation message
/// </summary>
/// <param name="context">Context</param>
/// <returns>
/// String if found; otherwise <c>null</c>.
/// </returns>
public string GetMessage(IMessageContext context)
{
if (context.Attribute is CompareAttribute)
return "The {0} and {1} fields to not match.";
return null;
}
示例2: HeartBeatWorker
/// <summary>
/// Initializes a new instance of the <see cref="HeartBeatWorker" /> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="context">The context.</param>
/// <param name="sendHeartBeat">The send heart beat.</param>
/// <param name="threadPool">The thread pool.</param>
/// <param name="log">The log.</param>
/// <param name="heartBeatNotificationFactory">The heart beat notification factory.</param>
public HeartBeatWorker(IHeartBeatConfiguration configuration,
IMessageContext context,
ISendHeartBeat sendHeartBeat,
IHeartBeatThreadPool threadPool,
ILogFactory log,
IWorkerHeartBeatNotificationFactory heartBeatNotificationFactory)
{
Guard.NotNull(() => configuration, configuration);
Guard.NotNull(() => context, context);
Guard.NotNull(() => sendHeartBeat, sendHeartBeat);
Guard.NotNull(() => threadPool, threadPool);
Guard.NotNull(() => log, log);
Guard.NotNull(() => heartBeatNotificationFactory, heartBeatNotificationFactory);
_context = context;
_checkTimespan = configuration.CheckTime;
_sendHeartbeat = sendHeartBeat;
_smartThreadPool = threadPool;
_logger = log.Create();
_runningLock = new ReaderWriterLockSlim();
_stoppedLock = new ReaderWriterLockSlim();
_cancel = new CancellationTokenSource();
context.WorkerNotification.HeartBeat = heartBeatNotificationFactory.Create(_cancel.Token);
}
示例3: Command
protected Command(Guid aggregateId, int version, IMessageContext context)
{
AggregateId = aggregateId;
UtcDate = SystemClock.UtcNow;
Version = version;
Metadata = context.Metadata;
}
示例4: Commit
/// <summary>
/// Commits the processed message, by deleting the message
/// </summary>
/// <param name="context">The context.</param>
public void Commit(IMessageContext context)
{
if (context.MessageId != null && context.MessageId.HasValue)
{
_deleteMessageCommand.Handle(new DeleteMessageCommand((long)context.MessageId.Id.Value));
}
}
示例5: Handle
/// <summary>
/// Handles processing the specified message with the context
/// </summary>
/// <param name="context">The context.</param>
/// <param name="transportMessage">The transport message.</param>
/// <returns></returns>
public bool Handle(IMessageContext context, IReceivedMessageInternal transportMessage)
{
using (var heartBeat = _heartBeatWorkerFactory.Create(context))
{
try
{
_methodToRun.Handle(transportMessage, context.WorkerNotification);
_commitMessage.Commit(context);
return true;
}
// ReSharper disable once UncatchableException
catch (ThreadAbortException)
{
heartBeat.Stop();
throw;
}
catch (OperationCanceledException)
{
heartBeat.Stop();
throw;
}
catch (Exception exception)
{
heartBeat.Stop();
_messageExceptionHandler.Handle(transportMessage, context, exception);
}
}
return false;
}
示例6: ProcessMessage
/// <summary>
/// messaging callback
/// see com.db4o.messaging.MessageRecipient#ProcessMessage()
/// </summary>
public void ProcessMessage(IMessageContext con, object message)
{
if (message is StopServer)
{
Close();
}
}
示例7: Publish
public void Publish(IMessage message, IMessageContext sender)
{
var messageTpye = message.GetType();
if (handlers.ContainsKey(messageTpye))
{
foreach (var handler in handlers[messageTpye])
{
dynamic instance = handlerFactory(handler);
try
{
if (HasResponse(message))
{
var result = instance.Handle((dynamic)(message.ToPublishedMessage(sender)));
sender.Respond(result);
}
else
instance.Handle((dynamic)(message.ToPublishedMessage(sender)));
}
catch (Exception ex)
{
sender.ErrorFormat("{0} , {1}", ex.Message, ex.StackTrace);
}
}
}
}
示例8: Send
/// <summary>
/// Updates the heart beat for a record.
/// </summary>
/// <param name="context">The context.</param>
/// <returns></returns>
public IHeartBeatStatus Send(IMessageContext context)
{
using (_timer.NewContext())
{
return _handler.Send(context);
}
}
示例9: Handle
public HandleResult Handle(IMessageContext msg)
{
if (msg.IsInitiallyPolled)
return HandleResult.Ignored;
var update = msg.Update;
if (update.Message.Chat.Id == -1001013065325)
{
var eva = new Regex(@"\b[eе]+[vв]+[aа]+\b", RegexOptions.IgnoreCase);
if (eva.IsMatch(update.Message.Text ?? ""))
{
_ctx.BotApi.SendMessageAsync(-1001013065325, "чо");
return HandleResult.HandledCompletely;
}
if (update.Message.From.Id == 146268050)
{
var roll = new Random().Next(10);
if (roll == 7)
_ctx.BotApi.SendMessageAsync(-1001013065325, "юль, ну впиши по-братски");
return HandleResult.HandledCompletely;
}
}
return HandleResult.Ignored;
}
示例10: MoveRecordToErrorQueueCommand
/// <summary>
/// Initializes a new instance of the <see cref="MoveRecordToErrorQueueCommand" /> class.
/// </summary>
/// <param name="exception">The exception.</param>
/// <param name="queueId">The queue identifier.</param>
/// <param name="context">The context.</param>
public MoveRecordToErrorQueueCommand(Exception exception, long queueId, IMessageContext context)
{
Guard.NotNull(() => context, context);
Exception = exception;
QueueId = queueId;
MessageContext = context;
}
示例11: Handle
/// <summary>
/// Handles processing the specified message with the context
/// </summary>
/// <param name="context">The context.</param>
/// <param name="transportMessage">The transport message.</param>
/// <returns></returns>
public async Task Handle(IMessageContext context, IReceivedMessageInternal transportMessage)
{
using (var heartBeat = _heartBeatWorkerFactory.Create(context))
{
try
{
await _methodToRun.HandleAsync(transportMessage, context.WorkerNotification).ConfigureAwait(false);
_commitMessage.Commit(context);
}
// ReSharper disable once UncatchableException
catch (ThreadAbortException)
{
heartBeat.Stop();
throw;
}
catch (OperationCanceledException)
{
heartBeat.Stop();
throw;
}
catch (Exception exception)
{
heartBeat.Stop();
_messageExceptionHandler.Handle(transportMessage, context, exception.InnerException ?? exception);
}
}
}
示例12: Respond
public Task Respond(ChatContextHolder chatContextHolder, IMessageContext context)
{
return Task.Run(() =>
{
foreach (LightPin pin in _lights)
{
pin.Set(context.Text, _pinManager);
}
LightPin[] allOn = _lights.Where(x => x.ContainsSection(context.Text) && x.IsOn(context.Text)).ToArray();
if (!allOn.Select(x => x.Color).Any())
{
context.Respond(string.Format("{0} lights are now off",
_lights.Where(x => x.ContainsSection(context.Text))
.Select(x => x.Section)
.Distinct()
.StringJoin()));
}
else
{
context.Respond(string.Format("{0} {1} lights are now on",
allOn.Select(x => x.Section).Distinct().StringJoin(),
allOn.Select(x => x.Color).Distinct().StringJoin()));
}
});
}
示例13: GetMessage
/// <summary>
/// Returns the next message, if any.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>
/// A message if one is found; null otherwise
/// </returns>
public IReceivedMessageInternal GetMessage(IMessageContext context)
{
//if stopping, exit now
if (_cancelToken.Tokens.Any(t => t.IsCancellationRequested))
{
return null;
}
//check for a specific MessageID to pull
IMessageId messageId = null;
var rpc = context.Get(_configuration.HeaderNames.StandardHeaders.RpcContext);
if (rpc?.MessageId != null && rpc.MessageId.HasValue)
{
messageId = rpc.MessageId;
}
//ask for the next message, or a specific message if we have a messageID
var receivedTransportMessage =
_receiveMessage.Handle(new ReceiveMessageQuery(messageId, _configuration.Routes));
//if no message (null) run the no message action and return
if (receivedTransportMessage == null)
{
return null;
}
//set the message ID on the context for later usage
context.MessageId = receivedTransportMessage.MesssageId;
return receivedTransportMessage;
}
示例14: End
public void End(IServiceLocator childServiceLocator, IMessageContext messageContext, Exception ex)
{
if (ex == null)
LogMessage("Commit");
else
LogMessage("Rollback, reason: " + ex);
}
示例15: ReceiveMessage
/// <summary>
/// Receives a new message.
/// </summary>
/// <param name="context">The context.</param>
/// <returns></returns>
public IReceivedMessageInternal ReceiveMessage(IMessageContext context)
{
context.Commit += ContextOnCommit;
context.Rollback += ContextOnRollback;
context.Cleanup += context_Cleanup;
TimeSpan? timeout = null;
IMessageId messageId = null;
var rpc = context.Get(_headers.StandardHeaders.RpcContext);
if (rpc?.Timeout != null)
{
timeout = rpc.Timeout;
}
if (rpc?.MessageId != null)
{
messageId = rpc.MessageId;
}
using (
var workSub = rpc?.MessageId != null && rpc.MessageId.HasValue
? _workSubFactory.Create(rpc.MessageId)
: _workSubFactory.Create())
{
while (true)
{
if (_cancelWork.Tokens.Any(m => m.IsCancellationRequested))
{
return null;
}
var message = GetMessage(context, messageId);
if (message != null && !message.Expired)
{
return message.Message;
}
if (_cancelWork.Tokens.Any(m => m.IsCancellationRequested))
{
return null;
}
workSub.Reset();
message = GetMessage(context, messageId);
if (message != null && !message.Expired)
{
return message.Message;
}
if (message != null && message.Expired)
{
continue;
}
if (workSub.Wait(timeout))
{
continue;
}
return null;
}
}
}