Skip to content

Commit f70e369

Browse files
committed
Updated storage var names to be consistent across solution
1 parent 5707c6d commit f70e369

File tree

7 files changed

+64
-60
lines changed

7 files changed

+64
-60
lines changed

Microsoft.Toolkit.Uwp.SampleApp/Controls/SampleAppMarkdownRenderer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using Microsoft.Toolkit.Helpers;
89
using Microsoft.Toolkit.Parsers.Markdown;
910
using Microsoft.Toolkit.Parsers.Markdown.Blocks;
1011
using Microsoft.Toolkit.Parsers.Markdown.Inlines;
@@ -405,19 +406,19 @@ public string DesiredLang
405406
{
406407
get
407408
{
408-
return storage.Read<string>(DesiredLangKey);
409+
return settingsStorage.Read<string>(DesiredLangKey);
409410
}
410411

411412
set
412413
{
413-
storage.Save(DesiredLangKey, value);
414+
settingsStorage.Save(DesiredLangKey, value);
414415
}
415416
}
416417

417418
/// <summary>
418-
/// The Local Storage Helper.
419+
/// The local app data storage helper for storing settings.
419420
/// </summary>
420-
private ApplicationDataStorageHelper storage = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
421+
private ISettingsStorageHelper settingsStorage = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
421422

422423
/// <summary>
423424
/// DocFX note types and styling info, keyed by identifier.

Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// TODO Reintroduce graph controls
2121
// using Microsoft.Toolkit.Graph.Converters;
2222
// using Microsoft.Toolkit.Graph.Providers;
23+
using Microsoft.Toolkit.Helpers;
2324
using Microsoft.Toolkit.Uwp.Helpers;
2425
using Microsoft.Toolkit.Uwp.Input.GazeInteraction;
2526
using Microsoft.Toolkit.Uwp.SampleApp.Models;
@@ -45,7 +46,7 @@ public class Sample
4546

4647
public static async void EnsureCacheLatest()
4748
{
48-
var settingsStorage = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
49+
ISettingsStorageHelper settingsStorage = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
4950

5051
var onlineDocsSHA = await GetDocsSHA();
5152
var cacheSHA = settingsStorage.Read<string>(_cacheSHAKey);

Microsoft.Toolkit.Uwp.SampleApp/Models/Samples.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text.Json;
1010
using System.Threading;
1111
using System.Threading.Tasks;
12+
using Microsoft.Toolkit.Helpers;
1213
using Microsoft.Toolkit.Uwp.Helpers;
1314

1415
namespace Microsoft.Toolkit.Uwp.SampleApp
@@ -21,7 +22,7 @@ public static class Samples
2122
private static SemaphoreSlim _semaphore = new SemaphoreSlim(1);
2223

2324
private static LinkedList<Sample> _recentSamples;
24-
private static ApplicationDataStorageHelper _appDataStorageHelper = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
25+
private static ISettingsStorageHelper _settingsStorage = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
2526

2627
public static async Task<SampleCategory> GetCategoryBySample(Sample sample)
2728
{
@@ -98,7 +99,7 @@ public static async Task<LinkedList<Sample>> GetRecentSamples()
9899
if (_recentSamples == null)
99100
{
100101
_recentSamples = new LinkedList<Sample>();
101-
var savedSamples = _appDataStorageHelper.Read<string>(_recentSamplesStorageKey);
102+
var savedSamples = _settingsStorage.Read<string>(_recentSamplesStorageKey);
102103

103104
if (savedSamples != null)
104105
{
@@ -144,7 +145,7 @@ private static void SaveRecentSamples()
144145
}
145146

146147
var str = string.Join(";", _recentSamples.Take(10).Select(s => s.Name).ToArray());
147-
_appDataStorageHelper.Save<string>(_recentSamplesStorageKey, str);
148+
_settingsStorage.Save<string>(_recentSamplesStorageKey, str);
148149
}
149150
}
150151
}

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
1010
{
1111
public sealed partial class ObjectStoragePage
1212
{
13-
private readonly ISettingsStorageHelper localStorageHelper = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
13+
private readonly ISettingsStorageHelper _settingsStorage = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
1414

1515
public ObjectStoragePage()
1616
{
@@ -25,9 +25,9 @@ private void ReadButton_Click(object sender, RoutedEventArgs e)
2525
}
2626

2727
// Read from local storage
28-
if (localStorageHelper.KeyExists(KeyTextBox.Text))
28+
if (_settingsStorage.KeyExists(KeyTextBox.Text))
2929
{
30-
ContentTextBox.Text = localStorageHelper.Read<string>(KeyTextBox.Text);
30+
ContentTextBox.Text = _settingsStorage.Read<string>(KeyTextBox.Text);
3131
}
3232
}
3333

@@ -44,7 +44,7 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
4444
}
4545

