Skip to content

Commit

Permalink
Merge pull request #242 from xibosignage/develop
Browse files Browse the repository at this point in the history
Release v3 R302
  • Loading branch information
dasgarner authored Jan 18, 2022
2 parents 4aec70b + 9cd9f06 commit 0210eff
Show file tree
Hide file tree
Showing 40 changed files with 2,155 additions and 213 deletions.
4 changes: 4 additions & 0 deletions Action/XmrSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ private void processMessage(NetMQMessage message, AsymmetricCipherKeyPair rsaKey
OnAction?.Invoke(JsonConvert.DeserializeObject<TriggerWebhookAction>(opened));
break;

case "purgeAll":
OnAction?.Invoke(action);
break;

default:
Trace.WriteLine(new LogMessage("XmrSubscriber - Run", "Unknown Message: " + action.action), LogType.Info.ToString());
break;
Expand Down
129 changes: 129 additions & 0 deletions Adspace/Ad.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* 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 GeoJSON.Net.Contrib.MsSqlSpatial;
using GeoJSON.Net.Feature;
using GeoJSON.Net.Geometry;
using Microsoft.SqlServer.Types;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Device.Location;
using System.Diagnostics;

namespace XiboClient.Adspace
{
public class Ad
{
public string Id;
public string AdId;
public string Title;
public string CreativeId;
public string Duration;
public string File;
public string Type;
public string XiboType;
public int Width;
public int Height;

public string Url;
public List<string> ImpressionUrls = new List<string>();
public List<string> ErrorUrls = new List<string>();

public bool IsWrapper;
public int CountWraps = 0;
public string AllowedWrapperType;
public string AllowedWrapperDuration;

public bool IsGeoAware = false;
public string GeoLocation = "";

public double AspectRatio
{
get
{
return (double)Width / Height;
}
}

/// <summary>
/// Get the duration in seconds
/// </summary>
/// <returns></returns>
public int GetDuration()
{
// Duration is a string
return (int)TimeSpan.Parse(Duration).TotalSeconds;
}

/// <summary>
/// Download this ad
/// </summary>
public void Download()
{
// We should download it.
new Url(Url).DownloadFileAsync(ApplicationSettings.Default.LibraryPath, File).ContinueWith(t =>
{
CacheManager.Instance.Add(File, CacheManager.Instance.GetMD5(File));
}, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion);
}

/// <summary>
/// Set whether or not this GeoSchedule is active.
/// </summary>
/// <param name="geoCoordinate"></param>
/// <returns></returns>
public bool IsGeoActive(GeoCoordinate geoCoordinate)
{
if (!IsGeoAware)
{
return true;
}
else if (geoCoordinate == null || geoCoordinate.IsUnknown)
{
return false;
}
else
{
try
{
// Current location.
Point current = new Point(new Position(geoCoordinate.Latitude, geoCoordinate.Longitude));

// Test against the geo location
var geo = JsonConvert.DeserializeObject<Feature>(GeoLocation);

// Use SQL spatial helper to calculate intersection or not
SqlGeometry polygon = (geo.Geometry as Polygon).ToSqlGeometry();

return current.ToSqlGeometry().STIntersects(polygon).Value;
}
catch (Exception e)
{
Trace.WriteLine(new LogMessage("ScheduleItem", "SetIsGeoActive: Cannot parse geo location: e = " + e.Message), LogType.Audit.ToString());
}
}

return false;
}
}
}
40 changes: 40 additions & 0 deletions Adspace/AdspaceNoAdException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Xibo - Digital Signage - http://www.xibo.org.uk
* Copyright (C) 2021 Xibo Signage Ltd
*
* 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.Adspace
{
class AdspaceNoAdException : Exception
{
public AdspaceNoAdException()
{

}

public AdspaceNoAdException(string message) : base(message)
{

}
}
}
Loading

0 comments on commit 0210eff

Please sign in to comment.