Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Set default behavior to automatically normalize line endings
* text=auto
6 changes: 6 additions & 0 deletions Microsoft.Extensions.Configuration.AzureAppConfiguration.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Properties", "Properties",
AzureAppConfigurationRules.ruleset = AzureAppConfigurationRules.ruleset
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureFlagDemo", "..\FeatureManagement-Dotnet\examples\FeatureFlagDemo\FeatureFlagDemo.csproj", "{C8365B29-013E-4E75-8660-ECC45E52E685}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -68,6 +70,10 @@ Global
{A6C611F1-D687-4262-8904-828C239CF2E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6C611F1-D687-4262-8904-828C239CF2E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6C611F1-D687-4262-8904-828C239CF2E5}.Release|Any CPU.Build.0 = Release|Any CPU
{C8365B29-013E-4E75-8660-ECC45E52E685}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C8365B29-013E-4E75-8660-ECC45E52E685}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8365B29-013E-4E75-8660-ECC45E52E685}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8365B29-013E-4E75-8660-ECC45E52E685}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
452 changes: 226 additions & 226 deletions NOTICE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="Local" value="C:\Users\ajusupovic\Downloads" />
</packageSources>
</configuration>
10 changes: 9 additions & 1 deletion examples/ConfigStoreDemo/ConfigStoreDemo.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>net8.0</TargetFramework>
<ApplicationInsightsResourceId>/subscriptions/77d5ab06-7edd-4eec-bce9-52c11b75bb37/resourceGroups/ajusupovic-rg/providers/microsoft.insights/components/ajusupovic-appinsights</ApplicationInsightsResourceId>
<UserSecretsId>d9f052a5-acc5-41da-bfd0-5ba7f11606eb</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<!--<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.1.2" />-->
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.Azure.AppConfiguration.AspNetCore\Microsoft.Azure.AppConfiguration.AspNetCore.csproj" />
</ItemGroup>
Expand Down
108 changes: 100 additions & 8 deletions examples/ConfigStoreDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Azure.Core;
using Azure.Data.AppConfiguration;
using Azure.Identity;
using ConfigStoreDemo;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.Examples.ConfigStoreDemo
{
Expand All @@ -16,26 +27,107 @@ public static void Main(string[] args)

public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
//ConfigurationClient client = new ConfigurationClient(new Uri("https://ajusupovic-ac2.azconfig.io"), new DefaultAzureCredential());

//ConfigurationSetting setting = client.GetConfigurationSetting("JsonKeyTest");

//setting.ContentType = "application/json;profile=\"https://azconfig.io/mime-profiles/ai/chat-completion\";charset=UTF-8";

//setting.Key = "JsonKeyTest2";

//client.SetConfigurationSetting(setting);

var builder = WebApplication.CreateBuilder(args);

string connectionString = builder.Configuration.GetConnectionString("AppConfig");

IList<string> tagsFilterList = new List<string> { " group=g1", "key1=value1", "any=" };

var host = WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
// 1. Load settings from a JSON file and Azure App Configuration
// 2. Retrieve the Azure App Configuration connection string from an environment variable
// 3. Set up the provider to listen for changes to the background color key-value in Azure App Configuration

var settings = config.AddJsonFile("appsettings.json").Build();
config.AddAzureAppConfiguration(options =>
{
options.Connect(settings["connection_string"])
.ConfigureRefresh(refresh =>
{
refresh.Register("Settings:BackgroundColor")
.SetRefreshInterval(TimeSpan.FromSeconds(10));
});
options.UseFeatureFlags(ff =>
{
ff.Select("TestFlag");
});
//options.SelectSnapshot("Test1");
//options.Select("TestLabel", "1", tagsFilterList);
options.Select("AppName");
options.Select("JsonKeyTest*");
options.Select("Settings*");
options.UseFeatureFlags(ff =>
{
ff.Select("OnOff");
ff.Select("TestVariants");
ff.SetRefreshInterval(TimeSpan.FromSeconds(2));
});
options.ConfigureStartupOptions(startup =>
{
startup.Timeout = TimeSpan.FromSeconds(60);
});
//options.Connect(Environment.GetEnvironmentVariable("ConnectionString"));
options.Connect(new Uri("https://ajusupovic-ac2.azconfig.io"), new DefaultAzureCredential());
options.ConfigureRefresh(refresh =>
{
//refresh.Register("Settings:BackgroundColor", refreshAll: true);
//refresh.Register("Settings:Messages");
refresh.RegisterAll();
refresh.SetRefreshInterval(TimeSpan.FromSeconds(2));
});
options.Map(setting =>
{
if (setting.Key.Contains("TestFlag"))
{
Console.WriteLine("\nTEST FLAG TIME\n");
}

if (setting.Key.Contains("Language"))
{
Console.WriteLine($"\nLANGUAGE: {setting.Value}\n");
}

return new ValueTask<ConfigurationSetting>(setting);
});
options.ConfigureClientOptions(clientOptions =>
{
clientOptions.AddPolicy(new ApiVersionHeaderPolicy(), HttpPipelinePosition.PerCall);
});
});

config.AddAzureAppConfiguration(options =>
{
options.Select("AppName");
options.UseFeatureFlags(ff =>
{
ff.Select("TestVariants2");
ff.SetRefreshInterval(TimeSpan.FromSeconds(2));
});
options.Connect(new Uri("https://ajusupovic-ac2.azconfig.io"), new DefaultAzureCredential());
});

//config.AddAzureAppConfiguration(options =>
//{
// options.Select("JsonAITest");
// options.Connect(Environment.GetEnvironmentVariable("PersonalConnectionString"));
// options.ConfigureRefresh(refresh =>
// {
// refresh.RegisterAll();
// refresh.SetRefreshInterval(TimeSpan.FromSeconds(1));
// });
//});
})
.UseStartup<Startup>()
.Build();

