Skip to content

Commit

Permalink
Merge pull request #312 from xibosignage/develop
Browse files Browse the repository at this point in the history
Release v4 R400
  • Loading branch information
dasgarner authored Sep 4, 2023
2 parents a6fa473 + 51549ea commit 99844c5
Show file tree
Hide file tree
Showing 37 changed files with 1,165 additions and 287 deletions.
25 changes: 23 additions & 2 deletions Adspace/ExchangeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void Configure()
if (lastFillDate < DateTime.Now.AddMinutes(-3))
{
// Fill our ad buffet
Fill(true);
Fill(true, false, null);
}

// Should we also prefetch?
Expand Down Expand Up @@ -350,11 +350,24 @@ public void Prefetch()
}
}

/// <summary>
/// Fill request for widget
/// </summary>
public void FillForWidget(string partner)
{
if (CountAvailableAds <= 1)
{
Fill(true, true, null);
}
}

/// <summary>
/// Fill the ad buffet
/// </summary>
/// <param name="force"></param>
private void Fill(bool force)
/// <param name="isUseWidget"></param>
/// <param name="partner"></param>
private void Fill(bool force, bool isUseWidget, string partner)
{
lastFillDate = DateTime.Now;

Expand All @@ -370,6 +383,14 @@ private void Fill(bool force)
.AppendPathSegment(ApplicationSettings.Default.HardwareKey)
.SetQueryParam("ownerKey", ApplicationSettings.Default.ServerUri);

// Are we requesting for a widget?
if (isUseWidget)
{
url = url
.SetQueryParam("isUseWidget", 1)
.SetQueryParam("partner", partner);
}

if (ClientInfo.Instance.CurrentGeoLocation != null && !ClientInfo.Instance.CurrentGeoLocation.IsUnknown)
{
url.SetQueryParam("lat", ClientInfo.Instance.CurrentGeoLocation.Latitude)
Expand Down
4 changes: 4 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,18 @@ private static void RunClient(bool screenSaver)
{
Trace.WriteLine(new LogMessage("Main", "Client Started"), LogType.Info.ToString());

#if !DEBUG
KeyInterceptor.SetHook();
MouseInterceptor.SetHook();
#endif

MainWindow windowMain = new MainWindow(screenSaver);
windowMain.ShowDialog();

#if !DEBUG
KeyInterceptor.UnsetHook();
MouseInterceptor.UnsetHook();
#endif
}

#region Exception Handlers
Expand Down
2 changes: 2 additions & 0 deletions Control/EmbeddedServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ private WebServer CreateWebServer(string url)
.WithController(() => new HookController(this)))
.WithWebApi("/duration", m => m
.WithController(() => new DurationController(this)))
.WithWebApi("/fault", m => m
.WithController(() => new FaultController()))
.WithModule(new RestrictiveFileModule("/", new FileSystemProvider(ApplicationSettings.Default.LibraryPath, false), paths), m => m
.ContentCaching = false);

Expand Down
73 changes: 73 additions & 0 deletions Control/FaultController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright (C) 2023 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 EmbedIO.Routing;
using EmbedIO;
using EmbedIO.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Runtime.Remoting.Contexts;

namespace XiboClient.Control
{
internal class FaultController : WebApiController
{
[Route(HttpVerbs.Post, "/")]
public async Task<string> Fault()
{
if (!HttpContext.Request.IsLocal)
{
throw HttpException.Forbidden();
}

try
{
var data = await HttpContext.GetRequestDataAsync<FaultRequest>();

// Do some work to get from the key to the layoutId/widgetId
if (string.IsNullOrEmpty(data.key) || !data.key.Contains("_"))
{
throw new Exception("Invalid key, must be in the format xiboIC_<widgetId>");
}

string[] splitKey = data.key.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
string widgetId = splitKey[1];

CacheManager.Instance.AddUnsafeWidget(
(UnsafeFaultCodes)data.code,
widgetId,
data.reason,
data.ttl
);
}
catch (Exception e)
{
LogMessage.Error("FaultController", "Fault", "Trigger: unable to parse request: " + e.Message);
throw HttpException.NotAcceptable();
}

return string.Empty;
}
}
}
36 changes: 36 additions & 0 deletions Control/FaultRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2023 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.Control
{
class FaultRequest
{
public int code { get; set; }
public string key { get; set; }
public int ttl { get; set; }
public string reason { get; set; }
}
}
14 changes: 13 additions & 1 deletion Control/InfoController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2021 Xibo Signage Ltd
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
Expand All @@ -22,6 +22,7 @@
using EmbedIO.Routing;
using EmbedIO.WebApi;
using Newtonsoft.Json.Linq;
using System;
using System.Text;
using XiboClient.Log;

Expand Down Expand Up @@ -62,6 +63,17 @@ public void GetInfo()
jObject.Add("longitude", null);
}

