Skip to content

Commit

Permalink
Merge pull request #37 from dasgarner/develop
Browse files Browse the repository at this point in the history
1.8.0-rc1
  • Loading branch information
dasgarner authored Nov 2, 2016
2 parents 9db4ef0 + a903662 commit 251f90c
Show file tree
Hide file tree
Showing 26 changed files with 574 additions and 225 deletions.
3 changes: 3 additions & 0 deletions Action/Rs232Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Rs232Command(Command command)

/// <summary>
/// Run the command
/// throws an exception if we cannot open or write to the port
/// </summary>
public string Run()
{
Expand All @@ -29,6 +30,8 @@ public string Run()
// Parse and configure the port
parse();

Trace.WriteLine(new LogMessage("Rs232Command - run", "Parsed command, will open port " + _port.PortName + " and write " + _toSend), LogType.Audit.ToString());

// try to open the COM port
if (!_port.IsOpen)
_port.Open();
Expand Down
2 changes: 1 addition & 1 deletion Action/XmrSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void Run()
}
catch (Exception e)
{
Trace.WriteLine(new LogMessage("XmrSubscriber - Run", "Unable to Subscribe to XMR: " + e.Message), LogType.Error.ToString());
Trace.WriteLine(new LogMessage("XmrSubscriber - Run", "Unable to Subscribe to XMR: " + e.Message), LogType.Info.ToString());
_clientInfoForm.XmrSubscriberStatus = e.Message;
}
}
Expand Down
9 changes: 8 additions & 1 deletion Control/EmbeddedServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ public void Run()

using (WebServer server = new WebServer(ApplicationSettings.Default.EmbeddedServerAddress))
{
server.RegisterModule(new StaticFilesModule(ApplicationSettings.Default.LibraryPath));
Dictionary<string, string> headers = new Dictionary<string, string>()
{
{ Constants.HeaderCacheControl, "no-cache, no-store, must-revalidate" },
{ Constants.HeaderPragma, "no-cache" },
{ Constants.HeaderExpires, "0" }
};

server.RegisterModule(new StaticFilesModule(ApplicationSettings.Default.LibraryPath, headers));
server.Module<StaticFilesModule>().UseRamCache = true;
server.Module<StaticFilesModule>().DefaultExtension = ".html";

Expand Down
64 changes: 41 additions & 23 deletions Control/Region.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Xibo - Digitial Signage - http://www.xibo.org.uk
* Copyright (C) 2006-2015 Daniel Garner
* Copyright (C) 2006-2016 Daniel Garner
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -171,18 +171,26 @@ private void EvalOptions()
if (!SetNextMediaNodeInOptions())
{
// For some reason we cannot set a media node... so we need this region to become invalid
_hasExpired = true;

if (DurationElapsedEvent != null)
DurationElapsedEvent();
return;
throw new InvalidOperationException("Unable to set any region media nodes.");
}

// If the sequence hasnt been changed, OR the layout has been expired
// there has been no change to the sequence, therefore the media we have already created is still valid
// or this media has actually been destroyed and we are working out way out the call stack
if (_layoutExpired || (_currentSequence == temp))
if (_layoutExpired)
{
return;
}
else if (_currentSequence == temp)
{
// Media has not changed, we are likely the only valid media item in the region
// the layout has not yet expired, so depending on whether we loop or not, we either
// reload the same media item again
// or do nothing (return)
// This could be made more succinct, but is clearer written as an elseif.
if (!_options.RegionLoop)
return;
}

// Store the Current Index
_options.CurrentIndex = _currentSequence;
Expand All @@ -199,7 +207,7 @@ private void EvalOptions()
// Try the next node
startSuccessful = false;
continue;
}
}

