这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override void OnStartup(StartupEventArgs e)
}
catch (Exception ex)
{
HandleUnhandledException(ex);
HandleUnhandledException(ex, false);
}

// Always flush at the end
Expand Down Expand Up @@ -124,59 +124,63 @@ private static void RunClient(bool screenSaver)
#region Exception Handlers
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
HandleUnhandledException(e.Exception);
HandleUnhandledException(e.Exception, true);
}

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
HandleUnhandledException(e.ExceptionObject);
HandleUnhandledException(e.ExceptionObject, true);
}

static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
HandleUnhandledException(e.Exception);
HandleUnhandledException(e.Exception, false);
}

/// <summary>
/// Event for unhandled exceptions
/// </summary>
/// <param name="o"></param>
static void HandleUnhandledException(Object o)
static void HandleUnhandledException(Object o, bool quit)
{
Exception e = o as Exception;

// What happens if we cannot start?
Trace.WriteLine(new LogMessage("Main", "Unhandled Exception: " + e.Message), LogType.Error.ToString());
Trace.WriteLine(new LogMessage("Main", "Stack Trace: " + e.StackTrace), LogType.Audit.ToString());

try
// Should we quit or continue
if (quit)
{
string productName = ApplicationSettings.GetProductNameFromAssembly();

// Also write to the event log
try
{
if (!EventLog.SourceExists(productName))
string productName = ApplicationSettings.GetProductNameFromAssembly();

// Also write to the event log
try
{
if (!EventLog.SourceExists(productName))
{
EventLog.CreateEventSource(productName, "Xibo");
}

EventLog.WriteEntry(productName, e.ToString(), EventLogEntryType.Error);
}
catch (Exception ex)
{
EventLog.CreateEventSource(productName, "Xibo");
Trace.WriteLine(new LogMessage("Main", "Couldn't write to event log: " + ex.Message), LogType.Info.ToString());
}

EventLog.WriteEntry(productName, e.ToString(), EventLogEntryType.Error);
Trace.Flush();
}
catch (Exception ex)
{
Trace.WriteLine(new LogMessage("Main", "Couldn't write to event log: " + ex.Message), LogType.Info.ToString());
Trace.WriteLine(new LogMessage("Main", "Unable to write to event log " + ex.Message), LogType.Info.ToString());
}

Trace.Flush();
}
catch (Exception ex)
{
Trace.WriteLine(new LogMessage("Main", "Unable to write to event log " + ex.Message), LogType.Info.ToString());
// Exit the application and allow it to be restarted by the Watchdog.
Environment.Exit(0);
}

// Exit the application and allow it to be restarted by the Watchdog.
Environment.Exit(0);
}

internal static class NativeMethods
Expand Down
2 changes: 1 addition & 1 deletion Logic/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static readonly Lazy<ApplicationSettings>
/// </summary>
private List<string> ExcludedProperties;

public string ClientVersion { get; } = "2 R253.3";
public string ClientVersion { get; } = "2 R253.5";
public string Version { get; } = "5";
public int ClientCodeVersion { get; } = 253;

Expand Down
20 changes: 13 additions & 7 deletions Logic/ScheduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,18 +1494,18 @@ private void InterruptInitState()
{
this._interruptState = JsonConvert.DeserializeObject<InterruptState>(File.ReadAllText(ApplicationSettings.Default.LibraryPath + @"\interrupt.json"));
}
else
{
// Create a new empty object
this._interruptState = InterruptState.EmptyState();
}
}
catch (Exception e)
{
this._interruptState = InterruptState.EmptyState();

Trace.WriteLine(new LogMessage("ScheduleManager", "InterruptInitState: Failed to read interrupt file. e = " + e.Message), LogType.Error.ToString());
}

// If we are still empty after loading, we should create an empty object
if (this._interruptState == null)
{
// Create a new empty object
this._interruptState = InterruptState.EmptyState();
}
}
}

Expand All @@ -1514,6 +1514,12 @@ private void InterruptInitState()
/// </summary>
private void InterruptPersistState()
{
// If the interrupt state is null for whatever reason, don't persist it to file
if (this._interruptState == null)
{
return;
}

try
{
lock (_locker)
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
// 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("2.253.3.0")]
[assembly: AssemblyFileVersion("2.253.3.0")]
[assembly: AssemblyVersion("2.253.5.0")]
[assembly: AssemblyFileVersion("2.253.5.0")]
[assembly: Guid("3bd467a4-4ef9-466a-b156-a79c13a863f7")]
94 changes: 78 additions & 16 deletions Stats/StatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using XiboClient.Log;
using XiboClient.XmdsAgents;
Expand Down Expand Up @@ -83,29 +85,81 @@ public void InitDatabase()

using (var connection = new SqliteConnection("Filename=" + this.databasePath))
{
string sql = "CREATE TABLE IF NOT EXISTS stat (" +
"_id INTEGER PRIMARY KEY, " +
"fromdt TEXT, " +
"todt TEXT, " +
"type TEXT, " +
"scheduleId INT, " +
"layoutId INT, " +
"widgetId TEXT, " +
"tag TEXT, " +
"processing INT" +
")";

// Open the connection
connection.Open();

// Create an execute a command.
using (var command = new SqliteCommand(sql, connection))
// What version are we?
int version = GetDbVersion(connection);

if (version == 0)
{
command.ExecuteNonQuery();
// Create the table fresh
string sql = "CREATE TABLE IF NOT EXISTS stat (" +
"_id INTEGER PRIMARY KEY, " +
"fromdt TEXT, " +
"todt TEXT, " +
"type TEXT, " +
"scheduleId INT, " +
"layoutId INT, " +
"widgetId TEXT, " +
"tag TEXT, " +
"processing INT" +
")";

// Create an execute a command.
using (var command = new SqliteCommand(sql, connection))
{
command.ExecuteNonQuery();
}
}

// Add the engagements column
if (version <= 1)
{
using (var command = new SqliteCommand("ALTER TABLE stat ADD COLUMN engagements TEXT", connection))
{
command.ExecuteNonQuery();
}

// Set the DB version to 2
SetDbVersion(connection, 2);
}
}
}

/// <summary>
/// Get the current DB version.
/// </summary>
/// <param name="connection"></param>
/// <returns></returns>
private int GetDbVersion(SqliteConnection connection)
{
try
{
using (var command = new SqliteCommand("PRAGMA user_version", connection))
{
return Convert.ToInt32(command.ExecuteScalar());
}
}
catch
{
return 0;
}
}

/// <summary>
/// Set the DB version
/// </summary>
/// <param name="connection"></param>
/// <param name="version"></param>
private void SetDbVersion(SqliteConnection connection, int version)
{
using (var command = new SqliteCommand("PRAGMA user_version = " + version, connection))
{
command.ExecuteNonQuery();
}
}

/// <summary>
/// Start the Stat Manager
/// </summary>
Expand Down Expand Up @@ -331,7 +385,15 @@ private void RecordStat(Stat stat)
}

// Execute and don't wait for the result
command.ExecuteNonQueryAsync();
command.ExecuteNonQueryAsync().ContinueWith(t =>
{
var aggException = t.Exception.Flatten();
foreach (var exception in aggException.InnerExceptions)
{
Trace.WriteLine(new LogMessage("StatManager", "RecordStat: Error saving stat to database. Ex = " + exception.Message), LogType.Error.ToString());
}
},
TaskContinuationOptions.OnlyOnFaulted);
}
}
catch (Exception ex)
Expand Down