-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from xibosignage/develop
1.8 Series stable release
- Loading branch information
Showing
126 changed files
with
3,889 additions
and
11,004 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
} |
Oops, something went wrong.