Esempio n. 1
0
        private static void RefreshAndFilterEventList(
            ListView listView, TextBox eventIDTextBox, DatePicker datePickerStart,
            DatePicker datePickerEnd, ComboBox eventTypeComboBox, ComboBox stateComboBox,
            ComboBox severityComboBox, ListBox keywordsListBox)
        {
            // Make a new list with all the current objects in the DB to reference.
            List <Alert> AlertList = SQLite_Data_Access.SelectAll_DB();

            // Make a reversed StateDictionary to compare the values to the keys
            Dictionary <String, String> ReversedStateDictionary = new Dictionary <string, string>();

            foreach (var state in Alert.StateDictionary)
            {
                ReversedStateDictionary.Add(state.Value, state.Key);
            }

            // Build LINQ query based on current values
            if (!string.IsNullOrEmpty(eventIDTextBox.Text))
            {
                AlertList = AlertList.Where(alert => alert.Id.Contains(eventIDTextBox.Text)).ToList();
            }
            if (datePickerStart.SelectedDate != null && datePickerEnd.SelectedDate != null)
            {
                AlertList = AlertList.Where(alert => DateTime.Parse(alert.Date) >= datePickerStart.SelectedDate && DateTime.Parse(alert.Date) <= datePickerEnd.SelectedDate).ToList();
            }
            if (!string.IsNullOrEmpty(eventTypeComboBox.Text))
            {
                AlertList = AlertList.Where(alert => alert.EventType == eventTypeComboBox.Text).ToList();
            }
            if (!string.IsNullOrEmpty(stateComboBox.Text))
            {
                AlertList = AlertList.Where(alert => alert.State == ReversedStateDictionary[stateComboBox.Text]).ToList();
            }
            if (!string.IsNullOrEmpty(severityComboBox.Text))
            {
                AlertList = AlertList.Where(alert => alert.Severity == severityComboBox.Text).ToList();
            }
            if (KeywordsFromCheckBoxs(keywordsListBox).Count > 0)
            {
                foreach (var word in KeywordsFromCheckBoxs(keywordsListBox))
                {
                    AlertList = AlertList.Where(alert => alert.DescriptionKeywords.Contains(word)).ToList();
                }
            }

            // Finally add all the Alert objects that were filtered to the ListView
            // And clear old records
            listView.Items.Clear();
            foreach (var Alert in AlertList)
            {
                listView.Items.Add(Alert);
            }
        }
        private void DeleteDB_Button_Click(object sender, RoutedEventArgs e)
        {
            // Give the user one last chance to change their mind before they reset the DB.
            SystemSounds.Exclamation.Play();
            InformUserDialog areYouSureDialog =
                new InformUserDialog("Are you sure you wish to reset the DB?", "DELETE",
                                     "WARNING: This action CLEARS ALL RECORDS in the database " +
                                     "and this cannot be undone. Are you absolutely sure?");

            areYouSureDialog.Owner = this;
            if ((bool)areYouSureDialog.ShowDialog())
            {
                SQLite_Data_Access.DeleteAllIn_DB();

                // Log info
                var Log = new LogHandler("WIPED all DB entries.");
                Log.WriteLogFile();
                this.Close();
            }
        }
        private void EditDB_Button_Click(object sender, RoutedEventArgs e)
        {
            // Allow user to edit the DB after confirming prompt.
            InformUserDialog areYouSureDialog =
                new InformUserDialog("Are you sure you wish to edit the DB?", "Continue",
                                     "WARNING: Improper modifications to this database can cause " +
                                     "corrupted data or put the database in a nonrecoverable state. " +
                                     "Continue with caution.");

            areYouSureDialog.Owner = this;
            if ((bool)areYouSureDialog.ShowDialog())
            {
                // Log info
                var Log = new LogHandler("Edit DB called.");
                Log.WriteLogFile();

                SQLite_Data_Access.UpdateIn_DB("");
                this.Close();
            }
        }
Esempio n. 4
0
        private static void UpdateUIStatusBar(StatusBar statusBar, ListView listView)
        {
            // Update all the items in the Status Bar

            // Grab all items in the statusbar
            List <StatusBarItem> ControlsInStatusBar = new List <StatusBarItem>();

            foreach (var item in statusBar.Items)
            {
                ControlsInStatusBar.Add((StatusBarItem)item);
            }

            // Handle the first StatusBar Item
            int NumberOfAllRecords   = SQLite_Data_Access.SelectAll_DB().Count;
            int NumberOfShownRecords = listView.Items.Count;

            ControlsInStatusBar[0].Content = $"Records Shown: {NumberOfShownRecords}/{NumberOfAllRecords}";

            // Handle the second StatusBar Item
            StartDispatcherTimer(ControlsInStatusBar[1]);
        }
