using System; using Microsoft.Extensions.Logging; using Quadarax.Foundation.Core.Business.Enums; using Quadarax.Foundation.Core.Business.Interface; using Quadarax.Foundation.Core.Data.Interface.Domain; using Quadarax.Foundation.Core.Data.Interface.Entity; using Quadarax.Foundation.Core.Data.Interface.Entity.Dto; using Quadarax.Foundation.Core.Logging; namespace Quadarax.Foundation.Core.Business { public abstract class AbstractService : IService { #region *** Properties *** protected IQLog Log { get; } protected IContext CurrentContext { get; } protected IQLogger Logger { get; } public ServiceStateEnum State { get; protected set; } #endregion #region *** Constructors *** protected AbstractService(IContext currentContext, IQLogger logger) { State = ServiceStateEnum.Initializing; CurrentContext = currentContext ?? throw new ArgumentNullException(nameof(currentContext)); if (logger == null)throw new ArgumentNullException(nameof(logger)); Logger = logger; Log = logger.GetLogger(GetType()); //if (currentContext == null) //{ // var genericIdentity = new GenericIdentity("genericIdentity"); // currentContext = new GenericPrincipal(genericIdentity, new string[] {}); //} Log.Log(LogSeverityEnum.Trace, $"Service '{GetType().Name}' [Hash:{GetHashCode()}] initialized."); State = ServiceStateEnum.Online; } #endregion #region *** Private Operations *** protected TResult TryCatchBlock(Func fnc) where TResult : ResultDto { if (fnc == null) return null; var result = Activator.CreateInstance(); try { result = fnc(); } catch (Exception e) { result.AppendException(e); } return result; } protected TContext GetContext() where TContext : IContext { return (TContext)CurrentContext; } #endregion #region *** Public Operations *** public IResult Test() { return new ResultPlain(); } #endregion } }