Skip to content

Commit

Permalink
V0.9.9.26 Updates
Browse files Browse the repository at this point in the history
- Added label to slew rate boxes.
- Added log folder link to main UI.
- Added log file flushing in case of crash.
  • Loading branch information
ClutchplateDude committed Feb 22, 2021
1 parent cce957c commit bfc2433
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 33 deletions.
39 changes: 25 additions & 14 deletions OATCommunications/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Log
private static List<string> lstBuffer = new List<string>();
private static DateTime dtLastUpdate = DateTime.Now.AddSeconds(5.0);
private static int maxBuffered = 0;
private static bool logging = true;


public static string Filename
{
Expand Down Expand Up @@ -82,34 +84,43 @@ private static string FormatMessage(string message, object[] args)
return sb.ToString();
}

protected static void Flush()
{
lock (Log.oLock)
{
var lines = string.Join("\r\n", Log.lstBuffer.ToArray()) + "\r\n";
File.AppendAllText(Log.sPath, lines);
Log.lstBuffer.Clear();
}
}

public static void WriteLine(string message, params object[] args)
{
if ((DateTime.UtcNow - Log.dtLastUpdate).TotalMilliseconds > 1000.0)
if (logging)
{
lock (Log.oLock)
if ((DateTime.UtcNow - Log.dtLastUpdate).TotalMilliseconds > 1000.0)
{
var lines = string.Join("\r\n", Log.lstBuffer.ToArray()) + "\r\n";
File.AppendAllText(Log.sPath, lines);
Log.lstBuffer.Clear();
Log.Flush();
Log.dtLastUpdate = DateTime.UtcNow;
}
Log.dtLastUpdate = DateTime.UtcNow;
}

string sLine = FormatMessage(message, args);
string sLine = FormatMessage(message, args);

lock (Log.oLock)
{
Log.lstBuffer.Add(sLine);
Debug.WriteLine(sLine);
if (Log.lstBuffer.Count > Log.maxBuffered)
lock (Log.oLock)
{
Log.maxBuffered = Log.lstBuffer.Count;
Log.lstBuffer.Add(sLine);
Debug.WriteLine(sLine);
if (Log.lstBuffer.Count > Log.maxBuffered)
{
Log.maxBuffered = Log.lstBuffer.Count;
}
}
}
}

public static void Quit()
{
logging = false;
if (Log.lstBuffer.Any())
{
lock (Log.oLock)
Expand Down
57 changes: 55 additions & 2 deletions OATControl/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using System.Threading.Tasks;
using System.Windows;
using OATCommunications.Utilities;
using System.Threading;
using System.Windows.Threading;

namespace OATControl
{
/// <summary>
Expand All @@ -15,6 +18,17 @@ namespace OATControl

public partial class App : Application
{
public App()
{
Log.Init("OatControl");

// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException += App.UnhandledException;

this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App.AppDispatcherUnhandledException);


}
protected override void OnStartup(StartupEventArgs e)
{
ThemeManager.AddAccent("RedAccent", new Uri("pack://application:,,,/OATControl;component/Resources/RedAccent.xaml"));
Expand All @@ -30,7 +44,7 @@ protected override void OnStartup(StartupEventArgs e)
ThemeManager.GetAccent("RedAccent"),
ThemeManager.GetAppTheme("RedTheme"));

Log.Init("OatControl");

base.OnStartup(e);
}

Expand All @@ -40,5 +54,44 @@ protected override void OnExit(ExitEventArgs e)

base.OnExit(e);
}
}

private static int exceptionReentrancy = 0;

/// <summary>
/// Delegate's instance to react to unhandled exception event happened on not UI thread.
/// </summary>
/// <param name="sender">the object where event happened.</param>
/// <param name="e">The exception related information.</param>
private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (Interlocked.CompareExchange(ref App.exceptionReentrancy, 1, 0) == 0)
{
Log.WriteLine("EXCPTN: Entered UnhandledException handler.\nException:\n{0}", (e.ExceptionObject != null) ? e.ExceptionObject.ToString() : "No exception!");
}

Log.Quit();
Environment.Exit(-1);
}


//-------------------------------------------------------------------------------------------------------------
/// <summary>
/// The application's unhandled exception handler.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="DispatcherUnhandledExceptionEventArgs"/> instance containing the event data.</param>
static void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
if (Interlocked.CompareExchange(ref App.exceptionReentrancy, 1, 0) == 0)
{
Log.WriteLine("EXCPTN: Entered AppDispatcherUnhandledException handler.\nException:\n{0}\nStacktrace:\n{1}", (e.Exception != null) ? e.Exception.ToString() : "No Exception!", (e.Exception != null) ? e.Exception.StackTrace : "No Stacktrace!");

// Prevent default unhandled exception processing
e.Handled = true;
}

