Skip to content

Commit

Permalink
Merge pull request #23 from dasgarner/develop
Browse files Browse the repository at this point in the history
Merge down before 1.8.0-alpha2 release
  • Loading branch information
dasgarner committed Dec 9, 2015
2 parents 6e22843 + deb2114 commit 12f3404
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 110 deletions.
6 changes: 5 additions & 1 deletion Action/XmrSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void Run()
try
{
NetMQMessage message = socket.ReceiveMultipartMessage();

// Update status
_clientInfoForm.XmrSubscriberStatus = "Connected (" + ApplicationSettings.Default.XmrNetworkAddress + "), last activity: " + DateTime.Now.ToString();

Expand Down Expand Up @@ -130,6 +130,10 @@ public void Run()
OnCollectNowAction();
break;

case "screenShot":
ScreenShot.TakeAndSend();
break;

default:
Trace.WriteLine(new LogMessage("XmrSubscriber - Run", "Unknown Message: " + action.action), LogType.Info.ToString());
break;
Expand Down
94 changes: 46 additions & 48 deletions Logic/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -38,16 +39,14 @@ public class ApplicationSettings
private static string _default = "default";

// Application Specific Settings we want to protect
private string _clientVersion = "1.7.5";
private string _clientVersion = "1.8.0-alpha2";
private string _version = "5";
private int _clientCodeVersion = 109;
private int _clientCodeVersion = 120;

public string ClientVersion { get { return _clientVersion; } }
public string Version { get { return _version; } }
public int ClientCodeVersion { get { return _clientCodeVersion; } }

private static readonly DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local);

public static ApplicationSettings Default
{
get
Expand Down Expand Up @@ -122,7 +121,6 @@ public object this[string propertyName]
}

public int XmdsResetTimeout { get; set; }
public double CmsTimeOffset { get; set; }

public decimal SizeX { get; set; }
public decimal SizeY { get; set; }
Expand Down Expand Up @@ -165,48 +163,59 @@ public object this[string propertyName]
public string XmrNetworkAddress { get; set; }

// Download window

public long DownloadStartWindow { get; set; }
public long DownloadEndWindow { get; set; }
public string DisplayTimeZone { get; set; }
public string DownloadStartWindow { get; set; }
public string DownloadEndWindow { get; set; }

public DateTime DownloadStartWindowTime
{
get
{
// Get the local time now and add our Unix timestamp to it.
// We know that the DownloadStartWindow is saved in UTC (GMT to be precise, but no biggie)
DateTime now = DateTime.Now;
DateTime start = unixEpoch.AddMilliseconds(DownloadStartWindow);

// start is now UTC download window start.
if (CmsTimeOffset != null && CmsTimeOffset != 0)
{
// Adjust for the timezone
start = start.AddHours(CmsTimeOffset);
}

// Reset to local time, using the H:m:i from the Unix Time.
// This gives us a local time
return new DateTime(now.Year, now.Month, now.Day, start.Hour, start.Minute, start.Second, DateTimeKind.Local);
return getDateFromHi(DownloadStartWindow);
}
}

public DateTime DownloadEndWindowTime
{
get
{
// See notes from DownloadStartWindowTime
DateTime now = DateTime.Now;
DateTime end = unixEpoch.AddMilliseconds(DownloadEndWindow);
return getDateFromHi(DownloadEndWindow);
}
}

