private void LoadMessagesFromFile()
        {
            // Empty the loaded messages and messages errors lists
            LoadedMessages.Clear();
            LoadedMessagesErrors.Clear();
            try
            {
                var(messages, unloadedMessages) = validator.ValidateFile(browseFile());
                // First Load All the errors related to the file
                foreach (var error in unloadedMessages)
                {
                    LoadedMessagesErrors.Add(error);
                }

                foreach (var message in messages)
                {
                    try
                    {
                        LoadedMessages.Add(processor.ProcessMessage(message));
                        // Update lists
                        UpdateLists(message);
                    }
                    catch (Exception ex)
                    {
                        // Display Error For This Message
                        LoadedMessagesErrors.Add(ex.Message.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                LoadedMessagesErrors.Add(ex.Message);
            }
        }
        private void SaveLoadedMessages()
        {
            // Clear Error Messages
            LoadedMessagesErrors.Clear();

            //set up a flag for a later message
            var unsaved = 0;
            var saved   = 0;

            // Save the message
            // Throw error if there is no error to be saved
            if (LoadedMessages.Count == 0)
            {
                LoadedMessagesErrors.Add("No message to be saved.");
                return;
            }
            // Try to save to database
            foreach (var message in LoadedMessages)
            {
                try
                {
                    database.serializeToJSON(message);
                    saved = saved + 1;
                }
                catch (Exception ex)
                {
                    LoadedMessagesErrors.Add(ex.Message.ToString());
                    unsaved = unsaved + 1;
                }
            }

            MessageBox.Show("Saving concluded.\nSaved messages: " + saved + "\nUnsaved messages: " + unsaved);
        }
Beispiel #3
0
        private void SaveLoadedMessages()
        {
            // Clear Error Messages
            LoadedMessagesErrors.Clear();

            // Save the message
            // Throw error if there is no error to be saved
            if (LoadedMessages.Count == 0)
            {
                LoadedMessagesErrors.Add("No message to be saved.");
                return;
            }
            // Try to save to database
            foreach (var message in LoadedMessages)
            {
                try
                {
                    database.serializeToJSON(message);
                }
                catch (Exception ex)
                {
                    LoadedMessagesErrors.Add(ex.Message.ToString());
                }
            }
        }