Log.Quit();
}

}
}
34 changes: 18 additions & 16 deletions OATControl/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:controls="clr-namespace:OATControl.Controls"
xmlns:converters="clr-namespace:OATControl.Converters"
mc:Ignorable="d"
Title="{Binding Version, StringFormat={} OpenAstroTracker Control V{0}}" MinHeight="698" MinWidth="720" Height="700" Width="720">
Title="{Binding Version, StringFormat={} OpenAstroTracker Control V{0}}" MinHeight="705" MinWidth="720" Height="705" Width="720">
<Window.Resources>
<converters:BoolToStringConverter x:Key="SlewModeConverter" TrueString="Pulsed" FalseString="Continuous" />
<converters:BoolToVisibilityConverter x:Key="TrueBoolToHidden" Collapse="False" IsReversed="True"/>
Expand Down Expand Up @@ -302,7 +302,8 @@
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" MinHeight="0" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
Expand All @@ -315,7 +316,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" MinHeight="10" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -357,7 +358,8 @@
<controls:Joystick Grid.Row="1" Grid.Column="1" Grid.RowSpan="1" Grid.ColumnSpan="2" Margin="0,0,0,8" CursorX="{Binding SlewXSpeed,Mode=OneWayToSource}" CursorY="{Binding SlewYSpeed,Mode=OneWayToSource}"/>

</Grid>
<ToggleButton Grid.Row="1" Grid.Column="0"
<TextBlock Grid.Row="1" HorizontalAlignment="Right" Text="Slew Rate" Style="{StaticResource TextBlockLabelSmall}"/>
<ToggleButton Grid.Row="2" Grid.Column="0"
Margin="10,0,0,0"
Width="80"
HorizontalAlignment="Left"
Expand All @@ -366,7 +368,7 @@
Style="{StaticResource AccentedDialogSquareButton}"
Content="{Binding IsCoarseSlewing, Converter={StaticResource SlewModeConverter}}" />

<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsEnabled="{Binding MountConnected}">
<StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" IsEnabled="{Binding MountConnected}">
<ToggleButton
Width="24" Margin="0,0,0,0"
Height="24"
Expand All @@ -393,7 +395,7 @@
Content="4"/>
</StackPanel>

<Grid Grid.Row="2" Grid.Column="1" >
<Grid Grid.Row="3" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -441,8 +443,8 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
Expand All @@ -457,7 +459,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5" >
<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -525,11 +527,10 @@
<TextBlock Grid.Row="3" Grid.Column="2" MinWidth="64" Text="{Binding TrkStepper}" Style="{StaticResource TextBlockLabelValue}" TextAlignment="Center" />
</Grid>

<TextBlock Grid.Column="0" Grid.Row="2" Text="Tracking" Margin="0,12,0,0" Style="{StaticResource TextBlockHeading}" />
<Controls:ToggleSwitchButton Grid.Column="1" Grid.Row="2" Margin="0,6,0,0" VerticalAlignment="Center" IsEnabled="{Binding MountConnected}" IsChecked="{Binding IsTracking}"/>
<TextBlock Grid.Column="0" Grid.Row="1" Text="Tracking" Margin="0,5,0,1" Style="{StaticResource TextBlockHeading}" />
<Controls:ToggleSwitchButton Grid.Column="1" Grid.Row="1" Margin="0,6,0,0" VerticalAlignment="Center" IsEnabled="{Binding MountConnected}" IsChecked="{Binding IsTracking}"/>


<Grid Grid.Row="3" Grid.Column="1" >
<Grid Grid.Row="2" Grid.Column="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
Expand All @@ -539,11 +540,12 @@
<TextBlock Grid.Column="2" Text="On" FontSize="10" Margin="0,-4,0,0" FontWeight="Bold" />
</Grid>

<Button Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="2" Content="Mini-Control" Margin="2,2,0,2" HorizontalAlignment="Right" Padding="15,0" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ShowMiniControllerCommand}"/>
<Button Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="3" Content="Settings" Margin="2,2,0,2" HorizontalAlignment="Right" Padding="15,0" IsEnabled="{Binding MountConnected}" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ShowSettingsCommand}"/>
<Button Grid.Row="3" Grid.Column="2" Content="Mini-Control" Margin="0,2" HorizontalAlignment="Right" Padding="15,0" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ShowMiniControllerCommand}" />
<Button Grid.Row="4" Grid.Column="2" Content="Settings" Margin="0,2" HorizontalAlignment="Right" Padding="15,0" IsEnabled="{Binding MountConnected}" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ShowSettingsCommand}"/>
<Button Grid.Row="5" Grid.Column="2" Content="Log Files" Margin="0,2" HorizontalAlignment="Right" Padding="15,0" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ShowLogFolderCommand}" />


<Grid Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="4" >
<Grid Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
Expand All @@ -552,7 +554,7 @@
<TextBlock Grid.Row="0" Grid.Column="1" Text="Mount" Style="{StaticResource TextBlockHeading}" Margin="0,10,0,0" HorizontalAlignment="Right"/>
<Button Grid.Column="2" Margin="10,12,0,0" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ConnectScopeCommand}" Content="{Binding ConnectCommandString}"/>
</Grid>
<TextBlock Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="3" Text="{Binding ScopeName}" Style="{StaticResource TextBlockLabel}" Margin="0,2,0,0" HorizontalAlignment="Right" />
<TextBlock Grid.Row="7" Grid.Column="2" Text="{Binding ScopeName}" Style="{StaticResource TextBlockLabel}" Margin="0,2,0,0" HorizontalAlignment="Right" />
</Grid>

</Grid>
Expand Down
2 changes: 1 addition & 1 deletion OATControl/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.9.25")]
[assembly: AssemblyVersion("0.9.9.26")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit bfc2433

Please sign in to comment.