1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Added markdown support to the changelog display

Added live log to the debug window
This commit is contained in:
SpoinkyNL 2016-10-24 23:30:10 +02:00
parent c8742b22c3
commit 00a7c4f351
15 changed files with 1433 additions and 12 deletions

View File

@ -21,6 +21,7 @@
Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
<ResourceDictionary Source="/Resources/Icons.xaml" />
<ResourceDictionary Source="Styles/ColorBox.xaml" />
<ResourceDictionary Source="Styles/MarkdownStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
<converters:MilliSecondTimespanConverter x:Key="MilliSecondTimespanConverter" />
</ResourceDictionary>

View File

@ -303,6 +303,10 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="ArtemisBootstrapper.cs" />
<Compile Include="Controls\Log\LoggingControl.xaml.cs">
<DependentUpon>LoggingControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\Log\MemoryEventTarget.cs" />
<Compile Include="DAL\ProfileProvider.cs" />
<Compile Include="DAL\SettingsProvider.cs" />
<Compile Include="DeviceProviders\Corsair\CorsairMice.cs" />
@ -313,6 +317,9 @@
<Compile Include="DeviceProviders\Logitech\G810.cs" />
<Compile Include="DeviceProviders\Logitech\LogitechGeneric.cs" />
<Compile Include="DeviceProviders\Logitech\LogitechKeyboard.cs" />
<Compile Include="Dialogs\MarkdownDialog.xaml.cs">
<DependentUpon>MarkdownDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Events\EffectChangedEventArgs.cs" />
<Compile Include="Events\EnabledChangedEventArgs.cs" />
<Compile Include="Events\KeyboardChangedEventArgs.cs" />
@ -511,6 +518,8 @@
<Compile Include="Utilities\Keyboard\KeyboardHook.cs" />
<Compile Include="Utilities\Logging.cs" />
<Compile Include="Utilities\DataReaders\PipeServer.cs" />
<Compile Include="Utilities\Markdown\Markdown.cs" />
<Compile Include="Utilities\Markdown\TextToFlowDocumentConverter.cs" />
<Compile Include="Utilities\Memory\GamePointer.cs" />
<Compile Include="Utilities\Keyboard\KeyboardRectangle.cs" />
<Compile Include="Utilities\Memory\Memory.cs" />
@ -686,6 +695,14 @@
</None>
</ItemGroup>
<ItemGroup>
<Page Include="Controls\Log\LoggingControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Dialogs\MarkdownDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Modules\Effects\Bubbles\BubblesView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -746,6 +763,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\MarkdownStyles.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\DebugView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -0,0 +1,27 @@
<UserControl x:Class="Artemis.Controls.Log.LoggingControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<!--<TextBox IsReadOnly="True" AcceptsReturn="True" Height="Auto" HorizontalAlignment="Stretch" Name="dgLog" VerticalAlignment="Stretch" Width="Auto"/>-->
<ListView ItemsSource="{Binding LogCollection}" Name="logView">
<ListView.View>
<GridView>
<GridView.Columns>
<!--<GridViewColumn DisplayMemberBinding="{Binding LoggerName}" Header="Logger"/>-->
<GridViewColumn DisplayMemberBinding="{Binding Level}" Header="Level" />
<GridViewColumn DisplayMemberBinding="{Binding TimeStamp, StringFormat=HH:mm:ss.ffffff}" Header="Time" />
<GridViewColumn DisplayMemberBinding="{Binding FormattedMessage}" Width="600" Header="Message" />
<GridViewColumn DisplayMemberBinding="{Binding Exception}" Width="Auto" Header="Exception" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
<!--<ListBox Height="Auto" HorizontalAlignment="Stretch" Name="dgLog" VerticalAlignment="Stretch" Width="Auto" />-->
</Grid>
</UserControl>

View File

