Skip to content

Commit 9ff702b

Browse files
committed
Added better app config and moved sql to contrib
1 parent 00faaf5 commit 9ff702b

36 files changed

+1528
-14
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{0A03F567-003B-4192-BC83-CF12861DFAC9}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>FeatureToggles.Contrib.SqlProvider</RootNamespace>
11+
<AssemblyName>FeatureToggles.Contrib.SqlProvider</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="System.Xml.Linq" />
37+
<Reference Include="System.Data.DataSetExtensions" />
38+
<Reference Include="Microsoft.CSharp" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Net.Http" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="Properties\AssemblyInfo.cs" />
45+
<Compile Include="Providers\SqlDataProvider.cs" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<ProjectReference Include="..\FeatureToggles\FeatureToggles.csproj">
49+
<Project>{ba473c25-d415-4323-8a7b-a4f34cf4fe43}</Project>
50+
<Name>FeatureToggles</Name>
51+
</ProjectReference>
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("FeatureToggles.Contrib.SqlProvider")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("FeatureToggles.Contrib.SqlProvider")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("0a03f567-003b-4192-bc83-cf12861dfac9")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

src/FeatureToggles/Providers/SqlDataProvider.cs renamed to src/FeatureToggles.Contrib.SqlProvider/Providers/SqlDataProvider.cs

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
// </copyright>
1818
//-----------------------------------------------------------------------
1919

20-
namespace FeatureToggles.Providers
20+
namespace FeatureToggles.Contrib.SqlProvider.Providers
2121
{
2222
using System;
2323
using System.Data;
2424
using System.Data.SqlClient;
25+
using FeatureToggles.Providers;
26+
using Models;
2527

2628
public class SqlDataProvider : IToggleDataProvider
2729
{
@@ -60,7 +62,60 @@ public Toggle GetFlag(string name)
6062

6163
}
6264

63-
return null;
65+
return Toggle.Empty;
66+
}
67+
68+
public Toggle GetFlag(string name, ToggleData userData)
69+
{
70+
Toggle flag;
71+
try
72+
{
73+
using (SqlConnection conn = new SqlConnection("ToggleFlagConnection"))
74+
{
75+
conn.Open();
76+
77+
using (SqlCommand reader = new SqlCommand("GetFlagWithChecks", conn))
78+
{
79+
reader.CommandType = CommandType.StoredProcedure;
80+
reader.Parameters.AddWithValue("@Name", name);
81+
82+
if (!string.IsNullOrWhiteSpace(userData.UserId))
83+
{
84+
reader.Parameters.AddWithValue("UserId", userData.UserId);
85+
}
86+
87+
if (!string.IsNullOrWhiteSpace(userData.IpAddress))
88+
{
89+
reader.Parameters.AddWithValue("IpAddress", userData.IpAddress);
90+
}
91+
92+
if (!string.IsNullOrWhiteSpace(userData.UserRoles))
93+
{
94+
reader.Parameters.AddWithValue("UserRoles", userData.UserRoles);
95+
}
96+
97+
object result = reader.ExecuteScalar();
98+
99+
if (result == null)
100+
{
101+
flag = Toggle.Empty;
102+
}
103+
else
104+
{
105+
bool enabled = (bool)result;
106+
flag = new Toggle(name, enabled);
107+
}
108+
}
109+
}
110+
111+
return flag;
112+
}
113+
catch (Exception)
114+
{
115+
116+
}
117+
118+
return Toggle.Empty;
64119
}
65120
}
66121
}

