本文整理汇总了C#中PartitionContext类的典型用法代码示例。如果您正苦于以下问题:C# PartitionContext类的具体用法?C# PartitionContext怎么用?C# PartitionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PartitionContext类属于命名空间,在下文中一共展示了PartitionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
var batch = new TableBatchOperation();
foreach(var msg in messages)
{
var snap = JsonConvert.DeserializeObject<BusSnapshotInfo>(Encoding.UTF8.GetString(msg.GetBytes()));
var entity = new DynamicTableEntity(snap.RouteShortName, snap.VehicleId.ToString());
entity.Properties.Add("RouteShortName", EntityProperty.GeneratePropertyForString(snap.RouteShortName));
entity.Properties.Add("VehicleId", EntityProperty.GeneratePropertyForInt(snap.VehicleId));
entity.Properties.Add("TripId", EntityProperty.GeneratePropertyForInt(snap.TripId));
entity.Properties.Add("Latitude", EntityProperty.GeneratePropertyForDouble(snap.Latitude));
entity.Properties.Add("Longitude", EntityProperty.GeneratePropertyForDouble(snap.Longitude));
entity.Properties.Add("DirectionOfTravel", EntityProperty.GeneratePropertyForString(snap.DirectionOfTravel.ToString()));
entity.Properties.Add("NextStopId", EntityProperty.GeneratePropertyForInt(snap.NextStopId));
entity.Properties.Add("Timeliness", EntityProperty.GeneratePropertyForString(snap.Timeliness.ToString()));
entity.Properties.Add("TimelinessOffset", EntityProperty.GeneratePropertyForInt(snap.TimelinessOffset));
entity.Properties.Add("Timestamp", EntityProperty.GeneratePropertyForDateTimeOffset(snap.Timestamp));
batch.Add(TableOperation.InsertOrReplace(entity));
}
var tableClient = _account.CreateCloudTableClient();
var table = tableClient.GetTableReference("snapshots");
await table.CreateIfNotExistsAsync();
await table.ExecuteBatchAsync(batch);
await context.CheckpointAsync();
}
示例2: Stopwatch
//------------------------------------------------------------------------------------------------------------------------
Task IEventProcessor.OpenAsync(PartitionContext context)
{
DebugEx.TraceLog("SimpleEventProcessor initialized. Partition: " + context.Lease.PartitionId + ", Offset: " + context.Lease.Offset);
this.checkpointStopWatch = new Stopwatch();
this.checkpointStopWatch.Start();
return Task.FromResult<object>(null);
}
示例3: foreach
async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
foreach (EventData eventData in messages)
{
_Logger.LogInfo(string.Format("Event received from partition: {0} - {1}", context.Lease.PartitionId,eventData.PartitionKey));
try
{
var httpMessage = HttpMessage.Parse(eventData.GetBodyStream());
await _MessageContentProcessor.ProcessHttpMessage(httpMessage);
}
catch (Exception ex)
{
_Logger.LogError(ex.Message);
}
}
//Call checkpoint every 5 minutes, so that worker can resume processing from the 5 minutes back if it restarts.
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
_Logger.LogInfo("Checkpointing");
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
示例4: OpenAsync
public async Task OpenAsync(PartitionContext context)
{
if (!WebJobsHelper.RunAsWebJobs)
Console.WriteLine(string.Format("EventProcessor initialization. Partition: '{0}', Offset: '{1}'",
context.Lease.PartitionId, context.Lease.Offset));
partitionContext = context;
var retries = 3;
while (retries > 0)
{
try
{
retries--;
hubClient = EventHubClient.CreateFromConnectionString(
ConfigurationManager.ConnectionStrings["SigfoxDemoAlertSender"].ConnectionString,
"alert");
cacheConnection = await ConnectionMultiplexer.ConnectAsync(ConfigurationManager.ConnectionStrings["SigfoxDemoCache"].ConnectionString);
cacheDatabase = cacheConnection.GetDatabase();
sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SigfoxDemoDatabase"].ConnectionString);
//sqlConnection.Open();
//sqlCommand = new SqlCommand("InsertAlert", sqlConnection) { CommandType = CommandType.StoredProcedure };
//sqlCommand.Parameters.Add(new SqlParameter("@Device", SqlDbType.VarChar));
retries = 0;
}
catch (Exception e)
{
Console.Error.WriteLine("Error opening destination Event Hub: " + e.Message);
if (retries == 0)
throw;
}
}
checkpointStopWatch = new Stopwatch();
checkpointStopWatch.Start();
}
示例5: CloseAsync
public async Task CloseAsync(PartitionContext context, CloseReason reason)
{
_log.InfoEvent("Close",
new Facet("reason", reason),
new Facet("partitionId", context.Lease.PartitionId),
new Facet("offset", context.Lease.Offset));
}
示例6: OpenAsync
public async Task OpenAsync(PartitionContext context)
{
_log.InfoEvent("Open",
new Facet("eventHubPath", context.EventHubPath),
new Facet("partitionId", context.Lease.PartitionId),
new Facet("offset", context.Lease.Offset));
}
示例7: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> events)
{
// Workaround for event hub sending null on timeout
events = events ?? Enumerable.Empty<EventData>();
if(!await _elasticSearchWriter.WriteAsync(events.ToList(), _token).ConfigureAwait(false))
{
return;
}
try
{
EventData checkpointEventData = events.LastOrDefault();
await context.CheckpointAsync(checkpointEventData);
WarmStorageEventSource.Log.CheckpointCompleted(ProcessorName, _eventHubName, context.Lease.PartitionId, checkpointEventData.Offset);
}
catch (Exception ex)
{
if (!(ex is StorageException || ex is LeaseLostException))
{
throw;
}
WarmStorageEventSource.Log.UnableToCheckpoint(ex, ProcessorName, _eventHubName, context.Lease.PartitionId);
}
}
示例8: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
Trace.TraceInformation("\n");
Trace.TraceInformation("........ProcessEventsAsync........");
foreach (EventData eventData in messages)
{
try
{
string jsonString = Encoding.UTF8.GetString(eventData.GetBytes());
Trace.TraceInformation(string.Format("Message received at '{0}'. Partition: '{1}'",
eventData.EnqueuedTimeUtc.ToLocalTime(), this.partitionContext.Lease.PartitionId));
Trace.TraceInformation(string.Format("-->Raw Data: '{0}'", jsonString));
SensorEvent newSensorEvent = this.DeserializeEventData(jsonString);
Trace.TraceInformation(string.Format("-->Serialized Data: '{0}', '{1}', '{2}', '{3}', '{4}'",
newSensorEvent.timestart, newSensorEvent.dsplalert, newSensorEvent.alerttype, newSensorEvent.message, newSensorEvent.targetalarmdevice));
// Issuing alarm to device.
string commandParameterNew = "{\"Name\":\"AlarmThreshold\",\"Parameters\":{\"SensorId\":\"" + newSensorEvent.dsplalert + "\"}}";
Trace.TraceInformation("Issuing alarm to device: '{0}', from sensor: '{1}'", newSensorEvent.targetalarmdevice, newSensorEvent.dsplalert);
Trace.TraceInformation("New Command Parameter: '{0}'", commandParameterNew);
await WorkerRole.iotHubServiceClient.SendAsync(newSensorEvent.targetalarmdevice, new Microsoft.Azure.Devices.Message(Encoding.UTF8.GetBytes(commandParameterNew)));
}
catch (Exception ex)
{
Trace.TraceInformation("Error in ProssEventsAsync -- {0}\n", ex.Message);
}
}
await context.CheckpointAsync();
}
示例9: Stopwatch
Task IEventProcessor.OpenAsync(PartitionContext context)
{
Console.WriteLine("SimpleEventProcessor initialized. Partition: '{0}', Offset: '{1}'", context.Lease.PartitionId, context.Lease.Offset);
this.checkpointStopWatch = new Stopwatch();
this.checkpointStopWatch.Start();
return Task.FromResult<object>(null);
}
示例10: OpenAsync
public Task OpenAsync(PartitionContext context)
{
Console.WriteLine("EventProcessor started");
this.stopWatch = new Stopwatch();
this.stopWatch.Start();
return Task.FromResult<object>(null);
}
示例11: DbService
async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
var iDbService = new DbService();
_client = iDbService.GetFirebaseClient();
foreach (EventData eventData in messages)
{
string data = Encoding.UTF8.GetString(eventData.GetBytes());
FirebaseResponse response = await _client.PushAsync("event", new EHdata
{
offset = eventData.Offset,
body = data,
partitionId = context.Lease.PartitionId
});
Console.WriteLine(String.Format("Message received. Partition: '{0}', Data: '{1}', Offset: '{2}'",
context.Lease.PartitionId, data, eventData.Offset));
}
//Call checkpoint every 5 minutes, so that worker can resume processing from the 5 minutes back if it restarts.
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
Console.WriteLine(this.checkpointStopWatch.Elapsed);
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
示例12: OpenAsync
public Task OpenAsync(PartitionContext context)
{
this.partitionContext = context;
this.checkpointStopWatch = new Stopwatch();
this.checkpointStopWatch.Start();
return Task.FromResult<object>(null);
}
示例13:
async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
{
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}
示例14: CreateEventProcessor
public IEventProcessor CreateEventProcessor(PartitionContext context)
{
var processor = new DeviceAdministrationProcessor(_deviceLogic, _configurationProvider);
processor.ProcessorClosed += this.ProcessorOnProcessorClosed;
this.eventProcessors.TryAdd(context.Lease.PartitionId, processor);
return processor;
}
示例15: AppendAndCheckpoint
async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
foreach (EventData eventData in messages)
{
byte[] data = eventData.GetBytes();
if (eventData.Properties.ContainsKey("messageType") && (string)eventData.Properties["messageType"] == "interactive")
{
var messageId = (string)eventData.SystemProperties["message-id"];
var queueMessage = new BrokeredMessage(new MemoryStream(data));
queueMessage.MessageId = messageId;
queueMessage.Properties["messageType"] = "interactive";
await queueClient.SendAsync(queueMessage);
WriteHighlightedMessage(string.Format("Received interactive message: {0}", messageId));
continue;
}
if (toAppend.Length + data.Length > MAX_BLOCK_SIZE || stopwatch.Elapsed > MAX_CHECKPOINT_TIME)
{
await AppendAndCheckpoint(context);
}
await toAppend.WriteAsync(data, 0, data.Length);
Console.WriteLine(string.Format("Message received. Partition: '{0}', Data: '{1}'",
context.Lease.PartitionId, Encoding.UTF8.GetString(data)));
}
}