var haha = builder.Configuration;

return host;
}
}
}
10 changes: 10 additions & 0 deletions examples/ConfigStoreDemo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration.FeatureManagement;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;

namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.Examples.ConfigStoreDemo
{
Expand All @@ -28,7 +32,13 @@ public void ConfigureServices(IServiceCollection services)

services.Configure<Settings>(Configuration.GetSection("Settings"));
services.AddAzureAppConfiguration();
services.AddAzureAppConfiguration();
services.AddMvc();
services.AddApplicationInsightsTelemetry();

var flags = Configuration.GetSection("feature_management").GetSection("feature_flags").Get<List<FeatureFlag>>();

Console.WriteLine("variant flags count: " + flags?.Count);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
11 changes: 7 additions & 4 deletions examples/ConfigStoreDemo/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},

"Settings": {
"AppName": "Azure App Configuration Demo",
"Version": 1.0,
Expand All @@ -14,5 +13,9 @@
"Language": "English",
"Messages": "Hello There;Thanks For Using Azure App Configuration",
"BackgroundColor": "Orange"
}
}
},
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=9a14e594-4d40-4f6b-813a-24849be65cc5;IngestionEndpoint=https://westus3-1.in.applicationinsights.azure.com/;LiveEndpoint=https://westus3.livediagnostics.monitor.azure.com/;ApplicationId=9615f574-2d07-4156-8a8f-4fc91b41dc56"
},
"AppConfig": "https://ajusupovic-ac2.azconfig.io"
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using DnsClient.Protocol;
using System;
using DnsClient.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.Extensions
{
internal static class ListExtensions
{
public static List<T> Shuffle<T>(this List<T> values)
{
var rdm = new Random();
int count = values.Count;
for (int i = count - 1; i > 0; i--)
{
int swapIndex = rdm.Next(i + 1);
if (swapIndex != i)
{
T value = values[swapIndex];
values[swapIndex] = values[i];
values[i] = value;
}
}
return values;
}
public static List<SrvRecord> SortSrvRecords(this List<SrvRecord> srvRecords)
{
srvRecords.Sort((a, b) =>
{
if (a.Priority != b.Priority)
return a.Priority.CompareTo(b.Priority);
if (a.Weight != b.Weight)
return b.Weight.CompareTo(a.Weight);
return 0;
});
return srvRecords;
}
public static List<T> Shuffle<T>(this List<T> values)
{
var rdm = new Random();
int count = values.Count;

for (int i = count - 1; i > 0; i--)
{
int swapIndex = rdm.Next(i + 1);

if (swapIndex != i)
{
T value = values[swapIndex];
values[swapIndex] = values[i];
values[i] = value;
}
}

return values;
}

public static List<SrvRecord> SortSrvRecords(this List<SrvRecord> srvRecords)
{
srvRecords.Sort((a, b) =>
{
if (a.Priority != b.Priority)
return a.Priority.CompareTo(b.Priority);

if (a.Weight != b.Weight)
return b.Weight.CompareTo(a.Weight);

return 0;
});

return srvRecords;
}

public static void AppendUnique<T>(this List<T> items, T item)
{
if (item == null)
{
throw new ArgumentNullException(nameof(item));
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}

T existingItem = items.FirstOrDefault(s => Equals(s, item));
Expand All @@ -63,6 +63,6 @@ public static void AppendUnique<T>(this List<T> items, T item)

// Append to the end, keeping precedence.
items.Add(item);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public static string BuildFeatureFlagsUnchangedMessage(string endpoint)
}

public static string BuildFeatureFlagsUpdatedMessage()
{
{
return LoggingConstants.RefreshFeatureFlagsUpdated;
}

public static string BuildSelectedKeyValueCollectionsUnchangedMessage(string endpoint)
{
return $"{LoggingConstants.RefreshSelectedKeyValueCollectionsUnchanged} Endpoint:'{endpoint?.TrimEnd('/')}'";
public static string BuildSelectedKeyValueCollectionsUnchangedMessage(string endpoint)
{
return $"{LoggingConstants.RefreshSelectedKeyValueCollectionsUnchanged} Endpoint:'{endpoint?.TrimEnd('/')}'";
}

public static string BuildSelectedKeyValuesAndFeatureFlagsUpdatedMessage()
Expand Down Expand Up @@ -91,12 +91,12 @@ public static string BuildLastEndpointFailedMessage(string endpoint)
}

public static string BuildFallbackClientLookupFailMessage(string exceptionMessage)
{
{
return $"{LoggingConstants.FallbackClientLookupError}\n{exceptionMessage}";
}
public static string BuildRefreshFailedDueToFormattingErrorMessage(string exceptionMessage)
{
return $"{LoggingConstants.RefreshFailedDueToFormattingError}\n{exceptionMessage}";
}
public static string BuildRefreshFailedDueToFormattingErrorMessage(string exceptionMessage)
{
return $"{LoggingConstants.RefreshFailedDueToFormattingError}\n{exceptionMessage}";
}
}
}
Loading