src/FeatureToggles.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureToggles", "FeatureTo
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToggleTests", "ToggleTests\ToggleTests.csproj", "{C16E711D-78AB-4854-AAEC-51635B5C87A1}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureToggles.Contrib.SqlProvider", "FeatureToggles.Contrib.SqlProvider\FeatureToggles.Contrib.SqlProvider.csproj", "{0A03F567-003B-4192-BC83-CF12861DFAC9}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{C16E711D-78AB-4854-AAEC-51635B5C87A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{C16E711D-78AB-4854-AAEC-51635B5C87A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{C16E711D-78AB-4854-AAEC-51635B5C87A1}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{0A03F567-003B-4192-BC83-CF12861DFAC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{0A03F567-003B-4192-BC83-CF12861DFAC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{0A03F567-003B-4192-BC83-CF12861DFAC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{0A03F567-003B-4192-BC83-CF12861DFAC9}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

src/FeatureToggles/Codeminers.Modules.Core.FeatureToggles.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Core: Feature Toggles</title>
66
<authors>Codeminers Limited</authors>
77
<owners>Codeminers Limited</owners>
8-
<version>1.0.0</version>
8+
<version>1.1.0</version>
99
<projectUrl>https://www.codeminers.co.uk</projectUrl>
1010
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1111
<description>A utility library for using feature toggles</description>

src/FeatureToggles/Configuration/AppConfigurationProvider.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-

1+
//-----------------------------------------------------------------------
2+
// <copyright file="AppConfigurationProvider.cs" company="Code Miners Limited">
3+
// Copyright (c) 2019 Code Miners Limited
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Lesser General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
13+
// GNU Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public License
16+
// along with this program.If not, see<https://www.gnu.org/licenses/>.
17+
// </copyright>
18+
//-----------------------------------------------------------------------
219

320
namespace FeatureToggles.Configuration
421
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace FeatureToggles.Configuration
2+
{
3+
using System.Configuration;
4+
5+
/// <summary>
6+
/// The url element represents the raw Xml config as an object
7+
/// </summary>
8+
public class IpAddressesElement : ConfigurationElement
9+
{
10+
/// <summary>
11+
/// The url element value. This will be the fully qualified url for the endpoint
12+
/// </summary>
13+
[ConfigurationProperty("value", IsRequired = true)]
14+
public string Value => this["value"] as string;
15+
}
16+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace FeatureToggles.Configuration
2+
{
3+
using System.Collections.Generic;
4+
using System.Configuration;
5+
6+
[ConfigurationCollection(typeof(IpAddressesElement), AddItemName = "ipaddress", CollectionType = ConfigurationElementCollectionType.BasicMap)]
7+
public class IpAddressesElementCollection : ConfigurationElementCollection, IEnumerable<IpAddressesElement>
8+
{
9+
/// <summary>
10+
/// Gets or sets a url element from the collection by index
11+
/// </summary>
12+
/// <param name="index">The index</param>
13+
/// <returns>The url element</returns>
14+
public IpAddressesElement this[int index]
15+
{
16+
get => BaseGet(index) as IpAddressesElement;
17+
set
18+
{
19+
if (Count <= 0)
20+
{
21+
BaseAdd(index, value);
22+
return;
23+
}
24+
25+
if (BaseGet(index) != null)
26+
{
27+
BaseRemoveAt(index);
28+
}
29+
30+
BaseAdd(index, value);
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Iterator for returning url elements from the collection
36+
/// </summary>
37+
/// <returns>A url element</returns>
38+
public new IEnumerator<IpAddressesElement> GetEnumerator()
39+
{
40+
int count = Count;
41+
for (int i = 0; i < count; i++)
42+
{
43+
yield return BaseGet(i) as IpAddressesElement;
44+
}
45+
}
46+
47+
/// <summary>
48+
/// Required protected method for returning a configuration element compatible with this
49+
/// collection
50+
/// </summary>
51+
/// <returns>The configuration element</returns>
52+
protected override ConfigurationElement CreateNewElement()
53+
{
54+
return new IpAddressesElement();
55+
}
56+
57+
/// <summary>
58+
/// Gets the configuration element key from the provided element
59+
/// </summary>
60+
/// <param name="element">The configuration element base class</param>
61+
/// <returns>The actual instance required</returns>
62+
protected override object GetElementKey(ConfigurationElement element)
63+
{
64+
return ((IpAddressesElement)element).Value;
65+
}
66+
}
67+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace FeatureToggles.Configuration
2+
{
3+
using System.Configuration;
4+
5+
/// <summary>
6+
/// The url element represents the raw Xml config as an object
7+
/// </summary>
8+
public class RoleElement : ConfigurationElement
9+
{
10+
/// <summary>
11+
/// The unique url element key
12+
/// </summary>
13+
[ConfigurationProperty("name", IsRequired = true)]
14+
public string Name => this["name"] as string;
15+
}
16+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace FeatureToggles.Configuration
2+
{
3+
using System.Collections.Generic;
4+
using System.Configuration;
5+
6+
[ConfigurationCollection(typeof(ToggleElement), AddItemName = "role", CollectionType = ConfigurationElementCollectionType.BasicMap)]
7+
public class RolesElementCollection : ConfigurationElementCollection, IEnumerable<RoleElement>
8+
{
9+
/// <summary>
10+
/// Gets or sets a url element from the collection by index
11+
/// </summary>
12+
/// <param name="index">The index</param>
13+
/// <returns>The url element</returns>
14+
public RoleElement this[int index]
15+
{
16+
get => BaseGet(index) as RoleElement;
17+
set
18+
{
19+
if (Count <= 0)
20+
{
21+
BaseAdd(index, value);
22+
return;
23+
}
24+
25+
if (BaseGet(index) != null)
26+
{
27+
BaseRemoveAt(index);
28+
}
29+
30+
BaseAdd(index, value);
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Iterator for returning url elements from the collection
36+
/// </summary>
37+
/// <returns>A url element</returns>
38+
public new IEnumerator<RoleElement> GetEnumerator()
39+
{
40+
int count = Count;
41+
for (int i = 0; i < count; i++)
42+
{
43+
yield return BaseGet(i) as RoleElement;
44+
}
45+
}
46+
47+
/// <summary>
48+
/// Required protected method for returning a configuration element compatible with this
49+
/// collection
50+
/// </summary>
51+
/// <returns>The configuration element</returns>
52+
protected override ConfigurationElement CreateNewElement()
53+
{
54+
return new RoleElement();
55+
}
56+
57+
/// <summary>
58+
/// Gets the configuration element key from the provided element
59+
/// </summary>
60+
/// <param name="element">The configuration element base class</param>
61+
/// <returns>The actual instance required</returns>
62+
protected override object GetElementKey(ConfigurationElement element)
63+
{
64+
return ((RoleElement)element).Name;
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)