コード例 #1
0
        private void TestGetAlerts(object sender, RoutedEventArgs e)
        {
            if (login == null || String.IsNullOrEmpty(login.SessionID))
            {
                AddMessage("Not logged in.");
                return;
            }
            try {
                List <string> sites    = new List <string>();
                List <string> allSites = new List <string>();
                foreach (CheckBox cb in SiteList.Items)
                {
                    if (cb.IsChecked == true)
                    {
                        sites.Add(cb.Tag.ToString());
                    }

                    allSites.Add(cb.Tag.ToString());
                }

                if (sites.Count() == 0)
                {
                    sites = allSites;                                     //if no site chosen, get alerts for all sites
                }
                int    count = 0;
                string msg   = "";
                for (int i = 0; i < sites.Count(); i++)
                {
                    alerts = api.GetAlerts(login.SessionID, startDate.Text, endDate.Text, Convert.ToInt32(sites.ElementAt(i)));

                    if (alerts.AlertList != null)
                    {
                        count += alerts.AlertList.Count();
                        for (int j = 0; j < alerts.AlertList.Count(); j++)
                        {
                            msg += string.Format("{0}-{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}{9}{10}", alerts.AlertList[j].SiteID, alerts.AlertList[j].AlertID, alerts.AlertList[j].SubCode,
                                                 alerts.AlertList[j].State, alerts.AlertList[j].HID, alerts.AlertList[j].Title, alerts.AlertList[j].Start, alerts.AlertList[j].End, alerts.AlertList[j].Message, Environment.NewLine, Environment.NewLine);
                        }
                    }
                }

                if (count == 0)
                {
                    AddMessage("No alerts found for specified dates.");
                }
                else
                {
                    AddMessage("*** Found " + count.ToString() + " Alerts" + Environment.NewLine + msg);
                }
            } catch (CommunicationException) {
                AddMessage("GetAlerts failed. Returned data may exceed allowable size. Try reducing the timespan on the query.");
            } catch {
                AddMessage("GetAlerts failed. Please check your connection.");
            }
        }