@ -0,0 +1,37 @@
using System.Collections.ObjectModel;
using System.Windows.Controls;
using Artemis.Utilities;
using NLog;
namespace Artemis.Controls.Log
{
/// <summary>
/// Interaction logic for LoggingControl.xaml
/// </summary>
public partial class LoggingControl : UserControl
{
public LoggingControl()
{
LogCollection = new ObservableCollection<LogEventInfo>();
InitializeComponent();
// init memory queue
Logging.ClearLoggingEvent();
Logging.MemoryEvent += EventReceived;
}
public static ObservableCollection<LogEventInfo> LogCollection { get; set; }
private async void EventReceived(LogEventInfo message)
{
await Dispatcher.InvokeAsync(() =>
{
if (LogCollection.Count >= 50)
LogCollection.RemoveAt(LogCollection.Count - 1);
LogCollection.Add(message);
});
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using NLog;
using NLog.Targets;
namespace Artemis.Controls.Log
{
public class MemoryEventTarget : Target
{
public event Action<LogEventInfo> EventReceived;
/// <summary>
/// Notifies listeners about new event
/// </summary>
/// <param name="logEvent">The logging event.</param>
protected override void Write(LogEventInfo logEvent)
{
EventReceived?.Invoke(logEvent);
}
}
}

View File

@ -0,0 +1,53 @@
<dialogs:CustomDialog x:Class="Artemis.Dialogs.MarkdownDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
xmlns:dialogs1="clr-namespace:Artemis.Dialogs"
xmlns:markdown="clr-namespace:Artemis.Utilities.Markdown"
xmlns:system="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<dialogs:CustomDialog.Resources>
<markdown:Markdown x:Key="Markdown"
DocumentStyle="{StaticResource DocumentStyle}"
Heading1Style="{StaticResource H1Style}"
Heading2Style="{StaticResource H2Style}"
Heading3Style="{StaticResource H3Style}"
Heading4Style="{StaticResource H4Style}"
LinkStyle="{StaticResource LinkStyle}"
ImageStyle="{StaticResource ImageStyle}"
SeparatorStyle="{StaticResource SeparatorStyle}"
AssetPathRoot="{x:Static system:Environment.CurrentDirectory}" />
<markdown:TextToFlowDocumentConverter x:Key="TextToFlowDocumentConverter"
Markdown="{StaticResource Markdown}" />
</dialogs:CustomDialog.Resources>
<Grid Margin="0 10 0 0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<FlowDocumentScrollViewer
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Margin="-15 -15 0 0"
FontSize="{Binding DialogMessageFontSize, RelativeSource={RelativeSource AncestorType=dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=dialogs:MessageDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
Document="{Binding Markdown, RelativeSource={RelativeSource AncestorType=dialogs1:MarkdownDialog, Mode=FindAncestor}, Converter={StaticResource TextToFlowDocumentConverter}, UpdateSourceTrigger=PropertyChanged}" IsSelectionEnabled="False" />
<StackPanel Grid.Row="1"
Height="85"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button x:Name="PART_AffirmativeButton"
Height="35"
MinWidth="80"
Margin="0 0 5 0"
Content="Alrighty, let's go!"
Style="{DynamicResource AccentedDialogSquareButton}" />
</StackPanel>
</Grid>
</dialogs:CustomDialog>

View File

@ -0,0 +1,28 @@
using System.Windows;
using System.Windows.Input;
namespace Artemis.Dialogs
{
/// <summary>
/// Interaction logic for MarkdownDialog.xaml
/// </summary>
public partial class MarkdownDialog
{
public static readonly DependencyProperty MarkdownProperty = DependencyProperty.Register("Markdown",
typeof(string), typeof(MarkdownDialog), new PropertyMetadata(default(string)));
public MarkdownDialog()
{
InitializeComponent();
CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage,
(sender, e) => System.Diagnostics.Process.Start((string) e.Parameter)));
}
public string Markdown
{
get { return (string) GetValue(MarkdownProperty); }
set { SetValue(MarkdownProperty, value); }
}
}
}

View File

@ -23,6 +23,8 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Artemis.Dialogs;
using Artemis.Styles;
using Caliburn.Micro;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
@ -53,6 +55,20 @@ namespace Artemis.Services
Execute.OnUIThread(() => GetActiveWindow().ShowMessageAsync(title, message));
}
public void ShowMarkdownDialog(string title, string markdown)
{
if (GetActiveWindow() == null)
return;
var dialog = new MarkdownDialog
{
Markdown = markdown,
Title = title
};
Execute.OnUIThread(() => GetActiveWindow().ShowMetroDialogAsync(dialog));
}
public override async Task<bool?> ShowQuestionMessageBox(string title, string message)
{
if (GetActiveWindow() == null)

View File

@ -0,0 +1,57 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Artemis.Styles">
<Style TargetType="FlowDocument" x:Key="DocumentStyle">
<Setter Property="FontFamily" Value="{StaticResource DefaultFont}" />
<Setter Property="Foreground" Value="{StaticResource LabelTextBrush}" />
<Setter Property="FontSize" Value="{StaticResource NormalFontSize}" />
<Setter Property="TextAlignment" Value="Left" />
</Style>
<Style x:Key="H1Style" TargetType="Paragraph">
<Setter Property="FontSize" Value="42" />
<Setter Property="Foreground" Value="{StaticResource LabelTextBrush}" />
<Setter Property="FontFamily" Value="{StaticResource HeaderFontFamily}" />
<Setter Property="Margin" Value="0" />
</Style>
<Style x:Key="H2Style" TargetType="Paragraph">
<Setter Property="FontSize" Value="20" />
<Setter Property="Foreground" Value="{StaticResource LabelTextBrush}" />
<Setter Property="FontFamily" Value="{StaticResource HeaderFontFamily}" />
<Setter Property="Margin" Value="0" />
</Style>
<Style x:Key="H3Style" TargetType="Paragraph">
<Setter Property="FontSize" Value="20" />
<Setter Property="Foreground" Value="{StaticResource LabelTextBrush}" />
<Setter Property="FontFamily" Value="{StaticResource HeaderFontFamily}" />
<Setter Property="Margin" Value="0" />
</Style>
<Style x:Key="H4Style" TargetType="Paragraph">
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="{StaticResource LabelTextBrush}" />
<Setter Property="FontFamily" Value="{StaticResource HeaderFontFamily}" />
<Setter Property="Margin" Value="0" />
</Style>
<Style x:Key="LinkStyle" TargetType="Hyperlink">
<Setter Property="Foreground" Value="{StaticResource AccentColorBrush}" />
</Style>
<Style x:Key="ImageStyle" TargetType="Image">
<Setter Property="RenderOptions.BitmapScalingMode" Value="NearestNeighbor" />
<Style.Triggers>
<Trigger Property="Tag" Value="imageright">
<Setter Property="Margin" Value="20,0,0,0" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="SeparatorStyle" TargetType="Line">
<Setter Property="X2" Value="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=FlowDocumentScrollViewer}}" />
<Setter Property="Stroke" Value="{StaticResource AccentColorBrush}" />
<Setter Property="StrokeThickness" Value="2" />
</Style>
</ResourceDictionary>

View File

@ -1,4 +1,6 @@
using NLog;
using System.Linq;
using Artemis.Controls.Log;
using NLog;
using NLog.Config;
using NLog.Targets;
@ -6,6 +8,8 @@ namespace Artemis.Utilities
{
public static class Logging
{
public static event LoggingEvent MemoryEvent;
public static void SetupLogging(string logLevel)
{
SetupLogging(LogLevel.FromString(logLevel));
@ -13,6 +17,9 @@ namespace Artemis.Utilities
public static void SetupLogging(LogLevel logLevel)
{
if (logLevel == LogManager.Configuration?.LoggingRules?.FirstOrDefault()?.Levels.FirstOrDefault())
return;
// Step 1. Create configuration object
var config = new LoggingConfiguration();
@ -23,6 +30,10 @@ namespace Artemis.Utilities
var fileTarget = new FileTarget();
config.AddTarget("file", fileTarget);
var memoryTarget = new MemoryEventTarget();
memoryTarget.EventReceived += MemoryTargetOnEventReceived;
config.AddTarget("memory", memoryTarget);
// Step 3. Set target properties
debuggerTarget.Layout = @"${logger:shortName=True} - ${uppercase:${level}}: ${message}";
fileTarget.FileName = "${specialfolder:folder=MyDocuments}/Artemis/logs/${shortdate}.txt";
@ -30,12 +41,14 @@ namespace Artemis.Utilities
fileTarget.EnableFileDelete = true;
fileTarget.MaxArchiveFiles = 7;
fileTarget.ArchiveEvery = FileArchivePeriod.Minute;
// Step 4. Define rules
var rule1 = new LoggingRule("*", logLevel, debuggerTarget);
config.LoggingRules.Add(rule1);
var rule2 = new LoggingRule("*", logLevel, fileTarget);
config.LoggingRules.Add(rule2);
var rule3 = new LoggingRule("*", logLevel, memoryTarget);
config.LoggingRules.Add(rule3);
// Step 5. Activate the configuration
LogManager.Configuration = config;
@ -44,5 +57,17 @@ namespace Artemis.Utilities
var logger = LogManager.GetCurrentClassLogger();
logger.Fatal("INFO: Set log level to {0}", logLevel);
}
private static void MemoryTargetOnEventReceived(LogEventInfo logEventInfo)
{
MemoryEvent?.Invoke(logEventInfo);
}
public static void ClearLoggingEvent()
{
MemoryEvent = delegate { };
}
}
public delegate void LoggingEvent(LogEventInfo logEventInfo);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,62 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Artemis.Utilities.Markdown
{
public class TextToFlowDocumentConverter : DependencyObject, IValueConverter
{
public Markdown Markdown
{
get { return (Markdown)GetValue(MarkdownProperty); }
set { SetValue(MarkdownProperty, value); }
}
// Using a DependencyProperty as the backing store for Markdown. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MarkdownProperty =
DependencyProperty.Register("Markdown", typeof(Markdown), typeof(TextToFlowDocumentConverter), new PropertyMetadata(null));
/// <summary>
/// Converts a value.
/// </summary>
/// <returns>
/// A converted value. If the method returns null, the valid null value is used.
/// </returns>
/// <param name="value">The value produced by the binding source.</param>
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
var text = (string)value;
var engine = Markdown ?? mMarkdown.Value;
return engine.Transform(text);
}
/// <summary>
/// Converts a value.
/// </summary>
/// <returns>
/// A converted value. If the method returns null, the valid null value is used.
/// </returns>
/// <param name="value">The value that is produced by the binding target.</param>
/// <param name="targetType">The type to convert to.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
private Lazy<Markdown> mMarkdown
= new Lazy<Markdown>(() => new Markdown());
}
}

View File

@ -60,8 +60,8 @@ namespace Artemis.Utilities
{
var settings = SettingsProvider.Load<GeneralSettings>();
var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
if ((settings.LastRanVersion != null) && (currentVersion > settings.LastRanVersion))
{
// if ((settings.LastRanVersion != null) && (currentVersion > settings.LastRanVersion))
// {
Logger.Info("Updated from {0} to {1}, showing changelog.", settings.LastRanVersion, currentVersion);
// Ask the user whether he/she wants to see what's new
@ -73,7 +73,7 @@ namespace Artemis.Utilities
// If user wants to see changelog, show it to them
if ((showChanges != null) && showChanges.Value)
await ShowChanges(dialogService, currentVersion);
}
// }
settings.LastRanVersion = currentVersion;
settings.Save();
@ -114,7 +114,7 @@ namespace Artemis.Utilities
}
if (release != null)
dialogService.ShowMessageBox(release["name"].Value<string>(), release["body"].Value<string>());
dialogService.ShowMarkdownDialog(release["name"].Value<string>(), release["body"].Value<string>());
else
dialogService.ShowMessageBox("Couldn't fetch release",
"Sorry, Artemis was unable to fetch the release data off of GitHub.\n" +

View File

@ -1,4 +1,7 @@
using System.Windows;
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using Caliburn.Micro;
@ -6,7 +9,6 @@ namespace Artemis.ViewModels
{
public class DebugViewModel : Screen
{
private DrawingImage _razerDisplay;
public DrawingImage RazerDisplay
@ -20,6 +22,18 @@ namespace Artemis.ViewModels
}
}
public void OpenLog()
{
// Get the logging directory
var logDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
+ @"\Artemis\logs");
// Get the newest log file
var currentLog = logDir.GetFiles().OrderByDescending(f => f.LastWriteTime).FirstOrDefault();
// Open the file with the user's default program
if (currentLog != null)
System.Diagnostics.Process.Start(currentLog.FullName);
}
public void UpdateRazerDisplay(Color[,] colors)
{
// No point updating the display if the view isn't visible
@ -31,10 +45,8 @@ namespace Artemis.ViewModels
{
dc.PushClip(new RectangleGeometry(new Rect(0, 0, 22, 6)));
for (var y = 0; y < 6; y++)
{
for (var x = 0; x < 22; x++)
dc.DrawRectangle(new SolidColorBrush(colors[y, x]), null, new Rect(x, y, 1, 1));
}
}
var drawnDisplay = new DrawingImage(visual.Drawing);
drawnDisplay.Freeze();

View File

@ -4,8 +4,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:log="clr-namespace:Artemis.Controls.Log"
mc:Ignorable="d"
Title="DebugView" Height="329.904" Width="446.624"
Title="DebugView" Height="600" Width="900"
GlowBrush="{DynamicResource AccentColorBrush}">
<Grid Margin="10">
<Grid.ColumnDefinitions>
@ -13,17 +14,27 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="80" />
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Razer output -->
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="20" Content="Razer display" />
<Label Grid.Row="0" Grid.Column="0" FontSize="20" Content="Razer display" />
<Border Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Height="75" Width="300" HorizontalAlignment="Left"
VerticalAlignment="Top" BorderThickness="1" BorderBrush="{StaticResource GrayBrush7}"
SnapsToDevicePixels="True">
<Image Source="{Binding Path=RazerDisplay}" />
</Border>
<!-- Log -->
<Label Grid.Row="2" Grid.Column="0" FontSize="20" Content="Log" />
<Button x:Name="OpenLog" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right"
Style="{DynamicResource SquareButtonStyle}" Content="Open log file" VerticalAlignment="Center" />
<Border Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="1"
BorderBrush="{StaticResource GrayBrush7}" SnapsToDevicePixels="True">
<log:LoggingControl />
</Border>
</Grid>
</controls:MetroWindow>