| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Linq;
- using System.Security.Principal;
- using Microsoft.Extensions.Logging;
- using Quadarax.Foundation.Core.Business.Interface;
- using Quadarax.Foundation.Core.Data.Interface.Entity;
- using Quadarax.Foundation.Core.Data.Interface.Entity.Dto;
- using Quadarax.Foundation.Core.Value;
- namespace Quadarax.Foundation.Core.Business
- {
- public abstract class AbstractService : IService
- {
- #region *** Properties ***
- protected ILogger<AbstractService> Log { get; }
- protected IPrincipal CurrentPrincipal { get; }
- #endregion
- #region *** Constructors ***
- protected AbstractService(IPrincipal currentPrincipal, ILoggerFactory logger)
- {
- Log = logger.CreateLogger<AbstractService>();
- if (currentPrincipal == null)
- {
- var genericIdentity = new GenericIdentity("genericIdentity");
- currentPrincipal = new GenericPrincipal(genericIdentity, new string[] {});
- }
- CurrentPrincipal = currentPrincipal;
- Log.LogTrace($"Service '{GetType().Name}' [Hash:{GetHashCode()}] initialized.");
- }
- #endregion
- #region *** Private Operations ***
- protected TResult TryCatchBlock<TResult>(Func<TResult> fnc) where TResult : ResultDto
- {
- if (fnc == null)
- return null;
- var result = default(TResult);
- try
- {
- result = fnc();
- }
- catch (Exception e)
- {
- result.AppendException(e);
- }
- return result;
- }
- #endregion
- #region *** Public Operations ***
- public IResult Test()
- {
- return new ResultPlain();
- }
- #endregion
- }
- }
|