4646
// Save into local storage
47-
localStorageHelper.Save(KeyTextBox.Text, ContentTextBox.Text);
47+
_settingsStorage.Save(KeyTextBox.Text, ContentTextBox.Text);
4848
}
4949
}
5050
}

Microsoft.Toolkit.Uwp/Helpers/SystemInformation.cs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using System.Linq;
88
using System.Threading.Tasks;
9+
using Microsoft.Toolkit.Helpers;
910
using Windows.ApplicationModel;
1011
using Windows.ApplicationModel.Activation;
1112
using Windows.Security.ExchangeActiveSyncProvisioning;
@@ -25,7 +26,7 @@ public sealed class SystemInformation
2526
/// <summary>
2627
/// The <see cref="ApplicationDataStorageHelper"/> instance used to save and retrieve application settings.
2728
/// </summary>
28-
private readonly ApplicationDataStorageHelper _localObjectStorageHelper = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
29+
private readonly ISettingsStorageHelper _settingsStorage = ApplicationDataStorageHelper.GetCurrent(new Toolkit.Helpers.SystemSerializer());
2930

3031
/// <summary>
3132
/// The starting time of the current application session (since app launch or last move to foreground).
@@ -216,7 +217,7 @@ public TimeSpan AppUptime
216217
if (LaunchCount > 0)
217218
{
218219
var subSessionLength = DateTime.UtcNow.Subtract(_sessionStart).Ticks;
219-
var uptimeSoFar = _localObjectStorageHelper.Read<long>(nameof(AppUptime));
220+
var uptimeSoFar = _settingsStorage.Read<long>(nameof(AppUptime));
220221

221222
return new(uptimeSoFar + subSessionLength);
222223
}
@@ -232,9 +233,9 @@ public TimeSpan AppUptime
232233
/// <param name="duration">The amount to time to add</param>
233234
public void AddToAppUptime(TimeSpan duration)
234235
{
235-
var uptimeSoFar = _localObjectStorageHelper.Read<long>(nameof(AppUptime));
236+
var uptimeSoFar = _settingsStorage.Read<long>(nameof(AppUptime));
236237

237-
_localObjectStorageHelper.Save(nameof(AppUptime), uptimeSoFar + duration.Ticks);
238+
_settingsStorage.Save(nameof(AppUptime), uptimeSoFar + duration.Ticks);
238239
}
239240

240241
/// <summary>
@@ -245,8 +246,8 @@ public void ResetLaunchCount()
245246
LastResetTime = DateTime.UtcNow;
246247
LaunchCount = 0;
247248

248-
_localObjectStorageHelper.Save(nameof(LastResetTime), LastResetTime.ToFileTimeUtc());
249-
_localObjectStorageHelper.Save(nameof(LaunchCount), LaunchCount);
249+
_settingsStorage.Save(nameof(LastResetTime), LastResetTime.ToFileTimeUtc());
250+
_settingsStorage.Save(nameof(LaunchCount), LaunchCount);
250251
}
251252

