< Summary

Class:MUNity.ViewModels.ListOfSpeakers.ListOfSpeakersViewModel
Assembly:MUNity.Schema
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNitySchema\Models\ListOfSpeakers\ListOfSpeakersViewModel.cs
Covered lines:0
Uncovered lines:401
Coverable lines:401
Total lines:748
Line coverage:0% (0 of 401)
Covered branches:0
Total branches:164
Branch coverage:0% (0 of 164)
Covered methods:0
Total methods:56
Method coverage:0% (0 of 56)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_ListOfSpeakersId()100%10%
get_PublicId()100%10%
set_PublicId(...)0%20%
get_Name()100%10%
set_Name(...)0%20%
get_Status()100%10%
set_Status(...)0%20%
get_SpeakerTime()100%10%
set_SpeakerTime(...)0%20%
get_QuestionTime()100%10%
set_QuestionTime(...)0%20%
get_PausedSpeakerTime()100%10%
set_PausedSpeakerTime(...)0%20%
get_PausedQuestionTime()100%10%
set_PausedQuestionTime(...)0%20%
get_RemainingSpeakerTime()0%140%
get_RemainingQuestionTime()0%40%
get_AllSpeakers()100%10%
get_Speakers()100%10%
get_Questions()100%10%
get_CurrentSpeaker()100%10%
get_CurrentQuestion()100%10%
.ctor()100%10%
get_ListClosed()100%10%
set_ListClosed(...)0%20%
get_QuestionsClosed()100%10%
set_QuestionsClosed(...)0%20%
get_StartSpeakerTime()100%10%
set_StartSpeakerTime(...)0%20%
get_StartQuestionTime()100%10%
set_StartQuestionTime(...)0%20%
_allSpeakers_CollectionChanged(...)0%60%
NotifyPropertyChanged(...)0%20%
AddSpeaker(...)0%20%
RemoveSpeaker(...)0%20%
AddQuestion(...)0%20%
CompareTo(...)0%620%
RemoveQuestion(...)0%20%
AddSpeakerSeconds(...)100%10%
AddQuestionSeconds(...)100%10%
NextSpeaker()0%20%
NextQuestion()0%40%
Pause()0%60%
ResumeQuestion()0%40%
StartAnswer()0%20%
ClearCurrentSpeaker()0%80%
ClearCurrentQuestion()0%40%
PauseSpeaker()0%40%
PauseQuestion()0%20%
StartQuestion()0%20%
ResumeSpeaker()0%60%
StartSpeaker()0%20%
ContinueSpeaker()100%10%
ContinueAnswer()100%10%
ResetSpeakerTime()100%10%
ResetQuestionTime()100%10%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNitySchema\Models\ListOfSpeakers\ListOfSpeakersViewModel.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Collections.ObjectModel;
 4using System.ComponentModel;
 5using System.Text;
 6using System.Linq;
 7using System.Text.Json.Serialization;
 8using MUNityBase.Interfances;
 9using System.Runtime.CompilerServices;
 10using MUNity.Base;
 11
 12namespace MUNity.ViewModels.ListOfSpeakers
 13{
 14
 15    /// <summary>
 16    /// The Base Structure for the List Of Speakers. Note that the logic can be found when using
 17    /// MUNity.Extensions.LoSExtensions.
 18    /// The ListOfSpeakers dont work with timers but with timestamps that can be tracked.
 19    /// To create a new List simply call the constructor.
 20    ///
 21    /// <code>
 22    /// var listOfSpeakers = new ListOfSpeakers();
 23    /// // Remember to import MUNity.Extension.LoSExtensions!
 24    /// // This will add a new Speaker to the list.
 25    /// listOfSpeakers.AddSpeaker("Germany", "de");
 26    ///
 27    /// // This will set Germany as the CurrentSpeaker
 28    /// listOfSpeakers.NextSpeaker();
 29    ///
 30    /// // This will activate the Speaking Mode.
 31    /// listOfSpeakers.StartSpeaker();
 32    /// // You could also use:
 33    /// // listofSpeakers.ResumeSpeaker();
 34    ///
 35    /// // You can get the remaining time from:
 36    /// var remaingingTime = listOfSpeakers.RemainingSpeakerTime;
 37    /// // You could use a timer to refresh/reload the ReaminingSpeakerTime every second to get a countdown.
 38    /// </code>
 39    /// <seealso cref="MUNity.Extensions.LoSExtensions"/>
 40    /// </summary>
 41    public class ListOfSpeakersViewModel : INotifyPropertyChanged, IComparable<ListOfSpeakersViewModel>, IListOfSpeakers
 42    {
 43
 44
 45        /// <summary>
 46        /// The Id of the List of Speakers will be given a new GUID when the constructor is called.
 47        /// </summary>
 048        public string ListOfSpeakersId { get; set; }
 49
 50        private string _publicId;
 51        /// <summary>
 52        /// A public Id for example a code that you can give out to others to be able to read the List of Speakers
 53        /// to be able to read but not interact with it. Note that the MUNityBase does not have a logic for this
 54        /// and it will be implemented in the API.
 55        /// </summary>
 56        public string PublicId
 57        {
 058            get => _publicId;
 59            set
 060            {
 061                if (value != this._publicId)
 062                {
 063                    this._publicId = value;
 064                    NotifyPropertyChanged(nameof(PublicId));
 065                }
 066            }
 67        }
 68
 69        private string _name;
 70        /// <summary>
 71        /// A Name of a list of Speakers. That can be displayed. The Name is not used to identify the list, to identitfy
 72        /// the ListOfSpeakersId.
 73        /// </summary>
 74        public string Name
 75        {
 076            get => _name;
 77            set
 078            {
 079                if (this._name != value)
 080                {
 081                    this._name = value;
 082                    NotifyPropertyChanged(nameof(Name));
 083                }
 084            }
 85        }
 86
 87        private ESpeakerListStatus _status;
 88        /// <summary>
 89        /// The Current Status of the list, is someone talking, paused or is the List reset to default.
 90        /// </summary>
 91        public ESpeakerListStatus Status
 92        {
 093            get => _status;
 94            set
 095            {
 096                if (_status != value)
 097                {
 098                    _status = value;
 099                    NotifyPropertyChanged(nameof(Status));
 0100                }
 0101            }
 102        }
 103
 104        private TimeSpan _speakerTime;
 105        /// <summary>
 106        /// The time that the Speakers are allowed to talk.
 107        /// </summary>
 108        public TimeSpan SpeakerTime
 109        {
 0110            get => _speakerTime;
 111            set
 0112            {
 0113                if (_speakerTime != value)
 0114                {
 0115                    _speakerTime = value;
 0116                    NotifyPropertyChanged(nameof(SpeakerTime));
 0117                }
 0118            }
 119        }
 120
 121        private TimeSpan _questionTime;
 122        /// <summary>
 123        /// The time that someone asking a question is allowed to talk and also how long the Speaker is allowed to answe
 124        /// </summary>
 125        public TimeSpan QuestionTime
 126        {
 0127            get => _questionTime;
 128            set
 0129            {
 0130                if (_questionTime != value)
 0131                {
 0132                    _questionTime = value;
 0133                    NotifyPropertyChanged(nameof(QuestionTime));
 0134                }
 0135            }
 136        }
 137
 138        private TimeSpan _pausedSpeakerTime;
 139        /// <summary>
 140        /// The Remaining Time that a Speaker had when he/she had been paused.
 141        /// </summary>
 142        public TimeSpan PausedSpeakerTime
 143        {
 0144            get => _pausedSpeakerTime;
 145            set
 0146            {
 0147                if (_pausedSpeakerTime != value)
 0148                {
 0149                    _pausedSpeakerTime = value;
 0150                    NotifyPropertyChanged(nameof(PausedSpeakerTime));
 0151                }
 0152            }
 153        }
 154
 155        private TimeSpan _pausedQuestionTime;
 156        /// <summary>
 157        /// The Remaining Time that a speaker had when he/she had been paused.
 158        /// </summary>
 159        public TimeSpan PausedQuestionTime
 160        {
 0161            get => _pausedQuestionTime;
 162            set
 0163            {
 0164                if (_pausedQuestionTime != value)
 0165                {
 0166                    _pausedQuestionTime = value;
 0167                    NotifyPropertyChanged(nameof(_pausedQuestionTime));
 0168                }
 0169            }
 170        }
 171
 172        /// <summary>
 173        /// Gives you the Remaining time a speaker had at the moment you call this Getter.
 174        /// This will not fire any sort of PropertyChanged event. If you want to implement a countdown
 175        /// you will have to create a timer and recall this getter every Second.
 176        /// </summary>
 177        [JsonIgnore]
 178        public TimeSpan RemainingSpeakerTime
 179        {
 180            get
 0181            {
 0182                if (Status == ESpeakerListStatus.Stopped)
 0183                    return SpeakerTime;
 0184                if (Status == ESpeakerListStatus.Question ||
 0185                    Status == ESpeakerListStatus.SpeakerPaused ||
 0186                    Status == ESpeakerListStatus.QuestionPaused ||
 0187                    Status == ESpeakerListStatus.AnswerPaused)
 0188                {
 0189                    return PausedSpeakerTime;
 190                }
 0191                else if (Status == ESpeakerListStatus.Speaking)
 0192                {
 0193                    var finishTime = StartSpeakerTime.AddSeconds(SpeakerTime.TotalSeconds);
 0194                    return finishTime - DateTime.Now.ToUniversalTime();
 195                    // Startzeitpunkt                 Startzeitpunkt + Speakertime
 196                    //       |---------------|<-------->|
 197                    //                          Verbleibende Zeit
 198                }
 0199                else if (Status == ESpeakerListStatus.Answer)
 0200                {
 0201                    var finishTime = StartSpeakerTime.AddSeconds(QuestionTime.TotalSeconds);
 0202                    return finishTime - DateTime.Now.ToUniversalTime();
 203                }
 204
 205                // Default return
 0206                var defaultReturn = StartSpeakerTime.AddSeconds(SpeakerTime.TotalSeconds);
 0207                return defaultReturn - DateTime.Now.ToUniversalTime();
 0208            }
 209        }
 210
 211        /// <summary>
 212        /// Will return the Remaining QuestionTime at the moment this Getter is called.
 213        /// Note that this will not fire a PropertyChangedEvent. If you want to create a countdown
 214        /// you will have to call this getter with a timer every second or minute howevery you want the countdown to hap
 215        /// </summary>
 216        [JsonIgnore]
 217        public TimeSpan RemainingQuestionTime
 218        {
 219            get
 0220            {
 0221                if (Status == ESpeakerListStatus.Stopped) return QuestionTime;
 0222                if (Status != ESpeakerListStatus.Question) return PausedQuestionTime;
 223
 0224                var finishTime = StartQuestionTime.AddSeconds(QuestionTime.TotalSeconds);
 0225                return finishTime - DateTime.Now.ToUniversalTime();
 0226            }
 227        }
 228
 229        /// <summary>
 230        /// List that holds all Speakers that are inside the Speakers or Questions List and also the Current Speaker/Que
 231        /// </summary>
 0232        public ObservableCollection<SpeakerViewModel> AllSpeakers { get; set; }
 233
 234        /// <summary>
 235        /// A list of speakers that are waiting to speak next.
 236        /// </summary>
 237        [JsonIgnore]
 238        public IEnumerable<SpeakerViewModel> Speakers
 239        {
 240            get
 0241            {
 0242                return AllSpeakers.Where(n => n.Mode == SpeakerModes.WaitToSpeak).OrderBy(n => n.OrdnerIndex);
 0243            }
 244        }
 245
 246        /// <summary>
 247        /// A list of people that want to ask a question.
 248        /// </summary>
 249        [JsonIgnore]
 250        public IEnumerable<SpeakerViewModel> Questions
 251        {
 252            get
 0253            {
 0254                return AllSpeakers.Where(n => n.Mode == SpeakerModes.WaitForQuesiton).OrderBy(n => n.OrdnerIndex);
 0255            }
 256        }
 257
 258        /// <summary>
 259        /// The person currently speaking or waiting to answer a question.
 260        /// </summary>
 261        [JsonIgnore]
 0262        public ISpeaker CurrentSpeaker => AllSpeakers.FirstOrDefault(n => n.Mode == SpeakerModes.CurrentlySpeaking);
 263
 264        /// <summary>
 265        /// The person currently asking a question.
 266        /// </summary>
 267        [JsonIgnore]
 0268        public ISpeaker CurrentQuestion => AllSpeakers.FirstOrDefault(n => n.Mode == SpeakerModes.CurrentQuestion);
 269
 270
 0271        private bool _listClosed = false;
 272        /// <summary>
 273        /// Is the List of Speakers closed. If this is true you should not add people to the Speakers.
 274        /// This will not be catched when calling Speakers.Add()/AddSpeaker("",""). This is more for visual
 275        /// feedback of a closed List.
 276        /// </summary>
 277        public bool ListClosed
 278        {
 0279            get => _listClosed;
 280            set
 0281            {
 0282                if (_listClosed != value)
 0283                {
 0284                    _listClosed = value;
 0285                    NotifyPropertyChanged(nameof(ListClosed));
 0286                }
 0287            }
 288        }
 289
 0290        private bool _questionsClosed = false;
 291        /// <summary>
 292        /// Are people allowed to get on the List of questions. This is only for visual feedback, you can
 293        /// technacally still add people to the list.
 294        /// </summary>
 295        public bool QuestionsClosed
 296        {
 0297            get => _questionsClosed;
 298            set
 0299            {
 0300                if (_questionsClosed != value)
 0301                {
 0302                    _questionsClosed = value;
 0303                    NotifyPropertyChanged(nameof(QuestionsClosed));
 0304                }
 0305            }
 306        }
 307
 308        private DateTime _startSpeakerTime;
 309        /// <summary>
 310        /// The time when to speaker started talking. With the diff between the StartTime and the SpeakerTime the
 311        /// RemainingSpeakerTime will be calculated.
 312        /// </summary>
 313        public DateTime StartSpeakerTime
 314        {
 0315            get => _startSpeakerTime;
 316            set
 0317            {
 0318                if (_startSpeakerTime != value)
 0319                {
 0320                    _startSpeakerTime = value;
 0321                    NotifyPropertyChanged(nameof(StartSpeakerTime));
 0322                }
 0323            }
 324        }
 325
 326        private DateTime _startQuestionTime;
 327        /// <summary>
 328        /// The time when the question started beeing asked. WIth the diff between this and the QuestionTime the
 329        /// RaminingQuestionTime will be calculated.
 330        /// </summary>
 331        public DateTime StartQuestionTime
 332        {
 0333            get => _startQuestionTime;
 334            set
 0335            {
 0336                if (_startQuestionTime != value)
 0337                {
 0338                    _startQuestionTime = value;
 0339                    NotifyPropertyChanged(nameof(StartQuestionTime));
 0340                }
 0341            }
 342        }
 343
 344        /// <summary>
 345        /// Will create a new ListOfSpeakers and generate a new GUID for it, will also init the Speakers and Questions
 346        /// as an empty collection and set the default SpeakerTime to 3 minutes and the QuestionTime to 30 seconds.
 347        /// </summary>
 0348        public ListOfSpeakersViewModel()
 0349        {
 0350            this.ListOfSpeakersId = Guid.NewGuid().ToString();
 0351            this.SpeakerTime = new TimeSpan(0, 3, 0);
 0352            this.QuestionTime = new TimeSpan(0, 0, 30);
 0353            this.PausedSpeakerTime = this.SpeakerTime;
 0354            this.PausedQuestionTime = this.QuestionTime;
 0355            AllSpeakers = new ObservableCollection<SpeakerViewModel>();
 0356            AllSpeakers.CollectionChanged += _allSpeakers_CollectionChanged;
 0357        }
 358
 359        private void _allSpeakers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChange
 0360        {
 0361            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
 0362            {
 0363                if (e.NewItems.OfType<SpeakerViewModel>().Any(n => n.Mode == SpeakerModes.WaitToSpeak))
 0364                {
 0365                    NotifyPropertyChanged(nameof(Speakers));
 0366                }
 0367                if (e.NewItems.OfType<SpeakerViewModel>().Any(n => n.Mode == SpeakerModes.WaitForQuesiton))
 0368                {
 0369                    NotifyPropertyChanged(nameof(Questions));
 0370                }
 0371            }
 0372        }
 373
 374        /// <summary>
 375        /// Gets called when a property inside the ListOfSpeakers has changed. This does not include the ListOfSpeakersI
 376        /// </summary>
 377        public event PropertyChangedEventHandler PropertyChanged;
 378
 379        /// <summary>
 380        /// Fire the PropertyChanged Event for a property with the given name.
 381        /// </summary>
 382        /// <param name="name"></param>
 383        public void NotifyPropertyChanged([CallerMemberName]string name = "")
 0384        {
 0385            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
 0386        }
 387
 388        /// <summary>
 389        /// Creates a new instance of s speaker and adds it to the end of speakers.
 390        /// The speaker will get an Id from a new Guid.
 391        /// </summary>
 392        /// <param name="list">The list of speakers that this should be added to.</param>
 393        /// <param name="name">The display name of the speaker.</param>
 394        /// <param name="iso">The iso that could be used to get an icon.</param>
 395        /// <returns></returns>
 396        public ISpeaker AddSpeaker(string name, string iso = "")
 0397        {
 0398            var newSpeaker = new SpeakerViewModel()
 0399            {
 0400                Id = Guid.NewGuid().ToString(),
 0401                Iso = iso,
 0402                Name = name,
 0403                ListOfSpeakers = this,
 0404                Mode = SpeakerModes.WaitToSpeak
 0405            };
 0406            if (this.Speakers.Any())
 0407            {
 0408                newSpeaker.OrdnerIndex = this.Speakers.Max(n => n.OrdnerIndex) + 1;
 0409            }
 0410            this.AllSpeakers.Add(newSpeaker);
 0411            return newSpeaker;
 0412        }
 413
 414        //public ISpeaker AddSpeaker(SpeakerViewModel speaker)
 415        //{
 416        //    var exisiting = this.AllSpeakers.FirstOrDefault(n => n.Id == speaker.Id);
 417        //    if (exisiting != null) return exisiting;
 418
 419        //    this.AllSpeakers.Add(speaker);
 420        //    return speaker;
 421        //}
 422
 423        public void RemoveSpeaker(string id)
 0424        {
 0425            var speaker = this.AllSpeakers.FirstOrDefault(n => n.Id == id);
 0426            if (speaker != null)
 0427                this.AllSpeakers.Remove(speaker);
 0428        }
 429
 430        /// <summary>
 431        /// Adds someone to the list of questions.
 432        /// </summary>
 433        /// <param name="list">The list that this should be added to.</param>
 434        /// <param name="name">The display name that should be shown inside the list of questions and the current questi
 435        /// <param name="iso">The iso that can be used to find an icon.</param>
 436        /// <returns></returns>
 437        public ISpeaker AddQuestion(string name, string iso = "")
 0438        {
 0439            var newSpeaker = new SpeakerViewModel()
 0440            {
 0441                Id = Guid.NewGuid().ToString(),
 0442                Iso = iso,
 0443                Name = name,
 0444                ListOfSpeakers = this,
 0445                Mode = SpeakerModes.WaitForQuesiton
 0446            };
 0447            if (this.Questions.Any())
 0448            {
 0449                newSpeaker.OrdnerIndex = this.Questions.Max(n => n.OrdnerIndex) + 1;
 0450            }
 0451            this.AllSpeakers.Add(newSpeaker);
 0452            return newSpeaker;
 0453        }
 454
 455        /// <summary>
 456        /// Compares this list of Speakers to another list of speakers by the given values.
 457        /// </summary>
 458        /// <param name="other"></param>
 459        /// <returns></returns>
 460        public int CompareTo(ListOfSpeakersViewModel other)
 0461        {
 0462            if (this.ListOfSpeakersId != other.ListOfSpeakersId)
 0463                return 1;
 0464            if (this.CurrentQuestion == null && other.CurrentQuestion != null)
 0465                return 1;
 0466            if (this.CurrentQuestion != null && other.CurrentQuestion == null)
 0467                return 1;
 0468            if (this.CurrentQuestion != null && other.CurrentQuestion != null)
 0469                if (this.CurrentQuestion.CompareTo(other.CurrentQuestion) != 0)
 0470                    return 1;
 471
 0472            if (this.CurrentSpeaker == null && other.CurrentSpeaker != null)
 0473                return 1;
 0474            if (this.CurrentSpeaker != null && other.CurrentSpeaker == null)
 0475                return 1;
 0476            if (this.CurrentSpeaker != null && other.CurrentSpeaker != null)
 0477                if (this.CurrentSpeaker.CompareTo(other.CurrentSpeaker) != 0)
 0478                    return 1;
 479
 0480            if (this.ListClosed != other.ListClosed)
 0481                return 1;
 0482            if (this.Name != other.Name)
 0483                return 1;
 0484            if (this.PausedQuestionTime != other.PausedQuestionTime)
 0485                return 1;
 0486            if (this.PausedSpeakerTime != other.PausedSpeakerTime)
 0487                return 1;
 0488            if (this.PublicId != other.PublicId)
 0489                return 1;
 0490            if (this.QuestionsClosed != other.QuestionsClosed)
 0491                return 1;
 0492            if (this.QuestionTime != other.QuestionTime)
 0493                return 1;
 0494            if (this.SpeakerTime != other.SpeakerTime)
 0495                return 1;
 0496            if (this.StartQuestionTime != other.StartQuestionTime)
 0497                return 1;
 0498            if (this.StartSpeakerTime != other.StartSpeakerTime)
 0499                return 1;
 0500            if (this.Status != other.Status)
 0501                return 1;
 0502            if (this.AllSpeakers.Count != other.AllSpeakers.Count)
 0503                return 1;
 0504            if (this.AllSpeakers.Any() && other.AllSpeakers.Any())
 0505            {
 0506                for (int i = 0; i < this.AllSpeakers.Count; i++)
 0507                {
 0508                    if (this.AllSpeakers[i].CompareTo(other.AllSpeakers[i]) != 0)
 0509                        return 1;
 0510                }
 0511            }
 512
 0513            return 0;
 514
 0515        }
 516
 517        public void RemoveQuestion(string id)
 0518        {
 0519            var speakerToRemove = this.AllSpeakers.FirstOrDefault(n => n.Id == id);
 0520            if (speakerToRemove != null)
 0521                this.AllSpeakers.Remove(speakerToRemove);
 0522        }
 523
 524        public void AddSpeakerSeconds(double seconds)
 0525        {
 0526            this.StartSpeakerTime = this.StartSpeakerTime.AddSeconds(seconds);
 0527        }
 528
 529        public void AddQuestionSeconds(double seconds)
 0530        {
 0531            this.StartQuestionTime = this.StartQuestionTime.AddSeconds(seconds);
 0532        }
 533
 534        public ISpeaker NextSpeaker()
 0535        {
 0536            if (this.AllSpeakers.Any(n => n.Mode == SpeakerModes.WaitToSpeak))
 0537            {
 538
 539                // Remove all Questions, Current Speakers and the one currently asking a Question.
 0540                var questions = this.AllSpeakers.Where(n => n.Mode != SpeakerModes.WaitToSpeak).ToList();
 0541                questions.ForEach(n => AllSpeakers.Remove(n));
 542
 543                // Remove the current Question
 0544                ClearCurrentQuestion();
 545
 546                // Pick the first speaker in line
 0547                var nextSpeaker = AllSpeakers.OrderBy(n => n.OrdnerIndex).First();
 0548                nextSpeaker.Mode = SpeakerModes.CurrentlySpeaking;
 0549                NotifyPropertyChanged(nameof(CurrentSpeaker));
 0550                NotifyPropertyChanged(nameof(CurrentQuestion));
 0551                NotifyPropertyChanged(nameof(Questions));
 0552                NotifyPropertyChanged(nameof(Speakers));
 0553            }
 554            else
 0555            {
 0556                ClearCurrentSpeaker();
 0557            }
 0558            Status = ESpeakerListStatus.Stopped;
 0559            return CurrentSpeaker;
 0560        }
 561
 562        public ISpeaker NextQuestion()
 0563        {
 0564            if (Questions.Any())
 0565            {
 566                // Delete the current Questions (remove all of this type of there is a bug and for some reason two are c
 0567                var currentQuestion = AllSpeakers.Where(n => n.Mode == SpeakerModes.CurrentQuestion).ToList();
 0568                currentQuestion.ForEach(n =>
 0569                    AllSpeakers.Remove(n));
 570
 0571                var nextQuestion = AllSpeakers.Where(n => n.Mode == SpeakerModes.WaitForQuesiton).OrderBy(n => n.OrdnerI
 0572                nextQuestion.Mode = SpeakerModes.CurrentQuestion;
 0573                NotifyPropertyChanged(nameof(Questions));
 0574                NotifyPropertyChanged(nameof(CurrentQuestion));
 0575            }
 576            else
 0577            {
 0578                ClearCurrentQuestion();
 0579            }
 580
 0581            if (Status == ESpeakerListStatus.Speaking)
 0582            {
 0583                PauseSpeaker();
 0584            }
 585            else
 0586            {
 0587                Status = ESpeakerListStatus.Stopped;
 0588            }
 0589            return CurrentQuestion;
 0590        }
 591
 592        public void Pause()
 0593        {
 0594            if (Status == ESpeakerListStatus.Question)
 0595                PauseQuestion();
 0596            else if (Status == ESpeakerListStatus.Speaking ||
 0597                Status == ESpeakerListStatus.Answer)
 0598                PauseSpeaker();
 0599        }
 600
 601        public void ResumeQuestion()
 0602        {
 0603            if (CurrentQuestion != null)
 0604            {
 0605                if (Status == ESpeakerListStatus.QuestionPaused)
 0606                {
 0607                    StartQuestionTime = DateTime.Now.ToUniversalTime().AddSeconds(RemainingQuestionTime.TotalSeconds - Q
 0608                }
 609                else
 0610                {
 0611                    StartQuestion();
 0612                }
 613
 0614                Status = ESpeakerListStatus.Question;
 0615            }
 616            else
 0617            {
 0618                Status = ESpeakerListStatus.Stopped;
 0619            }
 0620        }
 621
 622        public void StartAnswer()
 0623        {
 0624            if (CurrentSpeaker != null)
 0625            {
 0626                PausedQuestionTime = QuestionTime;
 0627                StartSpeakerTime = DateTime.Now.ToUniversalTime();
 0628                Status = ESpeakerListStatus.Answer;
 0629            }
 630            else
 0631            {
 0632                Status = ESpeakerListStatus.Stopped;
 0633            }
 0634        }
 635
 636        /// <summary>
 637        /// Resets the Current Speaker and sets that Status to Stopped if the current Status has something to do with th
 638        /// </summary>
 639        /// <param name="list"></param>
 640        public void ClearCurrentSpeaker()
 0641        {
 0642            if (Status == ESpeakerListStatus.Speaking ||
 0643                Status == ESpeakerListStatus.SpeakerPaused ||
 0644                Status == ESpeakerListStatus.Answer ||
 0645                Status == ESpeakerListStatus.AnswerPaused)
 0646                Status = ESpeakerListStatus.Stopped;
 647            // Delete the current Speaker (remove all of this type of there is a bug and for some reason two are current
 0648            var currentSpeakers = AllSpeakers.Where(n => n.Mode == SpeakerModes.CurrentlySpeaking).ToList();
 0649            currentSpeakers.ForEach(n => AllSpeakers.Remove(n));
 0650            NotifyPropertyChanged(nameof(CurrentSpeaker));
 0651        }
 652
 653        /// <summary>
 654        /// Removes the current Question and sets the status to stopped if the CurrentQuestion was talking of is paused.
 655        /// </summary>
 656        /// <param name="list"></param>
 657        public void ClearCurrentQuestion()
 0658        {
 0659            if (Status == ESpeakerListStatus.Question ||
 0660                Status == ESpeakerListStatus.QuestionPaused)
 0661                Status = ESpeakerListStatus.Stopped;
 662            // Delete the current Questions (remove all of this type of there is a bug and for some reason two are curre
 0663            var currentQuestion = AllSpeakers.Where(n => n.Mode == SpeakerModes.CurrentQuestion).ToList();
 0664            currentQuestion.ForEach(n => AllSpeakers.Remove(n));
 0665            NotifyPropertyChanged(nameof(CurrentQuestion));
 0666        }
 667
 668        private void PauseSpeaker()
 0669        {
 0670            PausedSpeakerTime = RemainingSpeakerTime;
 0671            if (Status == ESpeakerListStatus.Speaking)
 0672                Status = ESpeakerListStatus.SpeakerPaused;
 0673            else if (Status == ESpeakerListStatus.Answer)
 0674                Status = ESpeakerListStatus.AnswerPaused;
 0675        }
 676
 677        private void PauseQuestion()
 0678        {
 0679            PausedQuestionTime = RemainingQuestionTime;
 0680            if (Status == ESpeakerListStatus.Question)
 0681                Status = ESpeakerListStatus.QuestionPaused;
 0682        }
 683
 684        private void StartQuestion()
 0685        {
 0686            if (CurrentQuestion != null)
 0687            {
 688                // Reset the current Speaker time
 0689                PausedSpeakerTime = SpeakerTime;
 0690                StartQuestionTime = DateTime.Now.ToUniversalTime();
 0691                Status = ESpeakerListStatus.Question;
 0692            }
 0693        }
 694
 695        public void ResumeSpeaker()
 0696        {
 0697            if (CurrentSpeaker != null)
 0698            {
 0699                if (Status == ESpeakerListStatus.SpeakerPaused)
 0700                    ContinueSpeaker();
 0701                else if (Status == ESpeakerListStatus.AnswerPaused)
 0702                    ContinueAnswer();
 703                else
 0704                    StartSpeaker();
 705
 706                // Fixes a small glitch in the Question time!
 0707                StartQuestionTime = DateTime.Now.ToUniversalTime();
 708
 0709            }
 710            else
 0711            {
 0712                Status = ESpeakerListStatus.Stopped;
 0713            }
 0714        }
 715
 716        private void StartSpeaker()
 0717        {
 0718            if (CurrentSpeaker != null)
 0719            {
 0720                PausedQuestionTime = QuestionTime;
 0721                StartSpeakerTime = DateTime.Now.ToUniversalTime();
 0722                Status = ESpeakerListStatus.Speaking;
 0723            }
 0724        }
 725
 726        private void ContinueSpeaker()
 0727        {
 0728            StartSpeakerTime = DateTime.Now.ToUniversalTime().AddSeconds(RemainingSpeakerTime.TotalSeconds - SpeakerTime
 0729            Status = ESpeakerListStatus.Speaking;
 0730        }
 731
 732        private void ContinueAnswer()
 0733        {
 0734            StartSpeakerTime = DateTime.Now.ToUniversalTime().AddSeconds(RemainingSpeakerTime.TotalSeconds - QuestionTim
 0735            Status = ESpeakerListStatus.Answer;
 0736        }
 737
 738        public void ResetSpeakerTime()
 0739        {
 0740            StartSpeakerTime = DateTime.Now.ToUniversalTime();
 0741        }
 742
 743        public void ResetQuestionTime()
 0744        {
 0745            StartQuestionTime = DateTime.Now.ToUniversalTime();
 0746        }
 747    }
 748}