/// <summary> /// Checks to See if the <seealso cref="ServerEventMessage"/> contains an Object update /// </summary> /// <param name="eventMessage"></param> /// <returns></returns> public static bool IsObjectMessage(this ServerEventMessage eventMessage) { return(!String.IsNullOrWhiteSpace(eventMessage.ObjectType) && !String.IsNullOrWhiteSpace(eventMessage.ObjectId) && eventMessage.ObjectUpdate != null); }
public virtual void OnMessageEvent(ServerEventMessage msg) { Logger.Debug($"OnMessageEvent() - {msg.Selector} - {msg.Channel}"); }
/// <summary> /// Checks to See if the <seealso cref="ServerEventMessage"/> contains an Event /// </summary> /// <param name="eventMessage"></param> /// <returns></returns> public static bool IsServerEventMessage(this ServerEventMessage eventMessage) { return(!String.IsNullOrWhiteSpace(eventMessage.Topic)); }
/// <summary> /// Processes all Pending <seealso cref="ServerEventMessage"/> messages /// in the <seealso cref="IEventQueueStore"/> /// </summary> /// <returns></returns> public async Task ProcessAllMessagesInQueue() { using (var scope = serviceProvider.CreateScope()) { // Load store and other services necessary for coordination var eventQueueStore = scope.ServiceProvider.GetRequiredService <IEventQueueStore>(); var metadataService = scope.ServiceProvider.GetRequiredService <IMetadataService>(); var processingService = scope.ServiceProvider.GetRequiredService <IEventProcessingService>(); var objectUpdateService = scope.ServiceProvider.GetRequiredService <IObjectUpdateService>(); ServerEventMessage pendingEvent = await eventQueueStore.PeekEventAsync(); if (pendingEvent != null) { try { logger.LogDebug($"Processing Event #{pendingEvent.LogId}"); // Start with Metadata updates if (options.Value.AutoDiscoverEvents && pendingEvent.IsServerEventMessage()) { await metadataService.AutoDiscoverEventsAsync(pendingEvent); } if (options.Value.AutoDiscoverObjectTypes && pendingEvent.IsObjectMessage()) { await metadataService.AutoDiscoverObjectsAsync(pendingEvent); } // Process the Event (if Topic is Set) if (pendingEvent.IsServerEventMessage()) { await processingService.ProcessEvent(pendingEvent.Topic, pendingEvent.EventJson); } // Process the Object (if ObjectType is set) if (pendingEvent.IsObjectMessage()) { await objectUpdateService.UpdateObject(pendingEvent.ObjectType, pendingEvent.ObjectId, pendingEvent.ObjectUpdate); } // Clear the Event as Processed await eventQueueStore.DequeueEventAsync(pendingEvent.LogId); // Trigger Delivery triggerService.DeliveryStart.Set(); } catch (Exception ex) { logger.LogCritical(ex, ex.Message); await eventQueueStore.PoisonedEventAsync(pendingEvent.LogId); } } // Stop immediately if requested if (stoppingToken.IsCancellationRequested) { return; } // Keep checking for more Events pendingEvent = await eventQueueStore.PeekEventAsync(); } }
public bool OnStoreCommandReceived(Control control, ServerEventMessage seMsg) { if (control is SchedulerControl schedulerControl) { try { ServerEventMessageData msgJson = seMsg.Json.FromJson <ServerEventMessageData>(); // if (msgJson.FromClientGuid == Context.ClientInstanceGuid) if (msgJson.From == Context.LoggedInUser.UserName) { return(true); } IList <StandardAppointment> sAppts = msgJson.jsonDataString.FromJson <List <StandardAppointment> >(); schedulerControl.BeginUpdate(); if (sAppts.Any()) { foreach (StandardAppointment sAppt in sAppts) { Appointment appt = null; AppointmentType apptType = (AppointmentType)Enum.Parse(typeof(AppointmentType), sAppt.ApptTypeCode); if (new[] { AppointmentType.ChangedOccurrence, AppointmentType.DeletedOccurrence, AppointmentType.Occurrence }.Contains(apptType)) { //get the main pattern appt appt = schedulerControl.DataStorage.Appointments.Items .FirstOrDefault(a => a.CustomFields["ENTITY"] is StandardAppointment && a.Type == AppointmentType.Pattern && a.RecurrenceInfo.Id.ToString() == sAppt.RecurrenceId.ToString()); } else { appt = schedulerControl.DataStorage.Appointments.Items .FirstOrDefault(a => a.CustomFields["ENTITY"] is StandardAppointment && (a.CustomFields["ENTITY"] as StandardAppointment).Id == sAppt.Id); } //this appointment is most likely received from a server event so no need to post it back and forth. AllowServerPost = false; schedulerControl.InvokeIfRequired(sc => { appt = CreateOrUpdateAppointmentFromEntity(schedulerControl, sAppt, appt); }); AllowServerPost = true;//enable server posting again. } } } catch (Exception ex) { schedulerControl.InvokeIfRequired(sc => { sc.EndUpdate(); sc.Refresh(); }); Logger.Error(ex.Message, ex); #if DEBUG throw ex; #endif } finally { AllowServerPost = true;//enable server posting again. //schedulerControl.EndUpdate(); schedulerControl.InvokeIfRequired(sc => { sc.EndUpdate(); sc.Refresh(); }); } } return(true); }
private void HandleRelayCommand(ServerEventMessage msg) { if (msg.Target == "ZoneControl") { var zc = msg.Json.FromJson<ZoneControl>(); SetRelay((zc.RelayOn) ? GpioPinValue.High : GpioPinValue.Low); } }
public void BackgroundImage(string cssRule) { BackgroundImageReceived = cssRule; BackgroundImageRequestReceived = Request; }
public void Toggle(string message) { ToggleReceived = message; ToggleRequestReceived = Request; }
public static string GetRoutingGey(this ServerEventMessage message, string prefix) { return(RoutingKeyHelper.GetRoutingGey(prefix, message.ResourceType, message.ActionCode)); }
public Task <long> EnqueueEventAsync(ServerEventMessage message) { message.LogId = nextId++; store.TryAdd(message.LogId, message); return(Task.FromResult(message.LogId)); }