Skip to content

Commit

Permalink
Link up events on load
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLarsinator committed Jul 24, 2021
1 parent 09f0cae commit 71f3174
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 15 deletions.
13 changes: 10 additions & 3 deletions RevolveTestDiaryXf/Models/DiaryEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace RevolveTestDiaryXf.Models
public class DiaryEntry
{
public DateTime Timestamp { get; set; }

public event EventHandler<DiaryEntry> TriggerAutoSaveEvent;
public DiaryEntry(DateTime timestamp, EntryType entryType, string body)
{
Timestamp = timestamp;
Expand All @@ -25,9 +25,16 @@ public DiaryEntry()

[JsonIgnore]
public ObservableCollection<EntryType> EntryTypes => new ObservableCollection<EntryType>(Enum.GetValues(typeof(EntryType)).Cast<EntryType>());
public EntryType EntryType { get; set; }
public EntryType EntryType { get => entryType; set { entryType = value; TriggerAutoSaveEvent?.Invoke(this, this); } }

private string _body;
private EntryType entryType;

public string Body { get; set; }
public string Body
{
get { return _body; }
set { _body = value; TriggerAutoSaveEvent?.Invoke(this, this); }
}

public DiaryEntry(EntryType entryType, string body)
{
Expand Down
7 changes: 7 additions & 0 deletions RevolveTestDiaryXf/Models/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public Session() { }
public void AddDiaryEntryCommand()
{
var diaryEntry = new DiaryEntry(NewEntryType, NewEntryBody);
diaryEntry.TriggerAutoSaveEvent += TriggerAutoSaveFromEntry;
NewEntryBody = null;
AddDiaryEntry(diaryEntry);
TriggerAutoSaveEvent?.Invoke(this, this);
Expand All @@ -58,5 +59,11 @@ public void AddDiaryEntry(DiaryEntry entry)
SessionEntries.Add(entry);
this.RaisePropertyChanged(nameof(SessionEntries));
}


public void TriggerAutoSaveFromEntry(object? sender, DiaryEntry e)
{
TriggerAutoSaveEvent?.Invoke(this, this);
}
}
}
21 changes: 13 additions & 8 deletions RevolveTestDiaryXf/Models/TestDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void AddGoalCommand()
goal.TriggerAutoSaveEvent += TriggerAutoSaveFromGoal;
NewGoalBody = null;
AddGoal(goal);
TriggerAutoSaveEvent.Invoke(this, this);
TriggerAutoSaveEvent?.Invoke(this, this);
}
public void AddGoal(DiaryGoal goal)
{
Expand All @@ -93,22 +93,27 @@ public void AddSessionCommand()
session.TriggerAutoSaveEvent += TriggerAutoSaveFromSession;
NewSessionTitle = null;
AddSession(session);
TriggerAutoSaveEvent.Invoke(this, this);
TriggerAutoSaveEvent?.Invoke(this, this);
}

private void TriggerAutoSaveFromSession(object? sender, Session e)
public void TriggerAutoSaveFromSession(object? sender, Session e)
{
TriggerAutoSaveEvent.Invoke(this, this);
TriggerAutoSaveEvent?.Invoke(this, this);
}

private void TriggerAutoSaveFromGoal(object? sender, DiaryGoal e)
public void TriggerAutoSaveFromGoal(object? sender, DiaryGoal e)
{
TriggerAutoSaveEvent.Invoke(this, this);
TriggerAutoSaveEvent?.Invoke(this, this);
}

private void TriggerAutoSaveFromDebrief(object? sender, Debrief e)
public void TriggerAutoSaveFromDebrief(object? sender, Debrief e)
{
TriggerAutoSaveEvent.Invoke(this, this);
TriggerAutoSaveEvent?.Invoke(this, this);
}

public void TriggerAutoSaveFromEntry(object? sender, DiaryEntry e)
{
TriggerAutoSaveEvent?.Invoke(this, this);
}

