diff --git a/DevconBoothImages/CodexWrapper.cs b/DevconBoothImages/CodexWrapper.cs new file mode 100644 index 0000000..d59eb10 --- /dev/null +++ b/DevconBoothImages/CodexWrapper.cs @@ -0,0 +1,51 @@ +using CodexOpenApi; +using System.Net.Http; +using System.Windows; +using Utils; + +namespace DevconBoothImages +{ + public class CodexWrapper + { + public async Task> GetCodexes() + { + var config = new Configuration(); + var result = new List(); + + foreach (var endpoint in config.CodexEndpoints) + { + var splitIndex = endpoint.LastIndexOf(':'); + var host = endpoint.Substring(0, splitIndex); + var port = Convert.ToInt32(endpoint.Substring(splitIndex + 1)); + + var address = new Address( + host: host, + port: port + ); + + var client = new HttpClient(); + var codex = new CodexApi(client); + codex.BaseUrl = $"{address.Host}:{address.Port}/api/codex/v1"; + + await CheckCodex(codex, endpoint); + } + + return result; + } + + private async Task CheckCodex(CodexApi codex, string endpoint) + { + try + { + var info = await codex.GetDebugInfoAsync(); + if (string.IsNullOrEmpty(info.Id)) throw new Exception("Failed to fetch Codex node id"); + } + catch (Exception ex) + { + MessageBox.Show($"Failed to connect to codex '{endpoint}': {ex}"); + throw; + } + } + + } +} diff --git a/DevconBoothImages/Configuration.cs b/DevconBoothImages/Configuration.cs new file mode 100644 index 0000000..53f7687 --- /dev/null +++ b/DevconBoothImages/Configuration.cs @@ -0,0 +1,16 @@ +namespace DevconBoothImages +{ + public class Configuration + { + public string[] CodexEndpoints { get; } = + [ + "aaaa", + "bbbb" + ]; + + public string AuthUser { get; } = ""; + public string AuthPw { get; } = ""; + public string LocalNodeBootstrapInfo { get; } = ""; + public string WorkingDir { get; } = "D:\\DevconBoothApp"; + } +} diff --git a/DevconBoothImages/DevconBoothImages.csproj b/DevconBoothImages/DevconBoothImages.csproj index e3e33e3..52d33cb 100644 --- a/DevconBoothImages/DevconBoothImages.csproj +++ b/DevconBoothImages/DevconBoothImages.csproj @@ -8,4 +8,9 @@ true + + + + + diff --git a/DevconBoothImages/MainWindow.xaml b/DevconBoothImages/MainWindow.xaml index 61ab58a..6324646 100644 --- a/DevconBoothImages/MainWindow.xaml +++ b/DevconBoothImages/MainWindow.xaml @@ -14,8 +14,10 @@ -