public object Read(Item item) { object retVal = new object(); SQLConnectorConfigurationDatabase db = Configuration?.Databases?.Where(d => d.Name == "Demo").FirstOrDefault(); SQLConnectorConfigurationDatabaseQuery query = db?.Queries?.Where(q => item.FQN.EndsWith(q.Name)).FirstOrDefault(); retVal = Fetch(db.ConnectionString, query.Query); return retVal; }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { foreach (Item key in Subscriptions.Keys) { if (key.FQN.EndsWith("Batches")) { // check to see if the trigger has updated. ignore the polling time for demo purposes. SQLConnectorConfigurationDatabase db = Configuration.Databases.Where(d => d.Name == "Demo").FirstOrDefault(); SQLConnectorConfigurationDatabaseQuery query = db.Queries.Where(q => q.Name == "Batches").FirstOrDefault(); SQLConnectorConfigurationDatabaseQueryTrigger trigger = query.Trigger; if (trigger != default(SQLConnectorConfigurationDatabaseQueryTrigger)) { if (!string.IsNullOrEmpty(trigger.Query)) { DataTable triggerTable = (DataTable)Fetch(db.ConnectionString, trigger.Query); string triggerValue = triggerTable.Rows[0].ItemArray[0].ToString(); if (string.IsNullOrEmpty(triggerValue)) { } else { if (GetCachedTrigger(key) != triggerValue) { logger.Debug("Trigger changed. Firing update."); foreach (Action<object> callback in Subscriptions[key]) { callback.Invoke(Read(key)); } UpdateTriggerCache(key, triggerValue); } } } } } } }