Skip to content

Commit

Permalink
chore: add dotnet core sample (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre authored Nov 4, 2024
1 parent 48b7833 commit 3f2b80c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions samples/DotnetCore/DotnetCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Unleash\Unleash.csproj">
<Project>{4cf2127b-8fc8-46fc-8614-3918148463a5}</Project>
<Name>Unleash</Name>
</ProjectReference>
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions samples/DotnetCore/DotnetCore.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetCore", "DotnetCore.csproj", "{CE83946A-DD8A-4D2E-BC85-0B1F6E9A72CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CE83946A-DD8A-4D2E-BC85-0B1F6E9A72CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE83946A-DD8A-4D2E-BC85-0B1F6E9A72CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE83946A-DD8A-4D2E-BC85-0B1F6E9A72CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE83946A-DD8A-4D2E-BC85-0B1F6E9A72CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8085F125-1F8A-4991-BEC4-B7ADD45BA1C0}
EndGlobalSection
EndGlobal
31 changes: 31 additions & 0 deletions samples/DotnetCore/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Unleash;
using Unleash.ClientFactory;
using Unleash.Internal;

var settings = new UnleashSettings()
{
AppName = "dotnet-test",
UnleashApi = new Uri("http://localhost:4242/api"), //setup for running against a local unleash instance, feel free to change this
CustomHttpHeaders = new Dictionary<string, string>()
{
{"Authorization","add a valid client token here" }
},
SendMetricsInterval = TimeSpan.FromSeconds(1)
};

const string TOGGLE_NAME = "test";

Console.WriteLine("Starting Unleash SDK");

var unleashFactory = new UnleashClientFactory();
IUnleash unleash = await unleashFactory.CreateClientAsync(settings, synchronousInitialization: true);


while (true)
{
var enabled = unleash.IsEnabled(TOGGLE_NAME);
var variant = unleash.GetVariant(TOGGLE_NAME);

Console.WriteLine($"Toggle enabled: {enabled}, variant: {System.Text.Json.JsonSerializer.Serialize(variant)}");
await Task.Delay(1000);
}

0 comments on commit 3f2b80c

Please sign in to comment.