Skip to content

Commit

Permalink
Merge pull request #49 from xibosignage/develop
Browse files Browse the repository at this point in the history
Release 1.8.2
  • Loading branch information
dasgarner authored Jun 26, 2017
2 parents 2331553 + 9c16b7b commit 9163053
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 183 deletions.
16 changes: 14 additions & 2 deletions Action/Rs232Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class Rs232Command
private Command _command;

private SerialPort _port;
private string _toSend;
private string _toSend = null;
private bool _useHex = false;

public Rs232Command(Command command)
{
Expand All @@ -39,7 +40,15 @@ public string Run()
try
{
// Write our data stream
_port.Write(_toSend);
if (_useHex)
{
byte[] bytes = _toSend.Split(' ').Select(s => Convert.ToByte(s, 16)).ToArray();
_port.Write(bytes, 0, bytes.Length);
}
else
{
_port.Write(_toSend);
}

// Read
if (_command.notifyStatus())
Expand Down Expand Up @@ -86,6 +95,9 @@ private void parse()

// Get the actual command to send
_toSend = command[2];

// Do we have a HEX bit?
_useHex = (connection.Length >= 7 && connection[6] == "1");
}
}
}
308 changes: 218 additions & 90 deletions Action/XmrSubscriber.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Log/LogMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override string ToString()
// Just do this with a string builder rather than an XML builder.
String theMessage;

theMessage = String.Format("<logdate>{0}</logdate>", LogDate);
theMessage = String.Format("<logdate>{0}</logdate>", LogDate.ToString("yyyy-MM-dd HH:mm:ss"));
theMessage += String.Format("<thread>{0}</thread>", _thread);
theMessage += String.Format("<method>{0}</method>", _method);
theMessage += String.Format("<message>{0}</message>", SecurityElement.Escape(_message));
Expand Down
5 changes: 3 additions & 2 deletions Logic/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class ApplicationSettings
private List<string> _globalProperties;

// Application Specific Settings we want to protect
private string _clientVersion = "1.8.1";
private string _clientVersion = "1.8.2";
private string _version = "5";
private int _clientCodeVersion = 128;
private int _clientCodeVersion = 129;

public string ClientVersion { get { return _clientVersion; } }
public string Version { get { return _version; } }
Expand Down Expand Up @@ -498,6 +498,7 @@ public bool InDownloadWindow
public int CollectInterval { get; set; }
public int MaxConcurrentDownloads { get; set; }
public int ScreenShotRequestInterval { get; set; }
public int ScreenShotSize { get; set; }

private int _maxLogFileUploads;
public int MaxLogFileUploads { get { return ((_maxLogFileUploads == 0) ? 10 : _maxLogFileUploads); } set { _maxLogFileUploads = value; } }
Expand Down
89 changes: 39 additions & 50 deletions Logic/Schedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,38 +273,34 @@ void _scheduleManager_OnRefreshSchedule()
/// </summary>
void _scheduleManager_OnScheduleManagerCheckComplete()
{
// XMR address is present and has received at least 1 heart beat
bool xmrShouldBeRunning = (!string.IsNullOrEmpty(ApplicationSettings.Default.XmrNetworkAddress) && _xmrSubscriber.LastHeartBeat != DateTime.MinValue);

// If the agent threads are all alive, and either XMR shouldn't be running OR the subscriber thread is alive.
if (agentThreadsAlive())
{
// Update status marker on the main thread.
_clientInfoForm.UpdateStatusMarkerFile();
}
else
{
Trace.WriteLine(new LogMessage("Schedule - OnScheduleManagerCheckComplete", "Agent threads are dead, not updating status.json"), LogType.Error.ToString());
Trace.WriteLine(new LogMessage("Schedule - OnScheduleManagerCheckComplete", "Agent threads/XMR is dead, not updating status.json"), LogType.Error.ToString());
}

try

// Log for overdue XMR
if (xmrShouldBeRunning && _xmrSubscriber.LastHeartBeat < DateTime.Now.AddHours(-1))
{
// See if XMR should be running
if (!string.IsNullOrEmpty(ApplicationSettings.Default.XmrNetworkAddress) && _xmrSubscriber.LastHeartBeat != DateTime.MinValue)
{
// Log when severly overdue a check
if (_xmrSubscriber.LastHeartBeat < DateTime.Now.AddHours(-1))
{
Trace.WriteLine(new LogMessage("Schedule - OnScheduleManagerCheckComplete", "XMR heart beat last received over an hour ago."));
}
_clientInfoForm.XmrSubscriberStatus = "Long term Inactive (" + ApplicationSettings.Default.XmrNetworkAddress + "), last activity: " + _xmrSubscriber.LastHeartBeat.ToString();
Trace.WriteLine(new LogMessage("Schedule - OnScheduleManagerCheckComplete", "XMR heart beat last received over an hour ago."));

// Check to see if the last update date was over 5 minutes ago
if (_xmrSubscriber.LastHeartBeat < DateTime.Now.AddMinutes(-5))
{
// Reconfigure it
_registerAgent_OnXmrReconfigure();
}
}
// Issue an XMR restart if we've gone this long without connecting
// we do this because we suspect that the TCP socket has died without notifying the poller
restartXmr();
}
catch (Exception e)
else if (xmrShouldBeRunning && _xmrSubscriber.LastHeartBeat < DateTime.Now.AddMinutes(-5))
{
Trace.WriteLine(new LogMessage("Schedule - OnScheduleManagerCheckComplete", "Error = " + e.Message), LogType.Error.ToString());
_clientInfoForm.XmrSubscriberStatus = "Inactive (" + ApplicationSettings.Default.XmrNetworkAddress + "), last activity: " + _xmrSubscriber.LastHeartBeat.ToString();
Trace.WriteLine(new LogMessage("Schedule - OnScheduleManagerCheckComplete", "XMR heart beat last received over 5 minutes ago."), LogType.Audit.ToString());
}
}

