-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a basic example client for Freshli Lib.
- Loading branch information
Showing
12 changed files
with
286 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Application xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:ExampleClient" | ||
x:Class="ExampleClient.App"> | ||
<Application.DataTemplates> | ||
<local:ViewLocator/> | ||
</Application.DataTemplates> | ||
|
||
<Application.Styles> | ||
<FluentTheme Mode="Light"/> | ||
</Application.Styles> | ||
</Application> |
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,29 @@ | ||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Markup.Xaml; | ||
using ExampleClient.ViewModels; | ||
using ExampleClient.Views; | ||
|
||
namespace ExampleClient | ||
{ | ||
public class App : Application | ||
{ | ||
public override void Initialize() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
{ | ||
desktop.MainWindow = new MainWindow | ||
{ | ||
DataContext = new MainWindowViewModel(), | ||
}; | ||
} | ||
|
||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
} | ||
} |
Binary file not shown.
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,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Folder Include="Models\" /> | ||
<AvaloniaResource Include="Assets\**" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Avalonia" Version="0.10.2" /> | ||
<PackageReference Include="Avalonia.Desktop" Version="0.10.2" /> | ||
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.2" /> | ||
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Corgibytes.Freshli.Lib\Corgibytes.Freshli.Lib.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,23 @@ | ||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.ReactiveUI; | ||
using System; | ||
|
||
namespace ExampleClient | ||
{ | ||
class Program | ||
{ | ||
// Initialization code. Don't use any Avalonia, third-party APIs or any | ||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized | ||
// yet and stuff might break. | ||
public static void Main(string[] args) => BuildAvaloniaApp() | ||
.StartWithClassicDesktopLifetime(args); | ||
|
||
// Avalonia configuration, don't remove; also used by visual designer. | ||
public static AppBuilder BuildAvaloniaApp() | ||
=> AppBuilder.Configure<App>() | ||
.UsePlatformDetect() | ||
.LogToTrace() | ||
.UseReactiveUI(); | ||
} | ||
} |
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,32 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Templates; | ||
using ExampleClient.ViewModels; | ||
using System; | ||
|
||
namespace ExampleClient | ||
{ | ||
public class ViewLocator : IDataTemplate | ||
{ | ||
public bool SupportsRecycling => false; | ||
|
||
public IControl Build(object data) | ||
{ | ||
var name = data.GetType().FullName!.Replace("ViewModel", "View"); | ||
var type = Type.GetType(name); | ||
|
||
if (type != null) | ||
{ | ||
return (Control)Activator.CreateInstance(type)!; | ||
} | ||
else | ||
{ | ||
return new TextBlock { Text = "Not Found: " + name }; | ||
} | ||
} | ||
|
||
public bool Match(object data) | ||
{ | ||
return data is ViewModelBase; | ||
} | ||
} | ||
} |
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,63 @@ | ||
using System.Reactive; | ||
using Corgibytes.Freshli.Lib; | ||
using ReactiveUI; | ||
|
||
namespace ExampleClient.ViewModels { | ||
/// <summary> | ||
/// Allow developers to run Freshli Lib commands. | ||
/// </summary> | ||
public class MainWindowViewModel : ViewModelBase { | ||
/// <summary> | ||
/// The path to the Git repo to run Freshli against. | ||
/// </summary> | ||
public string GitPath { get; set; } | ||
|
||
/// <summary> | ||
/// Show the results from Freshli. | ||
/// </summary> | ||
public string Results { | ||
get => _results; | ||
set => this.RaiseAndSetIfChanged(ref _results, value); | ||
} | ||
private string _results; | ||
|
||
/// <summary> | ||
/// Close the window. | ||
/// </summary> | ||
public ReactiveCommand<Unit, Unit> CloseCommand { get; } | ||
|
||
/// <summary> | ||
/// Run Freshli. | ||
/// </summary> | ||
public ReactiveCommand<Unit, Unit> OnRunFreshliClick { get; } | ||
|
||
/// <summary> | ||
/// Initialize the view model. | ||
/// </summary> | ||
public MainWindowViewModel() { | ||
_results = ""; | ||
|
||
GitPath = ""; | ||
Results = ""; | ||
|
||
OnRunFreshliClick = ReactiveCommand.Create(RunFreshli); | ||
CloseCommand = ReactiveCommand.Create(execute: () => { }); | ||
} | ||
|
||
/// <summary> | ||
/// Run Freshli and show the results to the user. | ||
/// </summary> | ||
private void RunFreshli() { | ||
Results = $"Starting Freshli run for '{GitPath}'\n"; | ||
|
||
var runner = new Runner(); | ||
var metricResults = runner.Run(GitPath); | ||
|
||
foreach (var mr in metricResults) { | ||
Results += mr.ToString(); | ||
} | ||
|
||
Results += "Finished!\n"; | ||
} | ||
} | ||
} |
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,11 @@ | ||
using ReactiveUI; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace ExampleClient.ViewModels | ||
{ | ||
public class ViewModelBase : ReactiveObject | ||
{ | ||
} | ||
} |
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,29 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:vm="using:ExampleClient.ViewModels" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="ExampleClient.Views.MainWindow" | ||
Icon="/Assets/avalonia-logo.ico" | ||
Title="ExampleClient" | ||
Width="800" | ||
Height="450"> | ||
|
||
<Design.DataContext> | ||
<vm:MainWindowViewModel /> | ||
</Design.DataContext> | ||
|
||
<DockPanel> | ||
<Label DockPanel.Dock="Top" HorizontalAlignment="Center" FontSize="20">Freshli-Lib Example Client</Label> | ||
<DockPanel Margin="10"> | ||
<DockPanel DockPanel.Dock="Top" Margin="10"> | ||
<Label DockPanel.Dock="Left">Git Repo:</Label> | ||
<Button DockPanel.Dock="Right" Command="{Binding OnRunFreshliClick}" Margin="5, 0">Run Freshli</Button> | ||
<TextBox Text="{Binding GitPath}" HorizontalAlignment="Stretch" /> | ||
</DockPanel> | ||
<Button DockPanel.Dock="Bottom" Command="{Binding CloseCommand}" HorizontalAlignment="Right">Close</Button> | ||
<TextBox DockPanel.Dock="Top" Text="{Binding Results, Mode=TwoWay}" IsReadOnly="True" Margin="0 5" /> | ||
</DockPanel> | ||
</DockPanel> | ||
</Window> |
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,33 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Reactive; | ||
using Avalonia; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.ReactiveUI; | ||
using ExampleClient.ViewModels; | ||
using ReactiveUI; | ||
using Avalonia.Reactive; | ||
|
||
|
||
namespace ExampleClient.Views { | ||
public class MainWindow : ReactiveWindow<MainWindowViewModel> { | ||
|
||
public MainWindow() { | ||
InitializeComponent(); | ||
#if DEBUG | ||
this.AttachDevTools(); | ||
#endif | ||
|
||
// Close the Window when the close command is triggered. | ||
this.WhenActivated(block: d => { | ||
Debug.Assert(ViewModel != null, nameof(ViewModel) + " != null"); | ||
d(ViewModel.CloseCommand.Subscribe(onNext: (unit) => Close())); | ||
} | ||
); | ||
} | ||
|
||
private void InitializeComponent() { | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} | ||
} |
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<!-- | ||
To use the Avalonia CI feed to get unstable packages, move this file to the root of your solution. | ||
--> | ||
|
||
<configuration> | ||
<packageSources> | ||
<add key="AvaloniaCI" value="https://www.myget.org/F/avalonia-ci/api/v2" /> | ||
</packageSources> | ||
</configuration> |