Skip to content

Commit 5de4c53

Browse files
committed
Add DumpLog for GlobalTimeStamp sample, and other modification for clarity
1 parent f26cea7 commit 5de4c53

File tree

11 files changed

+51
-6
lines changed

11 files changed

+51
-6
lines changed

Samples/DatabaseTimeStamp/MobileSample/ViewModels/SetupViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public bool IsSynchronizationIdSet
6161
{
6262
databaseService.DumpLog();
6363

64-
await Application.Current.MainPage.DisplayAlert("Success", "Data is dumped to Log", "OK");
64+
await Application.Current.MainPage.DisplayAlert("Success", "Database Contents is dumped to Debug Log", "OK");
6565
});
6666
}
6767
}

Samples/DatabaseTimeStamp/MobileSample/Views/SetupPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Entry Text="{Binding SynchronizationId}" />
1414
<Button Text="Set" Command="{Binding SetSynchronizationIdCommand}" />
1515
<BoxView VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="1" WidthRequest="50" Color="#5b5d68" />
16-
<Button Text="Dump Log" Command="{Binding DumpLogCommand}" />
16+
<Button Text="Dump Database Contents To Log" Command="{Binding DumpLogCommand}" />
1717
</StackLayout>
1818
</ScrollView>
1919
</ContentPage.Content>

Samples/GlobalTimeStamp/MobileSample/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public App()
3636
//NOTE: Navigation (INavigation) is registered per life time scope basis on BaseContentPage.cs
3737

3838
List<Type> syncTypes = new List<Type>() { typeof(Department), typeof(Employee) };
39-
SyncConfiguration syncConfiguration = new SyncConfiguration(syncTypes.ToArray());
39+
SyncConfiguration syncConfiguration = new SyncConfiguration(syncTypes.ToArray(), SyncConfiguration.TimeStampStrategyEnum.GlobalTimeStamp);
4040
builder.RegisterInstance(syncConfiguration);
4141

4242
Container = builder.Build();

Samples/GlobalTimeStamp/MobileSample/Models/Configuration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ public class Configuration
1313
public string Id { get; set; }
1414
public string Key { get; set; }
1515
public string Value { get; set; }
16+
17+
public override string ToString()
18+
{
19+
return $"{nameof(Id)}: {Id}, {nameof(Key)}: {Key}, {nameof(Value)}: {Value}";
20+
}
1621
}
1722
}

Samples/GlobalTimeStamp/MobileSample/Models/Department.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ public class Department
2626

2727
[SyncProperty(PropertyIndicator = SyncPropertyAttribute.PropertyIndicatorEnum.Deleted)]
2828
public long? Deleted { get; set; }
29+
30+
public override string ToString()
31+
{
32+
return $"{nameof(Id)}: {Id}, {nameof(Name)}: {Name}, {nameof(LastUpdated)}: {LastUpdated}, {nameof(Deleted)}: {(Deleted == null ? "null" : Convert.ToString(Deleted.Value))}";
33+
}
2934
}
3035
}

Samples/GlobalTimeStamp/MobileSample/Models/Employee.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@ public class Employee
3535

3636
[SyncProperty(PropertyIndicator = SyncPropertyAttribute.PropertyIndicatorEnum.Deleted)]
3737
public long? Deleted { get; set; }
38+
39+
public override string ToString()
40+
{
41+
return $"{nameof(Id)}: {Id}, {nameof(Name)}: {Name}, {nameof(Birthday)}: {Birthday.ToString("dd-MMM-yyyy")}, {nameof(NumberOfComputers)}: {NumberOfComputers}, {nameof(SavingAmount)}: {SavingAmount.ToString("#,#0.00")}, {nameof(IsActive)}: {IsActive}, {nameof(Department)}: {Department?.Id}, {nameof(LastUpdated)}: {LastUpdated}, {nameof(Deleted)}: {(Deleted == null ? "null" : Convert.ToString(Deleted.Value))}";
42+
}
3843
}
3944
}

Samples/GlobalTimeStamp/MobileSample/Services/DatabaseService.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,26 @@ public void SetServerUrl(string serverUrl)
175175
databaseContext.SaveChanges();
176176
}
177177
}
178+
179+
public void DumpLog()
180+
{
181+
using (var databaseContext = GetDatabaseContext())
182+
{
183+
Log($"{nameof(Configuration)}:");
184+
databaseContext.Configurations.ToList().ForEach(data => Log(data.ToString()));
185+
Log("");
186+
Log($"{nameof(Department)}:");
187+
databaseContext.Departments.ToList().ForEach(data => Log(data.ToString()));
188+
Log("");
189+
Log($"{nameof(Employee)}:");
190+
databaseContext.Employees.ToList().ForEach(data => Log(data.ToString()));
191+
Log("");
192+
}
193+
}
194+
195+
private void Log(string message)
196+
{
197+
System.Diagnostics.Debug.WriteLine(message);
198+
}
178199
}
179200
}

Samples/GlobalTimeStamp/MobileSample/ViewModels/SetupViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,17 @@ public bool IsSynchronizationIdSet
6464
Application.Current.MainPage = new Views.MainPage();
6565
});
6666

67+
public ICommand DumpLogCommand => new Command(async () =>
68+
{
69+
databaseService.DumpLog();
70+
71+
await Application.Current.MainPage.DisplayAlert("Success", "Database Contents is dumped to Debug Log", "OK");
72+
});
73+
6774
public ICommand DateTimeCommand => new Command(async () =>
6875
{
6976
string text = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss");
70-
await Application.Current.MainPage.DisplayAlert("Date Time", text, "OK");
77+
await Application.Current.MainPage.DisplayAlert("Date Time", $"The system's Date and Time is: {text}. Make sure this is correct and accurate according to the real world clock time.", "OK");
7178
});
7279
}
7380
}

Samples/GlobalTimeStamp/MobileSample/ViewModels/SyncViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public string Log
6868
SyncClient syncClient = new SyncClient(synchronizationId, customSyncEngine, ServerUrl);
6969
Log = "";
7070

71-
SyncResult result = await syncClient.SynchronizeAsync();
71+
SyncResult result = await syncClient.SynchronizeAsync(SyncClient.SynchronizationMethodEnum.PushThenPull);
7272

7373
string tempLog = "";
7474
tempLog += $"Client Log: {Environment.NewLine}";

Samples/GlobalTimeStamp/MobileSample/Views/SetupPage.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<Entry Text="{Binding SynchronizationId}" />
1414
<Button Text="Set" Command="{Binding SetSynchronizationIdCommand}" />
1515
<BoxView VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="1" WidthRequest="50" Color="#5b5d68" />
16+
<Button Text="Dump Database Contents To Log" Command="{Binding DumpLogCommand}" />
17+
<BoxView VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="1" WidthRequest="50" Color="#5b5d68" />
1618
<Button Text="Date Time" Command="{Binding DateTimeCommand}" />
1719
</StackLayout>
1820
</ScrollView>

0 commit comments

Comments
 (0)