Skip to content

Commit 0d0a991

Browse files
committed
Added helper for managing stored application settings.
Updated the Diagnostics nuspec description to be more reader friendly.
1 parent c8da322 commit 0d0a991

6 files changed

Lines changed: 585 additions & 2 deletions

File tree

MADE.App.Diagnostics/MADE.App.Diagnostics.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<Authors>MADE Apps</Authors>
3333
<Company>MADE Apps</Company>
3434
<Product>MADE App Diagnostics Library</Product>
35-
<Description>Making App Development Easier with a collection of easy to diagnostic helpers for managing application exceptions and logging for .NET projects across Windows, Android, and iOS.</Description>
35+
<Description>Making App Development Easier with a collection of easy to use diagnostic helpers for managing application exceptions and logging for .NET projects across Windows, Android, and iOS.</Description>
3636
<Copyright>Copyright (C) MADE Apps. All rights reserved.</Copyright>
3737
<PackageLicenseUrl>https://github.com/MADE-Apps/MADE-App-Components/blob/master/LICENSE</PackageLicenseUrl>
3838
<PackageProjectUrl>https://github.com/MADE-Apps/MADE-App-Components</PackageProjectUrl>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;xamarin.ios10;monoandroid81;uap10.0.16299</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
8+
<DocumentationFile>bin\Debug\netstandard2.0\MADE.App.Storage.xml</DocumentationFile>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
12+
<DocumentationFile>bin\Release\netstandard2.0\MADE.App.Storage.xml</DocumentationFile>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<Compile Remove="api\**" />
17+
<Compile Remove="articles\**" />
18+
<Compile Remove="_site\**" />
19+
<EmbeddedResource Remove="api\**" />
20+
<EmbeddedResource Remove="articles\**" />
21+
<EmbeddedResource Remove="_site\**" />
22+
<None Remove="api\**" />
23+
<None Remove="articles\**" />
24+
<None Remove="_site\**" />
25+
</ItemGroup>
26+
27+
<PropertyGroup>
28+
<LogFile>Docfx-$(TargetFramework).log</LogFile>
29+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
30+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
31+
<Version>1.0.0.0</Version>
32+
<Authors>MADE Apps</Authors>
33+
<Company>MADE Apps</Company>
34+
<Product>MADE App Storage Library</Product>
35+
<Description>Making App Development Easier with a collection of easy to use storage helpers for managing application files and settings for .NET projects across Windows, Android, and iOS.</Description>
36+
<Copyright>Copyright (C) MADE Apps. All rights reserved.</Copyright>
37+
<PackageLicenseUrl>https://github.com/MADE-Apps/MADE-App-Components/blob/master/LICENSE</PackageLicenseUrl>
38+
<PackageProjectUrl>https://github.com/MADE-Apps/MADE-App-Components</PackageProjectUrl>
39+
<RepositoryUrl>https://github.com/MADE-Apps/MADE-App-Components</RepositoryUrl>
40+
<RepositoryType>git</RepositoryType>
41+
<PackageIconUrl>https://pbs.twimg.com/profile_images/927154020422160385/6HSRU36P_400x400.jpg</PackageIconUrl>
42+
<PackageTags>MADE App Development Storage StorageFile XPlat Settings Windows Android iOS Xamarin</PackageTags>
43+
</PropertyGroup>
44+
45+
<ItemGroup>
46+
<None Remove=".gitignore" />
47+
<None Remove="docfx.json" />
48+
<None Remove="index.md" />
49+
<None Remove="log.txt" />
50+
<None Remove="toc.yml" />
51+
<None Remove="Docfx-*.log" />
52+
</ItemGroup>
53+
54+
<ItemGroup>
55+
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.5.4" PrivateAssets="All" />
56+
</ItemGroup>
57+
58+
<ItemGroup Condition=" '$(TargetFramework)' == 'xamarin.ios10' ">
59+
<PackageReference Include="XPlat.Storage" Version="1.2.18073.5" />
60+
</ItemGroup>
61+
62+
<ItemGroup Condition=" '$(TargetFramework)' == 'monoandroid81' ">
63+
<PackageReference Include="XPlat.Storage" Version="1.2.18073.5" />
64+
</ItemGroup>
65+
66+
<ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0.16299' ">
67+
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.5" />
68+
</ItemGroup>
69+
70+
<ItemGroup>
71+
<Folder Include="Files\" />
72+
</ItemGroup>
73+
74+
<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
75+
76+
</Project>
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="ApplicationSettings.Windows.cs" company="MADE Apps">
3+
// Copyright (c) MADE Apps.
4+
// </copyright>
5+
// <summary>
6+
// Defines a helper for managing locally stored application settings.
7+
// </summary>
8+
// --------------------------------------------------------------------------------------------------------------------
9+
10+
#if WINDOWS_UWP
11+
namespace MADE.App.Storage.Settings
12+
{
13+
using System;
14+
15+
using Windows.Storage;
16+
17+
/// <summary>
18+
/// Defines a helper for managing locally stored application settings.
19+
/// </summary>
20+
public class ApplicationSettings : IApplicationSettings
21+
{
22+
/// <summary>
23+
/// Adds or updates a value stored within the application settings for the specified key.
24+
/// </summary>
25+
/// <param name="key">
26+
/// The key associated with the value to store.
27+
/// </param>
28+
/// <param name="value">
29+
/// The value to store.
30+
/// </param>
31+
/// <typeparam name="T">
32+
/// The value's expected type.
33+
/// </typeparam>
34+
/// <returns>
35+
/// True if added or updated successfully; otherwise, false.
36+
/// </returns>
37+
public void AddOrUpdate<T>(string key, T value)
38+
{
39+
if (value == null)
40+
{
41+
return;
42+
}
43+
44+
ApplicationData.Current.LocalSettings.Values[key] = value;
45+
}
46+
47+
/// <summary>
48+
/// Attempts to add or update a value stored within the application settings for the specified key.
49+
/// </summary>
50+
/// <param name="key">
51+
/// The key associated with the value to store.
52+
/// </param>
53+
/// <param name="value">
54+
/// The value to store.
55+
/// </param>
56+
/// <typeparam name="T">
57+
/// The value's expected type.
58+
/// </typeparam>
59+
/// <returns>
60+
/// True if added or updated successfully; otherwise, false.
61+
/// </returns>
62+
public bool TryAddOrUpdate<T>(string key, T value)
63+
{
64+
try
65+
{
66+
if (value == null)
67+
{
68+
return false;
69+
}
70+
71+
this.AddOrUpdate(key, value);
72+
return true;
73+
}
74+
catch (Exception)
75+
{
76+
// Ignored
77+
}
78+
79+
return false;
80+
}
81+
82+
/// <summary>
83+
/// Gets a value stored within the application settings for the specified key.
84+
/// </summary>
85+
/// <param name="key">
86+
/// The key associated with the value to retrieve.
87+
/// </param>
88+
/// <typeparam name="T">
89+
/// The value's expected type.
90+
/// </typeparam>
91+
/// <returns>
92+
/// The value as the expected type if stored; otherwise, default type value.
93+
/// </returns>
94+
public T Get<T>(string key)
95+
where T : class
96+
{
97+
return ApplicationData.Current.LocalSettings.Values[key] as T;
98+
}
99+
100+
/// <summary>
101+
/// Attempts to gets a value stored within the application settings for the specified key.
102+
/// </summary>
103+
/// <param name="key">
104+
/// The key associated with the value to retrieve.
105+
/// </param>
106+
/// <param name="value">
107+
/// The value as the expected type if stored.
108+
/// </param>
109+
/// <typeparam name="T">
110+
/// The value's expected type.
111+
/// </typeparam>
112+
/// <returns>
113+
/// True if the get was successful; otherwise, false.
114+
/// </returns>
115+
public bool TryGet<T>(string key, out T value)
116+
where T : class
117+
{
118+
value = default(T);
119+
120+
if (!this.ContainsKey(key))
121+
{
122+
return false;
123+
}
124+
125+
value = this.Get<T>(key);
126+
return true;
127+
128+
}
129+
130+
/// <summary>
131+
/// Checks whether the specified key is associated with a value stored within the application settings.
132+
/// </summary>
133+
/// <param name="key">
134+
/// The key to find.
135+
/// </param>
136+
/// <returns>
137+
/// True if the key exists; otherwise, false.
138+
/// </returns>
139+
public bool ContainsKey(string key)
140+
{
141+
return ApplicationData.Current.LocalSettings.Values.ContainsKey(key);
142+
}
143+
144+
/// <summary>
145+
/// Removes a key-value pair from the application settings for the specified key.
146+
/// </summary>
147+
/// <param name="key">
148+
/// The key associated with the key-value pair to remove.
149+
/// </param>
150+
public void Remove(string key)
151+
{
152+
ApplicationData.Current.LocalSettings.Values.Remove(key);
153+
}
154+
155+
/// <summary>
156+
/// Attempts to remove a key-value pair from the application settings for the specified key.
157+
/// </summary>
158+
/// <param name="key">
159+
/// The key associated with the key-value pair to remove.
160+
/// </param>
161+
/// <returns>
162+
///True if the key-value pair is removed; otherwise, false.
163+
/// </returns>
164+
public bool TryRemove(string key)
165+
{
166+
if (!this.ContainsKey(key))
167+
{
168+
return false;
169+
}
170+
171+
ApplicationData.Current.LocalSettings.Values.Remove(key);
172+
return true;
173+
}
174+
}
175+
}
176+
#endif

0 commit comments

Comments
 (0)