/// <summary> /// ローカルデータを読み込みます。 /// </summary> /// <param name="key"><see cref="string"/>キー</param> /// <returns><see cref="object"/>読み込みに成功したときに、このメソッドが返される時 object 型で値を格納します。読み込みに失敗したときは null を格納します。</returns> public static object Load(string key) { object val; try { ApplicationDataContainer container = ApplicationData.Current.LocalSettings; if (container.Values.ContainsKey(key)) { val = container.Values[key]; return(val); } else { val = null; return(val); } } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.Fail("Data.Load", ex.Message); #endif val = null; return(val); } }
/// <summary> /// 一時データを読み込みます /// </summary> /// <param name="key"><see cref="string"/>キー</param> /// <returns><see cref="string"/>文字列の値。存在しないときは string.Empty です</returns> public static IAsyncOperation <string> LoadTempAsync(string key) { return(AsyncInfo.Run((token) => { return Task.Run(async() => { try { StorageFolder folder = ApplicationData.Current.TemporaryFolder; StorageFile file = await folder.GetFileAsync(key); if (file != null) { return await FileIO.ReadTextAsync(file); } else { return string.Empty; } } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.Fail("Data.LoadTempAsync", ex.Message); #endif return string.Empty; } }); })); }
/// <summary> /// ローカルデータの中を一覧で取得します /// </summary> /// <returns><see cref="IReadOnlyList{String}"/></returns> public static IAsyncOperation <IReadOnlyList <string> > LoadTempAllKeysAsync() { return(AsyncInfo.Run((token) => { return Task.Run(async() => { List <string> keys = new List <string>(); try { StorageFolder folder = ApplicationData.Current.TemporaryFolder; var files = await folder.GetFilesAsync(); if (files != null) { foreach (var item in files) { keys.Add(item.Name); } } else { keys = new List <string>(); } } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.Fail("Data.LoadTempAllKeysAsync", ex.Message); #endif keys = new List <string>(); } return (IReadOnlyList <string>)keys; }); })); }
/// <summary> /// ローミングデータを保存します /// </summary> /// <param name="key"><see cref="string"/>キー</param> /// <param name="value"><see cref="string"/>値</param> public static void SaveRoaming(string key, object value) { try { ApplicationDataContainer container = ApplicationData.Current.RoamingSettings; container.Values[key] = value; } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.WriteLine(ex.Message); #endif } }
/// <summary> /// ローカルデータを保存します。 /// </summary> /// <param name="key">(<see cref="string"/>)キー</param> /// <param name="value"><see cref="object"/>値</param> public static void Save(string key, object value) { try { ApplicationDataContainer container = ApplicationData.Current.LocalSettings; container.Values[key] = value; } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.Fail("Data.Save", ex.Message); #endif } }
/// <summary> /// 一時データを保存します /// </summary> /// <param name="key"><see cref="string"/>キー</param> /// <param name="value"><see cref="string"/>値</param> public static async void SaveTemp(string key, object value) { try { StorageFolder folder = ApplicationData.Current.TemporaryFolder; StorageFile file = await folder.CreateFileAsync(key, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, $"{value}"); } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.Fail("Data.SaveTemp", ex.Message); #endif } }
/// <summary> /// ローミングデータを削除します。 /// </summary> /// <param name="key"><see cref="string"/>キー</param> /// <returns><see cref="bool"/>削除が成功した場合 true 、失敗した時は false を返します。</returns> public static bool DeleteRoaming(string key) { try { ApplicationDataContainer container = ApplicationData.Current.RoamingSettings; container.Values.Remove(key); return(true); } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.Fail("Data.DeleteRoaming", ex.Message); #endif } return(false); }
/// <summary> /// ローミングデータの中を一覧で取得します /// </summary> /// <returns><see cref="IReadOnlyList{String}"/></returns> public static IReadOnlyList <string> LoadRoamingAllKeys() { List <string> keys = new List <string>(); try { ApplicationDataContainer container = ApplicationData.Current.RoamingSettings; foreach (var item in container.Values) { keys.Add(item.Key); } } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.Fail("Data.LoadRoamingAllKeys", ex.Message); #endif return(new List <string>()); } return(keys); }
public static bool LoadRoaming(string key, out object val) { try { ApplicationDataContainer container = ApplicationData.Current.RoamingSettings; if (container.Values.ContainsKey(key)) { val = container.Values[key]; return(true); } else { val = null; return(false); } } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.Fail("Data.LoadRoaming", ex.Message); #endif val = null; return(false); } }
/// <summary> /// ローミングデータを読み込みます。 /// </summary> /// <param name="key"><see cref="string"/>キー</param> /// <returns><see cref="object"/>読み込みに成功したときに、このメソッドが返される時 object 型で値を格納します。読み込みに失敗したときは null を格納します。</returns> public static object LoadRoaming(string key) { object val; try { ApplicationDataContainer container = ApplicationData.Current.RoamingSettings; if (container.Values.ContainsKey(key)) { val = container.Values[key]; } else { val = null; } } catch (Exception ex) { #if DEBUG Screens.Message(ex.Message); Debug.WriteLine(ex.Message); #endif val = null; } return(val); }