Skip to content

Commit

Permalink
Feature/demo compile (#10)
Browse files Browse the repository at this point in the history
Conditional compiling with solution wide defines for demo mode.
  • Loading branch information
martinstoeckli authored Mar 18, 2019
1 parent b631056 commit e6c51fd
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 113 deletions.
57 changes: 31 additions & 26 deletions SilentNotes.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2037
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilentNotes.Android", "src\SilentNotes.Android\SilentNotes.Android.csproj", "{3D238724-CCC4-44E6-91D4-2CDFE089932F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilentNotes.Android", "src\SilentNotes.Android\SilentNotes.Android.csproj", "{7210805F-1AE7-4FAA-BA07-9E1B721C823A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilentNotes.UWP", "src\SilentNotes.UWP\SilentNotes.UWP.csproj", "{FCBCED63-C82E-40FE-A914-C4B44F6A2505}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilentNotesTest", "src\Tests\SilentNotesTest\SilentNotesTest.csproj", "{ED7328DA-7BAD-43CA-A7D1-78717BCE183D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{86D047AA-2E1E-439C-A165-3839D4C6EA66}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilentNotes.Shared", "src\SilentNotes.Shared\SilentNotes.Shared.csproj", "{37775BF3-F095-4BFC-ACD5-CF84E2C92F52}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SilentNotes.Shared", "src\SilentNotes.Shared\SilentNotes.Shared.csproj", "{37775BF3-F095-4BFC-ACD5-CF84E2C92F52}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8FAA55E2-E83B-4AB4-BC83-3664D79ADF46}"
ProjectSection(SolutionItems) = preProject
SolutionWideDefines.props = SolutionWideDefines.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -25,30 +30,30 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|ARM.ActiveCfg = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|ARM.Build.0 = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|ARM.Deploy.0 = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|x64.ActiveCfg = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|x64.Build.0 = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|x64.Deploy.0 = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|x86.ActiveCfg = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|x86.Build.0 = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Debug|x86.Deploy.0 = Debug|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|Any CPU.Build.0 = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|Any CPU.Deploy.0 = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|ARM.ActiveCfg = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|ARM.Build.0 = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|ARM.Deploy.0 = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|x64.ActiveCfg = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|x64.Build.0 = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|x64.Deploy.0 = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|x86.ActiveCfg = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|x86.Build.0 = Release|Any CPU
{3D238724-CCC4-44E6-91D4-2CDFE089932F}.Release|x86.Deploy.0 = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|ARM.ActiveCfg = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|ARM.Build.0 = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|ARM.Deploy.0 = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|x64.ActiveCfg = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|x64.Build.0 = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|x64.Deploy.0 = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|x86.ActiveCfg = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|x86.Build.0 = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Debug|x86.Deploy.0 = Debug|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|Any CPU.Build.0 = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|Any CPU.Deploy.0 = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|ARM.ActiveCfg = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|ARM.Build.0 = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|ARM.Deploy.0 = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|x64.ActiveCfg = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|x64.Build.0 = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|x64.Deploy.0 = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|x86.ActiveCfg = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|x86.Build.0 = Release|Any CPU
{7210805F-1AE7-4FAA-BA07-9E1B721C823A}.Release|x86.Deploy.0 = Release|Any CPU
{FCBCED63-C82E-40FE-A914-C4B44F6A2505}.Debug|Any CPU.ActiveCfg = Debug|x86
{FCBCED63-C82E-40FE-A914-C4B44F6A2505}.Debug|ARM.ActiveCfg = Debug|ARM
{FCBCED63-C82E-40FE-A914-C4B44F6A2505}.Debug|ARM.Build.0 = Debug|ARM
Expand Down
21 changes: 21 additions & 0 deletions SolutionWideDefines.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project>
<PropertyGroup>
<!--
Here we can define solution wide defines for conditional compiling. Write them semikolon
delimited after $(DefineConstants) like this...
$(DefineConstants);ENV_DEVELOPMENT;LANG_EN
...but don't forget to reset this file before building for production. After changing a
value, please rebuild the solution.
Known defines are:
ENV_PRODUCTION: Has no effect (default)
ENV_DEVELOPMENT: Uses different filenames for repository and settings (works only in DEBUG mode)
LANG_EN: Enforces an english localization (works only in DEBUG mode)
LANG_DE: Enforces a german localization (works only in DEBUG mode)
DEMO: Loads hard coded demo data (works only in DEBUG mode)
-->
<DefineConstants>$(DefineConstants)</DefineConstants>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/SilentNotes.Android/SilentNotes.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
</PropertyGroup>
<Import Project="$(SolutionDir)\SolutionWideDefines.props" />
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="System" />
Expand Down
80 changes: 12 additions & 68 deletions src/SilentNotes.Shared/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

using System;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("SilentNotesTest")]
Expand All @@ -16,82 +15,27 @@ namespace SilentNotes
public static class Config
{
/// <summary>
/// Gets the mode of the application.
/// Make sure this value is set to <see cref="RunningModes.Production"/> to deploy the application.
/// Initializes static members of the <see cref="Config"/> class.
/// </summary>
public static RunningModes RunningMode { get; internal set; } = RunningModes.Production;

/// <summary>
/// Gets the enforced language of the GUI. Use this setting when a language should be
/// explicitely set for debugging/testing, it works only when compiled in DEBUG mode.
/// </summary>
public static LanguageModes LanguageMode { get; internal set; } = LanguageModes.Auto;

/// <summary>
/// Gets the filename without path, used to store the note repository
/// </summary>
public static string RepositoryFileName
static Config()
{
get
{
switch (RunningMode)
{
case RunningModes.Production:
return "silentnotes_repository.silentnotes";
case RunningModes.Demo:
return "silentnotes_repository_demo.silentnotes";
case RunningModes.Development:
return "silentnotes_repository_dev.silentnotes";
case RunningModes.UnitTest:
return "silentnotes_repository_unittest.silentnotes";
default:
throw new ArgumentOutOfRangeException("Config.RunningMode");
}
}
}
RepositoryFileName = "silentnotes_repository.silentnotes";
UserSettingsFileName = "silentnotes_user_settings.config";

/// <summary>
/// Gets the filename without path, used to store the user settings
/// </summary>
public static string UserSettingsFileName
{
get
{
switch (RunningMode)
{
case RunningModes.Production:
return "silentnotes_user_settings.config";
case RunningModes.Demo:
return "silentnotes_user_settings_demo.config";
case RunningModes.Development:
return "silentnotes_user_settings_dev.config";
case RunningModes.UnitTest:
return "silentnotes_user_settings_unittest.config";
default:
throw new ArgumentOutOfRangeException("Config.RunningMode");
}
}
#if (ENV_DEVELOPMENT && DEBUG)
RepositoryFileName = "silentnotes_repository_dev.silentnotes";
UserSettingsFileName = "silentnotes_user_settings_dev.config";
#endif
}

/// <summary>
/// Enumeration of all known running modes.
/// Gets the filename without path, used to store the note repository
/// </summary>
public enum RunningModes
{
Production,
Demo,
Development,
UnitTest,
}
public static string RepositoryFileName { get; private set; }

/// <summary>
/// Enumeration of all known language modes.
/// Gets the filename without path, used to store the user settings
/// </summary>
public enum LanguageModes
{
Auto,
English,
German,
}
public static string UserSettingsFileName { get; private set; }
}
}
113 changes: 113 additions & 0 deletions src/SilentNotes.Shared/Models/DemoNoteRepositoryModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright © 2018 Martin Stoeckli.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

using System;
using System.Xml.Serialization;

namespace SilentNotes.Models
{
#if (DEMO && DEBUG)
/// <summary>
/// A <see cref="NoteRepositoryModel"/> filled with demo data to make screenshots.
/// </summary>
[XmlRoot(ElementName = "silentnotes")]
public class DemoNoteRepositoryModel : NoteRepositoryModel
{
/// <summary>
/// Initializes a new instance of the <see cref="DemoNoteRepositoryModel"/> class.
/// </summary>
public DemoNoteRepositoryModel()
{
Revision = NewestSupportedRevision;
Id = new Guid("093b917a-f69f-4dd3-91b7-ad175fe0a4c1");
OrderModifiedAt = DateTime.Parse("2018-12-18T13:25:20.8042714Z");

Notes.Add(new NoteModel {
Id = new Guid("d20dd71b-7cde-4894-8c69-1eaecf6930f6"),
BackgroundColorHex = "#d0f8f9",
InRecyclingBin = true,
CreatedAt = DateTime.Parse("2017-09-10T09:59:01.6635731Z"),
ModifiedAt = DateTime.Parse("2017-09-10T10:06:46.4459616Z"),
HtmlContent = @"<h1>Windows10 tips</h1><p>*** Set background color ***
1) Open command line > 'cmd.exe'
2) Type > control /name Microsoft.Personalization /page pageWallpaper
3) User defined color rgb: 210 230 240
</p>"
});

Notes.Add(new NoteModel
{
Id = new Guid("57f1b162-85e7-4402-8731-05b9c06c6915"),
BackgroundColorHex = "#fbf4c1",
InRecyclingBin = false,
CreatedAt = DateTime.Parse("2017-09-10T09:25:16.6787213Z"),
ModifiedAt = DateTime.Parse("2018-12-18T12:52:39.8746458Z"),
HtmlContent = @"<h1>Opening hours</h1><h3>Post office</h3><p>Monday - Friday 9:00-12:00 / 13:00-17:00</p><p>Saturday 9:00-12:00</p><h3>Supermarket</h3><p>Monday - Sunday 7:00-22:00</p><h3>Ticket shop</h3><p>Monday - Friday 8:00-18:30</p>"
});

Notes.Add(new NoteModel
{
Id = new Guid("a2b16ab9-9f7f-4389-916f-f2ef9a2f3a3a"),
BackgroundColorHex = "#fdd8bb",
InRecyclingBin = false,
CreatedAt = DateTime.Parse("2017-09-10T09:44:14.5098885Z"),
ModifiedAt = DateTime.Parse("2018-12-18T13:28:48.6114923Z"),
HtmlContent = @"<h1>Borrowed / loaned</h1><p>📗 'The Black Magician Trilogy' ➜ from aunt Maggie</p><p>📀 'The golden compass' ➜ from Tim</p><p>📕 'Harry potter 5' ➜ to Dawn Cook</p></p>"
});

Notes.Add(new NoteModel
{
Id = new Guid("c35de588-b92f-49a4-a19e-319f045619f5"),
BackgroundColorHex = "#d0f8f9",
InRecyclingBin = false,
CreatedAt = DateTime.Parse("2017-09-10T09:51:49.7504749Z"),
ModifiedAt = DateTime.Parse("2018-12-18T12:51:34.2026179Z"),
HtmlContent = @"<h1>Radio Songs</h1><ol><li>Spider's web (Katie Melua)</li><li>Seven mountains (77 Bombay Street)</li><li>Waiting for A.M. (Glen Of Guinness)</li></ol>"
});

Notes.Add(new NoteModel
{
Id = new Guid("33f00756-6c8b-416d-abe4-2e27d9f58615"),
BackgroundColorHex = "#d9f8c8",
InRecyclingBin = false,
CreatedAt = DateTime.Parse("2017-09-10T09:35:52.9190418Z"),
ModifiedAt = DateTime.Parse("2018-12-18T12:54:18.333087Z"),
HtmlContent = @"<h1>Printer refill</h1><p>brother DCP-9020CDW</p><p>Cartridge <strong>TN-241* </strong><em>(1400 pages)</em></p><p>Cartridge <strong>TN-245*</strong> <em>(2200 pages)</em></p>"
});

Notes.Add(new NoteModel
{
Id = new Guid("8f9e539d-172c-41e8-99ab-60effec84284"),
BackgroundColorHex = "#fbf4c1",
InRecyclingBin = false,
CreatedAt = DateTime.Parse("2018-12-18T12:53:09.3660557Z"),
ModifiedAt = DateTime.Parse("2018-12-18T13:25:55.8335803Z"),
HtmlContent = @"<h1>Recipe Yellow Split Pea Soup</h1><pre class='ql-syntax' spellcheck='false'>1.25 l Water put in pressure cooker.
200 g Yellow beans add to cooker.
2 Bouillon cube crumble and add to cooker.
Herbs as much as you like.
</pre><p><br></p><pre class='ql-syntax' spellcheck='false'>0.25 Celery
2 Carrots grate vegetables and add to cooker.
</pre><p>Bring the soup to boil, stir well so that no beans are 'sticking' to the bottom of the cooker, only now close the pressure cooker.</p><p><br></p><pre class='ql-syntax' spellcheck='false'>Time 30 min
Temperature 4 out of 10
</pre><p>Mix the soup with a blender and add some cream if you like.</p>"
});

Notes.Add(new NoteModel
{
Id = new Guid("70a25de4-2141-4164-aefc-b9b2624a112c"),
BackgroundColorHex = "#d0f8f9",
InRecyclingBin = false,
CreatedAt = DateTime.Parse("2017-09-10T09:39:12.8056002Z"),
ModifiedAt = DateTime.Parse("2018-12-18T13:25:41.3363938Z"),
HtmlContent = @"<h1>Shopping list</h1><ul><li>Milk</li><li>Toast</li><li>Sun cream</li><li>Garbage bags</li></ul>"
});

DeletedNotes.Add(new Guid("fae40c63-d850-4b78-a8bd-609893d2983b"));
}
}
#endif
}
19 changes: 4 additions & 15 deletions src/SilentNotes.Shared/Services/LanguageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

