-
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 #219 from xibosignage/develop
v3 R300
- Loading branch information
Showing
46 changed files
with
2,424 additions
and
630 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,162 @@ | ||
/** | ||
* Copyright (C) 2021 Xibo Signage Ltd | ||
* | ||
* Xibo - Digital Signage - http://www.xibo.org.uk | ||
* | ||
* This file is part of Xibo. | ||
* | ||
* Xibo is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* Xibo is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Xibo. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Xml; | ||
|
||
namespace XiboClient.Action | ||
{ | ||
public class Action | ||
{ | ||
public int Id { get; set; } | ||
public string ActionType { get; set; } | ||
public string TriggerType { get; set; } | ||
public string TriggerCode { get; set; } | ||
public int WidgetId { get; set; } | ||
public int SourceId { get; set; } | ||
public string Source { get; set; } | ||
public int TargetId { get; set; } | ||
public string Target { get; set; } | ||
public string LayoutCode { get; set; } | ||
public bool Bubble { get; set; } | ||
public bool IsDrawer { get; set; } | ||
|
||
public Rect Rect { get; set; } | ||
|
||
/// <summary> | ||
/// Create an Action from XmlNode | ||
/// </summary> | ||
/// <param name="node"></param> | ||
/// <returns></returns> | ||
public static Action CreateFromXmlNode(XmlNode node, int top, int left, int width, int height, bool isDrawer) | ||
{ | ||
XmlAttributeCollection attributes = node.Attributes; | ||
|
||
return new Action | ||
{ | ||
Id = int.Parse(attributes["id"].Value), | ||
ActionType = attributes["actionType"]?.Value, | ||
TriggerType = attributes["triggerType"]?.Value, | ||
TriggerCode = attributes["triggerCode"]?.Value, | ||
WidgetId = string.IsNullOrEmpty(attributes["widgetId"]?.Value) ? 0 : int.Parse(attributes["widgetId"].Value), | ||
SourceId = string.IsNullOrEmpty(attributes["sourceId"]?.Value) ? 0 : int.Parse(attributes["sourceId"].Value), | ||
Source = attributes["source"]?.Value, | ||
TargetId = string.IsNullOrEmpty(attributes["targetId"]?.Value) ? 0 : int.Parse(attributes["targetId"].Value), | ||
Target = attributes["target"]?.Value, | ||
LayoutCode = attributes["layoutCode"]?.Value, | ||
Bubble = false, | ||
IsDrawer = isDrawer, | ||
Rect = new Rect(left, top, width, height) | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Create a list of Actions from an XmlNodeList | ||
/// </summary> | ||
/// <param name="nodeList"></param> | ||
/// <returns></returns> | ||
public static List<Action> CreateFromXmlNodeList(XmlNodeList nodeList) | ||
{ | ||
return CreateFromXmlNodeList(nodeList, 0, 0, 0, 0, false); | ||
} | ||
|
||
/// <summary> | ||
/// Create a list of Actions from an XmlNodeList | ||
/// </summary> | ||
/// <param name="nodeList"></param> | ||
/// <returns></returns> | ||
public static List<Action> CreateFromXmlNodeList(XmlNodeList nodeList, bool isDrawer) | ||
{ | ||
return CreateFromXmlNodeList(nodeList, 0, 0, 0, 0, isDrawer); | ||
} | ||
|
||
/// <summary> | ||
/// Create a list of Actions from an XmlNodeList | ||
/// </summary> | ||
/// <param name="nodeList"></param> | ||
/// <returns></returns> | ||
public static List<Action> CreateFromXmlNodeList(XmlNodeList nodeList, int top, int left, int width, int height) | ||
{ | ||
return CreateFromXmlNodeList(nodeList, top, left, width, height, false); | ||
} | ||
|
||
/// <summary> | ||
/// Create a list of Actions from an XmlNodeList | ||
/// </summary> | ||
/// <param name="nodeList"></param> | ||
/// <param name="isDrawer"></param> | ||
/// <returns></returns> | ||
public static List<Action> CreateFromXmlNodeList(XmlNodeList nodeList, int top, int left, int width, int height, bool isDrawer) | ||
{ | ||
List<Action> actions = new List<Action>(); | ||
foreach (XmlNode node in nodeList) | ||
{ | ||
try | ||
{ | ||
actions.Add(CreateFromXmlNode(node, top, left, width, height, isDrawer)); | ||
} | ||
catch (Exception e) | ||
{ | ||
Trace.WriteLine(new LogMessage("Action", "CreateFromXmlNodeList: create from node failed. e = " + e.Message), LogType.Info.ToString()); | ||
} | ||
} | ||
return actions; | ||
} | ||
|
||
/// <summary> | ||
/// Get Priority for action source | ||
/// </summary> | ||
/// <param name="source"></param> | ||
/// <returns></returns> | ||
public static int PriorityForActionSource(string source) | ||
{ | ||
switch (source) | ||
{ | ||
case "widget": | ||
return 1; | ||
|
||
case "region": | ||
return 2; | ||
|
||
case "layout": | ||
return 3; | ||
|
||
default: | ||
return 4; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Is the point inside this action | ||
/// </summary> | ||
/// <param name="point"></param> | ||
/// <returns></returns> | ||
public bool IsPointInside(Point point) | ||
{ | ||
return Rect.Contains(point); | ||
} | ||
} | ||
} |
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
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,100 @@ | ||
/** | ||
* Copyright (C) 2021 Xibo Signage Ltd | ||
* | ||
* Xibo - Digital Signage - http://www.xibo.org.uk | ||
* | ||
* This file is part of Xibo. | ||
* | ||
* Xibo is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* Xibo is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Xibo. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
using Flurl; | ||
using Flurl.Http; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace XiboClient.Action | ||
{ | ||
class HttpCommand | ||
{ | ||
/// <summary> | ||
/// The command | ||
/// </summary> | ||
private Command _command; | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="command">The command to run</param> | ||
public HttpCommand(Command command) | ||
{ | ||
_command = command; | ||
} | ||
|
||
/// <summary> | ||
/// Run the command | ||
/// </summary> | ||
/// <returns></returns> | ||
public async Task<int> RunAsync() | ||
{ | ||
if (!_command.CommandString.StartsWith("http")) | ||
{ | ||
throw new ArgumentException("Not a HTTP command"); | ||
} | ||
|
||
// Split the command string by "pipe" | ||
string[] command = _command.CommandString.Split('|'); | ||
|
||
// The format is | ||
// http|<url>|<content-type|application/x-www-form-urlencoded|application/json|text/plain>|<body-data> | ||
var url = new Url(command[1]); | ||
var contentType = command[2]; | ||
var config = JsonConvert.DeserializeObject<HttpCommandConfig>(command[3]); | ||
|
||
if (!string.IsNullOrEmpty(config.headers)) | ||
{ | ||
url.WithHeaders(JObject.Parse(config.headers)); | ||
} | ||
|
||
IFlurlResponse result; | ||
switch (config.method.ToUpperInvariant()) | ||
{ | ||
case "GET": | ||
result = await url.GetAsync(); | ||
break; | ||
|
||
case "POST": | ||
result = (contentType == "application/json") ? await url.PostJsonAsync(JObject.Parse(config.body)) : await url.PostStringAsync(config.body); | ||
break; | ||
|
||
case "PUT": | ||
result = (contentType == "application/json") ? await url.PutJsonAsync(JObject.Parse(config.body)) : await url.PutStringAsync(config.body); | ||
break; | ||
|
||
case "DELETE": | ||
result = await url.DeleteAsync(); | ||
break; | ||
|
||
default: | ||
throw new Exception("Unsupported method: " + config.method); | ||
} | ||
|
||
return result.StatusCode; | ||
} | ||
} | ||
} |
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,35 @@ | ||
/** | ||
* Copyright (C) 2021 Xibo Signage Ltd | ||
* | ||
* Xibo - Digital Signage - http://www.xibo.org.uk | ||
* | ||
* This file is part of Xibo. | ||
* | ||
* Xibo is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* Xibo is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Xibo. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace XiboClient.Action | ||
{ | ||
class HttpCommandConfig | ||
{ | ||
public string method; | ||
public string headers; | ||
public string body; | ||
} | ||
} |
Oops, something went wrong.