Added some logging and dialog stuff, as well as made the add profile button actually add a critter to the db
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia.Android" />
|
<PackageReference Include="Avalonia.Android" />
|
||||||
|
<PackageReference Include="AvaloniaDialogs" />
|
||||||
<PackageReference Include="sqlite-net-pcl" />
|
<PackageReference Include="sqlite-net-pcl" />
|
||||||
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
||||||
<PackageReference Include="Xamarin.AndroidX.Core.SplashScreen" />
|
<PackageReference Include="Xamarin.AndroidX.Core.SplashScreen" />
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia.Browser" />
|
<PackageReference Include="Avalonia.Browser" />
|
||||||
|
<PackageReference Include="AvaloniaDialogs" />
|
||||||
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" />
|
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" />
|
||||||
<PackageReference Include="sqlite-net-pcl" />
|
<PackageReference Include="sqlite-net-pcl" />
|
||||||
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="AvaloniaDialogs" />
|
||||||
<PackageReference Include="sqlite-net-pcl" />
|
<PackageReference Include="sqlite-net-pcl" />
|
||||||
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:local="using:CritterFolio"
|
xmlns:local="using:CritterFolio"
|
||||||
x:Class="CritterFolio.App"
|
x:Class="CritterFolio.App"
|
||||||
|
xmlns:dialogHostAvalonia="using:DialogHostAvalonia"
|
||||||
RequestedThemeVariant="Default">
|
RequestedThemeVariant="Default">
|
||||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
|
|
||||||
<Application.Styles>
|
<Application.Styles>
|
||||||
<FluentTheme />
|
<FluentTheme />
|
||||||
|
<dialogHostAvalonia:DialogHostStyles />
|
||||||
<StyleInclude Source="Styles/MainStyles.axaml" />
|
<StyleInclude Source="Styles/MainStyles.axaml" />
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="AvaloniaDialogs" />
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm" />
|
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||||
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" />
|
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" />
|
||||||
<PackageReference Include="sqlite-net-pcl" />
|
<PackageReference Include="sqlite-net-pcl" />
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
|
using AvaloniaDialogs.Views;
|
||||||
using CritterFolio.Controls;
|
using CritterFolio.Controls;
|
||||||
using CritterFolio.DataModels;
|
using CritterFolio.DataModels;
|
||||||
using CritterFolio.Services;
|
using CritterFolio.Services;
|
||||||
@@ -63,13 +66,31 @@ public partial class HomePage : Page
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddProfileButton(Critter critter)
|
private async void AddProfileButton(Critter critter)
|
||||||
{
|
{
|
||||||
var newProfButton = new ProfileButton();
|
var newProfButton = new ProfileButton();
|
||||||
newProfButton.Init(critter);
|
newProfButton.Init(critter);
|
||||||
CritterStack.Children.Add(newProfButton);
|
CritterStack.Children.Add(newProfButton);
|
||||||
|
|
||||||
newProfButton.Clicked += (o, args) => { Console.WriteLine($"{critter.Name} button clicked"); };
|
|
||||||
|
|
||||||
|
newProfButton.Clicked += async (sender, args) =>
|
||||||
|
{
|
||||||
|
await ProfileButtonClicked(critter);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ProfileButtonClicked(Critter critter)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await DialogHelper.ShowMessage($"{critter.Name} was clicked");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
Logger.LogToFile(e.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void AddButtonClicked(object? sender, RoutedEventArgs e)
|
private async void AddButtonClicked(object? sender, RoutedEventArgs e)
|
||||||
@@ -79,6 +100,7 @@ public partial class HomePage : Page
|
|||||||
{
|
{
|
||||||
var result = await DatabaseService.AddCritter(newCritter);
|
var result = await DatabaseService.AddCritter(newCritter);
|
||||||
AddProfileButton(newCritter);
|
AddProfileButton(newCritter);
|
||||||
|
Logger.LogToFile("New critter was added");
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
<Button HorizontalAlignment="Stretch" Classes="normal">Insert test data</Button>
|
<Button HorizontalAlignment="Stretch" Classes="normal">Insert test data</Button>
|
||||||
<Button x:Name="ClearDbButton" HorizontalAlignment="Stretch" Classes="normal">Clear database</Button>
|
<Button x:Name="ClearDbButton" HorizontalAlignment="Stretch" Classes="normal">Clear database</Button>
|
||||||
<Button x:Name="ReInitButton" HorizontalAlignment="Stretch" Classes="normal">Re-init Database</Button>
|
<Button x:Name="ReInitButton" HorizontalAlignment="Stretch" Classes="normal">Re-init Database</Button>
|
||||||
|
<Label FontSize="20" HorizontalAlignment="Stretch">Logger</Label>
|
||||||
|
<Button x:Name="OpenLogButton" HorizontalAlignment="Stretch" Classes="normal">Open Log File</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Avalonia;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
using CritterFolio.Services;
|
using CritterFolio.Services;
|
||||||
|
|
||||||
namespace CritterFolio.Pages;
|
namespace CritterFolio.Pages;
|
||||||
@@ -18,12 +19,31 @@ public partial class TestPage : Page
|
|||||||
|
|
||||||
ClearDbButton.Click += ClearDbButtonClicked;
|
ClearDbButton.Click += ClearDbButtonClicked;
|
||||||
ReInitButton.Click += ReInitButtonClicked;
|
ReInitButton.Click += ReInitButtonClicked;
|
||||||
|
OpenLogButton.Click += OpenLogButtonClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearDbButtonClicked(object? sender, RoutedEventArgs e)
|
private void OpenLogButtonClicked(object? sender, RoutedEventArgs args)
|
||||||
{
|
{
|
||||||
var databasePath = Path.Combine(AppContext.BaseDirectory, "CritterFolio.db");
|
var logFilePath = Path.Combine(AppContext.BaseDirectory, "log.txt");
|
||||||
File.Delete(databasePath);
|
if (!File.Exists(logFilePath)) return;
|
||||||
|
var launcher = TopLevel.GetTopLevel(this)?.Launcher;
|
||||||
|
if (launcher is null) return;
|
||||||
|
|
||||||
|
launcher.LaunchUriAsync(new Uri("file://" + logFilePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async void ClearDbButtonClicked(object? sender, RoutedEventArgs args)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await DatabaseService.ClearAllTables();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogToFile(ex.ToString());
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void ReInitButtonClicked(object? sender, RoutedEventArgs e)
|
private async void ReInitButtonClicked(object? sender, RoutedEventArgs e)
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ public static class DatabaseService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task ClearAllTables()
|
||||||
|
{
|
||||||
|
await Init();
|
||||||
|
await _db?.DeleteAllAsync<Critter>()!;
|
||||||
|
await _db?.DeleteAllAsync<Document>()!;
|
||||||
|
}
|
||||||
|
|
||||||
#region Critter operations
|
#region Critter operations
|
||||||
|
|
||||||
public static async Task<bool> AddCritter(Critter critter)
|
public static async Task<bool> AddCritter(Critter critter)
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AvaloniaDialogs.Views;
|
||||||
|
|
||||||
|
namespace CritterFolio.Services;
|
||||||
|
|
||||||
|
public static class DialogHelper
|
||||||
|
{
|
||||||
|
public static async Task ShowMessage(string message)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await new SingleActionDialog()
|
||||||
|
{
|
||||||
|
Message = message,
|
||||||
|
ButtonText = "OK"
|
||||||
|
}.ShowAsync();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
critterfolio/CritterFolio/CritterFolio/Services/Logger.cs
Normal file
15
critterfolio/CritterFolio/CritterFolio/Services/Logger.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace CritterFolio.Services;
|
||||||
|
|
||||||
|
public class Logger
|
||||||
|
{
|
||||||
|
public static void LogToFile(string text)
|
||||||
|
{
|
||||||
|
var logFilePath = Path.Combine(AppContext.BaseDirectory, "log.txt");
|
||||||
|
|
||||||
|
File.AppendAllText(logFilePath, $"{DateTime.UtcNow} : {text}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,9 +4,12 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:vm="using:CritterFolio.ViewModels"
|
xmlns:vm="using:CritterFolio.ViewModels"
|
||||||
xmlns:critterFolio="clr-namespace:CritterFolio"
|
xmlns:critterFolio="clr-namespace:CritterFolio"
|
||||||
|
xmlns:views="clr-namespace:AvaloniaDialogs.Views;assembly=AvaloniaDialogs"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="CritterFolio.Views.MainView"
|
x:Class="CritterFolio.Views.MainView"
|
||||||
x:DataType="vm:MainViewModel">
|
x:DataType="vm:MainViewModel">
|
||||||
|
|
||||||
|
<views:ReactiveDialogHost CloseOnClickAway="True">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||||
@@ -19,5 +22,7 @@
|
|||||||
<ScrollViewer Grid.Row="1" x:Name="ScrollView" Margin="20"/>
|
<ScrollViewer Grid.Row="1" x:Name="ScrollView" Margin="20"/>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</views:ReactiveDialogHost>
|
||||||
|
|
||||||
|
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -4,9 +4,12 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:views="using:CritterFolio.Views"
|
xmlns:views="using:CritterFolio.Views"
|
||||||
|
xmlns:dialogs="using:AvaloniaDialogs.Views"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="CritterFolio.Views.MainWindow"
|
x:Class="CritterFolio.Views.MainWindow"
|
||||||
Icon="/Assets/icon.ico"
|
Icon="/Assets/icon.ico"
|
||||||
Title="CritterFolio">
|
Title="CritterFolio">
|
||||||
|
<dialogs:ReactiveDialogHost CloseOnClickAway="True">
|
||||||
<views:MainView />
|
<views:MainView />
|
||||||
|
</dialogs:ReactiveDialogHost>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<PackageVersion Include="Avalonia.iOS" Version="11.3.10" />
|
<PackageVersion Include="Avalonia.iOS" Version="11.3.10" />
|
||||||
<PackageVersion Include="Avalonia.Browser" Version="11.3.10" />
|
<PackageVersion Include="Avalonia.Browser" Version="11.3.10" />
|
||||||
<PackageVersion Include="Avalonia.Android" Version="11.3.10" />
|
<PackageVersion Include="Avalonia.Android" Version="11.3.10" />
|
||||||
|
<PackageVersion Include="AvaloniaDialogs" Version="3.7.0" />
|
||||||
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||||
<PackageVersion Include="SkiaSharp.NativeAssets.WebAssembly" Version="3.119.0" />
|
<PackageVersion Include="SkiaSharp.NativeAssets.WebAssembly" Version="3.119.0" />
|
||||||
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
||||||
|
|||||||
Reference in New Issue
Block a user