179 lines
4.8 KiB
C#
179 lines
4.8 KiB
C#
using DocumentFormat.OpenXml.InkML;
|
|
using HtmlAgilityPack;
|
|
using MailKit;
|
|
using Microsoft.Net.Http.Headers;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Helpers;
|
|
using Sarand.Net.Standard.Base.Net;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using Saxonite.Net.Core.Web.Base.Controllers;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using Saxonite.Net.Standard.Base.Bus.Reference;
|
|
using Saxonite.Net.Standard.Base.Mgr.Reference;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
|
|
namespace Saxonite.Net.Core.Web.Base.Procs
|
|
{
|
|
//======================================================================
|
|
public partial class SaxOrganisationEventsLookup : SaxProcess_Web
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
public enum Task
|
|
{
|
|
LookupEvents
|
|
}
|
|
|
|
public new class Config : SaxProcess_Web.Config
|
|
{
|
|
public Config(SaxSessionContext sessionContext, DbUpdateInfo dbUpdateInfo) : base(sessionContext, dbUpdateInfo)
|
|
{ }
|
|
/// <summary>Organisations.</summary>
|
|
public HashSet<SysId> OrganisationIdsIncluded { get; } = new HashSet<SysId>();
|
|
/// <summary>Tasks to be run under this instance of the USGA Data Lookup process.</summary>
|
|
public HashSet<Task> Tasks { get; } = new HashSet<Task>();
|
|
}
|
|
|
|
private class EventData
|
|
{
|
|
public DateTime EventAt { get; set; }
|
|
public String Caption { get; set; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private Config config;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SaxOrganisationEventsLookup(Config config) : base(config)
|
|
{
|
|
this.config = config;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
|
|
public override string ProcessDescription => "Organisation Events Lookup";
|
|
|
|
//-------------------------------------------------------------------
|
|
// Run the process.
|
|
protected override bool Run()
|
|
{
|
|
// Execute selected tasks.
|
|
foreach (Task task in config.Tasks)
|
|
{
|
|
switch (task)
|
|
{
|
|
case Task.LookupEvents:
|
|
LookupEventsForOrganisations();
|
|
break;
|
|
}
|
|
if (!OK) break;
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
// Event lookup.
|
|
//------------------------------------------------------------------
|
|
|
|
/// <summary>
|
|
/// Organisation event lookup.
|
|
/// </summary>
|
|
private bool LookupEventsForOrganisations()
|
|
{
|
|
if (!OK) return false;
|
|
|
|
using (DisposableCollection<SacsDisposable> disposableItems = new DisposableCollection<SacsDisposable>())
|
|
{
|
|
foreach (SysId organisationId in config.OrganisationIdsIncluded)
|
|
{
|
|
SaxOrganisation organisation = AccountMgr.GetOrganisationById(organisationId);
|
|
if (organisation == null)
|
|
{
|
|
AddWarningMessage($"Organisation not found for Id: {organisationId}.");
|
|
continue;
|
|
}
|
|
LookupOrganisationEvents(organisation);
|
|
}
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Organisation event lookup.
|
|
/// </summary>
|
|
private bool LookupOrganisationEvents(SaxOrganisation organisation)
|
|
{
|
|
List<EventData> eventsData = new List<EventData>();
|
|
|
|
try
|
|
{
|
|
|
|
|
|
// Query Countries on USGA website.
|
|
CancellationToken cancelToken = new CancellationToken();
|
|
SacsHttpRequestData request = new SacsHttpRequestData(cancelToken) { Url = "https://ncrdb.usga.org/" };
|
|
SacsHttpResponseData response = SacsHttpClient.DoRequest(request).Result;
|
|
String data = response.Data;
|
|
|
|
if (!StringUtil.IsBlank(response.Data))
|
|
{
|
|
// Parse HTML.
|
|
HtmlDocument htmlDoc = new HtmlDocument();
|
|
htmlDoc.LoadHtml(response.Data);
|
|
|
|
// Identify type of event schedule on page.
|
|
HtmlNode mobiscrollEventCalendarNode = htmlDoc.GetElementbyId("mobiscroll-event-calendar");
|
|
if (mobiscrollEventCalendarNode != null)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
if (eventsData.Any())
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc, "querying organisation events", 8)}");
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Organisation event lookup by MobiScroll calendar.
|
|
/// </summary>
|
|
private bool LookupOrganisationEvents_MobiScrollCalendar(SaxOrganisation organisation, List<EventData> eventsData, HtmlNode calendarNode)
|
|
{
|
|
|
|
HtmlNode headerNode = calendarNode.Descendants("div").First(node => node.HasClass("mbsc-calendar-header"));
|
|
if (headerNode != null)
|
|
{
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
}
|
|
//======================================================================
|
|
}
|