public void AddSession(Session session)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<SelfContained>false</SelfContained>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<History>True|2021-07-23T23:19:50.3698139Z;True|2021-07-24T00:19:21.3372652+01:00;True|2021-07-22T23:40:30.9776005+01:00;True|2021-07-22T23:39:18.5301353+01:00;True|2021-07-22T23:29:19.7722048+01:00;True|2021-07-22T23:28:55.1739726+01:00;True|2021-07-22T23:28:30.5225280+01:00;True|2021-07-22T23:26:31.3242797+01:00;True|2021-07-22T23:24:51.1262948+01:00;False|2021-07-22T23:24:11.4380470+01:00;True|2021-07-22T23:22:47.8896701+01:00;False|2021-07-22T23:21:01.9118945+01:00;True|2021-07-22T23:20:02.2727035+01:00;True|2021-07-22T23:19:19.2709540+01:00;True|2021-07-22T23:16:55.5922301+01:00;True|2021-07-22T23:15:51.4190974+01:00;False|2021-07-22T23:15:03.3156239+01:00;True|2021-07-22T23:14:19.7324710+01:00;True|2021-07-22T23:12:31.5976603+01:00;False|2021-07-22T23:11:48.1206383+01:00;True|2021-07-22T23:10:44.0144142+01:00;True|2021-07-22T23:09:34.5315819+01:00;True|2021-07-22T23:08:20.5062411+01:00;True|2021-07-22T23:07:46.8030011+01:00;True|2021-07-22T22:59:53.1099845+01:00;True|2021-07-22T22:52:25.1583748+01:00;True|2021-07-22T22:52:05.8567743+01:00;True|2021-07-22T22:36:16.6413609+01:00;True|2021-07-22T22:29:15.6562188+01:00;True|2021-07-20T23:59:57.3230195+01:00;True|2021-07-20T23:59:06.2065642+01:00;</History>
<History>True|2021-07-24T08:50:44.0579560Z;True|2021-07-24T09:49:48.4714980+01:00;True|2021-07-24T00:19:50.3698139+01:00;True|2021-07-24T00:19:21.3372652+01:00;True|2021-07-22T23:40:30.9776005+01:00;True|2021-07-22T23:39:18.5301353+01:00;True|2021-07-22T23:29:19.7722048+01:00;True|2021-07-22T23:28:55.1739726+01:00;True|2021-07-22T23:28:30.5225280+01:00;True|2021-07-22T23:26:31.3242797+01:00;True|2021-07-22T23:24:51.1262948+01:00;False|2021-07-22T23:24:11.4380470+01:00;True|2021-07-22T23:22:47.8896701+01:00;False|2021-07-22T23:21:01.9118945+01:00;True|2021-07-22T23:20:02.2727035+01:00;True|2021-07-22T23:19:19.2709540+01:00;True|2021-07-22T23:16:55.5922301+01:00;True|2021-07-22T23:15:51.4190974+01:00;False|2021-07-22T23:15:03.3156239+01:00;True|2021-07-22T23:14:19.7324710+01:00;True|2021-07-22T23:12:31.5976603+01:00;False|2021-07-22T23:11:48.1206383+01:00;True|2021-07-22T23:10:44.0144142+01:00;True|2021-07-22T23:09:34.5315819+01:00;True|2021-07-22T23:08:20.5062411+01:00;True|2021-07-22T23:07:46.8030011+01:00;True|2021-07-22T22:59:53.1099845+01:00;True|2021-07-22T22:52:25.1583748+01:00;True|2021-07-22T22:52:05.8567743+01:00;True|2021-07-22T22:36:16.6413609+01:00;True|2021-07-22T22:29:15.6562188+01:00;True|2021-07-20T23:59:57.3230195+01:00;True|2021-07-20T23:59:06.2065642+01:00;</History>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion RevolveTestDiaryXf/RevolveTestDiaryXf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<StartupObject>RevolveTestDiaryXf.Program</StartupObject>
<PackageIcon></PackageIcon>
<PackageIconUrl />
<Version>3.0.0</Version>
<Version>3.1.0</Version>
<PackageId></PackageId>
<Authors>Revolve NTNU</Authors>
<Company>Revolve NTNU</Company>
Expand Down
19 changes: 19 additions & 0 deletions RevolveTestDiaryXf/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ public async void LoadTestDayFromFileCommand()
try
{
TestDay testDay = await JsonSerializer.DeserializeAsync(stream, typeof(TestDay)) as TestDay;
testDay.TriggerAutoSaveEvent += SaveTestDay;
testDay.CloseTestDayEvent += CloseTestDay;

foreach (var session in testDay.Sessions)
{
session.TriggerAutoSaveEvent += testDay.TriggerAutoSaveFromSession;
foreach (var entry in session.SessionEntries)
{
entry.TriggerAutoSaveEvent += testDay.TriggerAutoSaveFromEntry;
}
}
foreach (var goal in testDay.Goals)
{
goal.TriggerAutoSaveEvent += testDay.TriggerAutoSaveFromGoal;
}

testDay.Debrief.TriggerAutoSaveEvent += testDay.TriggerAutoSaveFromDebrief;


if (testDay != null)
TestDays.Add(testDay);
}
Expand Down

0 comments on commit 71f3174

Please sign in to comment.