Esempio n. 5
0
        private static bool SyncInfoToDB()
        {
            // Declare bool to check if the data is still being entered or it is done
            bool IsSyncing = true;

            // Call log to write to later.
            LogHandler AlertLog = new LogHandler("Succesfully synced records.\nDuplicates skipped:");

            // Call and Read from GET request.
            var AlertInfoList = NWS_ApiController.ReturnApiCall();

            while (AlertInfoList.Count > 0 && AlertInfoList != null)
            {
                // Place to temporarily store values to construct Alert Objects
                string[] ValuesForObjectInstantiation = new string[11];

                // As each parameter is found add one to delete this number of indexes later.
                int LinesTriggered = 0;

                // Check if a Headline was found since it may not always be sent
                // These are used to make sure the index gets calculated correctly
                bool WasThereA_NwsHeadline = false;
                bool HasIdAlreadyBeenFound = false;

                // Have to check line by line incase some parameters wasn't sent
                for (int CurrentIndex = 0; CurrentIndex < 8; ++CurrentIndex)
                {
                    // Iterate through all entries and scan for certain keywords
                    if (AlertInfoList[CurrentIndex].StartsWith("@id:") && !HasIdAlreadyBeenFound)
                    {
                        // Grab ID
                        ValuesForObjectInstantiation[0] = Alert.ParseID(AlertInfoList[0]);
                        HasIdAlreadyBeenFound           = true;
                        LinesTriggered++;
                    }
                    else if (AlertInfoList[CurrentIndex].StartsWith("areaDesc:"))
                    {
                        // Grab Area Description
                        ValuesForObjectInstantiation[10] = Alert.ParseAreaDescription(AlertInfoList[1]);
                        LinesTriggered++;
                    }
                    else if (AlertInfoList[CurrentIndex].StartsWith("sent:"))
                    {
                        // Grab Date & Time
                        ValuesForObjectInstantiation[1] = Alert.ParseDate(AlertInfoList[2]);
                        ValuesForObjectInstantiation[2] = Alert.ParseTime(AlertInfoList[2]);
                        LinesTriggered++;
                    }
                    else if (AlertInfoList[CurrentIndex].StartsWith("severity:"))
                    {
                        // Grab Severity
                        ValuesForObjectInstantiation[6] = Alert.ParseSeverity(AlertInfoList[3]);
                        LinesTriggered++;
                    }
                    else if (AlertInfoList[CurrentIndex].StartsWith("event:"))
                    {
                        // Grab Event
                        ValuesForObjectInstantiation[3] = Alert.ParseEvent(AlertInfoList[4]);
                        LinesTriggered++;
                    }
                    else if (AlertInfoList[CurrentIndex].StartsWith("senderName:"))
                    {
                        // Grab State & City
                        ValuesForObjectInstantiation[4] = Alert.ParseState(AlertInfoList[5]);
                        ValuesForObjectInstantiation[5] = Alert.ParseCity(AlertInfoList[5]);
                        LinesTriggered++;
                    }
                    else if (AlertInfoList[CurrentIndex].StartsWith("description:"))
                    {
                        ValuesForObjectInstantiation[8]  = Alert.ParseDescription(AlertInfoList[6]);
                        ValuesForObjectInstantiation[9] += Alert.ParseForDescriptiveKeywords(AlertInfoList[6]);
                        LinesTriggered++;
                    }
                    else if (AlertInfoList[CurrentIndex].StartsWith("NWSheadline:"))
                    {
                        WasThereA_NwsHeadline = true;
                        // Grab NwsHeadline & DescriptionKeywords
                        ValuesForObjectInstantiation[7]  = Alert.ParseNWSHeadline(AlertInfoList[7]);
                        ValuesForObjectInstantiation[9] += Alert.ParseForDescriptiveKeywords(AlertInfoList[7]);
                        LinesTriggered++;
                    }
                }

                if (WasThereA_NwsHeadline && LinesTriggered == 8)
                {
                    // Create a new Alert Object and store it in the DB. Insert all the info from the temp array into the object.
                    Alert alert = new Alert(ValuesForObjectInstantiation[0], ValuesForObjectInstantiation[1],
                                            ValuesForObjectInstantiation[2], ValuesForObjectInstantiation[3], ValuesForObjectInstantiation[4],
                                            ValuesForObjectInstantiation[5], ValuesForObjectInstantiation[6], ValuesForObjectInstantiation[7],
                                            ValuesForObjectInstantiation[8], Alert.CleanDescriptiveKeywords(ValuesForObjectInstantiation[9]), ValuesForObjectInstantiation[10]);

                    // Construct the objects and for each skipped object out it to log
                    if (!SQLite_Data_Access.InsertIn_DB(alert))
                    {
                        AlertLog.LogMessage += $" ,{ValuesForObjectInstantiation[0]}";
                        AlertLog.NumOfObjects++;
                    }

                    //Remove and reset all elements that were used in the AlertInfoList for the creation of this object
                    AlertInfoList.RemoveRange(0, LinesTriggered);
                }

                // Check for certain properties that may not have been sent
                else if (WasThereA_NwsHeadline == false && LinesTriggered == 7)
                {
                    // Prevent NULL DB entry and specifically set the entries to
                    if (ValuesForObjectInstantiation[7] == null)
                    {
                        ValuesForObjectInstantiation[7] = "NOT SPECIFIED";
                    }

                    // Create a new Alert Object and store it in the DB. Insert all the info from the temp array into the object.
                    Alert alert = new Alert(ValuesForObjectInstantiation[0], ValuesForObjectInstantiation[1],
                                            ValuesForObjectInstantiation[2], ValuesForObjectInstantiation[3], ValuesForObjectInstantiation[4],
                                            ValuesForObjectInstantiation[5], ValuesForObjectInstantiation[6], ValuesForObjectInstantiation[7],
                                            ValuesForObjectInstantiation[8], Alert.CleanDescriptiveKeywords(ValuesForObjectInstantiation[9]), ValuesForObjectInstantiation[10]);

                    // Construct the objects and for each skipped object out it to log
                    if (!SQLite_Data_Access.InsertIn_DB(alert))
                    {
                        AlertLog.LogMessage += $" {ValuesForObjectInstantiation[0]},";
                        AlertLog.NumOfObjects++;
                    }

                    //Remove and reset all elements that were used in the AlertInfoList for the creation of this object
                    AlertInfoList.RemoveRange(0, LinesTriggered);
                }
            }
            // Output AlertLog
            AlertLog.LogMessage += "\nTotal Skipped Alerts: " + AlertLog.NumOfObjects;
            AlertLog.WriteLogFile();

            // return the bool value
            IsSyncing = false;
            return(IsSyncing);
        }