Skip to content

Commit 5067390

Browse files
The application settings have been integrated into SQLite. (#35)
* The application settings have been integrated into SQLite. * Improvements to the settings interface and localization --------- Co-authored-by: Ii Daisuke <[email protected]>
1 parent f105ac9 commit 5067390

16 files changed

Lines changed: 434 additions & 30 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SpoClient.Setting.Models
2+
{
3+
public static class AppSettingKeys
4+
{
5+
public const string Culture = "Culture";
6+
}
7+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
using SpoClient.Setting.Repositories;
2+
using System.Collections;
3+
using System.Collections.Specialized;
4+
5+
namespace SpoClient.Setting.Models
6+
{
7+
/// <summary>
8+
/// Application settings class.
9+
/// </summary>
10+
public class AppSettings : IAppSettings, IEnumerable<string?>
11+
{
12+
/// <summary>
13+
/// Singleton instance of the settings class.
14+
/// </summary>
15+
private Settings repository;
16+
17+
18+
/// <summary>
19+
/// The settings collection.
20+
/// </summary>
21+
public StringDictionary settings;
22+
23+
24+
25+
/// <summary>
26+
/// The singleton instance of the settings class.
27+
/// </summary>
28+
/// <param name="repository"></param>
29+
public AppSettings(Settings repository)
30+
{
31+
this.repository = repository;
32+
33+
this.settings = this.repository.GetAllDictionary();
34+
}
35+
36+
37+
public IEnumerator<string?> GetEnumerator()
38+
{
39+
foreach(var v in this.settings.Values)
40+
{
41+
yield return v?.ToString();
42+
}
43+
}
44+
45+
46+
public void Add(string key, string? value)
47+
{
48+
this.repository.Add(key, value);
49+
this.settings.Add(key, value);
50+
}
51+
52+
53+
public string? this[string key]
54+
{
55+
get
56+
{
57+
return this.settings[key];
58+
}
59+
set
60+
{
61+
if (this.settings.ContainsKey(key))
62+
{
63+
this.repository.Update(key, value);
64+
this.settings[key] = value;
65+
return;
66+
}
67+
else
68+
{
69+
this.repository.Add(key, value);
70+
this.settings[key] = value;
71+
}
72+
}
73+
}
74+
75+
76+
public int Count
77+
{
78+
get
79+
{
80+
return this.settings.Count;
81+
}
82+
}
83+
84+
85+
public bool IsSynchronized
86+
{
87+
get
88+
{
89+
return this.settings.IsSynchronized;
90+
}
91+
}
92+
93+
94+
public object SyncRoot
95+
{
96+
get
97+
{
98+
return this.settings.SyncRoot;
99+
}
100+
}
101+
102+
103+
public ICollection<string> Keys
104+
{
105+
get
106+
{
107+
return [.. this.settings.Keys.Cast<string>()];
108+
}
109+
}
110+
111+
112+
public ICollection<string?> Values
113+
{
114+
get
115+
{
116+
return [.. this.settings.Values.Cast<string?>()];
117+
}
118+
}
119+
120+
121+
public bool ContainsKey(string key)
122+
{
123+
return this.settings.ContainsKey(key);
124+
}
125+
126+
127+
public bool ContainsValue(string? value)
128+
{
129+
return this.settings.ContainsValue(value);
130+
}
131+
132+
133+
IEnumerator IEnumerable.GetEnumerator()
134+
{
135+
return this.settings.GetEnumerator();
136+
}
137+
138+
139+
public void Remove(string key)
140+
{
141+
this.repository.Delete(key);
142+
this.settings.Remove(key);
143+
}
144+
}
145+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
namespace SpoClient.Setting.Models
2+
{
3+
/// <summary>
4+
/// Application settings access object.
5+
/// </summary>
6+
public interface IAppSettings
7+
{
8+
/// <summary>
9+
/// Get or set the value of the specified key.
10+
/// </summary>
11+
/// <param name="key"></param>
12+
/// <returns></returns>
13+
string? this[string key] { get; set; }
14+
15+
16+
/// <summary>
17+
/// Add a new key-value pair to the settings.
18+
/// </summary>
19+
/// <param name="key"></param>
20+
/// <param name="value"></param>
21+
void Add(string key, string? value);
22+
23+
24+
/// <summary>
25+
/// Get the number of key-value pairs in the settings.
26+
/// </summary>
27+
int Count { get; }
28+
29+
30+
/// <summary>
31+
/// Indicates whether access to the StringDictionary is synchronized (thread-safe).
32+
/// This property is read only.
33+
/// </summary>
34+
bool IsSynchronized { get; }
35+
36+
37+
/// <summary>
38+
/// Gets an object that can be used to synchronize access to the StringDictionary.
39+
/// </summary>
40+
object SyncRoot { get; }
41+
42+
43+
/// <summary>
44+
/// Get all keys in the settings.
45+
/// </summary>
46+
ICollection<string> Keys { get; }
47+
48+
49+
/// <summary>
50+
/// Get all values in the settings.
51+
/// </summary>
52+
ICollection<string?> Values { get; }
53+
54+
55+
/// <summary>
56+
/// Determines if the string dictionary contains a specific key
57+
/// </summary>
58+
/// <param name="key"></param>
59+
/// <returns></returns>
60+
bool ContainsKey(string key);
61+
62+
63+
/// <summary>
64+
/// Determines if the string dictionary contains a specific value
65+
/// </summary>
66+
/// <param name="value"></param>
67+
/// <returns></returns>
68+
bool ContainsValue(string? value);
69+
70+
71+
/// <summary>
72+
/// Remove the specified key from the settings.
73+
/// </summary>
74+
void Remove(string key);
75+
}
76+
}

SpoClient.Setting/Models/SecureServer.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Security;
5-
using System.Text;
6-
using System.Threading.Tasks;
1+
using System.Security;
72

83
namespace SpoClient.Setting.Models
94
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace SpoClient.Setting.Models
2+
{
3+
public class Setting
4+
{
5+
public string Key { get; set; }
6+
7+
8+
public string? Value { get; set; } = null;
9+
10+
11+
12+
public Setting(string key)
13+
{
14+
Key = key;
15+
}
16+
17+
18+
public Setting(string key, string? value)
19+
{
20+
Key = key;
21+
Value = value;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)