Skip to content

Commit ca4eeac

Browse files
authored
Merge pull request #9 from NinjaRocks/dev-2.0.0
Upgrade to v2.0.0
2 parents 1e4643b + ad414b2 commit ca4eeac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1099
-313
lines changed

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
next-version: 1.0.6
1+
next-version: 2.0.0
22
tag-prefix: '[vV]'
33
mode: ContinuousDeployment
44
branches:

Ninja.FeatureOne.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureOne", "src\FeatureOn
2525
EndProject
2626
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureOne.Tests", "test\FeatureOne.Tests\FeatureOne.Tests.csproj", "{F51B62E7-1A8F-41DC-B027-074932A01D33}"
2727
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureOne.SQL", "src\FeatureOne.SQL\FeatureOne.SQL.csproj", "{FED48C4A-1EEC-491C-8F5D-886763DF9388}"
29+
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureOne.SQL.Tests", "test\FeatureOne.SQL.Tests\FeatureOne.SQL.Tests.csproj", "{A6102616-CA8C-4C7F-AF16-C8F451E6D62D}"
31+
EndProject
2832
Global
2933
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3034
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +43,14 @@ Global
3943
{F51B62E7-1A8F-41DC-B027-074932A01D33}.Debug|Any CPU.Build.0 = Debug|Any CPU
4044
{F51B62E7-1A8F-41DC-B027-074932A01D33}.Release|Any CPU.ActiveCfg = Release|Any CPU
4145
{F51B62E7-1A8F-41DC-B027-074932A01D33}.Release|Any CPU.Build.0 = Release|Any CPU
46+
{FED48C4A-1EEC-491C-8F5D-886763DF9388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{FED48C4A-1EEC-491C-8F5D-886763DF9388}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{FED48C4A-1EEC-491C-8F5D-886763DF9388}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{FED48C4A-1EEC-491C-8F5D-886763DF9388}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{A6102616-CA8C-4C7F-AF16-C8F451E6D62D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{A6102616-CA8C-4C7F-AF16-C8F451E6D62D}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{A6102616-CA8C-4C7F-AF16-C8F451E6D62D}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{A6102616-CA8C-4C7F-AF16-C8F451E6D62D}.Release|Any CPU.Build.0 = Release|Any CPU
4254
EndGlobalSection
4355
GlobalSection(SolutionProperties) = preSolution
4456
HideSolutionNode = FALSE
@@ -47,6 +59,8 @@ Global
4759
{FB8FCDD0-A3D4-4776-85E0-C47ECFB3D310} = {9930EAFC-568F-4676-82AB-2B8F9D7535B3}
4860
{65BD1F94-CEF4-4CC1-8482-3FF72BBF620F} = {B5EFC87D-E5C5-488E-AA89-06D26027E4C7}
4961
{F51B62E7-1A8F-41DC-B027-074932A01D33} = {E864826B-B5D2-4DAD-B53A-2A3976226B53}
62+
{FED48C4A-1EEC-491C-8F5D-886763DF9388} = {B5EFC87D-E5C5-488E-AA89-06D26027E4C7}
63+
{A6102616-CA8C-4C7F-AF16-C8F451E6D62D} = {E864826B-B5D2-4DAD-B53A-2A3976226B53}
5064
EndGlobalSection
5165
GlobalSection(ExtensibilityGlobals) = postSolution
5266
SolutionGuid = {745CC402-145C-4E31-BAB7-DA93F8292512}

README.md

Lines changed: 188 additions & 52 deletions
Large diffs are not rendered by default.

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
markdown: GFM

src/FeatureOne/Core/Stores/ConditionFactory.cs renamed to src/FeatureOne.SQL/ConditionDeserializer.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
using System.Reflection;
66
using System.Text.Json;
77
using System.Text.Json.Nodes;
8+
using FeatureOne.Core;
89

9-
namespace FeatureOne.Core.Stores
10+
namespace FeatureOne.SQL
1011
{
11-
public static class ConditionFactory
12+
internal class ConditionDeserializer : IConditionDeserializer
1213
{
1314
private static Type[] loaddedTypes;
1415

@@ -17,32 +18,36 @@ private static Type[] LoaddedTypes
1718
get
1819
{
1920
if (loaddedTypes == null || loaddedTypes.Length == 0)
20-
loaddedTypes = Assembly.GetExecutingAssembly().GetTypes();
21+
loaddedTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
22+
.Where(p => typeof(ICondition).IsAssignableFrom(p)).ToArray();
2123

2224
return loaddedTypes;
2325
}
2426
}
2527

26-
public static ICondition Create(JsonObject JsonObject)
28+
public ICondition Deserialize(JsonObject condition)
2729
{
28-
if (JsonObject == null)
29-
throw new ArgumentNullException(nameof(JsonObject));
30+
if (condition == null)
31+
throw new ArgumentNullException(nameof(condition));
3032

31-
var typeName = JsonObject?["type"]?.ToString();
33+
var typeName = condition?["type"]?.ToString();
3234

3335
var toggle = CreateInstance(new NamePostFix(typeName, "Condition"));
3436

35-
HydrateToggle(toggle, JsonObject);
37+
HydrateToggle(toggle, condition);
3638

3739
return toggle;
3840
}
3941

40-
public static ICondition[] Create(JsonObject[] conditions)
42+
private static ICondition CreateInstance(NamePostFix conditionName)
4143
{
42-
if (conditions == null)
43-
throw new ArgumentNullException(nameof(conditions));
44+
var type = LoaddedTypes
45+
.FirstOrDefault(p => typeof(ICondition).IsAssignableFrom(p) && p.Name.Equals(conditionName.Name, StringComparison.OrdinalIgnoreCase));
4446

45-
return conditions.Select(s => Create(s)).ToArray();
47+
if (type == null)
48+
throw new Exception($"Could not find a toggle type for: '{conditionName.Name}'");
49+
50+
return (ICondition)Activator.CreateInstance(type, true);
4651
}
4752

4853
private static void HydrateToggle(ICondition toggleCondition, JsonObject state)
@@ -75,16 +80,5 @@ private static PropertyInfo[] GetProperties(ICondition condition)
7580

7681
return propertyInfos;
7782
}
78-
79-
private static ICondition CreateInstance(NamePostFix conditionName)
80-
{
81-
var type = LoaddedTypes
82-
.FirstOrDefault(p => typeof(ICondition).IsAssignableFrom(p) && p.Name.Equals(conditionName.Name, StringComparison.OrdinalIgnoreCase));
83-
84-
if (type == null)
85-
throw new Exception($"Could not find a toggle type for: '{conditionName.Name}'");
86-
87-
return (ICondition)Activator.CreateInstance(type, true);
88-
}
8983
}
9084
}