Expand All @@ -317,42 +313,16 @@ private bool agentThreadsAlive()
return _registerAgentThread.IsAlive &&
_scheduleAndRfAgentThread.IsAlive &&
_logAgentThread.IsAlive &&
_libraryAgentThread.IsAlive;
_libraryAgentThread.IsAlive &&
_xmrSubscriberThread.IsAlive;
}

/// <summary>
/// XMR Reconfigure
/// </summary>
void _registerAgent_OnXmrReconfigure()
{
try
{
// Stop and start the XMR thread
if (_xmrSubscriberThread != null && _xmrSubscriberThread.IsAlive)
{
_xmrSubscriberThread.Abort();
}
}
catch (Exception e)
{
Trace.WriteLine(new LogMessage("Schedule - OnXmrReconfigure", "Unable to abort Subscriber. " + e.Message), LogType.Error.ToString());
}

try
{
// Reassert the hardware key, incase its changed at all
_xmrSubscriber.HardwareKey = _hardwareKey;

// Start the thread again
_xmrSubscriberThread = new Thread(new ThreadStart(_xmrSubscriber.Run));
_xmrSubscriberThread.Name = "XmrSubscriber";

_xmrSubscriberThread.Start();
}
catch (Exception e)
{
Trace.WriteLine(new LogMessage("Schedule - OnXmrReconfigure", "Unable to start Subscriber. " + e.Message), LogType.Error.ToString());
}
restartXmr();
}

/// <summary>
Expand Down Expand Up @@ -438,6 +408,22 @@ public void wakeUpXmds()
_logAgent.WakeUp();
}

/// <summary>
/// Restart XMR
/// </summary>
public void restartXmr()
{
try
{
// Stop and start the XMR thread
_xmrSubscriber.Restart();
}
catch (Exception e)
{
Trace.WriteLine(new LogMessage("Schedule - restartXmr", "Unable to restart XMR: " + e.Message), LogType.Error.ToString());
}
}

/// <summary>
/// Moves the layout on
/// </summary>
Expand Down Expand Up @@ -604,7 +590,10 @@ public void Stop()
_logAgent.Stop();

// Stop the subsriber thread
_xmrSubscriberThread.Abort();
_xmrSubscriber.Stop();

// Clean up any NetMQ sockets, etc (false means don't block).
NetMQ.NetMQConfig.Cleanup(false);

// Stop the embedded server
_server.Stop();
Expand Down
33 changes: 27 additions & 6 deletions Logic/ScheduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ public void Run()
}
}
}

// Write a flag to the status.xml file
if (OnScheduleManagerCheckComplete != null)
OnScheduleManagerCheckComplete();
}
catch (Exception ex)
{
Expand All @@ -271,7 +267,8 @@ public void Run()
}

// Completed this check
OnScheduleManagerCheckComplete();
if (OnScheduleManagerCheckComplete != null)
OnScheduleManagerCheckComplete();

// Sleep this thread for 10 seconds
_manualReset.WaitOne(10 * 1000);
Expand All @@ -286,6 +283,9 @@ public void Run()
/// <returns></returns>
private bool IsNewScheduleAvailable()
{
// Remove completed change actions
removeLayoutChangeActionIfComplete();

// Remove completed overlay actions
removeOverlayLayoutActionIfComplete();

Expand Down Expand Up @@ -789,8 +789,10 @@ private void LoadScheduleFromLayoutChangeActions()
if (action.downloadRequired)
continue;

DateTime actionCreateDt = DateTime.Parse(action.createdDt);

ScheduleItem item = new ScheduleItem();
item.FromDt = DateTime.MinValue;
item.FromDt = actionCreateDt.AddSeconds(-1);
item.ToDt = DateTime.MaxValue;
item.id = action.layoutId;
item.scheduleid = 0;
Expand Down Expand Up @@ -946,6 +948,9 @@ private string LayoutsInSchedule()

foreach (ScheduleItem layoutSchedule in CurrentSchedule)
{
if (layoutSchedule.Override)
layoutsInSchedule += "API Action ";

layoutsInSchedule += "LayoutId: " + layoutSchedule.id + ". Runs from " + layoutSchedule.FromDt.ToString() + Environment.NewLine;
}

Expand Down Expand Up @@ -1018,6 +1023,22 @@ public bool removeLayoutChangeActionIfComplete(ScheduleItem item)
return false;
}