using System;
using System.Collections.Generic;

namespace SilentNotes.Services
Expand Down Expand Up @@ -225,20 +224,10 @@ private void LoadGermanResources(Dictionary<string, string> resources)
/// <inheritdoc/>
protected override void LoadTextResources(Dictionary<string, string> textResources, string languageCode)
{
#if DEBUG
switch (Config.LanguageMode)
{
case Config.LanguageModes.Auto:
break;
case Config.LanguageModes.English:
languageCode = "en";
break;
case Config.LanguageModes.German:
languageCode = "de";
break;
default:
throw new ArgumentOutOfRangeException("Unknown Config.LanguageMode");
}
#if (LANG_EN && DEBUG)
languageCode = "en";
#elif (LANG_DE && DEBUG)
languageCode = "de";
#endif

switch (languageCode.ToLowerInvariant())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public RepositoryStorageServiceBase(IXmlFileService xmlFileService, ILanguageSer
_xmlFileService = xmlFileService;
_languageService = languageService;
_updater = new NoteRepositoryUpdater();

#if (DEMO && DEBUG)
_cachedRepository = new DemoNoteRepositoryModel();
#endif
}

/// <inheritdoc/>
Expand Down
1 change: 1 addition & 0 deletions src/SilentNotes.Shared/SilentNotes.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\bin\Shared</OutputPath>
</PropertyGroup>
<Import Project="$(SolutionDir)\SolutionWideDefines.props" />

<ItemGroup>
<None Remove="StoryBoards\SynchronizationStory\diagram-draw.io.xml" />
Expand Down
1 change: 1 addition & 0 deletions src/SilentNotes.UWP/SilentNotes.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<Import Project="$(SolutionDir)\SolutionWideDefines.props" />
<ItemGroup>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class DropboxCloudStorageServiceTest
[OneTimeSetUp]
public void TestSetup()
{
Config.RunningMode = Config.RunningModes.UnitTest;
_randomSource = new RandomSource4UnitTest();
}

Expand Down
Loading

0 comments on commit e6c51fd

Please sign in to comment.