Skip to content

Commit 340864b

Browse files
author
Ivo Salmre
committed
Adding better UI details on age of data cache
1 parent 9037558 commit 340864b

File tree

5 files changed

+111
-89
lines changed

5 files changed

+111
-89
lines changed

CloudbedsApp/CloudbedsSessionState.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ public bool IsDataAvailableForDailyOperationsReport()
4848
return reservationsManager.IsDataCached();
4949
}
5050

51+
52+
/// <summary>
53+
/// The time the cache was last updated
54+
/// </summary>
55+
public DateTime? ReservationsWithRooms_CacheLastUpdatedTimeUtc
56+
{
57+
get
58+
{
59+
var resCache = _reservationWithRoomsManager;
60+
if (resCache == null)
61+
{
62+
return null;
63+
}
64+
65+
return resCache.CacheLastUpdatedTimeUtc;
66+
}
67+
}
68+
5169
/// <summary>
5270
/// Genrate the daily operations report
5371
/// </summary>
@@ -419,11 +437,19 @@ public CloudbedsGuestManager EnsureGuestManager()
419437
return guestManager;
420438
}
421439

440+
/// <summary>
441+
/// Clear a cache...
442+
/// </summary>
443+
public void ReservationsWithRooms_ClearCache()
444+
{
445+
_reservationWithRoomsManager = null;
446+
}
447+
422448
/// <summary>
423449
/// Creates a reservation manager object if necessary
424450
/// </summary>
425451
/// <returns></returns>
426-
public CloudbedsReservationWithRoomsManager EnsureReservationWithRoomsManager()
452+
public CloudbedsReservationWithRoomsManager EnsureReservationWithRoomsManager()
427453
{
428454
var reservationManager = _reservationWithRoomsManager;
429455
if (reservationManager != null)

CloudbedsApp/CloudbedsSingletons.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ public static ICollection<CloudbedsSessionState> ListOfCBSessions
5151
}
5252
}
5353

54+
55+
/// <summary>
56+
/// Clear a cache
57+
/// </summary>
58+
public static void ReservationsWithRooms_ClearCache()
59+
{
60+
var session = s_selectedCBSessionState;
61+
if(session != null)
62+
{
63+
session.ReservationsWithRooms_ClearCache();
64+
}
65+
}
66+
67+
/// <summary>
68+
/// The time the cache was last updated
69+
/// </summary>
70+
public static DateTime? ReservationsWithRooms_CacheLastUpdatedTimeUtc
71+
{
72+
get
73+
{
74+
var session = s_selectedCBSessionState;
75+
if(session == null)
76+
{
77+
return null;
78+
}
79+
80+
return session.ReservationsWithRooms_CacheLastUpdatedTimeUtc;
81+
}
82+
}
83+
5484
/// <summary>
5585
/// Genrate the daily operations report
5686
/// </summary>

CloudbedsDataManagers/CloudbedsReservationWithRoomsManager.cs

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ partial class CloudbedsReservationWithRoomsManager
1313
private readonly TaskStatusLogs _statusLog;
1414
const int NumberDaysFutureReservations = 120;
1515

16-
1716
/// <summary>
1817
/// If true - we will save the data locally after re-querying it
1918
/// </summary>
@@ -134,63 +133,6 @@ public void EnsureCachedData_Async()
134133
object _syncLockForCacheQuery = new object();
135134

136135

137-
/*
138-
/// <summary>
139-
/// Store the cached data in a local file system file
140-
/// </summary>
141-
public void PersistToLocalStorage()
142-
{
143-
var persister = new Persistence_Save(this);
144-
145-
string pathXml = AppSettings.LocalFileSystemPath_CachedReservationsList;
146-
147-
var xmlWriter = System.Xml.XmlWriter.Create(pathXml);
148-
149-
using(xmlWriter)
150-
{
151-
persister.SaveAsXml(xmlWriter);
152-
xmlWriter.Close();
153-
}
154-
}
155-
*/
156-
157-
/*
158-
/// <summary>
159-
/// Load from XML file
160-
/// </summary>
161-
/// <returns></returns>
162-
public bool DepersistFromLocalStorageIfExists()
163-
{
164-
var statusLogs = CloudbedsSingletons.StatusLogs;
165-
166-
statusLogs.AddStatusHeader("Attempt load from local cache: Reservations list");
167-
168-
string pathXml = AppSettings.LocalFileSystemPath_CachedReservationsList;
169-
//Not fatal... just note if no file exists
170-
if(!System.IO.File.Exists(pathXml))
171-
{
172-
statusLogs.AddStatus("0128-1013: Skipping. No local reservations cache file exists at: " + pathXml);
173-
return false;
174-
}
175-
176-
var xmlDoc = new System.Xml.XmlDocument();
177-
xmlDoc.Load(pathXml);
178-
var loadResults = Persistence_Load.LoadFromXml(xmlDoc);
179-
if(loadResults != null)
180-
{
181-
_cachedData = loadResults;
182-
statusLogs.AddStatus("Successfully loaded reservation list from local cache");
183-
}
184-
else
185-
{
186-
CloudbedsSingletons.StatusLogs.AddError("0205-540: Internal error. No results returned from XML Guests cache load");
187-
return false;
188-
}
189-
190-
191-
return true;
192-
}
193-
*/
194136
/// <summary>
195137
/// TRUE: The data has already been querued
196138
/// </summary>
@@ -233,25 +175,6 @@ public void EnsureCachedData()
233175
}//end: Lock
234176
}
235177

