Skip to content

Commit

Permalink
final spit and polish pass
Browse files Browse the repository at this point in the history
* extended the logging operation to framework
* tweaked some graphical elements around (login field borders when focused, logout button icon)
* figured out how to reset password field w/o framework throwing a hissy fit (thanks, logging)
* added a KeyPress binds for login form fields (you can now press enter to login)
  • Loading branch information
OrletSoir committed Oct 13, 2019
1 parent d9868f7 commit d7cde1a
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<Border Background="Transparent" x:Name="Bd" BorderBrush="Transparent"
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
<Grid>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Name="content"/>
<StackPanel Orientation="Horizontal" Width="Auto" Height="Auto" HorizontalAlignment="Center" VerticalAlignment="Center">
<Image Source="/windows-party;component/Icons/logout.png" x:Name="btnIcon" Visibility="Visible" Stretch="Uniform" Height="16" Width="16" Margin="0,0,6,0" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Name="content"/>
</StackPanel>
</Grid>
</Border>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="#999" TargetName="Bd" />
<Setter Property="BorderBrush" Value="DarkGray" TargetName="Bd" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</MultiTrigger.Conditions>
<Setter Property="Visibility" Value="Collapsed" TargetName="watermarkText" />
<Setter Property="Background" Value="#999" TargetName="Bd" />
<Setter Property="BorderBrush" Value="DarkGray" TargetName="Bd" />
</MultiTrigger>

<MultiTrigger>
Expand Down
2 changes: 1 addition & 1 deletion src/windows-party/windows-party/Core/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</targets>

<rules>
<logger name="*" minlevel="Debug" writeTo="main" />
<logger name="*" minlevel="Info" writeTo="main" />
</rules>
</nlog>
</configuration>
48 changes: 44 additions & 4 deletions src/windows-party/windows-party/Core/AppBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using Caliburn.Micro;
using windows_party.DataContext.Auth;
using windows_party.DataContext.Server;
using windows_party.Helpers;
using windows_party.Login;
using windows_party.ServerList;

Expand All @@ -24,20 +26,40 @@ public class AppBootstrapper : BootstrapperBase
#region constructor/destructor
public AppBootstrapper()
{
// attach our logger wrapper to the framework logging
AttachCaliburnMicroLogging();

#if DEBUG
// if debugging configuration, enable debug level logging
EnableDebugLogging();
#endif

Logger.Debug("Initializing the AppBootstrapper");

Initialize();

// adding password box helper to convention manager
ConventionManager.AddElementConvention<PasswordBox>(PasswordBoxHelper.BoundPasswordProperty, "Password", "PasswordChanged");
}
#endregion

#region IoC container population
#region Bootstrapper configuration
protected override void Configure()
{
Logger.Debug("Configuring the bootstrapper");

// adding password box helper to convention manager
ConventionManager.AddElementConvention<PasswordBox>(PasswordBoxHelper.BoundPasswordProperty, "Password", "PasswordChanged");

// add a special value entry for key press
MessageBinder.SpecialValues.Add("$pressedkey", (context) =>
{
if (context.EventArgs is KeyEventArgs keyArgs)
return keyArgs.Key;

return null;
});

Logger.Debug("Initializing the IoC container");

// initialize the IoC container
container = new SimpleContainer();

// main singleton components
Expand Down Expand Up @@ -105,5 +127,23 @@ protected override void OnUnhandledException(object sender, DispatcherUnhandledE
base.OnUnhandledException(sender, e);
}
#endregion

#region private helpers
private void AttachCaliburnMicroLogging()
{
LogManager.GetLog = type => new FrameworkLogger(type);
}

private void EnableDebugLogging()
{
foreach (NLog.Config.LoggingRule rule in NLog.LogManager.Configuration.LoggingRules)
{
rule.EnableLoggingForLevel(NLog.LogLevel.Debug);
}

// Call to update existing Loggers created with GetLogger() or GetCurrentClassLogger()
NLog.LogManager.ReconfigExistingLoggers();
}
#endregion
}
}
33 changes: 33 additions & 0 deletions src/windows-party/windows-party/Helpers/FrameworkLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Caliburn.Micro;
using System;

