| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Collections.ObjectModel; |
| | | 4 | | using System.ComponentModel; |
| | | 5 | | using System.Text; |
| | | 6 | | using System.Linq; |
| | | 7 | | using System.Text.Json.Serialization; |
| | | 8 | | using MUNityBase.Interfances; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | using MUNity.Base; |
| | | 11 | | |
| | | 12 | | namespace 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> |
| | 0 | 48 | | 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 | | { |
| | 0 | 58 | | get => _publicId; |
| | | 59 | | set |
| | 0 | 60 | | { |
| | 0 | 61 | | if (value != this._publicId) |
| | 0 | 62 | | { |
| | 0 | 63 | | this._publicId = value; |
| | 0 | 64 | | NotifyPropertyChanged(nameof(PublicId)); |
| | 0 | 65 | | } |
| | 0 | 66 | | } |
| | | 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 | | { |
| | 0 | 76 | | get => _name; |
| | | 77 | | set |
| | 0 | 78 | | { |
| | 0 | 79 | | if (this._name != value) |
| | 0 | 80 | | { |
| | 0 | 81 | | this._name = value; |
| | 0 | 82 | | NotifyPropertyChanged(nameof(Name)); |
| | 0 | 83 | | } |
| | 0 | 84 | | } |
| | | 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 | | { |
| | 0 | 93 | | get => _status; |
| | | 94 | | set |
| | 0 | 95 | | { |
| | 0 | 96 | | if (_status != value) |
| | 0 | 97 | | { |
| | 0 | 98 | | _status = value; |
| | 0 | 99 | | NotifyPropertyChanged(nameof(Status)); |
| | 0 | 100 | | } |
| | 0 | 101 | | } |
| | | 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 | | { |
| | 0 | 110 | | get => _speakerTime; |
| | | 111 | | set |
| | 0 | 112 | | { |
| | 0 | 113 | | if (_speakerTime != value) |
| | 0 | 114 | | { |
| | 0 | 115 | | _speakerTime = value; |
| | 0 | 116 | | NotifyPropertyChanged(nameof(SpeakerTime)); |
| | 0 | 117 | | } |
| | 0 | 118 | | } |
| | | 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 | | { |
| | 0 | 127 | | get => _questionTime; |
| | | 128 | | set |
| | 0 | 129 | | { |
| | 0 | 130 | | if (_questionTime != value) |
| | 0 | 131 | | { |
| | 0 | 132 | | _questionTime = value; |
| | 0 | 133 | | NotifyPropertyChanged(nameof(QuestionTime)); |
| | 0 | 134 | | } |
| | 0 | 135 | | } |
| | | 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 | | { |
| | 0 | 144 | | get => _pausedSpeakerTime; |
| | | 145 | | set |
| | 0 | 146 | | { |
| | 0 | 147 | | if (_pausedSpeakerTime != value) |
| | 0 | 148 | | { |
| | 0 | 149 | | _pausedSpeakerTime = value; |
| | 0 | 150 | | NotifyPropertyChanged(nameof(PausedSpeakerTime)); |
| | 0 | 151 | | } |
| | 0 | 152 | | } |
| | | 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 | | { |
| | 0 | 161 | | get => _pausedQuestionTime; |
| | | 162 | | set |
| | 0 | 163 | | { |
| | 0 | 164 | | if (_pausedQuestionTime != value) |
| | 0 | 165 | | { |
| | 0 | 166 | | _pausedQuestionTime = value; |
| | 0 | 167 | | NotifyPropertyChanged(nameof(_pausedQuestionTime)); |
| | 0 | 168 | | } |
| | 0 | 169 | | } |
| | | 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 |
| | 0 | 181 | | { |
| | 0 | 182 | | if (Status == ESpeakerListStatus.Stopped) |
| | 0 | 183 | | return SpeakerTime; |
| | 0 | 184 | | if (Status == ESpeakerListStatus.Question || |
| | 0 | 185 | | Status == ESpeakerListStatus.SpeakerPaused || |
| | 0 | 186 | | Status == ESpeakerListStatus.QuestionPaused || |
| | 0 | 187 | | Status == ESpeakerListStatus.AnswerPaused) |
| | 0 | 188 | | { |
| | 0 | 189 | | return PausedSpeakerTime; |
| | | 190 | | } |
| | 0 | 191 | | else if (Status == ESpeakerListStatus.Speaking) |
| | 0 | 192 | | { |
| | 0 | 193 | | var finishTime = StartSpeakerTime.AddSeconds(SpeakerTime.TotalSeconds); |
| | 0 | 194 | | return finishTime - DateTime.Now.ToUniversalTime(); |
| | | 195 | | // Startzeitpunkt Startzeitpunkt + Speakertime |
| | | 196 | | // |---------------|<-------->| |
| | | 197 | | // Verbleibende Zeit |
| | | 198 | | } |
| | 0 | 199 | | else if (Status == ESpeakerListStatus.Answer) |
| | 0 | 200 | | { |
| | 0 | 201 | | var finishTime = StartSpeakerTime.AddSeconds(QuestionTime.TotalSeconds); |
| | 0 | 202 | | return finishTime - DateTime.Now.ToUniversalTime(); |
| | | 203 | | } |
| | | 204 | | |
| | | 205 | | // Default return |
| | 0 | 206 | | var defaultReturn = StartSpeakerTime.AddSeconds(SpeakerTime.TotalSeconds); |
| | 0 | 207 | | return defaultReturn - DateTime.Now.ToUniversalTime(); |
| | 0 | 208 | | } |
| | | 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 |
| | 0 | 220 | | { |
| | 0 | 221 | | if (Status == ESpeakerListStatus.Stopped) return QuestionTime; |
| | 0 | 222 | | if (Status != ESpeakerListStatus.Question) return PausedQuestionTime; |
| | | 223 | | |
| | 0 | 224 | | var finishTime = StartQuestionTime.AddSeconds(QuestionTime.TotalSeconds); |
| | 0 | 225 | | return finishTime - DateTime.Now.ToUniversalTime(); |
| | 0 | 226 | | } |
| | | 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> |
| | 0 | 232 | | 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 |
| | 0 | 241 | | { |
| | 0 | 242 | | return AllSpeakers.Where(n => n.Mode == SpeakerModes.WaitToSpeak).OrderBy(n => n.OrdnerIndex); |
| | 0 | 243 | | } |
| | | 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 |
| | 0 | 253 | | { |
| | 0 | 254 | | return AllSpeakers.Where(n => n.Mode == SpeakerModes.WaitForQuesiton).OrderBy(n => n.OrdnerIndex); |
| | 0 | 255 | | } |
| | | 256 | | } |
| | | 257 | | |
| | | 258 | | /// <summary> |
| | | 259 | | /// The person currently speaking or waiting to answer a question. |
| | | 260 | | /// </summary> |
| | | 261 | | [JsonIgnore] |
| | 0 | 262 | | public ISpeaker CurrentSpeaker => AllSpeakers.FirstOrDefault(n => n.Mode == SpeakerModes.CurrentlySpeaking); |
| | | 263 | | |
| | | 264 | | /// <summary> |
| | | 265 | | /// The person currently asking a question. |
| | | 266 | | /// </summary> |
| | | 267 | | [JsonIgnore] |
| | 0 | 268 | | public ISpeaker CurrentQuestion => AllSpeakers.FirstOrDefault(n => n.Mode == SpeakerModes.CurrentQuestion); |
| | | 269 | | |
| | | 270 | | |
| | 0 | 271 | | 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 | | { |
| | 0 | 279 | | get => _listClosed; |
| | | 280 | | set |
| | 0 | 281 | | { |
| | 0 | 282 | | if (_listClosed != value) |
| | 0 | 283 | | { |
| | 0 | 284 | | _listClosed = value; |
| | 0 | 285 | | NotifyPropertyChanged(nameof(ListClosed)); |
| | 0 | 286 | | } |
| | 0 | 287 | | } |
| | | 288 | | } |
| | | 289 | | |
| | 0 | 290 | | 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 | | { |
| | 0 | 297 | | get => _questionsClosed; |
| | | 298 | | set |
| | 0 | 299 | | { |
| | 0 | 300 | | if (_questionsClosed != value) |
| | 0 | 301 | | { |
| | 0 | 302 | | _questionsClosed = value; |
| | 0 | 303 | | NotifyPropertyChanged(nameof(QuestionsClosed)); |
| | 0 | 304 | | } |
| | 0 | 305 | | } |
| | | 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 | | { |
| | 0 | 315 | | get => _startSpeakerTime; |
| | | 316 | | set |
| | 0 | 317 | | { |
| | 0 | 318 | | if (_startSpeakerTime != value) |
| | 0 | 319 | | { |
| | 0 | 320 | | _startSpeakerTime = value; |
| | 0 | 321 | | NotifyPropertyChanged(nameof(StartSpeakerTime)); |
| | 0 | 322 | | } |
| | 0 | 323 | | } |
| | | 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 | | { |
| | 0 | 333 | | get => _startQuestionTime; |
| | | 334 | | set |
| | 0 | 335 | | { |
| | 0 | 336 | | if (_startQuestionTime != value) |
| | 0 | 337 | | { |
| | 0 | 338 | | _startQuestionTime = value; |
| | 0 | 339 | | NotifyPropertyChanged(nameof(StartQuestionTime)); |
| | 0 | 340 | | } |
| | 0 | 341 | | } |
| | | 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> |
| | 0 | 348 | | public ListOfSpeakersViewModel() |
| | 0 | 349 | | { |
| | 0 | 350 | | this.ListOfSpeakersId = Guid.NewGuid().ToString(); |
| | 0 | 351 | | this.SpeakerTime = new TimeSpan(0, 3, 0); |
| | 0 | 352 | | this.QuestionTime = new TimeSpan(0, 0, 30); |
| | 0 | 353 | | this.PausedSpeakerTime = this.SpeakerTime; |
| | 0 | 354 | | this.PausedQuestionTime = this.QuestionTime; |
| | 0 | 355 | | AllSpeakers = new ObservableCollection<SpeakerViewModel>(); |
| | 0 | 356 | | AllSpeakers.CollectionChanged += _allSpeakers_CollectionChanged; |
| | 0 | 357 | | } |
| | | 358 | | |
| | | 359 | | private void _allSpeakers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChange |
| | 0 | 360 | | { |
| | 0 | 361 | | if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) |
| | 0 | 362 | | { |
| | 0 | 363 | | if (e.NewItems.OfType<SpeakerViewModel>().Any(n => n.Mode == SpeakerModes.WaitToSpeak)) |
| | 0 | 364 | | { |
| | 0 | 365 | | NotifyPropertyChanged(nameof(Speakers)); |
| | 0 | 366 | | } |
| | 0 | 367 | | if (e.NewItems.OfType<SpeakerViewModel>().Any(n => n.Mode == SpeakerModes.WaitForQuesiton)) |
| | 0 | 368 | | { |
| | 0 | 369 | | NotifyPropertyChanged(nameof(Questions)); |
| | 0 | 370 | | } |
| | 0 | 371 | | } |
| | 0 | 372 | | } |
| | | 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 = "") |
| | 0 | 384 | | { |
| | 0 | 385 | | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); |
| | 0 | 386 | | } |
| | | 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 = "") |
| | 0 | 397 | | { |
| | 0 | 398 | | var newSpeaker = new SpeakerViewModel() |
| | 0 | 399 | | { |
| | 0 | 400 | | Id = Guid.NewGuid().ToString(), |
| | 0 | 401 | | Iso = iso, |
| | 0 | 402 | | Name = name, |
| | 0 | 403 | | ListOfSpeakers = this, |
| | 0 | 404 | | Mode = SpeakerModes.WaitToSpeak |
| | 0 | 405 | | }; |
| | 0 | 406 | | if (this.Speakers.Any()) |
| | 0 | 407 | | { |
| | 0 | 408 | | newSpeaker.OrdnerIndex = this.Speakers.Max(n => n.OrdnerIndex) + 1; |
| | 0 | 409 | | } |
| | 0 | 410 | | this.AllSpeakers.Add(newSpeaker); |
| | 0 | 411 | | return newSpeaker; |
| | 0 | 412 | | } |
| | | 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) |
| | 0 | 424 | | { |
| | 0 | 425 | | var speaker = this.AllSpeakers.FirstOrDefault(n => n.Id == id); |
| | 0 | 426 | | if (speaker != null) |
| | 0 | 427 | | this.AllSpeakers.Remove(speaker); |
| | 0 | 428 | | } |
| | | 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 = "") |
| | 0 | 438 | | { |
| | 0 | 439 | | var newSpeaker = new SpeakerViewModel() |
| | 0 | 440 | | { |
| | 0 | 441 | | Id = Guid.NewGuid().ToString(), |
| | 0 | 442 | | Iso = iso, |
| | 0 | 443 | | Name = name, |
| | 0 | 444 | | ListOfSpeakers = this, |
| | 0 | 445 | | Mode = SpeakerModes.WaitForQuesiton |
| | 0 | 446 | | }; |
| | 0 | 447 | | if (this.Questions.Any()) |
| | 0 | 448 | | { |
| | 0 | 449 | | newSpeaker.OrdnerIndex = this.Questions.Max(n => n.OrdnerIndex) + 1; |
| | 0 | 450 | | } |
| | 0 | 451 | | this.AllSpeakers.Add(newSpeaker); |
| | 0 | 452 | | return newSpeaker; |
| | 0 | 453 | | } |
| | | 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) |
| | 0 | 461 | | { |
| | 0 | 462 | | if (this.ListOfSpeakersId != other.ListOfSpeakersId) |
| | 0 | 463 | | return 1; |
| | 0 | 464 | | if (this.CurrentQuestion == null && other.CurrentQuestion != null) |
| | 0 | 465 | | return 1; |
| | 0 | 466 | | if (this.CurrentQuestion != null && other.CurrentQuestion == null) |
| | 0 | 467 | | return 1; |
| | 0 | 468 | | if (this.CurrentQuestion != null && other.CurrentQuestion != null) |
| | 0 | 469 | | if (this.CurrentQuestion.CompareTo(other.CurrentQuestion) != 0) |
| | 0 | 470 | | return 1; |
| | | 471 | | |
| | 0 | 472 | | if (this.CurrentSpeaker == null && other.CurrentSpeaker != null) |
| | 0 | 473 | | return 1; |
| | 0 | 474 | | if (this.CurrentSpeaker != null && other.CurrentSpeaker == null) |
| | 0 | 475 | | return 1; |
| | 0 | 476 | | if (this.CurrentSpeaker != null && other.CurrentSpeaker != null) |
| | 0 | 477 | | if (this.CurrentSpeaker.CompareTo(other.CurrentSpeaker) != 0) |
| | 0 | 478 | | return 1; |
| | | 479 | | |
| | 0 | 480 | | if (this.ListClosed != other.ListClosed) |
| | 0 | 481 | | return 1; |
| | 0 | 482 | | if (this.Name != other.Name) |
| | 0 | 483 | | return 1; |
| | 0 | 484 | | if (this.PausedQuestionTime != other.PausedQuestionTime) |
| | 0 | 485 | | return 1; |
| | 0 | 486 | | if (this.PausedSpeakerTime != other.PausedSpeakerTime) |
| | 0 | 487 | | return 1; |
| | 0 | 488 | | if (this.PublicId != other.PublicId) |
| | 0 | 489 | | return 1; |
| | 0 | 490 | | if (this.QuestionsClosed != other.QuestionsClosed) |
| | 0 | 491 | | return 1; |
| | 0 | 492 | | if (this.QuestionTime != other.QuestionTime) |
| | 0 | 493 | | return 1; |
| | 0 | 494 | | if (this.SpeakerTime != other.SpeakerTime) |
| | 0 | 495 | | return 1; |
| | 0 | 496 | | if (this.StartQuestionTime != other.StartQuestionTime) |
| | 0 | 497 | | return 1; |
| | 0 | 498 | | if (this.StartSpeakerTime != other.StartSpeakerTime) |
| | 0 | 499 | | return 1; |
| | 0 | 500 | | if (this.Status != other.Status) |
| | 0 | 501 | | return 1; |
| | 0 | 502 | | if (this.AllSpeakers.Count != other.AllSpeakers.Count) |
| | 0 | 503 | | return 1; |
| | 0 | 504 | | if (this.AllSpeakers.Any() && other.AllSpeakers.Any()) |
| | 0 | 505 | | { |
| | 0 | 506 | | for (int i = 0; i < this.AllSpeakers.Count; i++) |
| | 0 | 507 | | { |
| | 0 | 508 | | if (this.AllSpeakers[i].CompareTo(other.AllSpeakers[i]) != 0) |
| | 0 | 509 | | return 1; |
| | 0 | 510 | | } |
| | 0 | 511 | | } |
| | | 512 | | |
| | 0 | 513 | | return 0; |
| | | 514 | | |
| | 0 | 515 | | } |
| | | 516 | | |
| | | 517 | | public void RemoveQuestion(string id) |
| | 0 | 518 | | { |
| | 0 | 519 | | var speakerToRemove = this.AllSpeakers.FirstOrDefault(n => n.Id == id); |
| | 0 | 520 | | if (speakerToRemove != null) |
| | 0 | 521 | | this.AllSpeakers.Remove(speakerToRemove); |
| | 0 | 522 | | } |
| | | 523 | | |
| | | 524 | | public void AddSpeakerSeconds(double seconds) |
| | 0 | 525 | | { |
| | 0 | 526 | | this.StartSpeakerTime = this.StartSpeakerTime.AddSeconds(seconds); |
| | 0 | 527 | | } |
| | | 528 | | |
| | | 529 | | public void AddQuestionSeconds(double seconds) |
| | 0 | 530 | | { |
| | 0 | 531 | | this.StartQuestionTime = this.StartQuestionTime.AddSeconds(seconds); |
| | 0 | 532 | | } |
| | | 533 | | |
| | | 534 | | public ISpeaker NextSpeaker() |
| | 0 | 535 | | { |
| | 0 | 536 | | if (this.AllSpeakers.Any(n => n.Mode == SpeakerModes.WaitToSpeak)) |
| | 0 | 537 | | { |
| | | 538 | | |
| | | 539 | | // Remove all Questions, Current Speakers and the one currently asking a Question. |
| | 0 | 540 | | var questions = this.AllSpeakers.Where(n => n.Mode != SpeakerModes.WaitToSpeak).ToList(); |
| | 0 | 541 | | questions.ForEach(n => AllSpeakers.Remove(n)); |
| | | 542 | | |
| | | 543 | | // Remove the current Question |
| | 0 | 544 | | ClearCurrentQuestion(); |
| | | 545 | | |
| | | 546 | | // Pick the first speaker in line |
| | 0 | 547 | | var nextSpeaker = AllSpeakers.OrderBy(n => n.OrdnerIndex).First(); |
| | 0 | 548 | | nextSpeaker.Mode = SpeakerModes.CurrentlySpeaking; |
| | 0 | 549 | | NotifyPropertyChanged(nameof(CurrentSpeaker)); |
| | 0 | 550 | | NotifyPropertyChanged(nameof(CurrentQuestion)); |
| | 0 | 551 | | NotifyPropertyChanged(nameof(Questions)); |
| | 0 | 552 | | NotifyPropertyChanged(nameof(Speakers)); |
| | 0 | 553 | | } |
| | | 554 | | else |
| | 0 | 555 | | { |
| | 0 | 556 | | ClearCurrentSpeaker(); |
| | 0 | 557 | | } |
| | 0 | 558 | | Status = ESpeakerListStatus.Stopped; |
| | 0 | 559 | | return CurrentSpeaker; |
| | 0 | 560 | | } |
| | | 561 | | |
| | | 562 | | public ISpeaker NextQuestion() |
| | 0 | 563 | | { |
| | 0 | 564 | | if (Questions.Any()) |
| | 0 | 565 | | { |
| | | 566 | | // Delete the current Questions (remove all of this type of there is a bug and for some reason two are c |
| | 0 | 567 | | var currentQuestion = AllSpeakers.Where(n => n.Mode == SpeakerModes.CurrentQuestion).ToList(); |
| | 0 | 568 | | currentQuestion.ForEach(n => |
| | 0 | 569 | | AllSpeakers.Remove(n)); |
| | | 570 | | |
| | 0 | 571 | | var nextQuestion = AllSpeakers.Where(n => n.Mode == SpeakerModes.WaitForQuesiton).OrderBy(n => n.OrdnerI |
| | 0 | 572 | | nextQuestion.Mode = SpeakerModes.CurrentQuestion; |
| | 0 | 573 | | NotifyPropertyChanged(nameof(Questions)); |
| | 0 | 574 | | NotifyPropertyChanged(nameof(CurrentQuestion)); |
| | 0 | 575 | | } |
| | | 576 | | else |
| | 0 | 577 | | { |
| | 0 | 578 | | ClearCurrentQuestion(); |
| | 0 | 579 | | } |
| | | 580 | | |
| | 0 | 581 | | if (Status == ESpeakerListStatus.Speaking) |
| | 0 | 582 | | { |
| | 0 | 583 | | PauseSpeaker(); |
| | 0 | 584 | | } |
| | | 585 | | else |
| | 0 | 586 | | { |
| | 0 | 587 | | Status = ESpeakerListStatus.Stopped; |
| | 0 | 588 | | } |
| | 0 | 589 | | return CurrentQuestion; |
| | 0 | 590 | | } |
| | | 591 | | |
| | | 592 | | public void Pause() |
| | 0 | 593 | | { |
| | 0 | 594 | | if (Status == ESpeakerListStatus.Question) |
| | 0 | 595 | | PauseQuestion(); |
| | 0 | 596 | | else if (Status == ESpeakerListStatus.Speaking || |
| | 0 | 597 | | Status == ESpeakerListStatus.Answer) |
| | 0 | 598 | | PauseSpeaker(); |
| | 0 | 599 | | } |
| | | 600 | | |
| | | 601 | | public void ResumeQuestion() |
| | 0 | 602 | | { |
| | 0 | 603 | | if (CurrentQuestion != null) |
| | 0 | 604 | | { |
| | 0 | 605 | | if (Status == ESpeakerListStatus.QuestionPaused) |
| | 0 | 606 | | { |
| | 0 | 607 | | StartQuestionTime = DateTime.Now.ToUniversalTime().AddSeconds(RemainingQuestionTime.TotalSeconds - Q |
| | 0 | 608 | | } |
| | | 609 | | else |
| | 0 | 610 | | { |
| | 0 | 611 | | StartQuestion(); |
| | 0 | 612 | | } |
| | | 613 | | |
| | 0 | 614 | | Status = ESpeakerListStatus.Question; |
| | 0 | 615 | | } |
| | | 616 | | else |
| | 0 | 617 | | { |
| | 0 | 618 | | Status = ESpeakerListStatus.Stopped; |
| | 0 | 619 | | } |
| | 0 | 620 | | } |
| | | 621 | | |
| | | 622 | | public void StartAnswer() |
| | 0 | 623 | | { |
| | 0 | 624 | | if (CurrentSpeaker != null) |
| | 0 | 625 | | { |
| | 0 | 626 | | PausedQuestionTime = QuestionTime; |
| | 0 | 627 | | StartSpeakerTime = DateTime.Now.ToUniversalTime(); |
| | 0 | 628 | | Status = ESpeakerListStatus.Answer; |
| | 0 | 629 | | } |
| | | 630 | | else |
| | 0 | 631 | | { |
| | 0 | 632 | | Status = ESpeakerListStatus.Stopped; |
| | 0 | 633 | | } |
| | 0 | 634 | | } |
| | | 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() |
| | 0 | 641 | | { |
| | 0 | 642 | | if (Status == ESpeakerListStatus.Speaking || |
| | 0 | 643 | | Status == ESpeakerListStatus.SpeakerPaused || |
| | 0 | 644 | | Status == ESpeakerListStatus.Answer || |
| | 0 | 645 | | Status == ESpeakerListStatus.AnswerPaused) |
| | 0 | 646 | | 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 |
| | 0 | 648 | | var currentSpeakers = AllSpeakers.Where(n => n.Mode == SpeakerModes.CurrentlySpeaking).ToList(); |
| | 0 | 649 | | currentSpeakers.ForEach(n => AllSpeakers.Remove(n)); |
| | 0 | 650 | | NotifyPropertyChanged(nameof(CurrentSpeaker)); |
| | 0 | 651 | | } |
| | | 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() |
| | 0 | 658 | | { |
| | 0 | 659 | | if (Status == ESpeakerListStatus.Question || |
| | 0 | 660 | | Status == ESpeakerListStatus.QuestionPaused) |
| | 0 | 661 | | 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 |
| | 0 | 663 | | var currentQuestion = AllSpeakers.Where(n => n.Mode == SpeakerModes.CurrentQuestion).ToList(); |
| | 0 | 664 | | currentQuestion.ForEach(n => AllSpeakers.Remove(n)); |
| | 0 | 665 | | NotifyPropertyChanged(nameof(CurrentQuestion)); |
| | 0 | 666 | | } |
| | | 667 | | |
| | | 668 | | private void PauseSpeaker() |
| | 0 | 669 | | { |
| | 0 | 670 | | PausedSpeakerTime = RemainingSpeakerTime; |
| | 0 | 671 | | if (Status == ESpeakerListStatus.Speaking) |
| | 0 | 672 | | Status = ESpeakerListStatus.SpeakerPaused; |
| | 0 | 673 | | else if (Status == ESpeakerListStatus.Answer) |
| | 0 | 674 | | Status = ESpeakerListStatus.AnswerPaused; |
| | 0 | 675 | | } |
| | | 676 | | |
| | | 677 | | private void PauseQuestion() |
| | 0 | 678 | | { |
| | 0 | 679 | | PausedQuestionTime = RemainingQuestionTime; |
| | 0 | 680 | | if (Status == ESpeakerListStatus.Question) |
| | 0 | 681 | | Status = ESpeakerListStatus.QuestionPaused; |
| | 0 | 682 | | } |
| | | 683 | | |
| | | 684 | | private void StartQuestion() |
| | 0 | 685 | | { |
| | 0 | 686 | | if (CurrentQuestion != null) |
| | 0 | 687 | | { |
| | | 688 | | // Reset the current Speaker time |
| | 0 | 689 | | PausedSpeakerTime = SpeakerTime; |
| | 0 | 690 | | StartQuestionTime = DateTime.Now.ToUniversalTime(); |
| | 0 | 691 | | Status = ESpeakerListStatus.Question; |
| | 0 | 692 | | } |
| | 0 | 693 | | } |
| | | 694 | | |
| | | 695 | | public void ResumeSpeaker() |
| | 0 | 696 | | { |
| | 0 | 697 | | if (CurrentSpeaker != null) |
| | 0 | 698 | | { |
| | 0 | 699 | | if (Status == ESpeakerListStatus.SpeakerPaused) |
| | 0 | 700 | | ContinueSpeaker(); |
| | 0 | 701 | | else if (Status == ESpeakerListStatus.AnswerPaused) |
| | 0 | 702 | | ContinueAnswer(); |
| | | 703 | | else |
| | 0 | 704 | | StartSpeaker(); |
| | | 705 | | |
| | | 706 | | // Fixes a small glitch in the Question time! |
| | 0 | 707 | | StartQuestionTime = DateTime.Now.ToUniversalTime(); |
| | | 708 | | |
| | 0 | 709 | | } |
| | | 710 | | else |
| | 0 | 711 | | { |
| | 0 | 712 | | Status = ESpeakerListStatus.Stopped; |
| | 0 | 713 | | } |
| | 0 | 714 | | } |
| | | 715 | | |
| | | 716 | | private void StartSpeaker() |
| | 0 | 717 | | { |
| | 0 | 718 | | if (CurrentSpeaker != null) |
| | 0 | 719 | | { |
| | 0 | 720 | | PausedQuestionTime = QuestionTime; |
| | 0 | 721 | | StartSpeakerTime = DateTime.Now.ToUniversalTime(); |
| | 0 | 722 | | Status = ESpeakerListStatus.Speaking; |
| | 0 | 723 | | } |
| | 0 | 724 | | } |
| | | 725 | | |
| | | 726 | | private void ContinueSpeaker() |
| | 0 | 727 | | { |
| | 0 | 728 | | StartSpeakerTime = DateTime.Now.ToUniversalTime().AddSeconds(RemainingSpeakerTime.TotalSeconds - SpeakerTime |
| | 0 | 729 | | Status = ESpeakerListStatus.Speaking; |
| | 0 | 730 | | } |
| | | 731 | | |
| | | 732 | | private void ContinueAnswer() |
| | 0 | 733 | | { |
| | 0 | 734 | | StartSpeakerTime = DateTime.Now.ToUniversalTime().AddSeconds(RemainingSpeakerTime.TotalSeconds - QuestionTim |
| | 0 | 735 | | Status = ESpeakerListStatus.Answer; |
| | 0 | 736 | | } |
| | | 737 | | |
| | | 738 | | public void ResetSpeakerTime() |
| | 0 | 739 | | { |
| | 0 | 740 | | StartSpeakerTime = DateTime.Now.ToUniversalTime(); |
| | 0 | 741 | | } |
| | | 742 | | |
| | | 743 | | public void ResetQuestionTime() |
| | 0 | 744 | | { |
| | 0 | 745 | | StartQuestionTime = DateTime.Now.ToUniversalTime(); |
| | 0 | 746 | | } |
| | | 747 | | } |
| | | 748 | | } |