if (CmsTimeOffset != null && CmsTimeOffset != 0)
/// <summary>
/// Get a locally formatted date based on the H:i string provided.
/// </summary>
/// <param name="hi"></param>
/// <returns></returns>
private DateTime getDateFromHi(string hi)
{
DateTime now = DateTime.Now;

try
{
int h;
int m;

// Expect the format H:i (24 hour). If we don't have a : in it, then it is likely being fed by an old CMS, so disable
if (!hi.Contains(":"))
{
h = 0;
m = 0;
}
else
{
// Adjust for the timezone
end = end.AddHours(CmsTimeOffset);
string[] split = hi.Split(':');
h = int.Parse(split[0]);
m = int.Parse(split[1]);
}

// Reset to today
return new DateTime(now.Year, now.Month, now.Day, end.Hour, end.Minute, end.Second, DateTimeKind.Local);
return new DateTime(now.Year, now.Month, now.Day, h, m, 0, DateTimeKind.Local);
}
catch (Exception e)
{
Trace.WriteLine(new LogMessage("getDateFromHi", "Unable to parse H:i, Error = " + e.Message), LogType.Info.ToString());
return new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, DateTimeKind.Local);
}
}

Expand All @@ -219,10 +228,14 @@ public bool InDownloadWindow
{
try
{
if (DownloadStartWindow == 0 && DownloadEndWindow == 0)
if (DownloadStartWindow == DownloadEndWindow)
return true;

return (DownloadStartWindowTime <= DateTime.Now && DownloadEndWindowTime >= DateTime.Now);
DateTime startWindow = DownloadStartWindowTime;
if (DownloadEndWindowTime < startWindow)
startWindow = DownloadStartWindowTime.AddDays(-1);

return (startWindow <= DateTime.Now && DownloadEndWindowTime >= DateTime.Now);
}
catch
{
Expand Down Expand Up @@ -251,21 +264,6 @@ public bool InDownloadWindow
public bool UseCefWebBrowser { get; set; }
public bool SendCurrentLayoutAsStatusUpdate { get; set; }

private bool _screenShotRequested = false;
public bool ScreenShotRequested
{
get
{
return _screenShotRequested;
}
set
{
_screenShotRequested = value;
// Reset the Hash so that the next update is taken into account.
Hash = "0";
}
}

// XMDS Status Flags
private DateTime _xmdsLastConnection;
public DateTime XmdsLastConnection { get { return _xmdsLastConnection; } set { _xmdsErrorCountSinceSuccessful = 0; _xmdsLastConnection = value; } }
Expand Down
67 changes: 50 additions & 17 deletions Logic/ScheduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,35 +302,53 @@ private Collection<LayoutSchedule> LoadNewSchdule()
// Temporary default Layout incase we have no layout nodes.
LayoutSchedule defaultLayout = new LayoutSchedule();

// Store the valid layout id's
List<int> validLayoutIds = new List<int>();
List<int> invalidLayouts = new List<int>();

// For each layout in the schedule determine if it is currently inside the _currentSchedule, and whether it should be
foreach (LayoutSchedule layout in _layoutSchedule)
{
// Is the layout valid in the cachemanager?
try
// Is this already invalid
if (invalidLayouts.Contains(layout.id))
continue;

// If we haven't already assessed this layout before, then check that it is valid
if (!validLayoutIds.Contains(layout.id))
{
if (!_cacheManager.IsValidLayout(layout.id + ".xlf"))
// Is the layout valid in the cachemanager?
try
{
if (!_cacheManager.IsValidLayout(layout.id + ".xlf"))
{
invalidLayouts.Add(layout.id);
Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout invalid: " + layout.id), LogType.Error.ToString());
continue;
}
}
catch
{
Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout invalid: " + layout.id), LogType.Error.ToString());
// Ignore this layout.. raise an error?
invalidLayouts.Add(layout.id);
Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Unable to determine if layout is valid or not"), LogType.Error.ToString());
continue;
}
}
catch
{
// Ignore this layout.. raise an error?
Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Unable to determine if layout is valid or not"), LogType.Error.ToString());
continue;
}

// Check dependents
foreach (string dependent in layout.Dependents)
{
if (!_cacheManager.IsValidPath(dependent))
// Check dependents
foreach (string dependent in layout.Dependents)
{
Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout has invalid dependent: " + dependent), LogType.Info.ToString());
continue;
if (!_cacheManager.IsValidPath(dependent))
{
invalidLayouts.Add(layout.id);
Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout has invalid dependent: " + dependent), LogType.Info.ToString());
continue;
}
}
}

// Add to the valid layout ids
validLayoutIds.Add(layout.id);

// If this is the default, skip it
if (layout.NodeName == "default")
{
Expand Down Expand Up @@ -466,6 +484,21 @@ private void LoadScheduleFromFile()
}
}

// Look for dependents nodes
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.Name == "dependents")
{
foreach (XmlNode dependent in childNode.ChildNodes)
{
if (dependent.Name == "file")
{
temp.Dependents.Add(dependent.InnerText);
}
}
}
}