/// <summary>
/// Remove Layout Change actions if they have completed
/// </summary>
public void removeLayoutChangeActionIfComplete()
{
// Check every action to see if complete
foreach (LayoutChangePlayerAction action in _layoutChangeActions)
{
if (action.IsServiced())
{
_layoutChangeActions.Remove(action);
RefreshSchedule = true;
}
}
}

/// <summary>
/// Add an overlay layout action
/// </summary>
Expand Down
47 changes: 39 additions & 8 deletions Logic/ScreenShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,49 @@ public static void TakeAndSend()
g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
}

using (MemoryStream stream = new MemoryStream())
// Resize?
if (ApplicationSettings.Default.ScreenShotSize != 0)
{
bitmap.Save(stream, ImageFormat.Jpeg);
Size thumbSize;
double ratio = (double)bounds.Width / (double)bounds.Height;

byte[] bytes = stream.ToArray();

using (xmds.xmds screenShotXmds = new xmds.xmds())
if (bounds.Width > bounds.Height)
{
screenShotXmds.Url = ApplicationSettings.Default.XiboClient_xmds_xmds;
screenShotXmds.SubmitScreenShotCompleted += screenShotXmds_SubmitScreenShotCompleted;
screenShotXmds.SubmitScreenShotAsync(ApplicationSettings.Default.ServerKey, ApplicationSettings.Default.HardwareKey, bytes);
// Landscape
thumbSize = new Size(ApplicationSettings.Default.ScreenShotSize, (int)(ApplicationSettings.Default.ScreenShotSize / ratio));
}
else
{
// Portrait
thumbSize = new Size((int)(ApplicationSettings.Default.ScreenShotSize * ratio), ApplicationSettings.Default.ScreenShotSize);
}

// Create a bitmap at our desired resolution
using (Bitmap thumb = new Bitmap(bitmap, thumbSize.Width, thumbSize.Height))
{
send(thumb);
}
}
else
{
send(bitmap);
}
}
}

private static void send(Bitmap bitmap)
{
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Jpeg);

byte[] bytes = stream.ToArray();

using (xmds.xmds screenShotXmds = new xmds.xmds())
{
screenShotXmds.Url = ApplicationSettings.Default.XiboClient_xmds_xmds;
screenShotXmds.SubmitScreenShotCompleted += screenShotXmds_SubmitScreenShotCompleted;
screenShotXmds.SubmitScreenShotAsync(ApplicationSettings.Default.ServerKey, ApplicationSettings.Default.HardwareKey, bytes);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Xibo Digital Signage")]
[assembly: AssemblyProduct("Xibo")]
[assembly: AssemblyCopyright("Copyright Dan Garner © 2008-2016")]
[assembly: AssemblyCopyright("Copyright Dan Garner © 2008-2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -30,6 +30,6 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("10.8.1.0")]
[assembly: AssemblyFileVersion("10.8.1.0")]
[assembly: AssemblyVersion("10.8.2.0")]
[assembly: AssemblyFileVersion("10.8.2.0")]
[assembly: NeutralResourcesLanguageAttribute("en-GB")]
19 changes: 11 additions & 8 deletions XiboClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@
<HintPath>packages\NetMQ.4.0.0.1\lib\net40\NetMQ.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NodaTime, Version=1.3.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1, processorArchitecture=MSIL">
<HintPath>packages\NodaTime.1.3.2\lib\net35-Client\NodaTime.dll</HintPath>
<Reference Include="NodaTime, Version=2.0.2.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1, processorArchitecture=MSIL">
<HintPath>packages\NodaTime.2.0.2\lib\net45\NodaTime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -117,13 +116,17 @@
<Reference Include="System.Drawing" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Management" />
<Reference Include="System.Net.Http" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Unosquare.Labs.EmbedIO, Version=1.0.17.23128, Culture=neutral, PublicKeyToken=871377f68111dbd2, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>packages\EmbedIO.1.1.1\lib\net452\Unosquare.Labs.EmbedIO.dll</HintPath>
<Reference Include="Unosquare.Labs.EmbedIO, Version=1.4.6.15336, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\EmbedIO.1.6.9\lib\net452\Unosquare.Labs.EmbedIO.dll</HintPath>
</Reference>
<Reference Include="Unosquare.Swan, Version=0.14.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Unosquare.Swan.0.14.2\lib\net452\Unosquare.Swan.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit 9163053

Please sign in to comment.