Add project files.
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Saxonite.Net.Standard.Base.App;
|
||||
using Saxonite.Net.Standard.Base.Bus;
|
||||
using Saxonite.Net.Standard.Base.Consoles;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Saxonite.Net.Core.Web.Base.Consoles
|
||||
{
|
||||
//=======================================================================
|
||||
public class SaxDataCacheConsole_Web : SaxDataCacheConsole
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SaxInternals internals;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Protected construction.
|
||||
protected SaxDataCacheConsole_Web(SaxSessionContext sessionContext) :
|
||||
base(sessionContext)
|
||||
{
|
||||
internals = new SaxInternals(sessionContext);
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
internals.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Regions.
|
||||
public bool RegionsSupported { get; protected set; } = false;
|
||||
private class RegionsData
|
||||
{
|
||||
public Dictionary<SysId, SaxRegion> regions = null;
|
||||
public List<SaxRegion> activeRegions = null;
|
||||
}
|
||||
private readonly RegionsData regionsData = new RegionsData();
|
||||
public override List<SaxRegion> GetActiveRegions()
|
||||
{
|
||||
String fn = GetType().Name + ".ActiveRegions";
|
||||
if (!RegionsSupported) throw new NotSupportedException(fn + " Regions not supported.");
|
||||
List<SaxRegion> activeRegions = new List<SaxRegion>();
|
||||
lock (regionsData)
|
||||
{
|
||||
if (regionsData.regions == null) throw new NotSupportedException(fn + " Regions not populated.");
|
||||
activeRegions = new List<SaxRegion>(regionsData.activeRegions);
|
||||
}
|
||||
return activeRegions;
|
||||
}
|
||||
private bool IsRegionActive(SaxRegion region)
|
||||
{
|
||||
if (region == null) return false;
|
||||
if (!region.IsStatusActive) return false;
|
||||
if (SysId.IsValid(region.RegionIdParent))
|
||||
return IsRegionActive(regionsData.regions.GetValue(region.RegionIdParent, null));
|
||||
return true;
|
||||
}
|
||||
protected void RefreshRegions()
|
||||
{
|
||||
String fn = GetType().Name + ".RefreshRegions";
|
||||
if (!RegionsSupported) throw new NotSupportedException(fn + " Regions not supported.");
|
||||
SaLogger.Info(fn + " START.", false);
|
||||
DateTime startedAt = DateTime.Now;
|
||||
List<SaxRegion> oldRegions = null;
|
||||
Dictionary<SysId, SaxRegion> newRegions = new Dictionary<SysId, SaxRegion>();
|
||||
|
||||
// Query Regions.
|
||||
SaxRegion.Params prmRegion = new SaxRegion.Params();
|
||||
prmRegion.StatusCat = SaxRegion.StatusCat.NotDeleted;
|
||||
foreach (SaxRegion region in internals.ReferenceMgr.GetRegionList(prmRegion))
|
||||
newRegions[region.Id] = region;
|
||||
|
||||
// Replace the list of Regions.
|
||||
lock (regionsData)
|
||||
{
|
||||
oldRegions = regionsData.regions?.GetValues() ?? new List<SaxRegion>();
|
||||
regionsData.regions = newRegions;
|
||||
|
||||
// Populate list of active regions.
|
||||
regionsData.activeRegions = new List<SaxRegion>();
|
||||
foreach (SaxRegion region in regionsData.regions.GetValues())
|
||||
{
|
||||
if (IsRegionActive(region))
|
||||
{
|
||||
// Clone region to ensure internal list isn't modified.
|
||||
SaxRegion activeRegion = internals.ReferenceMgr.CreateRegion();
|
||||
activeRegion.SetData(region.GetData());
|
||||
regionsData.activeRegions.Add(activeRegion);
|
||||
}
|
||||
}
|
||||
|
||||
SaLogger.Info(fn + " END. Regions found: " + regionsData.regions.Count + ". Elapsed: " + DateUtil.FormatNumberOfSeconds((DateTime.Now - startedAt).TotalSeconds), true);
|
||||
}
|
||||
|
||||
// Dispose old regions.
|
||||
oldRegions.ClearAndDispose<SaxRegion>();
|
||||
oldRegions = null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Sports.
|
||||
public bool SportsSupported { get; protected set; } = false;
|
||||
private class SportsData
|
||||
{
|
||||
public Dictionary<SysId, SaxSport> sports = null;
|
||||
public List<SaxSport> activeSports = null;
|
||||
}
|
||||
private readonly SportsData sportsData = new SportsData();
|
||||
public override List<SaxSport> GetActiveSports()
|
||||
{
|
||||
String fn = GetType().Name + ".ActiveSports";
|
||||
if (!SportsSupported) throw new NotSupportedException(fn + " Sports not supported.");
|
||||
List<SaxSport> activeSports = new List<SaxSport>();
|
||||
lock (sportsData)
|
||||
{
|
||||
if (sportsData.sports == null) throw new NotSupportedException(fn + " Sports not populated.");
|
||||
foreach (SaxSport sport in sportsData.sports.GetValues())
|
||||
{
|
||||
if (IsSportActive(sport))
|
||||
{
|
||||
// Clone sport to ensure internal list isn't modified.
|
||||
SaxSport activeSport = internals.ReferenceMgr.CreateSport();
|
||||
activeSport.SetData(sport.GetData());
|
||||
activeSports.Add(activeSport);
|
||||
}
|
||||
}
|
||||
}
|
||||
return activeSports;
|
||||
}
|
||||
private bool IsSportActive(SaxSport sport)
|
||||
{
|
||||
if (sport == null) return false;
|
||||
if (!sport.IsStatusActive) return false;
|
||||
return true;
|
||||
}
|
||||
protected void RefreshSports()
|
||||
{
|
||||
String fn = GetType().Name + ".RefreshSports";
|
||||
if (!SportsSupported) throw new NotSupportedException(fn + " Sports not supported.");
|
||||
SaLogger.Info(fn + " START.", false);
|
||||
DateTime startedAt = DateTime.Now;
|
||||
List<SaxSport> oldSports = null;
|
||||
Dictionary<SysId, SaxSport> newSports = new Dictionary<SysId, SaxSport>();
|
||||
|
||||
// Query Sports.
|
||||
SaxSport.Params prmSport = new SaxSport.Params();
|
||||
prmSport.StatusCat = SaxSport.StatusCat.NotDeleted;
|
||||
foreach (SaxSport sport in internals.ReferenceMgr.GetSportList(prmSport))
|
||||
newSports[sport.Id] = sport;
|
||||
|
||||
// Replace the list of Sports.
|
||||
lock (sportsData)
|
||||
{
|
||||
oldSports = sportsData.sports?.GetValues() ?? new List<SaxSport>();
|
||||
sportsData.sports = newSports;
|
||||
|
||||
// Populate list of active sports.
|
||||
sportsData.activeSports = new List<SaxSport>();
|
||||
foreach (SaxSport sport in sportsData.sports.GetValues())
|
||||
{
|
||||
if (IsSportActive(sport))
|
||||
sportsData.activeSports.Add(sport);
|
||||
}
|
||||
|
||||
SaLogger.Info(fn + " END. Sports found: " + sportsData.sports.Count + ". Elapsed: " + DateUtil.FormatNumberOfSeconds((DateTime.Now - startedAt).TotalSeconds), true);
|
||||
}
|
||||
|
||||
// Dispose old sports.
|
||||
oldSports.ClearAndDispose<SaxSport>();
|
||||
oldSports = null;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user