252253
/// <summary>
@@ -258,30 +259,30 @@ public void TrackAppUse(IActivatedEventArgs args, XamlRoot xamlRoot = null)
258259
{
259260
if (args.PreviousExecutionState is ApplicationExecutionState.ClosedByUser or ApplicationExecutionState.NotRunning)
260261
{
261-
LaunchCount = _localObjectStorageHelper.Read<long>(nameof(LaunchCount)) + 1;
262-
TotalLaunchCount = _localObjectStorageHelper.Read<long>(nameof(TotalLaunchCount)) + 1;
262+
LaunchCount = _settingsStorage.Read<long>(nameof(LaunchCount)) + 1;
263+
TotalLaunchCount = _settingsStorage.Read<long>(nameof(TotalLaunchCount)) + 1;
263264

264265
// In case we upgraded the properties, make TotalLaunchCount is correct
265266
if (TotalLaunchCount < LaunchCount)
266267
{
267268
TotalLaunchCount = LaunchCount;
268269
}
269270

270-
_localObjectStorageHelper.Save(nameof(LaunchCount), LaunchCount);
271-
_localObjectStorageHelper.Save(nameof(TotalLaunchCount), TotalLaunchCount);
271+
_settingsStorage.Save(nameof(LaunchCount), LaunchCount);
272+
_settingsStorage.Save(nameof(TotalLaunchCount), TotalLaunchCount);
272273

273274
LaunchTime = DateTime.UtcNow;
274275

275-
var lastLaunch = _localObjectStorageHelper.Read<long>(nameof(LastLaunchTime));
276+
var lastLaunch = _settingsStorage.Read<long>(nameof(LastLaunchTime));
276277

277278
LastLaunchTime = lastLaunch != 0
278279
? DateTime.FromFileTimeUtc(lastLaunch)
279280
: LaunchTime;
280281

281-
_localObjectStorageHelper.Save(nameof(LastLaunchTime), LaunchTime.ToFileTimeUtc());
282-
_localObjectStorageHelper.Save(nameof(AppUptime), 0L);
282+
_settingsStorage.Save(nameof(LastLaunchTime), LaunchTime.ToFileTimeUtc());
283+
_settingsStorage.Save(nameof(AppUptime), 0L);
283284

284-
var lastResetTime = _localObjectStorageHelper.Read<long>(nameof(LastResetTime));
285+
var lastResetTime = _settingsStorage.Read<long>(nameof(LastResetTime));
285286

286287
LastResetTime = lastResetTime != 0
287288
? DateTime.FromFileTimeUtc(lastResetTime)
@@ -321,20 +322,20 @@ private void UpdateVisibility(bool visible)
321322
else
322323
{
323324
var subSessionLength = DateTime.UtcNow.Subtract(_sessionStart).Ticks;
324-
var uptimeSoFar = _localObjectStorageHelper.Read<long>(nameof(AppUptime));
325+
var uptimeSoFar = _settingsStorage.Read<long>(nameof(AppUptime));
325326

326-
_localObjectStorageHelper.Save(nameof(AppUptime), uptimeSoFar + subSessionLength);
327+
_settingsStorage.Save(nameof(AppUptime), uptimeSoFar + subSessionLength);
327328
}
328329
}
329330

330331
private bool DetectIfFirstUse()
331332
{
332-
if (_localObjectStorageHelper.KeyExists(nameof(IsFirstRun)))
333+
if (_settingsStorage.KeyExists(nameof(IsFirstRun)))
333334
{
334335
return false;
335336
}
336337

337-
_localObjectStorageHelper.Save(nameof(IsFirstRun), true);
338+
_settingsStorage.Save(nameof(IsFirstRun), true);
338339

339340
return true;
340341
}
@@ -347,13 +348,13 @@ private bool DetectIfFirstUse()
347348
// is ever called. That is, this is either the first time the app has been launched, or the first
348349
// time a previously existing app has run this method (or has run it after a new update of the app).
349350
// In this case, save the current version and report the same version as previous version installed.
350-
if (!_localObjectStorageHelper.KeyExists(nameof(currentVersion)))
351+
if (!_settingsStorage.KeyExists(nameof(currentVersion)))
351352
{
352-
_localObjectStorageHelper.Save(nameof(currentVersion), currentVersion);
353+
_settingsStorage.Save(nameof(currentVersion), currentVersion);
353354
}
354355
else
355356
{
356-
var previousVersion = _localObjectStorageHelper.Read<string>(nameof(currentVersion));
357+
var previousVersion = _settingsStorage.Read<string>(nameof(currentVersion));
357358

358359
// There are two possible cases if the "currentVersion" key exists:
359360
// 1) The previous version is different than the current one. This means that the application
@@ -363,7 +364,7 @@ private bool DetectIfFirstUse()
363364
// In this case we have nothing to do and just return the previous version installed to be the same.
364365
if (currentVersion != previousVersion)
365366
{
366-
_localObjectStorageHelper.Save(nameof(currentVersion), currentVersion);
367+
_settingsStorage.Save(nameof(currentVersion), currentVersion);
367368

368369
return (true, previousVersion.ToPackageVersion());
369370
}
@@ -374,28 +375,28 @@ private bool DetectIfFirstUse()
374375

375376
private DateTime DetectFirstUseTime()
376377
{
377-
if (_localObjectStorageHelper.KeyExists(nameof(FirstUseTime)))
378+
if (_settingsStorage.KeyExists(nameof(FirstUseTime)))
378379
{
379-
var firstUse = _localObjectStorageHelper.Read<long>(nameof(FirstUseTime));
380+
var firstUse = _settingsStorage.Read<long>(nameof(FirstUseTime));
380381

381382
return DateTime.FromFileTimeUtc(firstUse);
382383
}
383384

384385
DateTime utcNow = DateTime.UtcNow;
385386

386-
_localObjectStorageHelper.Save(nameof(FirstUseTime), utcNow.ToFileTimeUtc());
387+
_settingsStorage.Save(nameof(FirstUseTime), utcNow.ToFileTimeUtc());
387388

388389
return utcNow;
389390
}
390391

391392
private PackageVersion DetectFirstVersionInstalled()
392393
{
393-
if (_localObjectStorageHelper.KeyExists(nameof(FirstVersionInstalled)))
394+
if (_settingsStorage.KeyExists(nameof(FirstVersionInstalled)))
394395
{
395-
return _localObjectStorageHelper.Read<string>(nameof(FirstVersionInstalled)).ToPackageVersion();
396+
return _settingsStorage.Read<string>(nameof(FirstVersionInstalled)).ToPackageVersion();
396397
}
397398

398-
_localObjectStorageHelper.Save(nameof(FirstVersionInstalled), ApplicationVersion.ToFormattedString());
399+
_settingsStorage.Save(nameof(FirstVersionInstalled), ApplicationVersion.ToFormattedString());
399400

400401
return ApplicationVersion;
401402
}

0 commit comments

Comments
 (0)