using Blazored.LocalStorage; using Blazored.SessionStorage; using GPW.CORE.Data; using GPW.CORE.Data.DbModels; using Microsoft.AspNetCore.Components; using NLog; namespace GPW.CORE.Smart8.Data { public class MessageService { #region Public Fields public int orarioDip = 0; #endregion Public Fields #region Public Constructors public MessageService(ILocalStorageService genLocalStorage, ISessionStorageService sessStore) { localStorage = genLocalStorage; sessionStore = sessStore; } #endregion Public Constructors #region Public Events public event Action EA_DateChanged = null!; public event Action EA_DipUpdated = null!; public event Action EA_PageUpdated = null!; public event Action EA_CalModeChanged = null!; public event Action EA_TimbUpd = null!; #endregion Public Events #region Public Properties public RegAttivitaModel? clonedRA { get; set; } = null; /// /// Calcola HASH del codice impiego = payload utente /// /// public string HashDip { get { DataValidator cDV = new DataValidator(_rigaDip); string hash = cDV.HashDip; return hash; } } public int IdxDipendente { get { int answ = -1; if (_rigaDip != null) { answ = _rigaDip.IdxDipendente; } return answ; } } public bool IsActive { get { bool answ = false; if (_rigaDip != null && _rigaDip.Attivo != null) { answ = (bool)_rigaDip.Attivo; } return answ; } } public bool isRicTimb { get; set; } = false; public CalendarModeEnum.modoControllo modoCal { get; set; } = CalendarModeEnum.modoControllo.showCalendar; /// /// Indica ultima azione compiuta /// public string LastAction { get => lastAction; set { if (lastAction != value) { lastAction = value; } } } /// /// Indica se il prossimo stato timbratura sia entrata /// public bool NextIsEntrata { get => nextIsEntrata; set { if (nextIsEntrata != value) { nextIsEntrata = value; } } } public string PageIcon { get => _pageIcon; set { if (_pageIcon != value) { _pageIcon = value; ReportPageUpd(); } } } public string PageName { get => _pageName; set { if (_pageName != value) { _pageName = value; ReportPageUpd(); } } } public bool PayloadOk { get; set; } = false; public RegAttivitaModel? recordRA { get; set; } = null; public DipendentiModel? RigaDip { get => _rigaDip; set { // salvo _rigaDip = value; if (EA_DipUpdated != null) { EA_DipUpdated?.Invoke(); } } } public int selWeekNum { get; set; } = 0; public int selYear { get; set; } = DateTime.Today.Year; public bool ShowSearch { get => showSearch; set { if (showSearch != value) { showSearch = value; } } } public DateTime targetDate { get; set; } = DateTime.Today; public DateTime targetDateMancTimb { get; set; } #endregion Public Properties protected const string KeyDevSec = "DevSec"; protected const string KeyDevIp4 = "DevIpv4"; #region Public Methods /// /// Restituisce il valore di DeviceSecret da localstorage /// /// public async Task getDevSecretAsync() { string answ = ""; var result = await localStorage.GetItemAsync(KeyDevSec); if (result != null) { answ = result; } return answ; } /// /// Restituisce il valore Ipv4 del Device da localstorage /// /// public async Task getDevIpAsync() { string answ = ""; var result = await localStorage.GetItemAsync(KeyDevIp4); if (result != null) { answ = result; } return answ; } public void ReportDateChange() { if (EA_DateChanged != null) { EA_DateChanged?.Invoke(); } } public void setModeCalendar() { modoCal = CalendarModeEnum.modoControllo.showCalendar; if (EA_CalModeChanged != null) { EA_CalModeChanged?.Invoke(); } } public void setModeGauge() { modoCal = CalendarModeEnum.modoControllo.showGauge; if (EA_CalModeChanged != null) { EA_CalModeChanged?.Invoke(); } } public void setModeProj() { modoCal = CalendarModeEnum.modoControllo.showProj; if (EA_CalModeChanged != null) { EA_CalModeChanged?.Invoke(); } } public void setModeTempRil() { modoCal = CalendarModeEnum.modoControllo.showTempRil; if (EA_CalModeChanged != null) { EA_CalModeChanged?.Invoke(); } } public void setModeRichTimb() { modoCal = CalendarModeEnum.modoControllo.showTimbr; if (EA_CalModeChanged != null) { EA_CalModeChanged?.Invoke(); } } public void setModeShowWeek() { modoCal = CalendarModeEnum.modoControllo.showWeek; if (EA_CalModeChanged != null) { EA_CalModeChanged?.Invoke(); } } public void ReportTimbratura() { if (EA_TimbUpd != null) { EA_TimbUpd?.Invoke(); } } /// /// Scrive il valore di DeviceSecret nel localstoragee /// /// /// public async Task setDevSecretAsync(string newVal) { bool answ = false; try { await localStorage.SetItemAsync(KeyDevSec, newVal); answ = true; } catch (Exception ex) { Log.Error($"Eccezione in setDevSecretAsync{Environment.NewLine}{ex}"); } return answ; } /// /// Scrive il valore di IPV4 del device nel localstoragee /// /// /// public async Task setDevIpv4Async(string newVal) { bool answ = false; try { await localStorage.SetItemAsync(KeyDevIp4, newVal); answ = true; } catch (Exception ex) { Log.Error($"Eccezione in setDevIpv4Async{Environment.NewLine}{ex}"); } return answ; } #endregion Public Methods #region Protected Properties protected ILocalStorageService localStorage { get; set; } = null!; protected ISessionStorageService sessionStore { get; set; } = null!; #endregion Protected Properties #region Private Fields private string _pageIcon = ""; private string _pageName = ""; private DipendentiModel? _rigaDip; private Logger Log = LogManager.GetCurrentClassLogger(); private bool showSearch; #endregion Private Fields #region Private Properties private string lastAction { get; set; } = ""; private bool nextIsEntrata { get; set; } = true; #endregion Private Properties #region Private Methods private void ReportPageUpd() { if (EA_PageUpdated != null) { EA_PageUpdated?.Invoke(); } } #endregion Private Methods } }