236-
/*
237-
/// <summary>
238-
/// Try to persist the data locally
239-
/// </summary>
240-
private void TryPersistToLocalStorage()
241-
{
242-
243-
try
244-
{
245-
PersistToLocalStorage();
246-
}
247-
catch(Exception ex)
248-
{
249-
CloudbedsSingletons.StatusLogs.AddError("0205-422: Error persisting Reservations data locally: " + ex.Message);
250-
}
251-
252-
}
253-
*/
254-
255178
/// <summary>
256179
/// Get the latest data in the cache
257180
/// </summary>
@@ -265,14 +188,6 @@ public void ForceRefreshOfCachedData()
265188

266189
//Store the cached results
267190
_cachedData = new CachedData(queriedItems, queryTime);
268-
269-
/*
270-
//Save to to local storage...
271-
if (this.LocalPersistDataAfterQuery)
272-
{
273-
TryPersistToLocalStorage();
274-
}
275-
*/
276191
}
277192

278193
/// <summary>

UI/AppPages/appPageOperationalReport.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
<Button Background="#2020ff" Foreground="#ffffff" Padding="2" HorizontalAlignment="Left" Width="170" Click="ButtonQueryForData_Click" Name="btnRunQuery">Query server for data</Button>
1818
</StackPanel>
1919

20-
<StackPanel Orientation="Horizontal">
20+
<StackPanel Orientation="Vertical" Margin="0 10 0 10" Name="spLocalCacheInfo">
21+
<TextBlock x:Name="txtCacheAge">Fill me: Cache age goes here...</TextBlock>
22+
<Button Background="#ff2020" Foreground="#ffffff" Padding="2" HorizontalAlignment="Left" Width="170" Click="btnClearCache_Click" Name="btnClearCache">Clear Cache</Button>
23+
</StackPanel>
24+
25+
<StackPanel Orientation="Horizontal" x:Name="spGenerateCSVsOptions">
2126
<Button Click="ButtonGenerateOperationalReportCsv_Click" Width="180" Margin="0 0 10 0" Padding="2" Background="#7070ff" Foreground="#ffffff" BorderThickness="0" HorizontalAlignment="Left">
2227
<TextBlock>Save Daily Summary CSV...</TextBlock>
2328
</Button>

UI/AppPages/appPageOperationalReport.xaml.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ public appPageOperationalReport()
3434

3535
}
3636

37+
38+
/// <summary>
39+
/// Gives us information about the age of the data cache
40+
/// </summary>
41+
private void UpdateCacheAgeText()
42+
{
43+
var cacheAgeUtc = CloudbedsSingletons.ReservationsWithRooms_CacheLastUpdatedTimeUtc;
44+
if(cacheAgeUtc == null)
45+
{
46+
txtCacheAge.Text = "No data in local cache ...";
47+
return;
48+
}
49+
50+
51+
var localTime= cacheAgeUtc.Value.ToLocalTime();
52+
txtCacheAge.Text = "Cache updated: " + localTime.ToString();
53+
}
54+
55+
56+
/// <summary>
57+
/// Update UI visibility and contents
58+
/// </summary>
3759
private void ResetUiBasedOnDataAvailability()
3860
{
3961
//If we have the data cached, then generate the report...
@@ -43,15 +65,22 @@ private void ResetUiBasedOnDataAvailability()
4365

4466
//Hide the query data UI
4567
spQueryForDataIfNeeded.Visibility = Visibility.Collapsed;
68+
//Show the CSV options
69+
spGenerateCSVsOptions.Visibility = Visibility.Visible;
70+
spLocalCacheInfo.Visibility = Visibility.Visible;
71+
4672
}
4773
else
4874
{
4975
spContent.Children.Clear(); //Hide any list data
5076
//Show the query data UI
5177
spQueryForDataIfNeeded.Visibility = Visibility.Visible;
5278

79+
spGenerateCSVsOptions.Visibility = Visibility.Collapsed;
80+
spLocalCacheInfo.Visibility = Visibility.Collapsed;
5381
}
5482

83+
UpdateCacheAgeText();
5584
}
5685

5786

@@ -108,9 +137,12 @@ private void ButtonGenerateOperationalReportCsv_Click(object sender, RoutedEvent
108137
csvReport.GenerateCSVFile(fileOutputTo);
109138
}
110139

111-
// const string QueryButtonText_ready = "Query server for data";
112-
// const string QueryButtonText_queryUnderway = "(Query underway...)";
113140

141+
/// <summary>
142+
/// Query for data (or use data from cache) and fill in the grid
143+
/// </summary>
144+
/// <param name="sender"></param>
145+
/// <param name="e"></param>
114146
private void ButtonQueryForData_Click(object sender, RoutedEventArgs e)
115147
{
116148
//Since this may run a while, show the wait cursor
@@ -127,6 +159,8 @@ private void ButtonQueryForData_Click(object sender, RoutedEventArgs e)
127159

128160
this.Cursor = null; //revert to default
129161

162+
//Update the UI
163+
ResetUiBasedOnDataAvailability();
130164
}
131165

132166
/// <summary>
@@ -159,5 +193,17 @@ private void ButtonGenerateOperationalReportWithReservationDetailsCsv_Click(obje
159193
csvReport.GenerateCSVFile(fileOutputTo);
160194

161195
}
196+
197+
198+
/// <summary>
199+
/// Clear a local data cache
200+
/// </summary>
201+
/// <param name="sender"></param>
202+
/// <param name="e"></param>
203+
private void btnClearCache_Click(object sender, RoutedEventArgs e)
204+
{
205+
CloudbedsSingletons.ReservationsWithRooms_ClearCache();
206+
ResetUiBasedOnDataAvailability();
207+
}
162208
}
163209
}

0 commit comments

Comments
 (0)