-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
242 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
using System.Diagnostics; | ||
using J = Newtonsoft.Json.JsonPropertyAttribute; | ||
using I = Newtonsoft.Json.JsonIgnoreAttribute; | ||
|
||
namespace FModel.ViewModels.ApiEndpoints.Models; | ||
|
||
[DebuggerDisplay("{" + nameof(FileName) + "}")] | ||
public class MappingsResponse | ||
{ | ||
[J] public string Url { get; private set; } | ||
[J] public string FileName { get; private set; } | ||
[J] public string Hash { get; private set; } | ||
[J] public long Length { get; private set; } | ||
[J] public string Uploaded { get; private set; } | ||
[J] public Meta Meta { get; private set; } | ||
[J] public string Url { get; set; } | ||
[J] public string FileName { get; set; } | ||
[I][J] public string Hash { get; private set; } | ||
[I][J] public long Length { get; private set; } | ||
[I][J] public string Uploaded { get; private set; } | ||
[J] public Meta Meta { get; set; } | ||
|
||
public MappingsResponse() | ||
{ | ||
Url = string.Empty; | ||
FileName = string.Empty; | ||
Meta = new Meta(); | ||
} | ||
|
||
[I] public bool IsValid => !string.IsNullOrEmpty(Url) && | ||
!string.IsNullOrEmpty(FileName) && | ||
Meta != null; | ||
} | ||
|
||
[DebuggerDisplay("{" + nameof(CompressionMethod) + "}")] | ||
public class Meta | ||
{ | ||
[J] public string Version { get; private set; } | ||
[J] public string CompressionMethod { get; private set; } | ||
} | ||
[I][J] public string Version { get; private set; } | ||
[J] public string CompressionMethod { get; set; } | ||
|
||
public Meta() | ||
{ | ||
CompressionMethod = "Oodle"; | ||
} | ||
|
||
[I] public bool IsValid => CompressionMethod == "Oodle"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<adonisControls:AdonisWindow x:Class="FModel.Views.Resources.Controls.EndpointEditor" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:converters="clr-namespace:FModel.Views.Resources.Converters" | ||
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit" | ||
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI" | ||
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI" | ||
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI" | ||
WindowStartupLocation="CenterScreen" IconVisibility="Collapsed" ResizeMode="NoResize" | ||
Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.50'}" | ||
Height="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.30'}"> | ||
<adonisControls:AdonisWindow.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="../Resources.xaml"/> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</adonisControls:AdonisWindow.Resources> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="Auto"/> | ||
</Grid.RowDefinitions> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="5"/> | ||
<RowDefinition Height="*"/> | ||
</Grid.RowDefinitions> | ||
|
||
<Grid Grid.Row="0" Margin="{adonisUi:Space 1, 0.5}"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="10" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="5" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<TextBlock Grid.Column="0" Text="Endpoint" VerticalAlignment="Center" Margin="0 0 0 5" /> | ||
<TextBox x:Name="EndpointUrl" Grid.Column="2" Margin="0 0 0 5" /> | ||
<Button Grid.Column="4" Content="Send" HorizontalAlignment="Right" Margin="0 0 0 5" | ||
Style="{DynamicResource {x:Static adonisUi:Styles.AccentButton}}" Click="OnSend"/> | ||
</Grid> | ||
|
||
<Grid Grid.Row="2"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="5" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<avalonEdit:TextEditor x:Name="EndpointResponse" Grid.Column="0" Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}" | ||
FontFamily="Consolas" FontSize="8pt" IsReadOnly="True" ShowLineNumbers="True" Foreground="#DAE5F2" /> | ||
<avalonEdit:TextEditor x:Name="TargetResponse" Grid.Column="2" Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}" | ||
FontFamily="Consolas" FontSize="8pt" IsReadOnly="False" ShowLineNumbers="True" Foreground="#DAE5F2" /> | ||
</Grid> | ||
</Grid> | ||
|
||
<Border Grid.Row="1" | ||
Background="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}" | ||
adonisExtensions:LayerExtension.IncreaseLayer="True"> | ||
<Grid Margin="30, 12, 6, 12"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="Auto"/> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Button Grid.Column="0" MinWidth="78" Margin="0 0 12 0" IsDefault="True" IsCancel="False" | ||
HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="OK" Click="OnClick" /> | ||
<Button Grid.Column="1" MinWidth="78" Margin="0 0 12 0" IsDefault="False" IsCancel="True" | ||
HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="Cancel" /> | ||
</Grid> | ||
</Border> | ||
</Grid> | ||
</adonisControls:AdonisWindow> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Windows; | ||
using FModel.Extensions; | ||
using FModel.Framework; | ||
using FModel.ViewModels.ApiEndpoints.Models; | ||
using ICSharpCode.AvalonEdit.Document; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using RestSharp; | ||
|
||
namespace FModel.Views.Resources.Controls; | ||
|
||
public partial class EndpointEditor | ||
{ | ||
private readonly AesResponse _defaultAesResponse = new (); | ||
private readonly MappingsResponse[] _defaultMappingResponse = {new ()}; | ||
private JObject _body; | ||
|
||
public FEndpoint Endpoint { get; private set; } | ||
|
||
public EndpointEditor(FEndpoint endpoint, string title, EEndpointType type) | ||
{ | ||
DataContext = endpoint; | ||
|
||
InitializeComponent(); | ||
|
||
Title = title; | ||
EndpointUrl.Text = endpoint.Url; | ||
TargetResponse.SyntaxHighlighting = EndpointResponse.SyntaxHighlighting = AvalonExtensions.HighlighterSelector("json"); | ||
TargetResponse.Document = new TextDocument | ||
{ | ||
Text = JsonConvert.SerializeObject(type switch | ||
{ | ||
EEndpointType.Aes => _defaultAesResponse, | ||
EEndpointType.Mapping => _defaultMappingResponse, | ||
_ => throw new NotImplementedException() | ||
}, Formatting.Indented) | ||
}; | ||
} | ||
|
||
private void OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
Endpoint = new FEndpoint(EndpointUrl.Text); | ||
DialogResult = true; | ||
Close(); | ||
} | ||
|
||
private async void OnSend(object sender, RoutedEventArgs e) | ||
{ | ||
try | ||
{ | ||
var response = await new RestClient().ExecuteAsync(new FRestRequest(EndpointUrl.Text) | ||
{ | ||
OnBeforeDeserialization = resp => { resp.ContentType = "application/json; charset=utf-8"; } | ||
}).ConfigureAwait(false); | ||
_body = JObject.Parse(response.Content!); | ||
|
||
Application.Current.Dispatcher.Invoke(delegate | ||
{ | ||
EndpointResponse.Document = new TextDocument | ||
{ | ||
Text = _body.ToString(Formatting.Indented) | ||
}; | ||
}); | ||
} | ||
catch | ||
{ | ||
// | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters