/// <summary>
        /// Delete the given challenge from the database.
        /// </summary>
        /// <param name="Name">The name of the challenge.</param>
        public void DeleteChallenge(string Name)
        {
            if (Name == null)
            {
                throw new ArgumentNullException();
            }

            // Remove it from the database.
            Challenges.DeleteChallenge(Name);

            // Update the challenge list.
            challengeList = Challenges.GetChallenges();

            // Set a new current challenge.
            if (challengeList.Count == 0)
            {
                CurrentChallenge = "";
            }
            else
            {
                // TODO: Can we assume that the last item in the list is the newest?
                CurrentChallenge = challengeList.Last();
            }

            // We changed some of our public properties.
            NotifyPropertyChanged("ChallengeList");
            // TODO: These are redundant to what was done in CurrentChallenge.set
            // so they can probably be deleted.
            NotifyPropertyChanged("CurrentChallenge");
            NotifyPropertyChanged("SplitList");
        }
        public void CreateChallenge(string Name, List <string> Splits)
        {
            if (Name == null || Splits == null)
            {
                throw new ArgumentNullException();
            }
            if (Splits.Count == 0)
            {
                throw new ArgumentException();
            }

            Challenges.CreateChallenge(Name, Splits);
            challengeList    = Challenges.GetChallenges();
            CurrentChallenge = Name;

            // We changed some of our public properties.
            NotifyPropertyChanged("ChallengeList");
        }
        public SplitsViewModel(IUserSettings Settings, IHomunculusModel Model)
        {
            // If the caller is not supplying a user settings
            // interface object, just make our own.
            if (Settings == null)
            {
                UserSettings = new StandardUserSettings();
            }
            else
            {
                UserSettings = Settings;
            }

            // If the caller is not supplying a model object,
            // just make our own.
            if (Model == null)
            {
                Challenges = new ModelXml();
                if (System.IO.File.Exists("homunculus.xml"))
                {
                    Challenges.LoadDatabase("homunculus.xml");
                }
                else
                {
                    Challenges.CreateDatabase("homunculus.xml");
                }
            }
            else
            {
                Challenges = Model;
            }

            // Get the challenges and set one to current, if available.
            challengeList    = Challenges.GetChallenges();
            CurrentChallenge = (string)UserSettings.GetUserSetting("LastUsedChallenge");

            SuccessButtonText = "Success";
        }
        public void RearrangeChallenge(string Name, ObservableCollection <SplitVM> Splits)
        {
            if (Name == null || Splits == null)
            {
                throw new ArgumentNullException();
            }

            // Check for unique new Name before we start processing the splits.
            if (Name != currentChallenge && challengeList.Contains(Name))
            {
                throw new ArgumentException();
            }

            // Convert the split list into what the Model wants.
            List <Split> newSplits = new List <Split>();

            foreach (var s in Splits)
            {
                newSplits.Add(new Split {
                    Handle = s.Handle, Name = s.SplitName
                });
            }

            Challenges.ModifyChallenge(CurrentChallenge, newSplits, Name);

            // TODO: Update challenge list because the name might have changed.
            challengeList = Challenges.GetChallenges();

            // Update split list because the names and/or order might have changed.
            CurrentChallenge = "";             //  hack because CurrentChallenge name isn't different
            CurrentChallenge = Name;

            // We changed some of our public properties.
            NotifyPropertyChanged("CurrentChallenge");
            NotifyPropertyChanged("ChallengeList");
            NotifyPropertyChanged("SplitList");
        }