Add SettingsRepository.
This commit is contained in:
parent
e4e7f80ed2
commit
ff3086d9c8
60
Tests/Controller/SettingsRepositoryTest.cs
Executable file
60
Tests/Controller/SettingsRepositoryTest.cs
Executable file
@ -0,0 +1,60 @@
|
||||
/* SettingsRepositoryTest.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using zaaReloaded2.Controller;
|
||||
|
||||
namespace Tests.Controller
|
||||
{
|
||||
[TestFixture]
|
||||
class SettingsRepositoryTest
|
||||
{
|
||||
SettingsRepository _savedSettings;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_savedSettings = zaaReloaded2.Properties.Settings.Default.SettingsRepository;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
zaaReloaded2.Properties.Settings.Default.SettingsRepository = _savedSettings;
|
||||
zaaReloaded2.Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PersistSettingsRespository()
|
||||
{
|
||||
SettingsRepository sr = new SettingsRepository();
|
||||
Settings s = new Settings();
|
||||
string testName = "test";
|
||||
s.Name = testName;
|
||||
sr.Settings.Add(s);
|
||||
sr.Store();
|
||||
sr = null;
|
||||
sr = SettingsRepository.Load();
|
||||
Assert.AreEqual(1, sr.Settings.Count);
|
||||
Assert.AreEqual(testName, sr.Settings[0].Name);
|
||||
}
|
||||
}
|
||||
}
|
@ -66,6 +66,7 @@
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controller\SettingsRepositoryTest.cs" />
|
||||
<Compile Include="Thesaurus\ThesaurusTest.cs" />
|
||||
<Compile Include="Formatter\Elements\ItemsTest.cs" />
|
||||
<Compile Include="Formatter\FormatterTest.cs" />
|
||||
|
@ -32,6 +32,11 @@ namespace zaaReloaded2.Controller
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of these settings.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the reference style.
|
||||
/// </summary>
|
||||
|
64
zaaReloaded2/Controller/SettingsRepository.cs
Executable file
64
zaaReloaded2/Controller/SettingsRepository.cs
Executable file
@ -0,0 +1,64 @@
|
||||
/* SettingsRepository.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace zaaReloaded2.Controller
|
||||
{
|
||||
[Serializable]
|
||||
public class SettingsRepository : ApplicationSettingsBase
|
||||
{
|
||||
#region Persistence
|
||||
|
||||
public static SettingsRepository Load()
|
||||
{
|
||||
return
|
||||
zaaReloaded2.Properties.Settings.Default.SettingsRepository ??
|
||||
new SettingsRepository();
|
||||
}
|
||||
|
||||
public void Store()
|
||||
{
|
||||
zaaReloaded2.Properties.Settings.Default.SettingsRepository = this;
|
||||
zaaReloaded2.Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
[UserScopedSetting()]
|
||||
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
|
||||
public IList<Settings> Settings { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public SettingsRepository()
|
||||
{
|
||||
Settings = new List<Settings>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
11
zaaReloaded2/Properties/Settings.Designer.cs
generated
11
zaaReloaded2/Properties/Settings.Designer.cs
generated
@ -22,5 +22,16 @@ namespace zaaReloaded2.Properties {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public global::zaaReloaded2.Controller.SettingsRepository SettingsRepository {
|
||||
get {
|
||||
return ((global::zaaReloaded2.Controller.SettingsRepository)(this["SettingsRepository"]));
|
||||
}
|
||||
set {
|
||||
this["SettingsRepository"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="zaaReloaded2.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="SettingsRepository" Type="zaaReloaded2.Controller.SettingsRepository" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
24
zaaReloaded2/app.config
Executable file
24
zaaReloaded2/app.config
Executable file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
|
||||
<!--
|
||||
app.config
|
||||
part of zaaReloaded2
|
||||
|
||||
Copyright 2015 Daniel Kraus
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<configuration>
|
||||
<configSections>
|
||||
</configSections>
|
||||
</configuration>
|
@ -164,6 +164,7 @@
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Controller\Settings.cs" />
|
||||
<Compile Include="Controller\SettingsRepository.cs" />
|
||||
<Compile Include="Thesaurus\ThesaurusBase.cs" />
|
||||
<Compile Include="Formatter\IItemFormatterDictionary.cs" />
|
||||
<Compile Include="Formatter\ItemFormatter.cs" />
|
||||
@ -203,6 +204,7 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
@ -211,6 +213,7 @@
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="ThisAddIn.cs">
|
||||
<SubType>Code</SubType>
|
||||
|
Loading…
Reference in New Issue
Block a user