This commit is contained in:
2024-06-13 14:29:58 +01:00
parent 2f6395485a
commit 60427e8230
114 changed files with 2176 additions and 1124 deletions
@@ -2,6 +2,7 @@
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;
@@ -11,6 +12,7 @@ using Sarand.Net.Standard.Base.Helpers;
using Sarand.Net.Standard.Base.Net;
using Sarand.Net.Standard.Base.Utils;
using Saxonite.Net.Standard.Base.App;
using Saxonite.Net.Standard.Base.Bus.Reference;
using Saxonite.Net.Standard.Base.Mgr.Reference;
using System;
using System.Collections.Generic;
@@ -108,8 +110,8 @@ namespace Saxonite.Net.Core.Web.Base.Procs
public SysId CourseId { get; }
public SysId MarkerId { get; set; }
public string Caption { get { return StringUtil.TrimWhitespace(StringUtil.OnBlank(Tee) + " " + StringUtil.OnBlank(HolesCaption) + " " + StringUtil.OnBlank(Gender)); } }
public short Holes { get; }
public string HolesCaption { get; }
public short Holes { get; set; }
public string HolesCaption { get; set; }
public string Tee { get; set; }
public string Gender { get; set; }
public short SlopeRating { get; set; }
@@ -117,15 +119,16 @@ namespace Saxonite.Net.Core.Web.Base.Procs
public decimal CourseRating { get; set; }
public decimal BogeyRating { get; set; }
public short Length { get; set; }
public bool IsValid()
public bool IsValid(bool ignorePar = false)
{
if (!SysId.IsValid(CourseId)) return false;
if (!SysId.IsValid(MarkerId)) return false;
// 9 hole markers do not have there own Id.
//if (!SysId.IsValid(MarkerId)) return false;
if (Holes < 1) return false;
if (StringUtil.IsBlank(Tee)) return false;
if (StringUtil.IsBlank(Gender)) return false;
if (SlopeRating == 0) return false;
if (Par == 0) return false;
if (!ignorePar && Par == 0) return false;
if (CourseRating == 0) return false;
return true;
}
@@ -240,7 +243,7 @@ namespace Saxonite.Net.Core.Web.Base.Procs
try
{
// Query countries on USGA website.
// 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;
@@ -285,7 +288,7 @@ namespace Saxonite.Net.Core.Web.Base.Procs
countryData.CountryName = usgaCountry.Name;
countriesData.Add(countryData);
}
ReferenceGolfMgr.BulkUpdateUsgaCountries(countriesData, config.DbUpdateInfo);
ReferenceGolfMgr.BulkUpdateUsgaCountries(countriesData, DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA countries: {ReferenceGolfMgr.ErrorStateMessage}.");
@@ -308,77 +311,95 @@ namespace Saxonite.Net.Core.Web.Base.Procs
UsgaRequestData usgaRequestData = GetUsgaRequestData();
try
using (DisposableCollection<SacsDisposable> disposableItems = new DisposableCollection<SacsDisposable>())
{
// Query countries on USGA website.
CancellationToken cancelToken = new CancellationToken();
SacsHttpRequestData request = new SacsHttpRequestData(cancelToken) { Url = "https://ncrdb.usga.org/NCRListing?handler=LoadStates" };
// Headers.
request.RequestHeaders.Add(HeaderNames.Accept, "*/*");
request.RequestHeaders.Add(HeaderNames.AcceptEncoding, "gzip, deflate, br, zstd");
request.RequestHeaders.Add(HeaderNames.AcceptLanguage, "en-GB,en;q=0.9");
request.RequestHeaders.Add(HeaderNames.DNT, "1");
request.RequestHeaders.Add(HeaderNames.Origin, "https://ncrdb.usga.org/");
request.RequestHeaders.Add("Priority", "u=1, i");
request.RequestHeaders.Add(HeaderNames.Referer, "https://ncrdb.usga.org/");
if (!StringUtil.IsBlank(usgaRequestData.RequestVerificationToken))
request.RequestHeaders.Add("Requestverificationtoken", usgaRequestData.RequestVerificationToken);
// Content.
request.FormData.Add(new KeyValuePair<string, string>("countryCode", countryCode));
request.ContentHeaders.Add(HeaderNames.ContentType, "application/x-www-form-urlencoded; charset=UTF-8");
// Request.
SacsHttpResponseData response = SacsHttpClient.DoRequest(request).Result;
String data = response.Data;
if (!StringUtil.IsBlank(response.Data))
// Retrieve and validate country.
SaxGolfUsgaCountry usgaCountry = ReferenceGolfMgr.GetUsgaCountry(new SaxGolfUsgaCountry.Params() { CountryCodeFull = countryCode });
disposableItems.Add(usgaCountry);
if (usgaCountry == null)
{
dynamic provincesJson = SacsJsonHelper.DeserializeJsonObject(response.Data);
if (provincesJson is JArray)
SaLogger.Warn($"{SysUtil.Fn} USGA Country not found for code '{countryCode}'.");
return usgaProvinces;
}
try
{
// Query Provinces for Country on USGA website.
CancellationToken cancelToken = new CancellationToken();
SacsHttpRequestData request = new SacsHttpRequestData(cancelToken) { Url = "https://ncrdb.usga.org/NCRListing?handler=LoadStates" };
// Headers.
request.RequestHeaders.Add(HeaderNames.Accept, "*/*");
request.RequestHeaders.Add(HeaderNames.AcceptEncoding, "gzip, deflate, br, zstd");
request.RequestHeaders.Add(HeaderNames.AcceptLanguage, "en-GB,en;q=0.9");
request.RequestHeaders.Add(HeaderNames.DNT, "1");
request.RequestHeaders.Add(HeaderNames.Origin, "https://ncrdb.usga.org/");
request.RequestHeaders.Add("Priority", "u=1, i");
request.RequestHeaders.Add(HeaderNames.Referer, "https://ncrdb.usga.org/");
if (!StringUtil.IsBlank(usgaRequestData.RequestVerificationToken))
request.RequestHeaders.Add("Requestverificationtoken", usgaRequestData.RequestVerificationToken);
// Content.
request.FormData.Add(new KeyValuePair<string, string>("countryCode", countryCode));
request.ContentHeaders.Add(HeaderNames.ContentType, "application/x-www-form-urlencoded; charset=UTF-8");
// Request.
SacsHttpResponseData response = SacsHttpClient.DoRequest(request).Result;
String data = response.Data;
if (!StringUtil.IsBlank(response.Data))
{
JArray provincesArray = provincesJson as JArray;
foreach (var provinceToken in provincesArray)
dynamic provincesJson = SacsJsonHelper.DeserializeJsonObject(response.Data);
if (provincesJson is JArray)
{
// Province properties.
ProvinceData provinceData = new ProvinceData();
foreach (var propertyToken in provinceToken)
JArray provincesArray = provincesJson as JArray;
foreach (var provinceToken in provincesArray)
{
if (propertyToken is JProperty)
// Province properties.
ProvinceData provinceData = new ProvinceData();
foreach (var propertyToken in provinceToken)
{
JProperty provinceProperty = propertyToken as JProperty;
String propertyName = provinceProperty.Name;
String propertyStringValue = StringUtil.TrimWhitespace(provinceProperty.Value.ToString());
if (propertyName.EqualsCI("text"))
provinceData.Name = propertyStringValue;
else if (propertyName.EqualsCI("value"))
provinceData.Code = propertyStringValue;
else if (propertyName.EqualsCI("group")) { }
else if (propertyName.EqualsCI("selected")) { }
else if (propertyName.EqualsCI("disabled")) { }
if (propertyToken is JProperty)
{
JProperty provinceProperty = propertyToken as JProperty;
String propertyName = provinceProperty.Name;
String propertyStringValue = StringUtil.TrimWhitespace(provinceProperty.Value.ToString());
if (propertyName.EqualsCI("text"))
provinceData.Name = propertyStringValue;
else if (propertyName.EqualsCI("value"))
provinceData.Code = propertyStringValue;
else if (propertyName.EqualsCI("group")) { }
else if (propertyName.EqualsCI("selected")) { }
else if (propertyName.EqualsCI("disabled")) { }
}
}
if (!StringUtil.IsBlank(provinceData.Code) && !provinceData.Code.EqualsCI("(Select)") && !StringUtil.IsBlank(provinceData.Name))
usgaProvinces.Add(provinceData);
}
if (!StringUtil.IsBlank(provinceData.Code) && !provinceData.Code.EqualsCI("(Select)") && !StringUtil.IsBlank(provinceData.Name))
usgaProvinces.Add(provinceData);
}
}
}
// Store provinces.
List<SaxReferenceGolfMgr.UsgaProvinceData> provincesData = new List<SaxReferenceGolfMgr.UsgaProvinceData>();
foreach (ProvinceData usgaProvince in usgaProvinces)
{
SaxReferenceGolfMgr.UsgaProvinceData provinceData = new SaxReferenceGolfMgr.UsgaProvinceData();
provinceData.CountryCode = countryCode;
provinceData.ProvinceCode = usgaProvince.Code;
provinceData.ProvinceName = usgaProvince.Name;
provincesData.Add(provinceData);
// Store provinces.
List<SaxReferenceGolfMgr.UsgaProvinceData> provincesData = new List<SaxReferenceGolfMgr.UsgaProvinceData>();
foreach (ProvinceData usgaProvince in usgaProvinces)
{
SaxReferenceGolfMgr.UsgaProvinceData provinceData = new SaxReferenceGolfMgr.UsgaProvinceData();
provinceData.CountryCode = countryCode;
provinceData.ProvinceCode = usgaProvince.Code;
provinceData.ProvinceName = usgaProvince.Name;
provincesData.Add(provinceData);
}
ReferenceGolfMgr.BulkUpdateUsgaProvinces(provincesData, DbUpdateInfo);
if (!ReferenceGolfMgr.HasErrorState())
{
// Provinces updates OK.
// Clear country 'priority' flag.
usgaCountry.Priority = false;
ReferenceGolfMgr.UpdateUsgaCountry(usgaCountry, DbUpdateInfo);
}
else SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA provinces: {ReferenceGolfMgr.ErrorStateMessage}.");
}
catch (Exception exc)
{
SaLogger.Warn(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc, $"querying USGA provinces for {countryCode}", 0));
}
ReferenceGolfMgr.BulkUpdateUsgaProvinces(provincesData, config.DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA provinces: {ReferenceGolfMgr.ErrorStateMessage}.");
}
catch (Exception exc)
{
SaLogger.Warn(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc, $"querying USGA provinces for {countryCode}", 0));
}
return usgaProvinces;
}
@@ -394,179 +415,205 @@ namespace Saxonite.Net.Core.Web.Base.Procs
UsgaRequestData usgaRequestData = GetUsgaRequestData();
try
using (DisposableCollection<SacsDisposable> disposableItems = new DisposableCollection<SacsDisposable>())
{
// Query countries on USGA website.
CancellationToken cancelToken = new CancellationToken();
SacsHttpRequestData request = new SacsHttpRequestData(cancelToken) { Url = "https://ncrdb.usga.org/NCRListing?handler=LoadCourses" };
// Headers.
request.RequestHeaders.Add(HeaderNames.Accept, "*/*");
request.RequestHeaders.Add(HeaderNames.AcceptEncoding, "gzip, deflate, br, zstd");
request.RequestHeaders.Add(HeaderNames.AcceptLanguage, "en-GB,en;q=0.9");
request.RequestHeaders.Add(HeaderNames.DNT, "1");
request.RequestHeaders.Add(HeaderNames.Origin, "https://ncrdb.usga.org/");
request.RequestHeaders.Add("Priority", "u=1, i");
request.RequestHeaders.Add(HeaderNames.Referer, "https://ncrdb.usga.org/");
if (!StringUtil.IsBlank(usgaRequestData.RequestVerificationToken))
request.RequestHeaders.Add("Requestverificationtoken", usgaRequestData.RequestVerificationToken);
// Content.
request.FormData.Add(new KeyValuePair<string, string>("clubName", ""));
request.FormData.Add(new KeyValuePair<string, string>("clubCity", ""));
request.FormData.Add(new KeyValuePair<string, string>("clubState", provinceCode));
request.FormData.Add(new KeyValuePair<string, string>("clubCountry", countryCode));
request.ContentHeaders.Add(HeaderNames.ContentType, "application/x-www-form-urlencoded; charset=UTF-8");
// Request.
SacsHttpResponseData response = SacsHttpClient.DoRequest(request).Result;
String data = response.Data;
if (!StringUtil.IsBlank(response.Data))
// Retrieve and validate country.
SaxGolfUsgaCountry usgaCountry = ReferenceGolfMgr.GetUsgaCountry(new SaxGolfUsgaCountry.Params() { CountryCodeFull = countryCode });
disposableItems.Add(usgaCountry);
if (usgaCountry == null)
{
HashSet<String> UnrecognisedCourseProperties = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
dynamic coursesJson = SacsJsonHelper.DeserializeJsonObject(response.Data);
if (coursesJson is JArray)
SaLogger.Warn($"{SysUtil.Fn} USGA Country not found for code '{countryCode}'.");
return usgaCourses;
}
// Retrieve and validate province.
SaxGolfUsgaProvince usgaProvince = ReferenceGolfMgr.GetUsgaProvince(new SaxGolfUsgaProvince.Params() { ProvinceCodeFull = provinceCode });
disposableItems.Add(usgaProvince);
if (usgaProvince == null)
{
SaLogger.Warn($"{SysUtil.Fn} USGA Province not found for code '{provinceCode}'.");
return usgaCourses;
}
try
{
// Query Courses for Country & Province on USGA website.
CancellationToken cancelToken = new CancellationToken();
SacsHttpRequestData request = new SacsHttpRequestData(cancelToken) { Url = "https://ncrdb.usga.org/NCRListing?handler=LoadCourses" };
// Headers.
request.RequestHeaders.Add(HeaderNames.Accept, "*/*");
request.RequestHeaders.Add(HeaderNames.AcceptEncoding, "gzip, deflate, br, zstd");
request.RequestHeaders.Add(HeaderNames.AcceptLanguage, "en-GB,en;q=0.9");
request.RequestHeaders.Add(HeaderNames.DNT, "1");
request.RequestHeaders.Add(HeaderNames.Origin, "https://ncrdb.usga.org/");
request.RequestHeaders.Add("Priority", "u=1, i");
request.RequestHeaders.Add(HeaderNames.Referer, "https://ncrdb.usga.org/");
if (!StringUtil.IsBlank(usgaRequestData.RequestVerificationToken))
request.RequestHeaders.Add("Requestverificationtoken", usgaRequestData.RequestVerificationToken);
// Content.
request.FormData.Add(new KeyValuePair<string, string>("clubName", ""));
request.FormData.Add(new KeyValuePair<string, string>("clubCity", ""));
request.FormData.Add(new KeyValuePair<string, string>("clubState", provinceCode));
request.FormData.Add(new KeyValuePair<string, string>("clubCountry", countryCode));
request.ContentHeaders.Add(HeaderNames.ContentType, "application/x-www-form-urlencoded; charset=UTF-8");
// Request.
SacsHttpResponseData response = SacsHttpClient.DoRequest(request).Result;
String data = response.Data;
if (!StringUtil.IsBlank(response.Data))
{
JArray coursesArray = coursesJson as JArray;
foreach (var courseToken in coursesArray)
HashSet<String> UnrecognisedCourseProperties = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
dynamic coursesJson = SacsJsonHelper.DeserializeJsonObject(response.Data);
if (coursesJson is JArray)
{
// Course properties.
CourseData courseData = new CourseData();
foreach (var propertyToken in courseToken)
JArray coursesArray = coursesJson as JArray;
foreach (var courseToken in coursesArray)
{
if (propertyToken is JProperty)
// Course properties.
CourseData courseData = new CourseData();
foreach (var propertyToken in courseToken)
{
JProperty courseProperty = propertyToken as JProperty;
String propertyName = courseProperty.Name;
String propertyStringValue = StringUtil.TrimWhitespace(courseProperty.Value.ToString());
if (propertyName.EqualsCI("courseId"))
courseData.CourseId = propertyStringValue;
else if (propertyName.EqualsCI("legacyCRPCourseId"))
courseData.LegacyCrpCourseId = propertyStringValue;
else if (propertyName.EqualsCI("courseName"))
courseData.CourseName = propertyStringValue;
else if (propertyName.EqualsCI("facilityId"))
courseData.FacilityId = propertyStringValue;
else if (propertyName.EqualsCI("facilityName"))
courseData.FacilityName = propertyStringValue;
else if (propertyName.EqualsCI("fullName"))
courseData.FullName = propertyStringValue;
else if (propertyName.EqualsCI("address1"))
courseData.Address1 = propertyStringValue;
else if (propertyName.EqualsCI("address2"))
courseData.Address2 = propertyStringValue;
else if (propertyName.EqualsCI("city"))
courseData.City = propertyStringValue;
else if (propertyName.EqualsCI("entStateCode"))
courseData.EntProvinceCode = propertyStringValue;
else if (propertyName.EqualsCI("state"))
courseData.ProvinceCode = propertyStringValue;
else if (propertyName.EqualsCI("stateDisplay"))
courseData.Province = propertyStringValue;
else if (propertyName.EqualsCI("country"))
courseData.CountryCode = propertyStringValue;
else if (propertyName.EqualsCI("entCountryCode"))
courseData.EntCountryCode = propertyStringValue;
else if (propertyName.EqualsCI("email"))
courseData.Email = propertyStringValue;
else if (propertyName.EqualsCI("telephone"))
courseData.Telephone = propertyStringValue;
else if (propertyName.EqualsCI("ratings"))
if (propertyToken is JProperty)
{
if (courseProperty.Value.Count() > 0)
courseData.Ratings.Add("");
JProperty courseProperty = propertyToken as JProperty;
String propertyName = courseProperty.Name;
String propertyStringValue = StringUtil.TrimWhitespace(courseProperty.Value.ToString());
if (propertyName.EqualsCI("courseId"))
courseData.CourseId = propertyStringValue;
else if (propertyName.EqualsCI("legacyCRPCourseId"))
courseData.LegacyCrpCourseId = propertyStringValue;
else if (propertyName.EqualsCI("courseName"))
courseData.CourseName = propertyStringValue;
else if (propertyName.EqualsCI("facilityId"))
courseData.FacilityId = propertyStringValue;
else if (propertyName.EqualsCI("facilityName"))
courseData.FacilityName = propertyStringValue;
else if (propertyName.EqualsCI("fullName"))
courseData.FullName = propertyStringValue;
else if (propertyName.EqualsCI("address1"))
courseData.Address1 = propertyStringValue;
else if (propertyName.EqualsCI("address2"))
courseData.Address2 = propertyStringValue;
else if (propertyName.EqualsCI("city"))
courseData.City = propertyStringValue;
else if (propertyName.EqualsCI("entStateCode"))
courseData.EntProvinceCode = propertyStringValue;
else if (propertyName.EqualsCI("state"))
courseData.ProvinceCode = propertyStringValue;
else if (propertyName.EqualsCI("stateDisplay"))
courseData.Province = propertyStringValue;
else if (propertyName.EqualsCI("country"))
courseData.CountryCode = propertyStringValue;
else if (propertyName.EqualsCI("entCountryCode"))
courseData.EntCountryCode = propertyStringValue;
else if (propertyName.EqualsCI("email"))
courseData.Email = propertyStringValue;
else if (propertyName.EqualsCI("telephone"))
courseData.Telephone = propertyStringValue;
else if (propertyName.EqualsCI("ratings"))
{
if (courseProperty.Value.Count() > 0)
courseData.Ratings.Add("");
}
else UnrecognisedCourseProperties.Add(propertyName);
}
else UnrecognisedCourseProperties.Add(propertyName);
}
if (!StringUtil.IsBlank(courseData.CourseId) && !StringUtil.IsBlank(courseData.CourseName))
{
// Populate caption and add to list.
SetCourseCaption(courseData);
usgaCourses.Add(courseData);
}
}
if (!StringUtil.IsBlank(courseData.CourseId) && !StringUtil.IsBlank(courseData.CourseName))
{
// Populate caption and add to list.
SetCourseCaption(courseData);
usgaCourses.Add(courseData);
}
}
if (UnrecognisedCourseProperties.Any())
SaLogger.Warn(SysUtil.Fn + " Unrecognised USGA course properties: " + String.Join(", ", UnrecognisedCourseProperties));
}
if (UnrecognisedCourseProperties.Any())
SaLogger.Warn(SysUtil.Fn + " Unrecognised USGA course properties: " + String.Join(", ", UnrecognisedCourseProperties));
}
// Store countries.
Dictionary<String, SaxReferenceGolfMgr.UsgaCountryData> countriesData = new Dictionary<String, SaxReferenceGolfMgr.UsgaCountryData>();
foreach (CourseData usgaCourse in usgaCourses)
{
SaxReferenceGolfMgr.UsgaCountryData countryData = new SaxReferenceGolfMgr.UsgaCountryData();
countryData.CountryCode = usgaCourse.CountryCode;
countryData.EntCountryCode = usgaCourse.EntCountryCode;
countriesData[countryData.CountryCode] = countryData;
}
ReferenceGolfMgr.BulkUpdateUsgaCountries(countriesData.Values.ToList(), config.DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA countries: {ReferenceGolfMgr.ErrorStateMessage}.");
// Store provinces.
Dictionary<String, SaxReferenceGolfMgr.UsgaProvinceData> provincesData = new Dictionary<String, SaxReferenceGolfMgr.UsgaProvinceData>();
foreach (CourseData usgaCourse in usgaCourses)
{
SaxReferenceGolfMgr.UsgaProvinceData provinceData = new SaxReferenceGolfMgr.UsgaProvinceData();
provinceData.CountryCode = usgaCourse.CountryCode;
provinceData.ProvinceCode = usgaCourse.ProvinceCode;
provinceData.EntProvinceCode = usgaCourse.EntProvinceCode;
provincesData[provinceData.ProvinceCode] = provinceData;
}
ReferenceGolfMgr.BulkUpdateUsgaProvinces(provincesData.Values.ToList(), config.DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA provinces: {ReferenceGolfMgr.ErrorStateMessage}.");
// Store facilities.
Dictionary<SysId, SaxReferenceGolfMgr.UsgaFacilityData> facilitiesData = new Dictionary<SysId, SaxReferenceGolfMgr.UsgaFacilityData>();
foreach (CourseData usgaCourse in usgaCourses)
{
if (StringUtil.IsBlank(usgaCourse.FacilityId)) continue;
SaxReferenceGolfMgr.UsgaFacilityData facilityData = new SaxReferenceGolfMgr.UsgaFacilityData();
facilityData.ProvinceCode = provinceCode;
facilityData.FacilityId = StringUtil.ToSysId(usgaCourse.FacilityId);
facilityData.FacilityName = usgaCourse.FacilityName;
if (!SysId.IsValid(facilityData.FacilityId))
// Store countries.
Dictionary<String, SaxReferenceGolfMgr.UsgaCountryData> countriesData = new Dictionary<String, SaxReferenceGolfMgr.UsgaCountryData>();
foreach (CourseData usgaCourse in usgaCourses)
{
SaLogger.Warn($"{SysUtil.Fn} Invalid Facility Id for {usgaCourse.CourseName}: {usgaCourse.FacilityId}.");
continue;
SaxReferenceGolfMgr.UsgaCountryData countryData = new SaxReferenceGolfMgr.UsgaCountryData();
countryData.CountryCode = usgaCourse.CountryCode;
countryData.EntCountryCode = usgaCourse.EntCountryCode;
countriesData[countryData.CountryCode] = countryData;
}
facilitiesData[facilityData.FacilityId] = facilityData;
}
ReferenceGolfMgr.BulkUpdateUsgaFacilities(facilitiesData.Values.ToList(), config.DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA facilities: {ReferenceGolfMgr.ErrorStateMessage}.");
ReferenceGolfMgr.BulkUpdateUsgaCountries(countriesData.Values.ToList(), DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA countries: {ReferenceGolfMgr.ErrorStateMessage}.");
// Store courses.
Dictionary<SysId, SaxReferenceGolfMgr.UsgaCourseData> coursesData = new Dictionary<SysId, SaxReferenceGolfMgr.UsgaCourseData>();
foreach (CourseData usgaCourse in usgaCourses)
{
if (StringUtil.IsBlank(usgaCourse.CourseId)) continue;
SaxReferenceGolfMgr.UsgaCourseData courseData = new SaxReferenceGolfMgr.UsgaCourseData();
courseData.FacilityId = StringUtil.ToSysId(usgaCourse.FacilityId);
courseData.CourseId = StringUtil.ToSysId(usgaCourse.CourseId);
courseData.LegacyCrpCourseId = StringUtil.ToSysId(usgaCourse.LegacyCrpCourseId);
courseData.Caption = usgaCourse.Caption;
courseData.CourseName = usgaCourse.CourseName;
courseData.FullName = usgaCourse.FullName;
courseData.Address1 = usgaCourse.Address1;
courseData.Address2 = usgaCourse.Address2;
courseData.City = usgaCourse.City;
courseData.Email = usgaCourse.Email;
courseData.Telephone = usgaCourse.Telephone;
if (!SysId.IsValid(courseData.CourseId))
// Store provinces.
Dictionary<String, SaxReferenceGolfMgr.UsgaProvinceData> provincesData = new Dictionary<String, SaxReferenceGolfMgr.UsgaProvinceData>();
foreach (CourseData usgaCourse in usgaCourses)
{
SaLogger.Warn($"{SysUtil.Fn} Invalid Course Id for {usgaCourse.CourseName}: {usgaCourse.CourseId}.");
continue;
SaxReferenceGolfMgr.UsgaProvinceData provinceData = new SaxReferenceGolfMgr.UsgaProvinceData();
provinceData.CountryCode = usgaCourse.CountryCode;
provinceData.ProvinceCode = usgaCourse.ProvinceCode;
provinceData.EntProvinceCode = usgaCourse.EntProvinceCode;
provincesData[provinceData.ProvinceCode] = provinceData;
}
coursesData[courseData.CourseId] = courseData;
ReferenceGolfMgr.BulkUpdateUsgaProvinces(provincesData.Values.ToList(), DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA provinces: {ReferenceGolfMgr.ErrorStateMessage}.");
// Store facilities.
Dictionary<SysId, SaxReferenceGolfMgr.UsgaFacilityData> facilitiesData = new Dictionary<SysId, SaxReferenceGolfMgr.UsgaFacilityData>();
foreach (CourseData usgaCourse in usgaCourses)
{
if (StringUtil.IsBlank(usgaCourse.FacilityId)) continue;
SaxReferenceGolfMgr.UsgaFacilityData facilityData = new SaxReferenceGolfMgr.UsgaFacilityData();
facilityData.ProvinceCode = provinceCode;
facilityData.FacilityId = StringUtil.ToSysId(usgaCourse.FacilityId);
facilityData.FacilityName = usgaCourse.FacilityName;
if (!SysId.IsValid(facilityData.FacilityId))
{
SaLogger.Warn($"{SysUtil.Fn} Invalid Facility Id for {usgaCourse.CourseName}: {usgaCourse.FacilityId}.");
continue;
}
facilitiesData[facilityData.FacilityId] = facilityData;
}
ReferenceGolfMgr.BulkUpdateUsgaFacilities(facilitiesData.Values.ToList(), DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA facilities: {ReferenceGolfMgr.ErrorStateMessage}.");
// Store courses.
Dictionary<SysId, SaxReferenceGolfMgr.UsgaCourseData> coursesData = new Dictionary<SysId, SaxReferenceGolfMgr.UsgaCourseData>();
foreach (CourseData usgaCourse in usgaCourses)
{
if (StringUtil.IsBlank(usgaCourse.CourseId)) continue;
SaxReferenceGolfMgr.UsgaCourseData courseData = new SaxReferenceGolfMgr.UsgaCourseData();
courseData.FacilityId = StringUtil.ToSysId(usgaCourse.FacilityId);
courseData.CourseId = StringUtil.ToSysId(usgaCourse.CourseId);
courseData.LegacyCrpCourseId = StringUtil.ToSysId(usgaCourse.LegacyCrpCourseId);
courseData.Caption = usgaCourse.Caption;
courseData.CourseName = usgaCourse.CourseName;
courseData.FullName = usgaCourse.FullName;
courseData.Address1 = usgaCourse.Address1;
courseData.Address2 = usgaCourse.Address2;
courseData.City = usgaCourse.City;
courseData.Email = usgaCourse.Email;
courseData.Telephone = usgaCourse.Telephone;
if (!SysId.IsValid(courseData.CourseId))
{
SaLogger.Warn($"{SysUtil.Fn} Invalid Course Id for {usgaCourse.CourseName}: {usgaCourse.CourseId}.");
continue;
}
coursesData[courseData.CourseId] = courseData;
}
ReferenceGolfMgr.BulkUpdateUsgaCourses(coursesData.Values.ToList(), DbUpdateInfo);
if (!ReferenceGolfMgr.HasErrorState())
{
// Courses updates OK.
// Clear province 'priority' flag.
usgaProvince.Priority = false;
ReferenceGolfMgr.UpdateUsgaProvince(usgaProvince, DbUpdateInfo);
}
else SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA courses: {ReferenceGolfMgr.ErrorStateMessage}.");
}
catch (Exception exc)
{
SaLogger.Warn(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc, $"querying USGA courses for {countryCode}", 0));
}
ReferenceGolfMgr.BulkUpdateUsgaCourses(coursesData.Values.ToList(), config.DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA courses: {ReferenceGolfMgr.ErrorStateMessage}.");
}
catch (Exception exc)
{
SaLogger.Warn(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc, $"querying USGA courses for {countryCode}", 0));
}
return usgaCourses;
}
@@ -649,196 +696,240 @@ namespace Saxonite.Net.Core.Web.Base.Procs
public int ColIdx_Length { get; set; } = -1;
}
/// <summary>
/// Class to allow markers list to be serialised as 'Markers'.
/// </summary>
private class MarkersData
{
public List<MarkerData> Markers { get; } = new List<MarkerData>();
}
/// <summary>
/// USGA Markers for course.
/// </summary>
public List<MarkerData> LookupUsgaMarkersForCourse(SysId usgaCourseId)
{
List<MarkerData> usgaMarkers = new List<MarkerData>();
if (!SysId.IsValid(usgaCourseId)) return usgaMarkers;
MarkersData markersData = new MarkersData();
if (!SysId.IsValid(usgaCourseId)) return markersData.Markers;
MarkerColumnData markerColumns = new MarkerColumnData();
try
using (DisposableCollection<SacsDisposable> disposableItems = new DisposableCollection<SacsDisposable>())
{
// Query countries on USGA website.
CancellationToken cancelToken = new CancellationToken();
SacsHttpRequestData request = new SacsHttpRequestData(cancelToken) { Url = $"https://ncrdb.usga.org/courseTeeInfo?CourseID={usgaCourseId}" };
SacsHttpResponseData response = SacsHttpClient.DoRequest(request).Result;
String data = response.Data;
if (!StringUtil.IsBlank(response.Data))
// Retrieve and validate course.
SaxGolfUsgaCourse.Params prmCourse = new SaxGolfUsgaCourse.Params();
prmCourse.CourseIdsIncluded.Add(usgaCourseId);
SaxGolfUsgaCourse usgaCourse = ReferenceGolfMgr.GetUsgaCourse(prmCourse);
disposableItems.Add(usgaCourse);
if (usgaCourse == null)
{
// Parse HTML.
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(response.Data);
SaLogger.Warn($"{SysUtil.Fn} USGA Course not found for Id '{usgaCourseId}'.");
return markersData.Markers;
}
// Locate countries list.
HtmlNode teeTableNode = htmlDoc.GetElementbyId("gvTee");
if (teeTableNode != null)
try
{
// Query course markers on USGA website.
CancellationToken cancelToken = new CancellationToken();
SacsHttpRequestData request = new SacsHttpRequestData(cancelToken) { Url = $"https://ncrdb.usga.org/courseTeeInfo?CourseID={usgaCourseId}" };
SacsHttpResponseData response = SacsHttpClient.DoRequest(request).Result;
String data = response.Data;
if (!StringUtil.IsBlank(response.Data))
{
// Identify marker columns.
int teeColumnIdx = -1;
foreach (HtmlNode teeHeaderNode in teeTableNode.SelectNodes("./tr[1]/th"))
// Parse HTML.
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(response.Data);
// Locate countries list.
HtmlNode teeTableNode = htmlDoc.GetElementbyId("gvTee");
if (teeTableNode != null)
{
teeColumnIdx++;
String headerText = StringUtil.TrimWhitespace(WebUtil.HtmlDecode(teeHeaderNode.InnerText));
if (StringUtil.IsBlank(headerText) || headerText.EqualsCI("CH"))
{
// Columns ignored.
}
else if (headerText.EqualsCI("Tee Name")) markerColumns.ColIdx_Tee = teeColumnIdx;
else if (headerText.EqualsCI("Gender")) markerColumns.ColIdx_Gender = teeColumnIdx;
else if (headerText.EqualsCI("Par")) markerColumns.ColIdx_Par = teeColumnIdx;
else if (headerText.EqualsCI("TeeId")) markerColumns.ColIdx_MarkerId = teeColumnIdx;
else if (headerText.EqualsCI("Length")) markerColumns.ColIdx_Length = teeColumnIdx;
// Specific part-course (9 holes) values.
else if (headerText.EqualsCI("RatingF9")) markerColumns.ColIdx_Front9CourseRating = teeColumnIdx;
else if (headerText.EqualsCI("RatingB9")) markerColumns.ColIdx_Back9CourseRating = teeColumnIdx;
else if (headerText.EqualsCI("Front (9)")) markerColumns.ColIdx_Front9 = teeColumnIdx;
else if (headerText.EqualsCI("Back (9)")) markerColumns.ColIdx_Back9 = teeColumnIdx;
else if (headerText.EqualsCI("Bogey Rating (F9)")) markerColumns.ColIdx_Front9BogeyRating = teeColumnIdx;
else if (headerText.EqualsCI("Bogey Rating (B9)")) markerColumns.ColIdx_Back9BogeyRating = teeColumnIdx;
else if (headerText.EqualsCI("Slope (F9)")) markerColumns.ColIdx_Front9SlopeRating = teeColumnIdx;
else if (headerText.EqualsCI("Slope (B9)")) markerColumns.ColIdx_Back9SlopeRating = teeColumnIdx;
// Less specific full-course (commonly 18 holes) values.
else if (headerText.IsMatchCI("Course Rating")) markerColumns.ColIdx_CourseRating = teeColumnIdx;
else if (headerText.IsMatchCI("Bogey Rating")) markerColumns.ColIdx_BogeyRating = teeColumnIdx;
else if (headerText.IsMatchCI("Slope Rating")) markerColumns.ColIdx_SlopeRating = teeColumnIdx;
else SaLogger.Info($"{SysUtil.Fn} Unexpected Marker column header: {headerText}");
}
foreach (HtmlNode teeRowNode in teeTableNode.SelectNodes("./tr[position()>1]"))
{
MarkerData markerData18 = new MarkerData(usgaCourseId, 18, "18");
MarkerData markerDataF9 = new MarkerData(usgaCourseId, 9, "F9");
MarkerData markerDataB9 = new MarkerData(usgaCourseId, 9, "B9");
teeColumnIdx = -1;
foreach (HtmlNode teePropertyNode in teeRowNode.SelectNodes("./td"))
// Identify marker columns.
int teeColumnIdx = -1;
foreach (HtmlNode teeHeaderNode in teeTableNode.SelectNodes("./tr[1]/th"))
{
teeColumnIdx++;
String propertyText = StringUtil.TrimWhitespace(WebUtil.HtmlDecode(teePropertyNode.InnerText));
if (markerColumns.ColIdx_Tee == teeColumnIdx)
String headerText = StringUtil.TrimWhitespace(WebUtil.HtmlDecode(teeHeaderNode.InnerText));
if (StringUtil.IsBlank(headerText) || headerText.EqualsCI("CH"))
{
markerData18.Tee = propertyText;
markerDataF9.Tee = propertyText;
markerDataB9.Tee = propertyText;
}
else if (markerColumns.ColIdx_Gender == teeColumnIdx)
{
markerData18.Gender = propertyText;
markerDataF9.Gender = propertyText;
markerDataB9.Gender = propertyText;
}
else if (markerColumns.ColIdx_Par == teeColumnIdx)
{
markerData18.Par = StringUtil.ToShort(propertyText);
}
else if (markerColumns.ColIdx_CourseRating == teeColumnIdx)
{
markerData18.CourseRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_BogeyRating == teeColumnIdx)
{
markerData18.BogeyRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_SlopeRating == teeColumnIdx)
{
markerData18.SlopeRating = StringUtil.ToShort(propertyText);
}
else if (markerColumns.ColIdx_Front9CourseRating == teeColumnIdx)
{
if (markerDataF9.CourseRating == 0)
markerDataF9.CourseRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_Back9CourseRating == teeColumnIdx)
{
if (markerDataB9.CourseRating == 0)
markerDataB9.CourseRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_Front9 == teeColumnIdx)
{
// Format: CourseRating / SlopeRating.
markerDataF9.CourseRating = StringUtil.ToDecimal(Regex.Replace(propertyText, "\\s*/.*$", ""));
markerDataF9.SlopeRating = StringUtil.ToShort(Regex.Replace(propertyText, "^.*/\\s*", ""));
}
else if (markerColumns.ColIdx_Back9 == teeColumnIdx)
{
// Format: CourseRating / SlopeRating.
markerDataB9.CourseRating = StringUtil.ToDecimal(Regex.Replace(propertyText, "\\s*/.*$", ""));
markerDataB9.SlopeRating = StringUtil.ToShort(Regex.Replace(propertyText, "^.*/\\s*", ""));
}
else if (markerColumns.ColIdx_Front9BogeyRating == teeColumnIdx)
{
markerDataF9.BogeyRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_Back9BogeyRating == teeColumnIdx)
{
markerDataB9.BogeyRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_Front9SlopeRating == teeColumnIdx)
{
if (markerDataF9.SlopeRating == 0)
markerDataF9.SlopeRating = StringUtil.ToShort(propertyText);
}
else if (markerColumns.ColIdx_Back9SlopeRating == teeColumnIdx)
{
// Back 9 Slope Rating populated with value for Front 9.
//markerDataB9.SlopeRating = StringUtil.ToInt(propertyText);
}
else if (markerColumns.ColIdx_MarkerId == teeColumnIdx)
{
markerData18.MarkerId = StringUtil.ToSysId(propertyText);
// Unclear if Tee Id is relevant to 9 holes.
//markerDataF9.MarkerId = StringUtil.ToSysId(propertyText);
//markerDataB9.MarkerId = StringUtil.ToSysId(propertyText);
}
else if (markerColumns.ColIdx_Length == teeColumnIdx)
{
markerData18.Length = StringUtil.ToShort(propertyText);
// Columns ignored.
}
else if (headerText.EqualsCI("Tee Name")) markerColumns.ColIdx_Tee = teeColumnIdx;
else if (headerText.EqualsCI("Gender")) markerColumns.ColIdx_Gender = teeColumnIdx;
else if (headerText.EqualsCI("Par")) markerColumns.ColIdx_Par = teeColumnIdx;
else if (headerText.EqualsCI("TeeId")) markerColumns.ColIdx_MarkerId = teeColumnIdx;
else if (headerText.EqualsCI("Length")) markerColumns.ColIdx_Length = teeColumnIdx;
// Specific part-course (9 holes) values.
else if (headerText.EqualsCI("RatingF9")) markerColumns.ColIdx_Front9CourseRating = teeColumnIdx;
else if (headerText.EqualsCI("RatingB9")) markerColumns.ColIdx_Back9CourseRating = teeColumnIdx;
else if (headerText.EqualsCI("Front (9)")) markerColumns.ColIdx_Front9 = teeColumnIdx;
else if (headerText.EqualsCI("Back (9)")) markerColumns.ColIdx_Back9 = teeColumnIdx;
else if (headerText.EqualsCI("Bogey Rating (F9)")) markerColumns.ColIdx_Front9BogeyRating = teeColumnIdx;
else if (headerText.EqualsCI("Bogey Rating (B9)")) markerColumns.ColIdx_Back9BogeyRating = teeColumnIdx;
else if (headerText.EqualsCI("Slope (F9)")) markerColumns.ColIdx_Front9SlopeRating = teeColumnIdx;
else if (headerText.EqualsCI("Slope (B9)")) markerColumns.ColIdx_Back9SlopeRating = teeColumnIdx;
// Less specific full-course (commonly 18 holes) values.
else if (headerText.IsMatchCI("Course Rating")) markerColumns.ColIdx_CourseRating = teeColumnIdx;
else if (headerText.IsMatchCI("Bogey Rating")) markerColumns.ColIdx_BogeyRating = teeColumnIdx;
else if (headerText.IsMatchCI("Slope Rating")) markerColumns.ColIdx_SlopeRating = teeColumnIdx;
else SaLogger.Info($"{SysUtil.Fn} Unexpected Marker column header: {headerText}");
}
foreach (HtmlNode teeRowNode in teeTableNode.SelectNodes("./tr[position()>1]"))
{
MarkerData markerData18 = new MarkerData(usgaCourseId, 18, "18");
MarkerData markerDataF9 = new MarkerData(usgaCourseId, 9, "F9");
MarkerData markerDataB9 = new MarkerData(usgaCourseId, 9, "B9");
teeColumnIdx = -1;
foreach (HtmlNode teePropertyNode in teeRowNode.SelectNodes("./td"))
{
teeColumnIdx++;
String propertyText = StringUtil.TrimWhitespace(WebUtil.HtmlDecode(teePropertyNode.InnerText));
if (markerColumns.ColIdx_Tee == teeColumnIdx)
{
markerData18.Tee = propertyText;
markerDataF9.Tee = propertyText;
markerDataB9.Tee = propertyText;
}
else if (markerColumns.ColIdx_Gender == teeColumnIdx)
{
markerData18.Gender = propertyText;
markerDataF9.Gender = propertyText;
markerDataB9.Gender = propertyText;
}
else if (markerColumns.ColIdx_Par == teeColumnIdx)
{
markerData18.Par = StringUtil.ToShort(propertyText);
if (markerData18.Par <= 50)
{
markerData18.Holes = 9;
markerData18.HolesCaption = "9";
}
}
else if (markerColumns.ColIdx_CourseRating == teeColumnIdx)
{
markerData18.CourseRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_BogeyRating == teeColumnIdx)
{
markerData18.BogeyRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_SlopeRating == teeColumnIdx)
{
markerData18.SlopeRating = StringUtil.ToShort(propertyText);
}
else if (markerColumns.ColIdx_Front9CourseRating == teeColumnIdx)
{
if (markerDataF9.CourseRating == 0)
markerDataF9.CourseRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_Back9CourseRating == teeColumnIdx)
{
if (markerDataB9.CourseRating == 0)
markerDataB9.CourseRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_Front9 == teeColumnIdx)
{
// Format: CourseRating / SlopeRating.
markerDataF9.CourseRating = StringUtil.ToDecimal(Regex.Replace(propertyText, "\\s*/.*$", ""));
markerDataF9.SlopeRating = StringUtil.ToShort(Regex.Replace(propertyText, "^.*/\\s*", ""));
}
else if (markerColumns.ColIdx_Back9 == teeColumnIdx)
{
// Format: CourseRating / SlopeRating.
markerDataB9.CourseRating = StringUtil.ToDecimal(Regex.Replace(propertyText, "\\s*/.*$", ""));
markerDataB9.SlopeRating = StringUtil.ToShort(Regex.Replace(propertyText, "^.*/\\s*", ""));
}
else if (markerColumns.ColIdx_Front9BogeyRating == teeColumnIdx)
{
markerDataF9.BogeyRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_Back9BogeyRating == teeColumnIdx)
{
markerDataB9.BogeyRating = StringUtil.ToDecimal(propertyText);
}
else if (markerColumns.ColIdx_Front9SlopeRating == teeColumnIdx)
{
if (markerDataF9.SlopeRating == 0)
markerDataF9.SlopeRating = StringUtil.ToShort(propertyText);
}
else if (markerColumns.ColIdx_Back9SlopeRating == teeColumnIdx)
{
// Back 9 Slope Rating populated with value for Front 9.
//markerDataB9.SlopeRating = StringUtil.ToInt(propertyText);
}
else if (markerColumns.ColIdx_MarkerId == teeColumnIdx)
{
markerData18.MarkerId = StringUtil.ToSysId(propertyText);
// Unclear if Tee Id is relevant to 9 holes.
//markerDataF9.MarkerId = StringUtil.ToSysId(propertyText);
//markerDataB9.MarkerId = StringUtil.ToSysId(propertyText);
}
else if (markerColumns.ColIdx_Length == teeColumnIdx)
{
markerData18.Length = StringUtil.ToShort(propertyText);
}
}
// Add valid markers to list.
if (markerData18.IsValid())
usgaMarkers.Add(markerData18);
if (markerDataF9.IsValid())
usgaMarkers.Add(markerDataF9);
if (markerDataB9.IsValid())
usgaMarkers.Add(markerDataB9);
// Front and Back 9 likely missing par values - derive from course ratings.
if (markerData18.IsValid() && markerDataF9.IsValid(true) && markerDataF9.Par == 0 && markerDataB9.IsValid(true) && markerDataB9.Par == 0)
{
decimal combined9sCourseRating = markerDataF9.CourseRating + markerDataB9.CourseRating;
markerDataF9.Par = (short)Math.Round(markerData18.Par * markerDataF9.CourseRating / combined9sCourseRating);
markerDataB9.Par = (short)(markerData18.Par - markerDataF9.Par);
}
// Add valid markers to list.
if (markerData18.IsValid())
markersData.Markers.Add(markerData18);
if (markerDataF9.IsValid())
markersData.Markers.Add(markerDataF9);
if (markerDataB9.IsValid())
markersData.Markers.Add(markerDataB9);
}
}
else SaLogger.Warn(SysUtil.Fn + " Tee table not found.");
}
// Store markers.
List<SaxReferenceGolfMgr.UsgaMarkerData> markersUpdateData = new List<SaxReferenceGolfMgr.UsgaMarkerData>();
foreach (MarkerData usgaMarker in markersData.Markers)
{
if (!SysId.IsValid(usgaMarker.CourseId)) continue;
//if (!SysId.IsValid(usgaMarker.MarkerId)) continue;
if (StringUtil.IsBlank(usgaMarker.Caption)) continue;
SaxReferenceGolfMgr.UsgaMarkerData markerData = new SaxReferenceGolfMgr.UsgaMarkerData();
markerData.CourseId = usgaMarker.CourseId;
markerData.MarkerId = usgaMarker.MarkerId;
markerData.Caption = usgaMarker.Caption;
markerData.Holes = usgaMarker.Holes;
markerData.HolesCaption = usgaMarker.HolesCaption;
markerData.Tee = usgaMarker.Tee;
markerData.Gender = usgaMarker.Gender;
markerData.SlopeRating = usgaMarker.SlopeRating;
markerData.Par = usgaMarker.Par;
markerData.CourseRating = usgaMarker.CourseRating;
markerData.BogeyRating = usgaMarker.BogeyRating;
markerData.Length = usgaMarker.Length;
markersUpdateData.Add(markerData);
}
ReferenceGolfMgr.BulkUpdateUsgaMarkers(markersUpdateData, DbUpdateInfo);
if (!ReferenceGolfMgr.HasErrorState())
{
// Courses updates OK.
// Store Marker data and clear Course 'priority' flag.
if (markersData.Markers.Any())
{
usgaCourse.MarkersData = JsonConvert.SerializeObject(markersData);
usgaCourse.Priority = false;
ReferenceGolfMgr.UpdateUsgaCourse(usgaCourse, DbUpdateInfo);
}
}
else SaLogger.Warn(SysUtil.Fn + " Tee table not found.");
else SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA markers: {ReferenceGolfMgr.ErrorStateMessage}.");
}
// Store markers.
List<SaxReferenceGolfMgr.UsgaMarkerData> markersData = new List<SaxReferenceGolfMgr.UsgaMarkerData>();
foreach (MarkerData usgaMarker in usgaMarkers)
catch (Exception exc)
{
if (!SysId.IsValid(usgaMarker.CourseId)) continue;
//if (!SysId.IsValid(usgaMarker.MarkerId)) continue;
if (StringUtil.IsBlank(usgaMarker.Caption)) continue;
SaxReferenceGolfMgr.UsgaMarkerData markerData = new SaxReferenceGolfMgr.UsgaMarkerData();
markerData.CourseId = usgaMarker.CourseId;
markerData.MarkerId = usgaMarker.MarkerId;
markerData.Caption = usgaMarker.Caption;
markerData.Holes = usgaMarker.Holes;
markerData.HolesCaption = usgaMarker.HolesCaption;
markerData.Tee = usgaMarker.Tee;
markerData.Gender = usgaMarker.Gender;
markerData.SlopeRating = usgaMarker.SlopeRating;
markerData.Par = usgaMarker.Par;
markerData.CourseRating = usgaMarker.CourseRating;
markerData.BogeyRating = usgaMarker.BogeyRating;
markerData.Length = usgaMarker.Length;
markersData.Add(markerData);
SaLogger.Warn(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc, $"querying USGA markers for course Id: {usgaCourseId}", 0));
}
ReferenceGolfMgr.BulkUpdateUsgaMarkers(markersData, config.DbUpdateInfo);
if (ReferenceGolfMgr.HasErrorState())
SaLogger.Warn($"{SysUtil.Fn} Error bulk updating USGA markers: {ReferenceGolfMgr.ErrorStateMessage}.");
}
catch (Exception exc)
{
SaLogger.Warn(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc, $"querying USGA markers for course Id: {usgaCourseId}", 0));
}
return usgaMarkers;
return markersData.Markers;
}
//------------------------------------------------------------------