本文整理汇总了C#中IEndpointInstance.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# IEndpointInstance.Publish方法的具体用法?C# IEndpointInstance.Publish怎么用?C# IEndpointInstance.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEndpointInstance
的用法示例。
在下文中一共展示了IEndpointInstance.Publish方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
static async Task Start(IEndpointInstance endpointInstance)
{
Console.WriteLine("Press '1' to publish IEvent");
Console.WriteLine("Press '2' to publish EventMessage");
Console.WriteLine("Press '3' to publish AnotherEventMessage");
Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");
#region PublishLoop
while (true)
{
ConsoleKeyInfo key = Console.ReadKey();
Console.WriteLine();
Guid eventId = Guid.NewGuid();
switch (key.Key)
{
case ConsoleKey.D1:
await endpointInstance.Publish<IMyEvent>(m =>
{
m.EventId = eventId;
m.Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null;
m.Duration = TimeSpan.FromSeconds(99999D);
});
Console.WriteLine("Published IMyEvent with Id {0}.", eventId);
continue;
case ConsoleKey.D2:
EventMessage eventMessage = new EventMessage
{
EventId = eventId,
Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
Duration = TimeSpan.FromSeconds(99999D)
};
await endpointInstance.Publish(eventMessage);
Console.WriteLine("Published EventMessage with Id {0}.", eventId);
continue;
case ConsoleKey.D3:
AnotherEventMessage anotherEventMessage = new AnotherEventMessage
{
EventId = eventId,
Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
Duration = TimeSpan.FromSeconds(99999D)
};
await endpointInstance.Publish(anotherEventMessage);
Console.WriteLine("Published AnotherEventMessage with Id {0}.", eventId);
continue;
default:
return;
}
}
#endregion
}
示例2: PublishEvent
static async Task PublishEvent(IEndpointInstance endpointInstance)
{
Guid eventId = Guid.NewGuid();
await endpointInstance.Publish<IMyEvent>(m =>
{
m.EventId = eventId;
});
Console.WriteLine("Event published, id: " + eventId);
}
示例3: Start
static async Task Start(IEndpointInstance endpointInstance)
{
Console.WriteLine("Press '1' to publish IEvent");
Console.WriteLine("Press '2' to publish EventMessage");
Console.WriteLine("Press '3' to publish AnotherEventMessage");
Console.WriteLine("Press any other key to exit");
#region PublishLoop
while (true)
{
var key = Console.ReadKey();
Console.WriteLine();
var eventId = Guid.NewGuid();
switch (key.Key)
{
case ConsoleKey.D1:
await endpointInstance.Publish<IMyEvent>(m =>
{
m.EventId = eventId;
m.Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null;
m.Duration = TimeSpan.FromSeconds(99999D);
})
.ConfigureAwait(false);
Console.WriteLine($"Published IMyEvent with Id {eventId}.");
continue;
case ConsoleKey.D2:
var eventMessage = new EventMessage
{
EventId = eventId,
Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
Duration = TimeSpan.FromSeconds(99999D)
};
await endpointInstance.Publish(eventMessage)
.ConfigureAwait(false);
Console.WriteLine($"Published EventMessage with Id {eventId}.");
continue;
case ConsoleKey.D3:
var anotherEventMessage = new AnotherEventMessage
{
EventId = eventId,
Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
Duration = TimeSpan.FromSeconds(99999D)
};
await endpointInstance.Publish(anotherEventMessage)
.ConfigureAwait(false);
Console.WriteLine($"Published AnotherEventMessage with Id {eventId}.");
continue;
default:
return;
}
}
#endregion
}
示例4: Start
static void Start(IEndpointInstance busSession)
{
Console.WriteLine("Press Enter to publish the SomethingHappened Event");
Console.WriteLine("Press any key to exit");
#region publisher-loop
while (true)
{
ConsoleKeyInfo key = Console.ReadKey();
Console.WriteLine();
if (key.Key != ConsoleKey.Enter)
{
return;
}
busSession.Publish(new SomethingHappened());
Console.WriteLine("SomethingHappened Event published");
}
#endregion
}