Skip to content

Commit 920204c

Browse files
committed
Changed condition in StorageController.LoadAsync method to check for null reference prior to create new StorageDictionary instance and trying loading its data from disk
Changed file write and read methods in StorageManager class to use unified Unicode encoding Changed use of VolumeSeparatorChar to DirectorySeparatorChar as it is used in context of creating a relative folder insider the local app data special folder Changed ParseClient.Initialize behaviour to use MetadataBasedStorageConfiguration.NoCompanyInferred as default configuration of no other was set (did override any existing with the old switch statement) Added subclass registration of ParseInstallation class which caused an error with the other changes made when reading and parsing local cached information to an ParseInstallation instance at runtime.
1 parent 8d99527 commit 920204c

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

Parse/Internal/Storage/Controller/StorageController.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
156156
/// Loads a settings dictionary from the file wrapped by <see cref="File"/>.
157157
/// </summary>
158158
/// <returns>A storage dictionary containing the deserialized content of the storage file targeted by the <see cref="StorageController"/> instance</returns>
159-
public Task<IStorageDictionary<string, object>> LoadAsync() => Queue.Enqueue(toAwait => toAwait.ContinueWith(_ => Task.FromResult((IStorageDictionary<string, object>) Storage) ?? (Storage = new StorageDictionary(File)).LoadAsync().OnSuccess(__ => Storage as IStorageDictionary<string, object>)).Unwrap(), CancellationToken.None);
159+
public Task<IStorageDictionary<string, object>> LoadAsync()
160+
{
161+
// check if storage dictionary is already created from the controllers file (create if not)
162+
if (Storage == null)
163+
Storage = new StorageDictionary(File);
164+
// load storage dictionary content async and return the resulting dictionary type
165+
return Queue.Enqueue(toAwait => toAwait.ContinueWith(_ => Storage.LoadAsync().OnSuccess(__ => Storage as IStorageDictionary<string, object>)).Unwrap(), CancellationToken.None);
166+
}
160167

161168
/// <summary>
162169
///

Parse/Internal/Utilities/StorageManager.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ internal static class StorageManager
3131
public static async Task WriteToAsync(this FileInfo file, string content)
3232
{
3333
using (FileStream stream = new FileStream(Path.GetFullPath(file.FullName), FileMode.Create, FileAccess.Write, FileShare.Read, 4096, FileOptions.SequentialScan | FileOptions.Asynchronous))
34-
await stream.WriteAsync(Encoding.Unicode.GetBytes(content), 0, content.Length * 2 /* UTF-16, so two bytes per character of length. */);
34+
{
35+
byte[] data = Encoding.Unicode.GetBytes(content);
36+
await stream.WriteAsync(data, 0, data.Length);
37+
}
3538
}
3639

3740
/// <summary>
@@ -41,7 +44,7 @@ public static async Task WriteToAsync(this FileInfo file, string content)
4144
/// <returns>A task that should contain the little-endian 16-bit character string (UTF-16) extracted from the <paramref name="file"/> if the read completes successfully</returns>
4245
public static async Task<string> ReadAllTextAsync(this FileInfo file)
4346
{
44-
using (StreamReader reader = file.OpenText())
47+
using (StreamReader reader = new StreamReader(file.OpenRead(), Encoding.Unicode))
4548
return await reader.ReadToEndAsync();
4649
}
4750

@@ -72,14 +75,15 @@ public static FileInfo GetWrapperForRelativePersistentStorageFilePath(string pat
7275
{
7376
path = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), path));
7477

75-
Directory.CreateDirectory(path.Substring(0, path.LastIndexOf(Path.VolumeSeparatorChar)));
78+
Directory.CreateDirectory(path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar)));
7679
return new FileInfo(path);
7780
}
7881

7982
public static async Task TransferAsync(string originFilePath, string targetFilePath)
8083
{
8184
if (!String.IsNullOrWhiteSpace(originFilePath) && !String.IsNullOrWhiteSpace(targetFilePath) && new FileInfo(originFilePath) is FileInfo originFile && originFile.Exists && new FileInfo(targetFilePath) is FileInfo targetFile)
82-
using (StreamWriter writer = targetFile.CreateText()) using (StreamReader reader = originFile.OpenText())
85+
using (StreamWriter writer = new StreamWriter(targetFile.OpenWrite(), Encoding.Unicode))
86+
using (StreamReader reader = new StreamReader(originFile.OpenRead(), Encoding.Unicode))
8387
await writer.WriteAsync(await reader.ReadToEndAsync());
8488
}
8589
}

Parse/Public/ParseClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ public static void Initialize(Configuration configuration)
251251

252252
switch (configuration.StorageConfiguration)
253253
{
254-
case IStorageController controller when !(controller is null):
254+
case null:
255+
configuration.StorageConfiguration = Configuration.MetadataBasedStorageConfiguration.NoCompanyInferred;
255256
break;
256257
default:
257-
configuration.StorageConfiguration = Configuration.MetadataBasedStorageConfiguration.NoCompanyInferred;
258258
break;
259259
}
260260

@@ -263,6 +263,7 @@ public static void Initialize(Configuration configuration)
263263
ParseObject.RegisterSubclass<ParseUser>();
264264
ParseObject.RegisterSubclass<ParseRole>();
265265
ParseObject.RegisterSubclass<ParseSession>();
266+
ParseObject.RegisterSubclass<ParseInstallation>();
266267

267268
ParseModuleController.Instance.ParseDidInitialize();
268269
}

Parse/Public/ParseInstallation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ protected override Task SaveAsync(Task toAwait, CancellationToken cancellationTo
284284
return base.SaveAsync(toAwait, cancellationToken);
285285
}).Unwrap().OnSuccess(_ =>
286286
{
287-
if (CurrentInstallationController.IsCurrent(this))
287+
if (!CurrentInstallationController.IsCurrent(this))
288288
{
289289
return Task.FromResult(0);
290290
}

0 commit comments

Comments
 (0)