private void timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (running)
     {
         // 1. open the datastream
         ExportUI exportUI = new ExportUI();
         exportUI.SetupDataStream(true, accountName.Text, accountKey.Text, homeID.Text, appID.Text, streamID.Text);
         // 2. get latest
         Dictionary <IKey, Tuple <IValue, DateTime> > latestVals = getLatestHelper(exportUI);
         // 3. check rules
         checkRules(latestVals);
         // 4. close datastream
         exportUI.CloseDataStream();
     }
 }
        public MainWindow()
        {
            InitializeComponent();
            accountName.Text = ConfigurationManager.AppSettings.Get("AccountName");
            accountKey.Text  = ConfigurationManager.AppSettings.Get("AccountSharedKey");
            homeID.Text      = ConfigurationManager.AppSettings.Get("HomeId");
            appID.Text       = ConfigurationManager.AppSettings.Get("AppId");
            streamID.Text    = ConfigurationManager.AppSettings.Get("StreamId");

            uiE = new ExportUI();

            data_pull_timer          = new System.Timers.Timer(60 * 1000);
            data_pull_timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            data_pull_timer.Enabled  = true;
            running = true;
        }
        private Dictionary <IKey, Tuple <IValue, DateTime> > getLatestHelper(ExportUI exportUIObj)
        {
            HashSet <IKey> selectedKeys = getSelectedKeys();

            Dictionary <IKey, Tuple <IValue, DateTime> > latestVals = exportUIObj.GetLatest(selectedKeys);

            if (latestVals != null)
            {
                foreach (IKey tag in latestVals.Keys)
                {
                    tbLatest.Text += tag + "," + latestVals[tag].Item1.ToString() + "," + latestVals[tag].Item2.ToString() + "\n";
                }
            }

            //  tbLatest.Text = latestVals.ToString();
            // btnExportData.IsEnabled = true;
            return(latestVals);
        }