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) { } /// Organisations. public HashSet OrganisationIdsIncluded { get; } = new HashSet(); /// Tasks to be run under this instance of the USGA Data Lookup process. public HashSet Tasks { get; } = new HashSet(); } 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. //------------------------------------------------------------------ /// /// Organisation event lookup. /// private bool LookupEventsForOrganisations() { if (!OK) return false; using (DisposableCollection disposableItems = new DisposableCollection()) { 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; } /// /// Organisation event lookup. /// private bool LookupOrganisationEvents(SaxOrganisation organisation) { List eventsData = new List(); 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; } /// /// Organisation event lookup by MobiScroll calendar. /// private bool LookupOrganisationEvents_MobiScrollCalendar(SaxOrganisation organisation, List eventsData, HtmlNode calendarNode) { HtmlNode headerNode = calendarNode.Descendants("div").First(node => node.HasClass("mbsc-calendar-header")); if (headerNode != null) { } return OK; } //------------------------------------------------------------------ } //====================================================================== }