Skip to content

Commit

Permalink
[FEAT-174] Create example application for .net SDK - part 2. Removed …
Browse files Browse the repository at this point in the history
…references for local Featureflow .NET client project
  • Loading branch information
Александр Назин committed Feb 11, 2019
1 parent bac399b commit f4af6c6
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 12 deletions.
6 changes: 0 additions & 6 deletions FeatureflowExample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureflowExample", "Featu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureflowWpfExample", "FeatureflowWpfExample\FeatureflowWpfExample.csproj", "{AF38CDE1-EF0F-4306-AFAF-7BD89D2D0B5B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Featureflow", "..\featureflow-dotnet-client\Featureflow\Featureflow.csproj", "{F4D323C7-0600-4E1E-9D3B-407904A7B3AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -22,10 +20,6 @@ Global
{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
{F4D323C7-0600-4E1E-9D3B-407904A7B3AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4D323C7-0600-4E1E-9D3B-407904A7B3AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4D323C7-0600-4E1E-9D3B-407904A7B3AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4D323C7-0600-4E1E-9D3B-407904A7B3AA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions FeatureflowWpfExample/Converters/ExampleToViewConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
case ExampleTag.SimpleSwitch:
pathToXaml = "Views/SimpleSwitchPage.xaml";
break;

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

if (pathToXaml != null)
Expand Down
13 changes: 7 additions & 6 deletions FeatureflowWpfExample/FeatureflowWpfExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<Compile Include="Views\SimpleSwitchPage.xaml.cs">
<DependentUpon>SimpleSwitchPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\TrafficLightPage.xaml.cs">
<DependentUpon>TrafficLightPage.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -81,6 +84,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\TrafficLightPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down Expand Up @@ -108,11 +115,5 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\featureflow-dotnet-client\Featureflow\Featureflow.csproj">
<Project>{f4d323c7-0600-4e1e-9d3b-407904a7b3aa}</Project>
<Name>Featureflow</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
61 changes: 61 additions & 0 deletions FeatureflowWpfExample/Views/TrafficLightPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<main:BaseExamplePage x:Class="FeatureflowWpfExample.Views.TrafficLightView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:main="clr-namespace:FeatureflowWpfExample"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="TrafficLightView"
x:Name="myself"
DataContext="{Binding ElementName=myself}">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock Style="{StaticResource ExampleCaptionTextStyle}">
<Span>This example displays that the feature can contains more than two values. In our case the feature named</Span>
<Span Foreground="DarkBlue">color-set</Span>
<Span> have three values: 'red', 'yellow' and 'green'.</Span>
<LineBreak/>
<Span>You can create different rules to manage them all in your</Span>
<Span Foreground="Blue">featureflow.io</Span>
<Span>account. Selected color displays current feature value.</Span>
</TextBlock>

<ItemsControl Grid.Row="2" ItemsSource="{Binding Colors}"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Margin="10">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid IsItemsHost="True" Rows="3" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemTemplate>
<DataTemplate DataType="Point">
<Ellipse Fill="{Binding Color, Converter={StaticResource ColorToBrushConverter}}"
Stretch="Uniform"
Margin="4,4,4,4">
<Ellipse.Style>
<Style TargetType="Ellipse">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="true" >
<Setter Property="Opacity" Value="1" />
</DataTrigger>
<DataTrigger Binding="{Binding IsSelected}" Value="false" >
<Setter Property="Opacity" Value="0.1" />
</DataTrigger>
</Style.Triggers>
</Style>
</Ellipse.Style>
</Ellipse>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</main:BaseExamplePage>
85 changes: 85 additions & 0 deletions FeatureflowWpfExample/Views/TrafficLightPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Interaction logic for TrafficLightView.xaml
/// </summary>
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); }
}
}
}

0 comments on commit f4af6c6

Please sign in to comment.