#if DEBUG
jObject.Add("scheduleStatus", ClientInfo.Instance.ScheduleStatus);
jObject.Add("requiredFileStatus", ClientInfo.Instance.RequiredFilesStatus);
jObject.Add("xmrStatus", ClientInfo.Instance.XmrSubscriberStatus);
jObject.Add("currentlyPlaying", ClientInfo.Instance.CurrentlyPlaying);
jObject.Add("controlCount", ClientInfo.Instance.ControlCount);
jObject.Add("scheduleManagerStatus", ClientInfo.Instance.ScheduleManagerStatus);
jObject.Add("unsafeList", ClientInfo.Instance.UnsafeList);
jObject.Add("requiredFileList", ClientInfo.Instance.RequiredFilesList);
#endif

writer.Write(jObject.ToString());
}
}
Expand Down
7 changes: 4 additions & 3 deletions Logic/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ private static readonly Lazy<ApplicationSettings>
/// </summary>
private List<string> ExcludedProperties;

public string ClientVersion { get; } = "3 R310.1";
public string Version { get; } = "6";
public int ClientCodeVersion { get; } = 310;
public string ClientVersion { get; } = "4 R400.6";
public string Version { get; } = "7";
public int ClientCodeVersion { get; } = 400;

private ApplicationSettings()
{
Expand Down Expand Up @@ -374,6 +374,7 @@ public void PopulateFromXml(XmlDocument document)
public bool ForceHttps { get; set; }
public bool UseFFmpeg { get; set; }
public bool UseFFmpegForHls { get; set; }
public bool AllowSingleSignOnUsingOSPrimaryAccount { get; set; }

public int LibraryAgentInterval { get; set; }

Expand Down
95 changes: 87 additions & 8 deletions Logic/CacheManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2021 Xibo Signage Ltd
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
Expand Down Expand Up @@ -197,11 +197,12 @@ public void Add(string path, string md5)
}

// We need to generate the MD5 and store it for later
Md5Resource md5Resource = new Md5Resource();

md5Resource.path = path;
md5Resource.md5 = md5;
md5Resource.cacheDate = DateTime.Now;
Md5Resource md5Resource = new Md5Resource
{
path = path,
md5 = md5,
cacheDate = DateTime.Now
};

// Add the resource to the collection
_files.Add(md5Resource);
Expand Down Expand Up @@ -348,6 +349,46 @@ public void Regenerate()

#region Unsafe List

/// <summary>
/// Add an unsafe widget to the list
/// </summary>
/// <param name="code"></param>
/// <param name="widgetId"></param>
/// <param name="reason"></param>
/// <param name="ttl"></param>
public void AddUnsafeWidget(UnsafeFaultCodes code, string widgetId, string reason, int ttl)
{
if (ttl == 0)
{
ttl = 86400;
}

try
{
UnsafeItem item = _unsafeItems
.Where(i => i.Type == UnsafeItemType.Widget && i.Id == widgetId)
.First();

item.DateTime = DateTime.Now;
item.Code = code;
item.Reason = reason;
}
catch
{
_unsafeItems.Add(new UnsafeItem
{
DateTime = DateTime.Now,
Type = UnsafeItemType.Widget,
Code = code,
Id = widgetId,
Reason = reason,
Ttl = ttl
});
}

ClientInfo.Instance.UpdateUnsafeList(UnsafeListAsString());
}

/// <summary>
/// Add an unsafe item to the list
/// </summary>
Expand Down Expand Up @@ -493,6 +534,43 @@ public bool IsUnsafeMedia(string mediaId)
return found;
}

/// <summary>
/// Is the provided widgetId unsafe?
/// </summary>
/// <param name="widgetId"></param>
/// <returns></returns>
public bool IsUnsafeWidget(string widgetId)
{
bool updateList = false;
bool found = false;

for (int i = _unsafeItems.Count - 1; i >= 0; i--)
{
UnsafeItem item = _unsafeItems[i];
if (item.Type == UnsafeItemType.Widget && item.Id == widgetId)
{
// Test the Ttl
if (DateTime.Now > item.DateTime.AddSeconds(item.Ttl))
{
_unsafeItems.RemoveAt(i);
updateList = true;
}
else
{
found = true;
break;
}
}
}

if (updateList)
{
ClientInfo.Instance.UpdateUnsafeList(UnsafeListAsString());
}

return found;
}

/// <summary>
/// Get the unsafe list represented as a string
/// </summary>
Expand All @@ -502,7 +580,7 @@ private string UnsafeListAsString()
string list = "";
foreach (UnsafeItem item in _unsafeItems)
{
list += item.Type.ToString() + ": " + item.LayoutId + ", [" + (int)item.Code + "] " + item.Reason + ", ttl: " + item.Ttl + Environment.NewLine;
list += item.Type.ToString() + ": " + item.Id + ", [" + (int)item.Code + "] " + item.Reason + ", ttl: " + item.Ttl + Environment.NewLine;
}
return list;
}
Expand Down Expand Up @@ -751,7 +829,8 @@ public enum UnsafeFaultCodes
ImageDecode=3001,
ImageOutOfMemory=3002,
RemteResourceFailed=4404,
XlfNoContent=5000
XlfNoContent=5000,
XlfNoWidgetData=5001
}

/// <summary>
Expand Down
Loading

0 comments on commit 99844c5

Please sign in to comment.