namespace windows_party.Helpers
{
/**
* Framework-level logging idea from
* https://buksbaum.us/2010/08/08/how-to-do-logging-with-caliburn.micro/
*/

class FrameworkLogger : ILog
{
#region Logger
private readonly NLog.Logger Logger;
#endregion

#region constructor/destructor
public FrameworkLogger(Type type)
{
Logger = NLog.LogManager.GetLogger(type.Name);
}
#endregion

#region logging handlers
public void Error(Exception exception) => Logger.Error(exception, exception.Message);

public void Warn(string format, params object[] args) => Logger.Warn(format, args);

// ILog does not have "Debug" level messages, so everything non-essential gets dumped into Info, redirect it properly
public void Info(string format, params object[] args) => Logger.Debug(format, args);
#endregion
}
}
Binary file added src/windows-party/windows-party/Icons/logout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/windows-party/windows-party/Login/LoginView.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<UserControl x:Class="windows_party.Login.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.caliburnproject.org"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:Behaviors="clr-namespace:windows_party.Helpers"
xmlns:dtb="clr-namespace:windows_party.Controls.DecoratedTextBox">
Expand Down Expand Up @@ -37,10 +38,10 @@
</Grid>

<!-- custom decorated text box with watermark element -->
<dtb:DecoratedTextBox x:Name="Username" Watermark="👤 Username" Margin="0,0,0,10" />
<dtb:DecoratedTextBox x:Name="Username" Watermark="👤 Username" Margin="0,0,0,10" cal:Message.Attach="[Event KeyDown] = [Action ExecuteFilterView($pressedKey)]" />

<!-- normal password box, but with custom style and loads of h4x on top of it -->
<PasswordBox x:Name="Password" Style="{StaticResource DecoratedPasswordBox}" Margin="0,0,0,10">
<PasswordBox x:Name="Password" Style="{StaticResource DecoratedPasswordBox}" Margin="0,0,0,10" cal:Message.Attach="[Event KeyDown] = [Action ExecuteFilterView($pressedKey)]">
<i:Interaction.Behaviors>
<Behaviors:PasswordBoxWatermarkBehavior LabelName="watermark" />
</i:Interaction.Behaviors>
Expand Down
14 changes: 11 additions & 3 deletions src/windows-party/windows-party/Login/LoginViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Caliburn.Micro;
using System;
using System.ComponentModel.Composition;
using System.Windows.Input;
using windows_party.DataContext.Auth;

namespace windows_party.Login
Expand Down Expand Up @@ -118,6 +119,14 @@ public void Login()
_auth.AuthenticateAsync(Username, Password);
}
}
public void ExecuteFilterView(Key key)
{
if (key == Key.Enter && CanLogin)
{
Login();
}
}

#endregion

#region activate/deactivate actions
Expand All @@ -128,9 +137,8 @@ protected override void OnActivate()
// base call
base.OnActivate();

// make sure qe have the password field cleared as we start
// for some reason this breaks the binding -- investigate later
//Password = string.Empty;
// make sure qe have the password field cleared as we start/restart
Password = null;
}
#endregion

Expand Down
3 changes: 3 additions & 0 deletions src/windows-party/windows-party/Main/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.ComponentModel.Composition;
using windows_party.Login;
using windows_party.Properties;
using windows_party.ServerList;

namespace windows_party
Expand Down Expand Up @@ -56,6 +57,8 @@ protected override void OnActivate()
{
Logger.Debug("MainView is now active");

DisplayName = Resources.MainViewTitle;

if (LoginPanel != null)
LoginPanel.LoginSuccess += OnLoginSuccess;
else
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/windows-party/windows-party/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
<value>Exception of type "{0}" was thrown during HTTP POST operation. The message was: "{1}". Url string that caused this error: "{2}", POST payload: "{3}"</value>
<comment>Used in HTTP class</comment>
</data>
<data name="MainViewTitle" xml:space="preserve">
<value>windows-party</value>
<comment>Main window's title</comment>
</data>
<data name="ServersUrl" xml:space="preserve">
<value>http://playground.tesonet.lt/v1/servers</value>
<comment>User for fetching the servers list</comment>
Expand Down
6 changes: 6 additions & 0 deletions src/windows-party/windows-party/windows-party.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<Compile Include="DataContext\Server\ServerItem.cs" />
<Compile Include="DataContext\Auth\PartyAuth.cs" />
<Compile Include="DataContext\Web\HttpResult.cs" />
<Compile Include="Helpers\FrameworkLogger.cs" />
<Compile Include="Helpers\WeakPropertyChangeNotifier.cs" />
<Compile Include="Helpers\PasswordBoxWatermarkBehavior.cs" />
<Compile Include="Libs\JSON\Json.cs" />
Expand Down Expand Up @@ -208,5 +209,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="Icons\logout.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit d7cde1a

Please sign in to comment.