src/FeatureOne.SQL/DbRecord.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace FeatureOne.SQL
2+
{
3+
public class DbRecord
4+
{
5+
public string Name { get; set; }
6+
public string Toggle { get; set; }
7+
}
8+
}

src/FeatureOne.SQL/FeatureCache.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Runtime.Caching;
3+
4+
namespace FeatureOne.SQL
5+
{
6+
internal class FeatureCache : ICache
7+
{
8+
public void Add(string key, object value, int expiry)
9+
=> MemoryCache.Default.Add(key, value, new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(expiry) });
10+
11+
public object Get(string key) => MemoryCache.Default.Get(key);
12+
}
13+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>disable</Nullable>
7+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
8+
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
9+
<GeneratedAssemblyInfoFile>AssemblyInfo.cs</GeneratedAssemblyInfoFile>
10+
<PackRelease>true</PackRelease>
11+
<IsPackable>true</IsPackable>
12+
<AssemblyName>FeatureOne.SQL</AssemblyName>
13+
<RootNamespace>FeatureOne.SQL</RootNamespace>
14+
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
15+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
16+
<Title>FeatureOne.SQL</Title>
17+
<Authors>ninja.shayk</Authors>
18+
<Company>Ninja.Sha!4H</Company>
19+
<Product>FeatureOne</Product>
20+
<Description>.Net library to implement feature toggles with SQL backend.</Description>
21+
<Copyright>Copyright (c) 2023 Ninja Sha!4h</Copyright>
22+
<PackageReadmeFile>README.md</PackageReadmeFile>
23+
<RepositoryUrl>https://github.com/NinjaRocks/FeatureOne</RepositoryUrl>
24+
<RepositoryType>git</RepositoryType>
25+
<PackageTags>feature-toggle; feature-flag; feature-flags; feature-toggles; .netstandard2.1; featureOne; SQL-Backend; SQL-Toggles; SQL</PackageTags>
26+
<Version>2.0.0</Version>
27+
<PackageLicenseFile>License.md</PackageLicenseFile>
28+
<PackageIcon>ninja-icon-16.png</PackageIcon>
29+
<PackageReleaseNotes>
30+
Release Notes v2.0.0. - SQL Storage Provider
31+
Core Functionality :-
32+
Added support for SQL storage provider for Feature Toggle.
33+
- Supports MSSQL, SQLite, ODBC, OLEDB, MySQL, PostgreSQL Db providers.
34+
- Provides memory caching - enabled via configuration.
35+
- Added extensibility for Custom implementations-
36+
- Provides extension point to support more SQL providers.
37+
- Provides extenion point for custom caching.
38+
- Provides extension point for custom deserializer for Toggle Conditions.
39+
</PackageReleaseNotes>
40+
</PropertyGroup>
41+
42+
<ItemGroup>
43+
<None Include="..\..\License.md">
44+
<Pack>True</Pack>
45+
<PackagePath>\</PackagePath>
46+
</None>
47+
<None Include="..\..\ninja-icon-16.png">
48+
<Pack>True</Pack>
49+
<PackagePath>\</PackagePath>
50+
</None>
51+
<None Include="..\..\README.md">
52+
<Pack>True</Pack>
53+
<PackagePath>\</PackagePath>
54+
</None>
55+
</ItemGroup>
56+
57+
<ItemGroup>
58+
<PackageReference Include="Npgsql" Version="7.0.4" />
59+
<PackageReference Include="System.Data.Common" Version="4.3.0" />
60+
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
61+
<PackageReference Include="System.Data.Odbc" Version="7.0.0" />
62+
<PackageReference Include="System.Data.OleDb" Version="7.0.0" />
63+
<PackageReference Include="System.Data.SQLite" Version="1.0.86" />
64+
<PackageReference Include="MySql.Data" Version="8.0.33" />
65+
<PackageReference Include="System.Runtime.Caching " Version="7.0.0" />
66+
<PackageReference Include="System.Text.Json" Version="7.0.1" />
67+
</ItemGroup>
68+
69+
<ItemGroup>
70+
<ProjectReference Include="..\FeatureOne\FeatureOne.csproj" />
71+
</ItemGroup>
72+
73+
</Project>

src/FeatureOne.SQL/ICache.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace FeatureOne.SQL
2+
{
3+
public interface ICache
4+
{
5+
/// <summary>
6+
/// Add item to cache
7+
/// </summary>
8+
/// <param name="key"></param>
9+
/// <param name="value"></param>
10+
/// <param name="expiry"></param>
11+
void Add(string key, object value, int expiry);
12+
13+
/// <summary>
14+
/// Get item from cache
15+
/// </summary>
16+
/// <param name="key"></param>
17+
/// <returns></returns>
18+
object Get(string key);
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Text.Json.Nodes;
2+
using FeatureOne.Core;
3+
4+
namespace FeatureOne.SQL
5+
{
6+
/// <summary>
7+
/// Implement to provide deserialization strategy of condition types.
8+
/// </summary>
9+
public interface IConditionDeserializer
10+
{
11+
ICondition Deserialize(JsonObject condition);
12+
}
13+
}

0 commit comments

Comments
 (0)