Skip to content

Commit

Permalink
Merge pull request #45 from xibosignage/develop
Browse files Browse the repository at this point in the history
1.8 Series stable release
  • Loading branch information
dasgarner authored Mar 21, 2017
2 parents 23a3c8c + 0214193 commit daf318f
Show file tree
Hide file tree
Showing 126 changed files with 3,889 additions and 11,004 deletions.
96 changes: 96 additions & 0 deletions Action/Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace XiboClient.Logic
{
[Serializable]
public class Command
{
public string Code;
public string CommandString;
public string Validation;

public bool notifyStatus()
{
return !string.IsNullOrEmpty(Validation);
}

/// <summary>
/// Run the Command
/// </summary>
/// <returns>true on success</returns>
public bool Run()
{
if (string.IsNullOrEmpty(CommandString))
throw new ArgumentNullException("Command string is empty, please check your Display Profile " + Code + " command for a valid command string.");

// Parse the command string to work out how we should run this command.
if (CommandString.StartsWith("rs232"))
{
Rs232Command rs232 = new Rs232Command(this);
string line = rs232.Run();

if (notifyStatus())
{
return line == Validation;
}
else
{
return true;
}
}
else
{
// Process with CMD
using (Process process = new Process())
{
ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C " + CommandString;
startInfo.UseShellExecute = false;

if (notifyStatus())
startInfo.RedirectStandardOutput = true;

process.StartInfo = startInfo;
process.Start();

if (notifyStatus())
{
string line = "";
while (!process.StandardOutput.EndOfStream)
{
line += process.StandardOutput.ReadLine();
}

return line == Validation;
}
else
return true;
}
}
}

/// <summary>
/// Get a command from Application Settings based on its Command Code
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public static Command GetByCode(string code)
{
foreach (Command command in ApplicationSettings.Default.Commands)
{
if (command.Code == code)
return command;
}

throw new KeyNotFoundException("Command Not Found");
}
}
}
82 changes: 82 additions & 0 deletions Action/LayoutChangePlayerAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XiboClient.Action
{
class LayoutChangePlayerAction : PlayerActionInterface
{
public const string Name = "changeLayout";

public int layoutId;
public int duration;
public bool downloadRequired;
public string changeMode;
public string createdDt;

private int _playCount;
private Guid _id;

public LayoutChangePlayerAction()
{
_playCount = 0;
}

/// <summary>
/// Get Action Name
/// </summary>
/// <returns></returns>
public string GetActionName()
{
return Name;
}

/// <summary>
/// Layout change id
/// </summary>
/// <returns></returns>
public Guid GetId()
{
if (_id == null || _id == Guid.Empty)
_id = Guid.NewGuid();

return _id;
}

/// <summary>
/// Is a download required.
/// </summary>
/// <returns></returns>
public bool IsDownloadRequired()
{
return downloadRequired;
}

/// <summary>
/// Set that this action has been played
/// </summary>
public void SetPlayed()
{
_playCount++;
}

/// <summary>
/// Has this change action been serviced?
/// </summary>
/// <returns></returns>
public bool IsServiced()
{
if (duration == 0)
{
return (_playCount > 0);
}
else
{
// Have we played for our entire duration.
DateTime date = DateTime.Parse(createdDt);
return (date.AddSeconds(duration) < DateTime.Now);
}
}
}
}
60 changes: 60 additions & 0 deletions Action/OverlayLayoutPlayerAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XiboClient.Action
{
class OverlayLayoutPlayerAction : PlayerActionInterface
{
public const string Name = "overlayLayout";

public int layoutId;
public int duration;
public bool downloadRequired;
public string createdDt;

private Guid _id;

/// <summary>
/// Get Action Name
/// </summary>
/// <returns></returns>
public string GetActionName()
{
return Name;
}

/// <summary>
/// Layout change id
/// </summary>
/// <returns></returns>
public Guid GetId()
{
if (_id == null || _id == Guid.Empty)
_id = Guid.NewGuid();

return _id;
}

/// <summary>
/// Is a download required.
/// </summary>
/// <returns></returns>
public bool IsDownloadRequired()
{
return downloadRequired;
}

/// <summary>
/// Has this change action been serviced?
/// </summary>
/// <returns></returns>
public bool IsServiced()
{
// Have we played for our entire duration.
DateTime date = DateTime.Parse(createdDt);
return (date.AddSeconds(duration) < DateTime.Now);
}
}
}
20 changes: 20 additions & 0 deletions Action/PlayerAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XiboClient.Action
{
class PlayerAction : PlayerActionInterface
{
public string action;

public DateTime createdDt;
public int ttl;

public String GetActionName()
{
return action;
}
}
}
16 changes: 16 additions & 0 deletions Action/PlayerActionInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XiboClient.Action
{
interface PlayerActionInterface
{
/// <summary>
/// Get Action Name
/// </summary>
/// <returns></returns>
String GetActionName();
}
}
17 changes: 17 additions & 0 deletions Action/RevertToSchedulePlayerAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XiboClient.Action
{
class RevertToSchedulePlayerAction : PlayerActionInterface
{
public const string Name = "revertToSchedule";

public string GetActionName()
{
return Name;
}
}
}
91 changes: 91 additions & 0 deletions Action/Rs232Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Ports;
using System.Linq;
using System.Text;

namespace XiboClient.Logic
{
public class Rs232Command
{
private Command _command;

private SerialPort _port;
private string _toSend;

public Rs232Command(Command command)
{
_command = command;
}

/// <summary>
/// Run the command
/// throws an exception if we cannot open or write to the port
/// </summary>
public string Run()
{
string response = "";

// 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();

try
{
// Write our data stream
_port.Write(_toSend);

// Read
if (_command.notifyStatus())
{
_port.ReadTimeout = 5000;
response = _port.ReadLine();
}
}
catch (Exception e)
{
Trace.WriteLine(new LogMessage("CommandRs232 - run", e.Message), LogType.Error.ToString());
}
finally
{
// Close the port
_port.Close();
}

return response;
}

/// <summary>
/// Parses the command string
/// </summary>
private void parse()
{
if (!_command.CommandString.StartsWith("rs232"))
throw new ArgumentException("Not a RS232 command");

// Split the command string by "space"
string[] command = _command.CommandString.Split('|');

// The second part of the string is our comma separated connection string
// Port,Baud,Data,Parity,Stop,Flow
string[] connection = command[1].Split(',');

_port = new SerialPort();
_port.PortName = connection[0];
_port.BaudRate = Convert.ToInt32(connection[1]);
_port.DataBits = Convert.ToInt16(connection[2]);
_port.Parity = (Parity)Enum.Parse(typeof(Parity), connection[3]);
_port.StopBits = (StopBits)Enum.Parse(typeof(StopBits), connection[4]);
_port.Handshake = (Handshake)Enum.Parse(typeof(Handshake), connection[5]);

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

0 comments on commit daf318f

Please sign in to comment.