private bool EditText(string xPath)
        {
            string xmlNamespace = "http://www.w3schools.com";

            Console.WriteLine("What is the new text that you would like in this field of the .xml message?");
            var newText = Console.ReadLine().ToLower();
            var editor  = new MessageEditor(_message);

            // The below logic adds the given namespace as the default, making the xPath below work.
            _message.AddDefaultNamespace(xmlNamespace);
            _message.UnvalidatedFile = editor.EditMessage(xPath, newText);
            var errors = _message.Parse(xmlNamespace);

            Console.WriteLine("Xml document {0}\n", errors == "" ? "validated" : $"failed validation\n{errors}" + "\nPlease try again");
            if (!(errors == ""))
            {
                _log.Log(errors, Levels.WARNING);
            }
            return(!(errors == ""));
            // return true if 'errors' string contains anything, false if empty.
        }
Beispiel #2
0
        private void UserSave(XDocument saveFile)
        {
            Console.WriteLine("Please select a name to save the file as\n");
            string saveAs     = Console.ReadLine();
            bool   fileExists = File.Exists(saveAs);

            if (fileExists)
            {
                string aborted = "Save Aborted/n";
                Console.WriteLine("File already exists. Continue saving and overwrite?\ny/n\n");
                string userChoice = (Console.ReadLine());
                userChoice = userChoice.ToLower();
                switch (userChoice)
                {
                case "y":
                case "yes":
                    MessageEditor.Save(saveFile, saveAs, _message);
                    Console.WriteLine("File saved\n\n");
                    Console.ReadKey();
                    break;

                case "n":
                case "no":
                    Console.WriteLine(aborted);
                    break;

                default:
                    Console.WriteLine("I'm sorry, I don't understand that input\n" + aborted);
                    break;
                }
            }
            else
            {
                MessageEditor.Save(saveFile, saveAs, _message);
                Console.WriteLine("File saved\n\n");
            }
        }