| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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<TResult>(Func<TResult> fnc) where TResult : ResultDto
- {
- if (fnc == null)
- return null;
- var result = Activator.CreateInstance<TResult>();
- try
- {
- result = fnc();
- }
- catch (Exception e)
- {
- result.AppendException(e);
- }
- return result;
- }
- protected TContext GetContext<TContext>() where TContext : IContext
- {
- return (TContext)CurrentContext;
- }
- #endregion
- #region *** Public Operations ***
- public IResult Test()
- {
- return new ResultPlain();
- }
- #endregion
- }
- }
|