public void Update(DestinyCharacterActivitiesComponent?other) { if (other is null) { return; } if (DateActivityStarted != other.DateActivityStarted) { DateActivityStarted = other.DateActivityStarted; OnPropertyChanged(nameof(DateActivityStarted)); } if (!AvailableActivities.DeepEqualsList(other.AvailableActivities)) { AvailableActivities = other.AvailableActivities; OnPropertyChanged(nameof(AvailableActivities)); } if (CurrentActivityHash != other.CurrentActivityHash) { CurrentActivityHash = other.CurrentActivityHash; OnPropertyChanged(nameof(CurrentActivityHash)); } if (CurrentActivityModeHash != other.CurrentActivityModeHash) { CurrentActivityModeHash = other.CurrentActivityModeHash; OnPropertyChanged(nameof(CurrentActivityModeHash)); } if (CurrentActivityModeType != other.CurrentActivityModeType) { CurrentActivityModeType = other.CurrentActivityModeType; OnPropertyChanged(nameof(CurrentActivityModeType)); } if (!CurrentActivityModeHashes.DeepEqualsListNaive(other.CurrentActivityModeHashes)) { CurrentActivityModeHashes = other.CurrentActivityModeHashes; OnPropertyChanged(nameof(CurrentActivityModeHashes)); } if (!CurrentActivityModeTypes.DeepEqualsListNaive(other.CurrentActivityModeTypes)) { CurrentActivityModeTypes = other.CurrentActivityModeTypes; OnPropertyChanged(nameof(CurrentActivityModeTypes)); } if (CurrentPlaylistActivityHash != other.CurrentPlaylistActivityHash) { CurrentPlaylistActivityHash = other.CurrentPlaylistActivityHash; OnPropertyChanged(nameof(CurrentPlaylistActivityHash)); } if (LastCompletedStoryHash != other.LastCompletedStoryHash) { LastCompletedStoryHash = other.LastCompletedStoryHash; OnPropertyChanged(nameof(LastCompletedStoryHash)); } }
public bool DeepEquals(DestinyCharacterActivitiesComponent?other) { return(other is not null && DateActivityStarted == other.DateActivityStarted && AvailableActivities.DeepEqualsList(other.AvailableActivities) && CurrentActivityHash == other.CurrentActivityHash && CurrentActivityModeHash == other.CurrentActivityModeHash && CurrentActivityModeType == other.CurrentActivityModeType && CurrentActivityModeHashes.DeepEqualsListNaive(other.CurrentActivityModeHashes) && CurrentActivityModeTypes.DeepEqualsListNaive(other.CurrentActivityModeTypes) && CurrentPlaylistActivityHash == other.CurrentPlaylistActivityHash && LastCompletedStoryHash == other.LastCompletedStoryHash); }
public bool Equals(DestinyCharacterActivitiesComponent input) { if (input == null) { return(false); } return (( DateActivityStarted == input.DateActivityStarted || (DateActivityStarted != null && DateActivityStarted.Equals(input.DateActivityStarted)) ) && ( AvailableActivities == input.AvailableActivities || (AvailableActivities != null && AvailableActivities.SequenceEqual(input.AvailableActivities)) ) && ( CurrentActivityHash == input.CurrentActivityHash || (CurrentActivityHash.Equals(input.CurrentActivityHash)) ) && ( CurrentActivityModeHash == input.CurrentActivityModeHash || (CurrentActivityModeHash.Equals(input.CurrentActivityModeHash)) ) && ( CurrentActivityModeType == input.CurrentActivityModeType || (CurrentActivityModeType.Equals(input.CurrentActivityModeType)) ) && ( CurrentActivityModeHashes == input.CurrentActivityModeHashes || (CurrentActivityModeHashes != null && CurrentActivityModeHashes.SequenceEqual(input.CurrentActivityModeHashes)) ) && ( CurrentActivityModeTypes == input.CurrentActivityModeTypes || (CurrentActivityModeTypes != null && CurrentActivityModeTypes.SequenceEqual(input.CurrentActivityModeTypes)) ) && ( CurrentPlaylistActivityHash == input.CurrentPlaylistActivityHash || (CurrentPlaylistActivityHash.Equals(input.CurrentPlaylistActivityHash)) ) && ( LastCompletedStoryHash == input.LastCompletedStoryHash || (LastCompletedStoryHash.Equals(input.LastCompletedStoryHash)) )); }
public string PerformAction(int activityId) { AvailableActivities selectedActivity = _descriptionOfActivities.Keys.ElementAt(activityId); switch (selectedActivity) { case AvailableActivities.AddBookToCatalog: Console.Write("Title: "); string title = Console.ReadLine().Trim(); Console.Write("Author: "); string author = Console.ReadLine().Trim(); Console.Write("ISBN: "); string isbn = Console.ReadLine().Trim(); if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(author) || string.IsNullOrWhiteSpace(isbn)) { return("Incorrect data provided. Try again."); } try { if (_bookRepository.AddBookToCatalog(title, author, isbn)) { return($"Book \"{title}\" has been added to the catalog."); } else { throw new Exception(); } } catch (Exception) { return($"[Warning] Book \"{title}\" has not been added to the catalog. Try again."); } case AvailableActivities.RemoveBookFromCatalog: try { BookRecord bookToRemove = GetBookRecord(); if (bookToRemove != null) { if (_bookRepository.RemoveBookFromCatalog(bookToRemove)) { return("Book has been removed from catalog correctly."); } else { throw new Exception(); } } else { return("[Warning] The book was not found. Try again."); } } catch (Exception) { return($"[Warning] Book has not been removed from catalog. Try again."); } case AvailableActivities.SearchBookByParameter: try { BookRecord bookRecord = GetBookRecord(); if (bookRecord != null) { string response = $"The book was found. Title: \"{bookRecord.Book.Title}\", author: {bookRecord.Book.Author}, ISBN: {bookRecord.Book.ISBN}."; if (bookRecord.LastBorrowDate == DateTime.MinValue || bookRecord.LastBorrowDate == null) { response += "\n(not borrowed yet)"; } else { response += $"\nBorrowed by {bookRecord.LastBorrower.Name} {bookRecord.LastBorrower.LastName} (Date: {bookRecord.LastBorrowDate.ToShortDateString()})"; } return(response); } } catch (Exception) { } return("[Warning] The book was not found. Try again."); case AvailableActivities.SearchBooksNotBorrowedForWeeks: try { Console.Write("Number of weeks: "); int weeks = int.Parse(Console.ReadLine().Trim()); try { List <BookRecord> booksNotBorrowed = _bookRepository.GetBooksNotBorrowedForWeeks(weeks); foreach (BookRecord bookNotBorrowed in booksNotBorrowed) { Console.WriteLine($"\nBook: \"{bookNotBorrowed.Book.Title}\" {bookNotBorrowed.Book.Author} ISBN: {bookNotBorrowed.Book.ISBN}."); if (bookNotBorrowed.LastBorrowDate == DateTime.MinValue || bookNotBorrowed.LastBorrowDate == null) { Console.WriteLine("(not borrowed yet)"); } else { Console.WriteLine($"Borrowed by {bookNotBorrowed.LastBorrower.Name} {bookNotBorrowed.LastBorrower.LastName} (Date: {bookNotBorrowed.LastBorrowDate.ToShortDateString()})"); } } return($"{booksNotBorrowed.Count} records were found correctly."); } catch (Exception) { return("[Warning] There was a problem downloading the data. Try again."); } } catch (Exception) { return("[Warning] Incorrect data provided. Try again."); } case AvailableActivities.BorrowBook: try { Console.Write("Borrower name: "); string borrowerName = Console.ReadLine().Trim(); Console.Write("Borrower last name: "); string borrowerLastName = Console.ReadLine().Trim(); if (string.IsNullOrWhiteSpace(borrowerName) || string.IsNullOrWhiteSpace(borrowerLastName)) { return("Incorrect data provided. Try again."); } Borrower borrower = new Borrower() { Name = borrowerName, LastName = borrowerLastName }; BookRecord bookToBorrow = GetBookRecord(); if (bookToBorrow != null) { bookToBorrow.LastBorrower = borrower; bookToBorrow.LastBorrowDate = DateTime.Now; if (_bookRepository.BorrowBook(bookToBorrow)) { return("Book has been borrowed correctly."); } else { return("[Warning] Book has not been borrowed. Try again."); } } else { return("[Warning] The book was not found. Try again."); } } catch (Exception) { return($"[Warning] Book has not been borrowed. Try again."); } case AvailableActivities.GetCurrentBorrowers: try { List <BorrowerRecord> borrowers = _bookRepository.GetCurrentBorrowers(); foreach (BorrowerRecord borrower in borrowers) { Console.WriteLine($"{borrower.LastBorrower.Name} {borrower.LastBorrower.LastName}: {borrower.NumberOfBooksBorrowed} books"); } return($"{borrowers.Count} records were found correctly."); } catch (Exception) { return("[Warning] There was a problem downloading the data. Try again."); } } return("[Error] Action for selected activity is not defined."); }
public void ScheduleActivity(ActivityInfo activity, ScheduledActivity scheduledActivity) { if (!activity.Flags.HasFlag(ActivityFlags.Manual) && (!activity.Flags.HasFlag(ActivityFlags.Exclusive) || !activity.Flags.HasFlag(ActivityFlags.Excess))) { TotalScheduledDuration += activity.Duration; } else { TotalManualDuration += activity.Duration; } bool repeatable = activity.Flags.HasFlag(ActivityFlags.Repeatable); bool multiDorm = activity.Flags.HasFlag(ActivityFlags.MultiDorm); AvailableActivitiesToday.Remove(activity.ID); if (multiDorm) { AvailableMultiDormActivitiesToday.Remove(activity.ID); } bool clear = !repeatable; if (repeatable) { if (!RepeatableHistory.Add(activity.ID)) { clear = true; } else { if (ActivityPriorities.TryGetValue(activity.ID, out int activityPriority)) { if (--activityPriority == 0) { ActivityPriorities.Remove(activity.ID); } } else { ActivityPriorities.Add(activity.ID, -1); } } /*if (!RepeatableTodayHistory.Add(activity.ID)) * throw new IndexOutOfRangeException("Activity repeated twice the same day.");*/ } if (clear) { AvailableActivities.Remove(activity.ID); if (multiDorm) { AvailableMultiDormActivities.Remove(activity.ID); } } ActivitiesDoneToday.Add(activity.ID); if (activity.IncompatibleActivities.Any()) { AvailableActivitiesToday.ExceptWith(activity.IncompatibleActivities); AvailableMultiDormActivitiesToday.ExceptWith(activity.IncompatibleActivities); } ScheduleHistory.Add(scheduledActivity.Abbreviation); if (scheduledActivity.HasOther) { if (scheduledActivity.Dorm == Dorm) { if ( DormPriorities.TryGetValue( scheduledActivity.OtherDorm, out InterDormTracking otherDorm ) && otherDorm.ScheduleActivity( scheduledActivity, !OtherDormsDoneToday.Add(scheduledActivity.OtherDorm), repeatable, multiDorm ) ) { UsedUpOtherDorms.Add((InterDormTracking)otherDorm.Clone()); DormPriorities.Remove(scheduledActivity.OtherDorm); } } } else { DormPriorities[Dorm].ScheduleActivity(scheduledActivity, false, repeatable, multiDorm); OtherDormsDoneToday.Add(Dorm); } }
internal void ClearFromHistory(ScheduledActivity scheduledActivity, bool ignoreHasOther = false) { ScheduleHistory.Remove(scheduledActivity.Abbreviation); var activity = Schedule.Activities[scheduledActivity.Activity]; bool repeatable = activity.Flags.HasFlag(ActivityFlags.Repeatable); bool multiDorm = activity.Flags.HasFlag(ActivityFlags.MultiDorm); if (activity.IncompatibleActivities.Any()) { var incompat = new SortedSet <int>(activity.IncompatibleActivities); incompat.ExceptWith(ActivitiesDoneToday); if (incompat.Any()) { AvailableActivitiesToday.UnionWith(incompat); AvailableMultiDormActivitiesToday.UnionWith(incompat.Intersect(ActivityInfo.MultiDormActivities)); } } ActivitiesDoneToday.Remove(activity.ID); if (scheduledActivity.HasOther) { if (!ignoreHasOther) { if (!DormPriorities.TryGetValue(scheduledActivity.OtherDorm, out InterDormTracking interDorm)) { var index = UsedUpOtherDorms.FindIndex(d => d.Dorm == scheduledActivity.OtherDorm); interDorm = (InterDormTracking)UsedUpOtherDorms[index].Clone(); UsedUpOtherDorms.RemoveAt(index); DormPriorities.Add(scheduledActivity.OtherDorm, interDorm); } interDorm.ClearFromHistory(scheduledActivity, repeatable, multiDorm); OtherDormsDoneToday.Remove(scheduledActivity.OtherDorm); } } else { DormPriorities[Dorm].ClearFromHistory(scheduledActivity, repeatable, multiDorm); OtherDormsDoneToday.Remove(Dorm); } if (repeatable) { if (RepeatableHistory.Contains(activity.ID)) { // if it wasn't cleared, it was the first time the activity was done by that dorm if (!AvailableActivities.Add(activity.ID)) { RepeatableHistory.Remove(activity.ID); } if (multiDorm) { AvailableMultiDormActivities.Add(activity.ID); } RepeatableTodayHistory.Remove(activity.ID); } else { throw new NotImplementedException("Activity being cleared hasn't been undergone."); } if (ActivityPriorities.TryGetValue(activity.ID, out int activityPriority)) { if (++activityPriority == 0) { ActivityPriorities.Remove(activity.ID); } } else { ActivityPriorities.Add(activity.ID, 1); } } else { if (!AvailableActivities.Add(activity.ID)) { throw new NotImplementedException("Activity being cleared hasn't been undergone."); } if (multiDorm) { AvailableMultiDormActivities.Add(activity.ID); } } AvailableActivitiesToday.Add(activity.ID); if (multiDorm) { AvailableMultiDormActivitiesToday.Add(activity.ID); } if (!activity.Flags.HasFlag(ActivityFlags.Manual) && (!activity.Flags.HasFlag(ActivityFlags.Exclusive) || !activity.Flags.HasFlag(ActivityFlags.Excess))) { TotalScheduledDuration -= activity.Duration; } else { TotalManualDuration -= activity.Duration; } }