-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT-174] Create example application for .net SDK - part 2. Removed …
…references for local Featureflow .NET client project
- Loading branch information
Александр Назин
committed
Feb 11, 2019
1 parent
bac399b
commit f4af6c6
Showing
5 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); } | ||
} | ||
} | ||
} |