private void ProcessMessage(string sBody) { // Check if this is sensort notification if (NotificationEventSchema.IsValid(sBody)) { OnNotificationEventArgs eventData = JsonConvert.DeserializeObject <OnNotificationEventArgs>(sBody); if (eventData != null && OnNotification != null) { OnNotification.Invoke(sBody, eventData); } } else if (ScheduleUpdateEventSchema.IsValid(sBody)) { OnScheduleUpdateEventArgs eventData = JsonConvert.DeserializeObject <OnScheduleUpdateEventArgs>(sBody); eventData.Schedule = this.FilterAppointments(eventData); if (eventData != null && OnScheduleUpdate != null) { OnScheduleUpdate.Invoke(sBody, eventData); } } else { /// Unknow schema - probably an error this.LogEvent(EventTypeConsts.Error, "Unknown json format", sBody); } }
private async void ProcessMessage(string sBody, int eventsExpiration) { // Check if this is sensort notification if (NotificationEventSchema.IsValid(sBody)) { OnNotificationEventArgs eventData = JsonConvert.DeserializeObject <OnNotificationEventArgs>(sBody); if (eventData != null && OnNotification != null) { var dispatcher = DispatcherHelper.GetDispatcher; await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { double fValue = 0.0; if (double.TryParse(eventData.Value, out fValue)) { eventData.Value = fValue.ToString("F1"); } OnNotification.Invoke(sBody, eventData); }); } } else if (ScheduleUpdateEventSchema.IsValid(sBody)) { OnScheduleUpdateEventArgs eventData = JsonConvert.DeserializeObject <OnScheduleUpdateEventArgs>(sBody); eventData.Schedule = this.FilterAppointments(eventData, eventsExpiration); if (eventData != null && OnScheduleUpdate != null) { var dispatcher = DispatcherHelper.GetDispatcher; await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { OnScheduleUpdate.Invoke(sBody, eventData); }); } } else { /// Unknow schema - probably an error this.LogEvent(EventTypeConsts.Error, "Unknown json format", sBody); } }
private void ProcessMessage(string sBody, int eventsExpiration) { // Check if this is sensort notification if (NotificationEventSchema.IsValid(sBody)) { OnNotificationEventArgs eventData = JsonConvert.DeserializeObject <OnNotificationEventArgs>(sBody); if (eventData != null && OnNotification != null) { DispatcherHelper.CheckBeginInvokeOnUI(() => { double fValue = 0.0; if (double.TryParse(eventData.Value, out fValue)) { eventData.Value = fValue.ToString("F1"); } OnNotification.Invoke(sBody, eventData); }); } } else if (ScheduleUpdateEventSchema.IsValid(sBody)) { OnScheduleUpdateEventArgs eventData = JsonConvert.DeserializeObject <OnScheduleUpdateEventArgs>(sBody); List <Appointment> filteredList = this.FilterAppointments(eventData, eventsExpiration); if (filteredList != null && OnScheduleUpdate != null) { DispatcherHelper.CheckBeginInvokeOnUI(() => { OnScheduleUpdate.Invoke(sBody, filteredList); }); } } else { /// Unknow schema - probably an error this.LogEvent(EventTypeConsts.Error, "Unknown json format", sBody); } }
public async void ReadMessageAsync(string Location, int eventsExpiration) { if (string.IsNullOrEmpty(Location)) { this.LogEvent(EventTypeConsts.Error, "Invalid argument Locaton", " value is null or empty"); return; } ReaderMutex.WaitOne(MutexWaitTime); // Wait one minute for mutex try { string[] Locations = Location.Split(';'); string sXml = await HttpHelper.GetStringResponse(this.UrlAddress); if (!string.IsNullOrEmpty(sXml)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(sXml); XmlNodeList eventsNodes = doc.SelectNodes("Appointments/Appointment"); List <Appointment> Appointments = new List <Appointment>(); foreach (string tmpLocation in Locations) { Appointment[] roomAppointments = ReadEventForLocation(eventsNodes, tmpLocation, eventsExpiration); if (roomAppointments != null) { Appointments.AddRange(roomAppointments); } } OnScheduleUpdateEventArgs eventData = new OnScheduleUpdateEventArgs() { RoomId = Location }; if (Appointments.Count > 0) { eventData.Schedule = Appointments.Distinct <Appointment>(new AppointmentComparer()).ToArray(); } else { eventData.Schedule = new Appointment[0]; } var dispatcher = DispatcherHelper.GetDispatcher; //CoreApplication.GetCurrentView().Dispatcher; await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (OnScheduleUpdate != null) { OnScheduleUpdate.Invoke("", eventData); } }); } else { this.LogEvent(EventTypeConsts.Error, "Empty response from WebService", this.UrlAddress); } } catch (Exception ex) { this.LogEvent(EventTypeConsts.Error, "Webservice read message error", ex.Message + " " + ex.StackTrace); }finally { ReaderMutex.ReleaseMutex(); } }