OLD | NEW |
1 /* | 1 /* |
2 Copyright 2013 Google Inc | 2 Copyright 2013 Google Inc |
3 | 3 |
4 Licensed under the Apache License, Version 2.0 (the "License"); | 4 Licensed under the Apache License, Version 2.0 (the "License"); |
5 you may not use this file except in compliance with the License. | 5 you may not use this file except in compliance with the License. |
6 You may obtain a copy of the License at | 6 You may obtain a copy of the License at |
7 | 7 |
8 http://www.apache.org/licenses/LICENSE-2.0 | 8 http://www.apache.org/licenses/LICENSE-2.0 |
9 | 9 |
10 Unless required by applicable law or agreed to in writing, software | 10 Unless required by applicable law or agreed to in writing, software |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 using Google.Apis.Json; | 23 using Google.Apis.Json; |
24 using Google.Apis.Logging; | 24 using Google.Apis.Logging; |
25 | 25 |
26 namespace Google.Apis.Util.Store | 26 namespace Google.Apis.Util.Store |
27 { | 27 { |
28 /// <summary> | 28 /// <summary> |
29 /// Windows Store data store that implements <see cref="IDataStore"/>. This
store creates a different file for each· | 29 /// Windows Store data store that implements <see cref="IDataStore"/>. This
store creates a different file for each· |
30 /// combination of type and key. | 30 /// combination of type and key. |
31 /// </summary> | 31 /// </summary> |
32 public class StroageDataStore : IDataStore | 32 public class StorageDataStore : IDataStore |
33 { | 33 { |
34 // TODO(peleyal): consider adding also PasswordValutDataStore | 34 // TODO(peleyal): consider adding also PasswordValutDataStore |
35 | 35 |
36 private static readonly StorageFolder LocalFolder = ApplicationData.Curr
ent.LocalFolder; | 36 private static readonly StorageFolder LocalFolder = ApplicationData.Curr
ent.LocalFolder; |
37 private static readonly ILogger Logger = ApplicationContext.Logger.ForTy
pe<StroageDataStore>(); | 37 private static readonly ILogger Logger = ApplicationContext.Logger.ForTy
pe<StorageDataStore>(); |
38 | 38 |
39 #region IDataStore Members | 39 #region IDataStore Members |
40 | 40 |
41 public async Task StoreAsync<T>(string key, T value) | 41 public async Task StoreAsync<T>(string key, T value) |
42 { | 42 { |
43 StorageFile file = await LocalFolder.CreateFileAsync(GenerateStoredK
ey(key, typeof(T)), | 43 StorageFile file = await LocalFolder.CreateFileAsync(GenerateStoredK
ey(key, typeof(T)), |
44 CreationCollisionOption.ReplaceExisting); | 44 CreationCollisionOption.ReplaceExisting); |
45 | 45 |
46 var content = Encoding.UTF8.GetBytes(NewtonsoftJsonSerializer.Instan
ce.Serialize(value)); | 46 var content = Encoding.UTF8.GetBytes(NewtonsoftJsonSerializer.Instan
ce.Serialize(value)); |
47 using (var stream = await file.OpenStreamForWriteAsync().ConfigureAw
ait(false)) | 47 using (var stream = await file.OpenStreamForWriteAsync().ConfigureAw
ait(false)) |
(...skipping 28 matching lines...) Expand all Loading... |
76 } | 76 } |
77 | 77 |
78 #endregion | 78 #endregion |
79 | 79 |
80 private string GenerateStoredKey(string key, Type t) | 80 private string GenerateStoredKey(string key, Type t) |
81 { | 81 { |
82 return string.Format("{0}-{1}", t.FullName, key); | 82 return string.Format("{0}-{1}", t.FullName, key); |
83 } | 83 } |
84 } | 84 } |
85 } | 85 } |
OLD | NEW |