57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using System;
|
|
using System.Reactive;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using Flawless.Client.Service;
|
|
using ReactiveUI;
|
|
using ReactiveUI.SourceGenerators;
|
|
using Refit;
|
|
|
|
namespace Flawless.Client.ViewModels;
|
|
|
|
public partial class ServerSetupPageViewModel : ViewModelBase, IRoutableViewModel
|
|
{
|
|
|
|
public string? UrlPathSegment { get; } = Guid.NewGuid().ToString();
|
|
|
|
public IScreen HostScreen { get; }
|
|
|
|
[Reactive] private string _host = "http://localhost:5256/";
|
|
|
|
[Reactive(SetModifier = AccessModifier.Protected)] private string? _issue;
|
|
|
|
public IObservable<bool> CanSetHost { get; }
|
|
|
|
public ServerSetupPageViewModel(IScreen hostScreen)
|
|
{
|
|
HostScreen = hostScreen;
|
|
|
|
// Must clear this gateway
|
|
if (Api.Current.IsGatewayReady) Api.Current.ClearGateway();
|
|
|
|
CanSetHost = this.WhenAnyValue(x => x.Host, s => !string.IsNullOrWhiteSpace(s));
|
|
}
|
|
|
|
|
|
[ReactiveCommand]
|
|
private async Task SetHostAsync()
|
|
{
|
|
try
|
|
{
|
|
Issue = string.Empty;
|
|
await Api.Current.SetGatewayAsync(Host);
|
|
HostScreen.Router.Navigate.Execute(new LoginPageViewModel(HostScreen));
|
|
}
|
|
catch (ApiException ex)
|
|
{
|
|
await Console.Error.WriteLineAsync("Can not connect to server: " + ex.ToString());
|
|
Issue = ex.Content;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await Console.Error.WriteLineAsync("Can not connect to server: " + ex.ToString());
|
|
Issue = ex.Message;
|
|
}
|
|
}
|
|
|
|
} |