mirror of
https://github.com/BlossomiShymae/Needlework.Net.git
synced 2025-12-06 10:10:48 +01:00
Improve endpoint loading times by using lazy loading
This commit is contained in:
@@ -19,15 +19,12 @@ namespace Needlework.Net.ViewModels
|
|||||||
public SolidColorBrush Color { get; }
|
public SolidColorBrush Color { get; }
|
||||||
public string Path { get; }
|
public string Path { get; }
|
||||||
public OperationViewModel Operation { get; }
|
public OperationViewModel Operation { get; }
|
||||||
|
|
||||||
public ProcessInfo? ProcessInfo { get; }
|
public ProcessInfo? ProcessInfo { get; }
|
||||||
|
|
||||||
[ObservableProperty] private bool _isBusy;
|
[ObservableProperty] private bool _isBusy;
|
||||||
[ObservableProperty] private string? _responsePath;
|
|
||||||
[ObservableProperty] private string? _responseStatus;
|
[ObservableProperty] private Lazy<ResponseViewModel> _response;
|
||||||
[ObservableProperty] private string? _responseAuthentication;
|
|
||||||
[ObservableProperty] private string? _responseUsername;
|
|
||||||
[ObservableProperty] private string? _responsePassword;
|
|
||||||
[ObservableProperty] private string? _responseAuthorization;
|
|
||||||
|
|
||||||
public PathOperationViewModel(PathOperation pathOperation)
|
public PathOperationViewModel(PathOperation pathOperation)
|
||||||
{
|
{
|
||||||
@@ -35,26 +32,7 @@ namespace Needlework.Net.ViewModels
|
|||||||
Color = new SolidColorBrush(GetColor(Method));
|
Color = new SolidColorBrush(GetColor(Method));
|
||||||
Path = pathOperation.Path;
|
Path = pathOperation.Path;
|
||||||
Operation = new OperationViewModel(pathOperation.Operation);
|
Operation = new OperationViewModel(pathOperation.Operation);
|
||||||
ProcessInfo = GetProcessInfo();
|
Response = new(() => new ResponseViewModel(pathOperation.Path));
|
||||||
if (ProcessInfo != null)
|
|
||||||
{
|
|
||||||
ResponsePath = $"https://127.0.0.1:{ProcessInfo.AppPort}{Path}";
|
|
||||||
var riotAuth = new RiotAuthentication(ProcessInfo.RemotingAuthToken);
|
|
||||||
ResponseUsername = riotAuth.Username;
|
|
||||||
ResponsePassword = riotAuth.Password;
|
|
||||||
ResponseAuthorization = $"Basic {riotAuth.Value}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ProcessInfo? GetProcessInfo()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var processInfo = ProcessFinder.Get();
|
|
||||||
return processInfo;
|
|
||||||
}
|
|
||||||
catch (Exception) { }
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
@@ -112,11 +90,11 @@ namespace Needlework.Net.ViewModels
|
|||||||
}
|
}
|
||||||
else WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(responseBody, "EndpointResponseEditor")));
|
else WeakReferenceMessenger.Default.Send(new EditorUpdateMessage(new(responseBody, "EndpointResponseEditor")));
|
||||||
|
|
||||||
ResponseStatus = $"{(int)response.StatusCode} {response.StatusCode}";
|
Response.Value.Status = $"{(int)response.StatusCode} {response.StatusCode}";
|
||||||
ResponsePath = $"https://127.0.0.1:{processInfo.AppPort}{uri}";
|
Response.Value.Path = $"https://127.0.0.1:{processInfo.AppPort}{uri}";
|
||||||
ResponseAuthentication = $"Basic {riotAuthentication.Value}";
|
Response.Value.Authentication = Response.Value.Authorization = $"Basic {riotAuthentication.Value}";
|
||||||
ResponseUsername = riotAuthentication.Username;
|
Response.Value.Username = riotAuthentication.Username;
|
||||||
ResponsePassword = riotAuthentication.Password;
|
Response.Value.Password = riotAuthentication.Password;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
35
Needlework.Net/ViewModels/ResponseViewModel.cs
Normal file
35
Needlework.Net/ViewModels/ResponseViewModel.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using BlossomiShymae.GrrrLCU;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
namespace Needlework.Net.ViewModels
|
||||||
|
{
|
||||||
|
public partial class ResponseViewModel : ObservableObject
|
||||||
|
{
|
||||||
|
[ObservableProperty] private string? _path;
|
||||||
|
[ObservableProperty] private string? _status;
|
||||||
|
[ObservableProperty] private string? _authentication;
|
||||||
|
[ObservableProperty] private string? _username;
|
||||||
|
[ObservableProperty] private string? _password;
|
||||||
|
[ObservableProperty] private string? _authorization;
|
||||||
|
|
||||||
|
public ResponseViewModel(string path)
|
||||||
|
{
|
||||||
|
Path = path;
|
||||||
|
var processInfo = GetProcessInfo();
|
||||||
|
if (processInfo != null)
|
||||||
|
{
|
||||||
|
var riotAuthentication = new RiotAuthentication(processInfo.RemotingAuthToken);
|
||||||
|
Path = $"https://127.0.0.1:{processInfo.AppPort}{path}";
|
||||||
|
Username = riotAuthentication.Username;
|
||||||
|
Password = riotAuthentication.Password;
|
||||||
|
Authorization = $"Basic {riotAuthentication.RawValue}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ProcessInfo? GetProcessInfo()
|
||||||
|
{
|
||||||
|
if (ProcessFinder.IsActive()) return ProcessFinder.Get();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
<TextBox Grid.Row="0"
|
<TextBox Grid.Row="0"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
FontSize="12"
|
FontSize="12"
|
||||||
Text="{Binding SelectedPathOperation.ResponsePath}"
|
Text="{Binding SelectedPathOperation.Response.Value.Path}"
|
||||||
IsReadOnly="True"/>
|
IsReadOnly="True"/>
|
||||||
<StackPanel Grid.Row="0"
|
<StackPanel Grid.Row="0"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="0 0 0 8"
|
Margin="0 0 0 8"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Text="{Binding SelectedPathOperation.ResponseUsername}" />
|
Text="{Binding SelectedPathOperation.Response.Value.Username}" />
|
||||||
<TextBlock FontSize="12"
|
<TextBlock FontSize="12"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
@@ -201,7 +201,7 @@
|
|||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="0 0 0 8"
|
Margin="0 0 0 8"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Text="{Binding SelectedPathOperation.ResponsePassword}"/>
|
Text="{Binding SelectedPathOperation.Response.Value.Password}"/>
|
||||||
<TextBlock FontSize="12"
|
<TextBlock FontSize="12"
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
@@ -212,7 +212,7 @@
|
|||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Text="{Binding SelectedPathOperation.ResponseAuthorization}"/>
|
Text="{Binding SelectedPathOperation.Response.Value.Authorization}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="Schemas">
|
<TabItem Header="Schemas">
|
||||||
@@ -304,7 +304,7 @@
|
|||||||
FontSize="10"
|
FontSize="10"
|
||||||
Padding="12 4 12 4"
|
Padding="12 4 12 4"
|
||||||
Classes="Flat"
|
Classes="Flat"
|
||||||
Content="{Binding SelectedPathOperation.ResponseStatus}"/>
|
Content="{Binding SelectedPathOperation.Response.Value.Status}"/>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Grid Grid.Row="1" Grid.Column="4">
|
<Grid Grid.Row="1" Grid.Column="4">
|
||||||
|
|||||||
Reference in New Issue
Block a user