Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 174 add wpf example application #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ Thumbs.db

# dotCover
*.dotCover

# VS
.vs/
19 changes: 16 additions & 3 deletions FeatureflowExample.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureflowExample", "FeatureflowExample\FeatureflowExample.csproj", "{F484363C-6E27-4C73-884B-D1E39A84ABB1}"
# Visual Studio 15
VisualStudioVersion = 15.0.28307.329
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureflowExample", "FeatureflowExample\FeatureflowExample.csproj", "{F484363C-6E27-4C73-884B-D1E39A84ABB1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureflowWpfExample", "FeatureflowWpfExample\FeatureflowWpfExample.csproj", "{AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -13,5 +16,15 @@ Global
{F484363C-6E27-4C73-884B-D1E39A84ABB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F484363C-6E27-4C73-884B-D1E39A84ABB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F484363C-6E27-4C73-884B-D1E39A84ABB1}.Release|Any CPU.Build.0 = Release|Any CPU
{AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B0BF013A-5B4A-44FF-9BD7-21C2A78090EF}
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions FeatureflowWpfExample/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
18 changes: 18 additions & 0 deletions FeatureflowWpfExample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Application x:Class="FeatureflowWpfExample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FeatureflowWpfExample"
xmlns:converters="clr-namespace:FeatureflowWpfExample.Converters"
StartupUri="MainWindow.xaml">
<Application.Resources>
<converters:ExampleToViewConverter x:Key="ExampleToViewConverter"/>
<converters:BooleanToOnOffConverter x:Key="BooleanToOnOffConverter"/>
<converters:ColorToBrushConverter x:Key="ColorToBrushConverter"/>

<Style x:Key="ExampleCaptionTextStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="16" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</Application.Resources>
</Application>
22 changes: 22 additions & 0 deletions FeatureflowWpfExample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace FeatureflowWpfExample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
FeatureflowClientProvider.IntializeClient("<< TYPE YOUR FEATUREFLOW KEY HERE >>");
}
}
}
40 changes: 40 additions & 0 deletions FeatureflowWpfExample/BaseExamplePage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace FeatureflowWpfExample
{
public class BaseExamplePage
: Page
{
public BaseExamplePage()
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
}

private void OnLoaded(object sender, RoutedEventArgs e)
{
Loaded -= OnLoaded;
Activate();
}

private void OnUnloaded(object sender, RoutedEventArgs e)
{
Unloaded -= OnUnloaded;
Deactivate();
}

protected virtual void Activate()
{
}

protected virtual void Deactivate()
{
}
}
}
29 changes: 29 additions & 0 deletions FeatureflowWpfExample/Converters/BooleanToOnOffConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace FeatureflowWpfExample.Converters
{
public class BooleanToOnOffConverter
: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}

return (bool)value ? "On" : "Off";
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
34 changes: 34 additions & 0 deletions FeatureflowWpfExample/Converters/ColorToBrushConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace FeatureflowWpfExample.Converters
{
public class ColorToBrushConverter
: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string s)
{
try
{
return (SolidColorBrush)(new BrushConverter().ConvertFromString(s));
}
catch (Exception) { }
}

return new SolidColorBrush(Colors.Black);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
48 changes: 48 additions & 0 deletions FeatureflowWpfExample/Converters/ExampleToViewConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Markup;

namespace FeatureflowWpfExample.Converters
{
public class ExampleToViewConverter
: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Example e)
{
string pathToXaml = null;

switch (e.Tag)
{
case ExampleTag.SimpleSwitch:
pathToXaml = "Views/SimpleSwitchPage.xaml";
break;

case ExampleTag.TrafficLight:
pathToXaml = "Views/TrafficLightPage.xaml";
break;
}

if (pathToXaml != null)
{
return (Page)Application.LoadComponent(new Uri(pathToXaml, UriKind.Relative));
}
}

return null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
22 changes: 22 additions & 0 deletions FeatureflowWpfExample/Example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FeatureflowWpfExample
{
public class Example
{
public ExampleTag Tag { get; set; }

public string Caption { get; set; }
}

public enum ExampleTag
{
SimpleSwitch,
TrafficLight,
Other,
}
}
66 changes: 66 additions & 0 deletions FeatureflowWpfExample/FeatureflowClientProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Featureflow.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FeatureflowWpfExample
{
/// <summary>
/// Wrapper for access to faetureflow client singleton
/// </summary>
/// <returns></returns>
static class FeatureflowClientProvider
{
private static IFeatureflowClient _client;

internal static void IntializeClient(string apiKey)
{
IntializeClient(apiKey, null, null);
}

internal static void IntializeClient(string apiKey, FeatureflowConfig config)
{
IntializeClient(apiKey, null, config);
}

internal static void IntializeClient(string apiKey, IEnumerable<Feature> predefinedFeatures)
{
IntializeClient(apiKey, predefinedFeatures, null);
}

internal static void IntializeClient(string apiKey, IEnumerable<Feature> predefinedFeatures, FeatureflowConfig config)
{
EnsureUninitialized();
_client = Create(apiKey, predefinedFeatures, config);
}

internal static IFeatureflowClient GetClient()
{
EnsureInitialized();
return _client;
}

private static void EnsureUninitialized()
{
if (_client != null)
{
throw new ApplicationException("Featureflow client already initialized");
}
}

private static void EnsureInitialized()
{
if (_client == null)
{
throw new ApplicationException("Featureflow client must be initialized before using");
}
}

private static IFeatureflowClient Create(string apiKey, IEnumerable<Feature> predefinedFeatures, FeatureflowConfig config)
{
return FeatureflowClientFactory.Create(apiKey, predefinedFeatures, config);
}
}
}
Loading