Add Azure AI service (Azure AI Foundry), Add the AppConfig manager

This commit is contained in:
Namhyeon Go 2025-04-02 11:25:23 +09:00
parent 56ee12741c
commit 96dbe7b2cd
5 changed files with 49 additions and 3 deletions

View File

@ -195,7 +195,7 @@ namespace WelsonJS.Launcher
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Program.OpenWebBrowser(Properties.Resources.RepositoryUrl);
Program.OpenWebBrowser(Program.GetAppConfig("RepositoryUrl"));
}
private void userdefinedVariablesToolStripMenuItem_Click(object sender, EventArgs e)
@ -245,7 +245,7 @@ namespace WelsonJS.Launcher
{
if (Program.resourceServer == null)
{
Program.resourceServer = new ResourceServer(Properties.Resources.ResourceServerPrefix, "editor.html");
Program.resourceServer = new ResourceServer(Program.GetAppConfig("ResourceServerPrefix"), "editor.html");
}
if (!Program.resourceServer.IsRunning())
@ -273,7 +273,7 @@ namespace WelsonJS.Launcher
private void openCopilotToolStripMenuItem_Click(object sender, EventArgs e)
{
Program.OpenWebBrowser(Properties.Resources.CopilotUrl);
Program.OpenWebBrowser(Program.GetAppConfig("CopilotUrl"));
}
}
}

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using System.Configuration;
using WelsonJS.Launcher.Tools;
namespace WelsonJS.Launcher
@ -156,5 +157,22 @@ namespace WelsonJS.Launcher
UseShellExecute = true
});
}
public static string GetAppConfig(string key)
{
string value = ConfigurationManager.AppSettings[key];
if (!string.IsNullOrEmpty(value))
{
return value;
}
value = Properties.Resources.ResourceManager.GetString(key);
if (!string.IsNullOrEmpty(value))
{
return value;
}
return null;
}
}
}

View File

@ -133,6 +133,14 @@ namespace WelsonJS.Launcher.Tools
return;
}
// Serve a value of App Config request
const string configPrefix = "config/";
if (path.StartsWith(configPrefix, StringComparison.OrdinalIgnoreCase))
{
ServeConfigRequest(context, path.Substring(configPrefix.Length));
return;
}
// Serve a resource
ServeResource(context, GetResource(_resourceName), "text/html");
}
@ -272,6 +280,18 @@ namespace WelsonJS.Launcher.Tools
ServeResource(context);
}
public void ServeConfigRequest(HttpListenerContext context, string key)
{
string value = Program.GetAppConfig(key);
if (!String.IsNullOrEmpty(value))
{
ServeResource(context, value, "text/plain", 200);
return;
}
ServeResource(context);
}
private void ServeResource(HttpListenerContext context)
{
ServeResource(context, "<error>Not Found</error>", "application/xml", 404);

View File

@ -57,6 +57,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />

View File

@ -1,5 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ResourceServerPrefix" value="http://localhost:3000/"/>
<add key="RepositoryUrl" value="https://github.com/gnh1201/welsonjs"/>
<add key="CopilotUrl" value="https://copilot.microsoft.com/"/>
<add key="AzureAiServiceUrl" value="https://ai-catswords656881030318.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview"/>
<add key="AzureAiServiceApiKey" value=""/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>