_layoutSchedule.Add(temp);
}
}
Expand Down
12 changes: 7 additions & 5 deletions Media/CefWebMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CefWebMedia(RegionOptions options)
_filePath = ApplicationSettings.Default.LibraryPath + @"\" + _options.mediaid + ".htm";
}

Color backgroundColor = ColorTranslator.FromHtml(_options.backgroundColor);
Color backgroundColor = ColorTranslator.FromHtml(_options.Dictionary.Get("backgroundColor", _options.backgroundColor));

CefBrowserSettings settings = new CefBrowserSettings();
settings.BackgroundColor = new CefColor(backgroundColor.A, backgroundColor.R, backgroundColor.G, backgroundColor.B);
Expand Down Expand Up @@ -216,14 +216,15 @@ private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourc

// Handle the background
String bodyStyle;
String backgroundColor = _options.Dictionary.Get("backgroundColor", _options.backgroundColor);

if (_options.backgroundImage == null || _options.backgroundImage == "")
{
bodyStyle = "background-color:" + _options.backgroundColor + " ;";
bodyStyle = "background-color:" + backgroundColor + " ;";
}
else
{
bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + _options.backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
}

string html = cachedFile.Replace("</head>", "<style type='text/css'>body {" + bodyStyle + " }</style></head>");
Expand Down Expand Up @@ -274,14 +275,15 @@ private void UpdateCacheIfNecessary()
{
// Handle the background
String bodyStyle;
String backgroundColor = _options.Dictionary.Get("backgroundColor", _options.backgroundColor);

if (_options.backgroundImage == null || _options.backgroundImage == "")
{
bodyStyle = "background-color:" + _options.backgroundColor + " ;";
bodyStyle = "background-color:" + backgroundColor + " ;";
}
else
{
bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + _options.backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
}

string html = cachedFile.Replace("</head>", "<style type='text/css'>body {" + bodyStyle + " }</style></head>");
Expand Down
10 changes: 6 additions & 4 deletions Media/IeWebMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourc

// Handle the background
String bodyStyle;
String backgroundColor = _options.Dictionary.Get("backgroundColor", _options.backgroundColor);

if (_options.backgroundImage == null || _options.backgroundImage == "")
{
bodyStyle = "background-color:" + _options.backgroundColor + " ;";
bodyStyle = "background-color:" + backgroundColor + " ;";
}
else
{
bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + _options.backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
}

string html = cachedFile.Replace("</head>", "<style type='text/css'>body {" + bodyStyle + " }</style></head>");
Expand Down Expand Up @@ -264,14 +265,15 @@ private void UpdateCacheIfNecessary()
{
// Handle the background
String bodyStyle;
String backgroundColor = _options.Dictionary.Get("backgroundColor", _options.backgroundColor);

if (_options.backgroundImage == null || _options.backgroundImage == "")
{
bodyStyle = "background-color:" + _options.backgroundColor + " ;";
bodyStyle = "background-color:" + backgroundColor + " ;";
}
else
{
bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + _options.backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;";
}

string html = cachedFile.Replace("</head>", "<style type='text/css'>body {" + bodyStyle + " }</style></head>");
Expand Down
Loading

0 comments on commit 12f3404

Please sign in to comment.