// First thing we do is stop the current stat record
if (!initialMedia)
Expand Down Expand Up @@ -449,23 +457,26 @@ private void ParseOptionsForMediaNode(XmlNode mediaNode, XmlAttributeCollection
// And some stuff on Raw nodes
XmlNode rawNode = mediaNode.SelectSingleNode("raw");

foreach (XmlNode raw in rawNode.ChildNodes)
if (rawNode != null)
{
if (raw.Name == "text")
{
_options.text = raw.InnerText;
}
else if (raw.Name == "template")
{
_options.documentTemplate = raw.InnerText;
}
else if (raw.Name == "embedHtml")
foreach (XmlNode raw in rawNode.ChildNodes)
{
_options.text = raw.InnerText;
}
else if (raw.Name == "embedScript")
{
_options.javaScript = raw.InnerText;
if (raw.Name == "text")
{
_options.text = raw.InnerText;
}
else if (raw.Name == "template")
{
_options.documentTemplate = raw.InnerText;
}
else if (raw.Name == "embedHtml")
{
_options.text = raw.InnerText;
}
else if (raw.Name == "embedScript")
{
_options.javaScript = raw.InnerText;
}
}
}

Expand Down Expand Up @@ -539,6 +550,8 @@ private Media CreateNextMediaNode(RegionOptions options)
}
else
{
// We've set our next media node in options already
// this includes checking that file based media is valid.
switch (options.type)
{
case "image":
Expand Down Expand Up @@ -775,11 +788,16 @@ private void media_DurationElapsedEvent(int filesPlayed)

/// <summary>
/// Clears the Region of anything that it shouldnt still have...
/// called when Destroying a Layout and when Removing an Overlay
/// </summary>
public void Clear()
{
try
{
// Stop the current media item
if (_media != null)
StopMedia(_media);

// What happens if we are disposing this region but we have not yet completed the stat event?
if (string.IsNullOrEmpty(_stat.toDate))
{
Expand Down
13 changes: 12 additions & 1 deletion Control/WatchDogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class WatchDogManager
public static void Start()
{
// Check to see if the WatchDog EXE exists where we expect it to be
// Uncomment to test local watchdog install.
//string path = @"C:\Program Files (x86)\Xibo Player\watchdog\x86\XiboClientWatchdog.exe";
string path = Path.GetDirectoryName(Application.ExecutablePath) + @"\watchdog\x86\XiboClientWatchdog.exe";
string args = "-p \"" + Application.ExecutablePath + "\" -l \"" + ApplicationSettings.Default.LibraryPath + "\"";

Expand All @@ -21,7 +23,16 @@ public static void Start()
{
try
{
Process.Start(path, args);
Process process = new Process();
ProcessStartInfo info = new ProcessStartInfo();

info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.FileName = "cmd.exe";
info.Arguments = "/c start \"watchdog\" \"" + path + "\" " + args;

process.StartInfo = info;
process.Start();
}
catch (Exception e)
{
Expand Down
12 changes: 12 additions & 0 deletions Error/DefaultLayoutException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XiboClient.Error
{
class DefaultLayoutException : Exception
{
}
}
27 changes: 27 additions & 0 deletions Log/ClientInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public partial class ClientInfo : Form
public delegate void StatusDelegate(string status);
public delegate void AddLogMessage(string message, LogType logType);

// Delegate for updating the status file
public delegate void UpdateStatusFile();

/// <summary>
/// Set the schedule status
/// </summary>
Expand Down Expand Up @@ -298,5 +301,29 @@ private void saveFileDialog_FileOk(object sender, CancelEventArgs e)

MessageBox.Show("Log saved as " + saveFileDialog.FileName, "Log Saved");
}

/// <summary>
/// Update Status Marker File
/// </summary>
public void UpdateStatusMarkerFile()
{
if (InvokeRequired)
{
BeginInvoke(new UpdateStatusFile(updateStatusFile));
}
else
{
updateStatusFile();
}
}

/// <summary>
/// Update status file
/// </summary>
private void updateStatusFile()
{
File.WriteAllText(Path.Combine(ApplicationSettings.Default.LibraryPath, "status.json"),
"{\"lastActivity\":\"" + DateTime.Now.ToString() + "\",\"state\":\"" + Thread.State.ToString() + "\",\"xmdsLastActivity\":\"" + ApplicationSettings.Default.XmdsLastConnection.ToString() + "\",\"xmdsCollectInterval\":\"" + ApplicationSettings.Default.CollectInterval.ToString() + "\"}");
}
}
}
4 changes: 2 additions & 2 deletions Logic/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public class ApplicationSettings
private static string _default = "default";

// Application Specific Settings we want to protect
private string _clientVersion = "1.8.0-beta";
private string _clientVersion = "1.8.0-rc1";
private string _version = "5";
private int _clientCodeVersion = 122;
private int _clientCodeVersion = 124;

public string ClientVersion { get { return _clientVersion; } }
public string Version { get { return _version; } }
Expand Down
89 changes: 1 addition & 88 deletions Logic/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public bool IsValidPath(String path)
{
// If we cached it over 2 minutes ago, then check the GetLastWriteTime
if (file.cacheDate > DateTime.Now.AddMinutes(-2))
return true;
return File.Exists(ApplicationSettings.Default.LibraryPath + @"\" + path);

try
{
Expand Down Expand Up @@ -231,93 +231,6 @@ public bool IsValidPath(String path)
}
}

/// <summary>
/// Is the provided layout file a valid layout (has all media)
/// </summary>
/// <param name="layoutFile"></param>
/// <returns></returns>
public bool IsValidLayout(string layoutFile)
{
lock (_locker)
{
Debug.WriteLine("Checking if Layout " + layoutFile + " is valid");

if (!IsValidPath(layoutFile))
return false;


// Load the XLF, get all media ID's
XmlDocument layoutXml = new XmlDocument();
layoutXml.Load(ApplicationSettings.Default.LibraryPath + @"\" + layoutFile);

try
{
XmlNodeList mediaNodes = layoutXml.SelectNodes("//media");

// Store some information about the validity of local video to decide if this layout should be valid or not.
int countInvalidLocalVideo = 0;

foreach (XmlNode media in mediaNodes)
{
// Is this a stored media type?
switch (media.Attributes["type"].Value)
{
case "video":
case "image":
case "flash":
case "powerpoint":

// Get the path and see if its
if (!IsValidPath(GetUri(media)))
{
Trace.WriteLine(new LogMessage("CacheManager - IsValidLayout", "Invalid Media: " + media.Attributes["id"].Value.ToString()), LogType.Audit.ToString());
return false;
}

break;

default:
continue;
}
}

// If the number of invalid local video elements is equal to the number of elements on the layout, then don't show
if (countInvalidLocalVideo == mediaNodes.Count)
return false;
}
catch (Exception ex)
{
Trace.WriteLine(new LogMessage("CacheManager - IsValidLayout", "Exception checking media. " + ex.Message), LogType.Audit.ToString());
return false;
}

// Also check to see if there is a background image that needs to be downloaded
try
{
XmlNode layoutNode = layoutXml.SelectSingleNode("/layout");
XmlAttributeCollection layoutAttributes = layoutNode.Attributes;

if (layoutAttributes["background"] != null && !string.IsNullOrEmpty(layoutAttributes["background"].Value))
{
if (!IsValidPath(layoutAttributes["background"].Value))
{
Debug.WriteLine("Invalid background: " + layoutAttributes["background"].Value);
return false;
}
}
}
catch
{
// We dont want a missing background attribute to stop this process
return true;
}

Debug.WriteLine("Layout " + layoutFile + " is valid");

return true;
}
}

/// <summary>
/// Get the URI of this media item
/// </summary>
Expand Down
Loading

0 comments on commit 251f90c

Please sign in to comment.