本文整理汇总了C#中EventData.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# EventData.GetBytes方法的具体用法?C# EventData.GetBytes怎么用?C# EventData.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventData
的用法示例。
在下文中一共展示了EventData.GetBytes方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteJsonEntry
private void WriteJsonEntry(EventData e)
{
_writer.WriteStartObject();
_writer.WritePropertyName("index");
// Write the batch "index" operation header
_writer.WriteStartObject();
// ES index names must be lower case and cannot contain whitespace or any of the following characters \/*?"<>|,
WriteValue("_index", this.GetIndexName(e.EnqueuedTimeUtc));
WriteValue("_type", _entryType);
_writer.WriteEndObject();
_writer.WriteEndObject();
_writer.WriteRaw("\n"); //ES requires this \n separator
var payload = JObject.Parse(Encoding.UTF8.GetString(e.GetBytes()));
foreach (var property in e.Properties)
{
payload.Add("Properties-" + property.Key, new JValue(property.Value));
}
_writer.WriteRaw(payload.ToString(Formatting.None));
_writer.WriteRaw("\n");
}
示例2: EventHubMessage
public EventHubMessage(string partitionId, EventData message)
{
PartitionId = partitionId;
MessageBody = Encoding.UTF8.GetString(message.GetBytes());
EnqueueTimeStamp = message.EnqueuedTimeUtc;
Publisher = message.SystemProperties[EventDataSystemPropertyNames.Publisher] as string;
Offset = message.Offset;
SequenceNumber = message.SequenceNumber;
}
示例3: Deserialize
private dynamic Deserialize(EventData raw)
{
try
{
var body = Encoding.UTF8.GetString(raw.GetBytes());
return JsonConvert.DeserializeObject<dynamic>(body);
}
catch (Exception)
{
return null;
}
}
示例4: WriteJsonEntry
private void WriteJsonEntry(EventData e)
{
_writer.WriteStartObject();
_writer.WritePropertyName("index");
// Write the batch "index" operation header
_writer.WriteStartObject();
// ES index names must be lower case and cannot contain whitespace or any of the following characters \/*?"<>|,
WriteValue("_index", this.GetIndexName(e.EnqueuedTimeUtc));
WriteValue("_type", _entryType);
_writer.WriteEndObject();
_writer.WriteEndObject();
_writer.WriteRaw("\n"); //ES requires this \n separator
_writer.WriteRaw(Encoding.UTF8.GetString(e.GetBytes()));
_writer.WriteRaw("\n");
}
示例5: ConvertEventData2String
// EventData --> String
private static string ConvertEventData2String(EventData x)
{
return Encoding.UTF8.GetString(x.GetBytes());
}
示例6: DeserializeEventData
private static Alert DeserializeEventData(EventData eventData)
{
return JsonConvert.DeserializeObject<Alert>(Encoding.UTF8.GetString(eventData.GetBytes()));
}
示例7: GetBytesInEvent
// You should provide your own implementation of this method if you need
// to customize the serialization.
private static byte[] GetBytesInEvent(EventData eData)
{
var eventToPersist = new ColdStorageEvent();
eventToPersist.Offset = eData.Offset;
eventToPersist.Properties = GetStringDictionary(eData.Properties);
try
{
//We are asuming serialization and encoding from the sender.
eventToPersist.Payload = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(eData.GetBytes()));
}
catch (JsonReaderException)
{
eventToPersist.Payload = Encoding.UTF8.GetString(eData.GetBytes());
}
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(eventToPersist) + EventDelimiter);
}
示例8: DeserializeEventData
MetricEvent DeserializeEventData(EventData eventData)
{
return JsonConvert.DeserializeObject<MetricEvent>(Encoding.UTF8.GetString(eventData.GetBytes()));
}
示例9: GetBytesInEvent
// [TODO] - we want to call out the "change" points very clearly (where a customer would extend)
// In this sample we are assuming that certain properties are in the EventData.
// You should provide your own implementation of this method if you need
// to customize the serialization.
private static byte[] GetBytesInEvent(EventData eData)
{
var eventToPersist = new ColdStorageEvent();
eventToPersist.Offset = eData.Offset;
eventToPersist.MessageType = (string)eData.Properties[EventDataPropertyKeys.MessageType];
eventToPersist.Payload = Encoding.UTF8.GetString(eData.GetBytes());
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(eventToPersist) + EventDelimiter);
}
示例10: ProcessMessage
public static async Task ProcessMessage(EventData eventData, string partition, CancellationToken cancelToken, TextWriter log)
{
var data = Encoding.UTF8.GetString(eventData.GetBytes());
log.WriteLine("Message received. Partition: {0} Data: '{1}'", partition, data);
var request = JsonConvert.DeserializeObject<PostRequest>(data);
await SaveToTableStorage(eventData, cancelToken, request);
await SaveToDatabase(cancelToken, request);
}
示例11: ProcessAsync
/// <summary>
/// Process the message contained in the event data object,
/// handling timeouts, errors and telemetry
/// </summary>
private async Task ProcessAsync(EventData msg, string partitionId)
{
var context = new ProcessingContext(_eventHubName, partitionId, msg.Offset);
Exception ex = null;
string handlerName = "[handler not yet resolved]";
byte[] content = EmptyContent;
Dictionary<string, string> props = null;
try
{
// The message stream can only be read once, extract the body up front
content = msg.GetBytes();
// if only some properties are used in the happy path but all are needed in some cases.
props = msg.Properties.ToDictionary(
k => k.Key,
v => v.Value.ToString());
// Promote standard EventHub properties into the property collection (for logging)
var msgId = String.Concat(_eventHubName, "/", msg.PartitionKey, "/", msg.Offset);
props.Add(Constants.ID, msgId);
props.Add(Constants.MSG_OFFSET, msg.Offset);
props.Add(Constants.PARTITION, msg.PartitionKey);
// Look up the message type handler, using the payload and
// associated properties
var handler = _handlerResolver.GetHandler(props, msgId);
handlerName = handler.Name;
// Create a task to track timeout
var sw = Stopwatch.StartNew();
var timeoutTask = Task.Delay(handler.Timeout);
// Invoke the handler, using the continuation token to handle exceptions and
// elapsed time logging. Note: if this method throws synchronously (a misbehaving
// handler) then we handle it in the catch statement below
var handlerTask = handler
.ExecuteAsync(context, content, props)
.ContinueWith(async t => await HandleCompletionAsync(t, sw, handlerName, content, props, context).ConfigureAwait(false));
_instrumentationPublisher.TaskStarted();
_circuitBreaker.Increment();
// Wait for either the timeout task or the handler to complete
await Task.WhenAny(handlerTask, timeoutTask).ConfigureAwait(false);
// If the message did not complete before the timeout, flag for further review
if (handlerTask.Status != TaskStatus.RanToCompletion)
{
props.Add("timeoutDuration", handler.Timeout.ToString());
_instrumentationPublisher.TimeoutOccured();
await Logger.LogHandlerTimeout(handler, context, content, props);
}
}
catch (Exception ex0)
{
ex = ex0;
}
// Misbehaving handler threw a synchronous exception
if (ex != null)
{
// We can't await in a catch block
await Logger.HandlerThrewException(
handlerName,
context,
content,
props ?? new Dictionary<string, string>(),
ex);
}
}
示例12: Handle
public void Handle(EventData eventData, string partitionId)
{
var store = GetEventStore(eventData, partitionId);
var bytes = eventData.GetBytes();
store.Write(bytes);
}
示例13: GetEventDataString
protected string GetEventDataString(EventData eventData)
{
var result = Encoding.UTF8.GetString(eventData.GetBytes());
return result;
}