diff --git a/.gitignore b/.gitignore index 13d2fde..b96ce4a 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ Thumbs.db # dotCover *.dotCover + +# VS +.vs/ \ No newline at end of file diff --git a/FeatureflowExample.sln b/FeatureflowExample.sln index 4389856..871c16c 100644 --- a/FeatureflowExample.sln +++ b/FeatureflowExample.sln @@ -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 @@ -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 diff --git a/FeatureflowWpfExample/App.config b/FeatureflowWpfExample/App.config new file mode 100644 index 0000000..8c16bd8 --- /dev/null +++ b/FeatureflowWpfExample/App.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FeatureflowWpfExample/App.xaml b/FeatureflowWpfExample/App.xaml new file mode 100644 index 0000000..fa73a94 --- /dev/null +++ b/FeatureflowWpfExample/App.xaml @@ -0,0 +1,18 @@ + + + + + + + + + diff --git a/FeatureflowWpfExample/App.xaml.cs b/FeatureflowWpfExample/App.xaml.cs new file mode 100644 index 0000000..a722769 --- /dev/null +++ b/FeatureflowWpfExample/App.xaml.cs @@ -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 +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + FeatureflowClientProvider.IntializeClient("<< TYPE YOUR FEATUREFLOW KEY HERE >>"); + } + } +} diff --git a/FeatureflowWpfExample/BaseExamplePage.cs b/FeatureflowWpfExample/BaseExamplePage.cs new file mode 100644 index 0000000..9349a7b --- /dev/null +++ b/FeatureflowWpfExample/BaseExamplePage.cs @@ -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() + { + } + } +} diff --git a/FeatureflowWpfExample/Converters/BooleanToOnOffConverter.cs b/FeatureflowWpfExample/Converters/BooleanToOnOffConverter.cs new file mode 100644 index 0000000..2a9738a --- /dev/null +++ b/FeatureflowWpfExample/Converters/BooleanToOnOffConverter.cs @@ -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(); + } + } +} diff --git a/FeatureflowWpfExample/Converters/ColorToBrushConverter.cs b/FeatureflowWpfExample/Converters/ColorToBrushConverter.cs new file mode 100644 index 0000000..fe3df08 --- /dev/null +++ b/FeatureflowWpfExample/Converters/ColorToBrushConverter.cs @@ -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(); + } + } +} diff --git a/FeatureflowWpfExample/Converters/ExampleToViewConverter.cs b/FeatureflowWpfExample/Converters/ExampleToViewConverter.cs new file mode 100644 index 0000000..79ae74d --- /dev/null +++ b/FeatureflowWpfExample/Converters/ExampleToViewConverter.cs @@ -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(); + } + } +} diff --git a/FeatureflowWpfExample/Example.cs b/FeatureflowWpfExample/Example.cs new file mode 100644 index 0000000..90e8a22 --- /dev/null +++ b/FeatureflowWpfExample/Example.cs @@ -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, + } +} diff --git a/FeatureflowWpfExample/FeatureflowClientProvider.cs b/FeatureflowWpfExample/FeatureflowClientProvider.cs new file mode 100644 index 0000000..59ce843 --- /dev/null +++ b/FeatureflowWpfExample/FeatureflowClientProvider.cs @@ -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 +{ + /// + /// Wrapper for access to faetureflow client singleton + /// + /// + 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 predefinedFeatures) + { + IntializeClient(apiKey, predefinedFeatures, null); + } + + internal static void IntializeClient(string apiKey, IEnumerable 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 predefinedFeatures, FeatureflowConfig config) + { + return FeatureflowClientFactory.Create(apiKey, predefinedFeatures, config); + } + } +} diff --git a/FeatureflowWpfExample/FeatureflowWpfExample.csproj b/FeatureflowWpfExample/FeatureflowWpfExample.csproj new file mode 100644 index 0000000..f7ffa9b --- /dev/null +++ b/FeatureflowWpfExample/FeatureflowWpfExample.csproj @@ -0,0 +1,140 @@ + + + + + Debug + AnyCPU + {AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B} + WinExe + FeatureflowWpfExample + FeatureflowWpfExample + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Featureflow.1.1.1\lib\net45\Featureflow.dll + + + ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll + + + + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + + + + SimpleSwitchPage.xaml + + + TrafficLightPage.xaml + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + + + + MainWindow.xaml + Code + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + \ No newline at end of file diff --git a/FeatureflowWpfExample/MainWindow.xaml b/FeatureflowWpfExample/MainWindow.xaml new file mode 100644 index 0000000..be19dd4 --- /dev/null +++ b/FeatureflowWpfExample/MainWindow.xaml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + diff --git a/FeatureflowWpfExample/MainWindow.xaml.cs b/FeatureflowWpfExample/MainWindow.xaml.cs new file mode 100644 index 0000000..bf7afcf --- /dev/null +++ b/FeatureflowWpfExample/MainWindow.xaml.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace FeatureflowWpfExample +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + Examples = new[] + { + new Example + { + Tag = ExampleTag.SimpleSwitch, + Caption = "Simple switch", + }, + new Example + { + Tag = ExampleTag.TrafficLight, + Caption = "Traffic light", + }, + new Example + { + Tag = ExampleTag.Other, + Caption = "Coming soon...", + }, + }; + + InitializeComponent(); + } + + public Example[] Examples + { + get; + } + } +} diff --git a/FeatureflowWpfExample/Properties/AssemblyInfo.cs b/FeatureflowWpfExample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c4cb0d7 --- /dev/null +++ b/FeatureflowWpfExample/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FeatureflowWpfExample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FeatureflowWpfExample")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FeatureflowWpfExample/Properties/Resources.Designer.cs b/FeatureflowWpfExample/Properties/Resources.Designer.cs new file mode 100644 index 0000000..da06741 --- /dev/null +++ b/FeatureflowWpfExample/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FeatureflowWpfExample.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FeatureflowWpfExample.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/FeatureflowWpfExample/Properties/Resources.resx b/FeatureflowWpfExample/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/FeatureflowWpfExample/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FeatureflowWpfExample/Properties/Settings.Designer.cs b/FeatureflowWpfExample/Properties/Settings.Designer.cs new file mode 100644 index 0000000..b0c5389 --- /dev/null +++ b/FeatureflowWpfExample/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FeatureflowWpfExample.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/FeatureflowWpfExample/Properties/Settings.settings b/FeatureflowWpfExample/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/FeatureflowWpfExample/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/FeatureflowWpfExample/SingleEntryFrame.cs b/FeatureflowWpfExample/SingleEntryFrame.cs new file mode 100644 index 0000000..691aa4e --- /dev/null +++ b/FeatureflowWpfExample/SingleEntryFrame.cs @@ -0,0 +1,39 @@ +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 SingleEntryFrame + : Frame + { + public SingleEntryFrame() + { + Loaded += OnLoaded; + Unloaded += OnUnloaded; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + Loaded -= OnLoaded; + Navigated += SingleEntryFrame_Navigated; + + NavigationUIVisibility = System.Windows.Navigation.NavigationUIVisibility.Hidden; + } + + private void OnUnloaded(object sender, RoutedEventArgs e) + { + Unloaded -= OnUnloaded; + Navigated -= SingleEntryFrame_Navigated; + } + + private void SingleEntryFrame_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) + { + NavigationService.RemoveBackEntry(); + } + } +} diff --git a/FeatureflowWpfExample/Views/SimpleSwitchPage.xaml b/FeatureflowWpfExample/Views/SimpleSwitchPage.xaml new file mode 100644 index 0000000..757876c --- /dev/null +++ b/FeatureflowWpfExample/Views/SimpleSwitchPage.xaml @@ -0,0 +1,32 @@ + + + + + This example displays the behaviour of the simple feature, that have two values: 'On' and 'Off'. You can change the feature value in your + featureflow.io + account to affect the checkbox on this page. + + We assume that the feature key is + is-available + + If not, please change the constant in .cs file. + + + + Now feature has + + value + + + + diff --git a/FeatureflowWpfExample/Views/SimpleSwitchPage.xaml.cs b/FeatureflowWpfExample/Views/SimpleSwitchPage.xaml.cs new file mode 100644 index 0000000..1bbd10e --- /dev/null +++ b/FeatureflowWpfExample/Views/SimpleSwitchPage.xaml.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace FeatureflowWpfExample.Views +{ + /// + /// Interaction logic for SimpleSwitchPage.xaml + /// + public partial class SimpleSwitchPage : BaseExamplePage + { + public static DependencyProperty IsFeatureOnProperty = + DependencyProperty.Register("IsFeatureOn", typeof(bool), typeof(SimpleSwitchPage)); + + public const string ExampleFeatureKey = "is-available"; + + public SimpleSwitchPage() + { + InitializeComponent(); + } + + protected override void Activate() + { + base.Activate(); + + var client = FeatureflowClientProvider.GetClient(); + client.FeatureUpdated += Client_FeatureUpdated; + UpdateFeatureValue(); + } + + protected override void Deactivate() + { + var client = FeatureflowClientProvider.GetClient(); + client.FeatureUpdated -= Client_FeatureUpdated; + + base.Deactivate(); + } + + public bool IsFeatureOn + { + get { return (bool)GetValue(IsFeatureOnProperty); } + set { SetValue(IsFeatureOnProperty, value); } + } + + private void Client_FeatureUpdated(Featureflow.Client.IFeatureflowClient sender, Featureflow.Client.FeatureUpdatedEventArgs args) + { + if (args.FeatureKey == ExampleFeatureKey) + { + UpdateFeatureValue(); + } + } + + private void UpdateFeatureValue() + { + Dispatcher.InvokeAsync(() => + { + IsFeatureOn = FeatureflowClientProvider.GetClient().Evaluate(ExampleFeatureKey).IsOn(); + }); + } + } +} diff --git a/FeatureflowWpfExample/Views/TrafficLightPage.xaml b/FeatureflowWpfExample/Views/TrafficLightPage.xaml new file mode 100644 index 0000000..dc42843 --- /dev/null +++ b/FeatureflowWpfExample/Views/TrafficLightPage.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + This example displays that the feature can contains more than two values. In our case the feature named + color-set + have three values: 'red', 'yellow' and 'green'. + + You can create different rules to manage them all in your + featureflow.io + account. Selected color displays current feature value. + + + + + + + + + + + + + + + + + + + + + diff --git a/FeatureflowWpfExample/Views/TrafficLightPage.xaml.cs b/FeatureflowWpfExample/Views/TrafficLightPage.xaml.cs new file mode 100644 index 0000000..4bf0ecc --- /dev/null +++ b/FeatureflowWpfExample/Views/TrafficLightPage.xaml.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace FeatureflowWpfExample.Views +{ + /// + /// Interaction logic for TrafficLightView.xaml + /// + public partial class TrafficLightView : BaseExamplePage + { + public const string ExampleFeatureKey = "color-set"; + + public TrafficLightView() + { + InitializeComponent(); + } + + protected override void Activate() + { + base.Activate(); + FeatureflowClientProvider.GetClient().FeatureUpdated += Client_FeatureUpdated; + UpdateFeatureValue(); + } + + public ColorFeature[] Colors { get; } = new ColorFeature[] + { + new ColorFeature{ Color = "red" }, + new ColorFeature{ Color = "yellow" }, + new ColorFeature{ Color = "green" }, + }; + + protected override void Deactivate() + { + FeatureflowClientProvider.GetClient().FeatureUpdated -= Client_FeatureUpdated; + base.Deactivate(); + } + + private void Client_FeatureUpdated(Featureflow.Client.IFeatureflowClient sender, Featureflow.Client.FeatureUpdatedEventArgs args) + { + if (args.FeatureKey == ExampleFeatureKey) + { + UpdateFeatureValue(); + } + } + + private void UpdateFeatureValue() + { + Dispatcher.InvokeAsync(() => + { + string value = FeatureflowClientProvider.GetClient().Evaluate(ExampleFeatureKey).Value(); + foreach (var color in Colors) + { + color.IsSelected = color.Color == value; + } + }); + } + } + + public class ColorFeature + : DependencyObject + { + public static DependencyProperty IsSelectedProperty = + DependencyProperty.Register("IsSelected", typeof(bool), typeof(ColorFeature)); + + public string Color { get; set; } + + public bool IsSelected + { + get { return (bool)GetValue(IsSelectedProperty); } + set { SetValue(IsSelectedProperty, value); } + } + } +} diff --git a/FeatureflowWpfExample/packages.config b/FeatureflowWpfExample/packages.config new file mode 100644 index 0000000..1509c5c --- /dev/null +++ b/FeatureflowWpfExample/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file