Exemplo n.º 1
0
 public async Task ReloadCacheAsync(ICustomContext context)
 {
     foreach (var item in _cache)
     {
         await item.Value.ReloadDataAsync(context);
     }
 }
Exemplo n.º 2
0
 public async Task ReloadCacheAsync(ICustomContext context, string cacheName)
 {
     if (_cache.TryGetValue(cacheName, out IData <dynamic> cache))
     {
         await cache.ReloadDataAsync(context);
     }
 }
Exemplo n.º 3
0
        public static string GetTableName <T>(this ICustomContext context) where T : class
        {
            var mapping   = context.Model.FindEntityType(typeof(T));
            var tableName = $"[{mapping.GetSchema()}].[{mapping.GetTableName()}]";

            return(tableName);
        }
Exemplo n.º 4
0
 public async Task <T> GetItemFromCache <T>(ICustomContext context,
                                            string cacheName,
                                            bool forceImmediateReload = false) where T : class
 {
     if (_cache.TryGetValue(cacheName, out IData <dynamic> cachedDataObject))
     {
         return(await cachedDataObject.GetAsync(context, forceImmediateReload));
     }
     return(null);
 }
Exemplo n.º 5
0
        public async Task <T> GetAsync(ICustomContext context, bool forceReload = false)
        {
            if (IsExpired || forceReload)
            {
                await ReloadDataAsync(context);
            }
            var data = DeepCopy.ObjectCloner.Clone(_cachedData, false);

            return(data);
        }
Exemplo n.º 6
0
 public virtual ICustomContext GetLocalContext(IWorkerContext context)
 {
     try {
         ICustomContext cc = context.Get(GetContextKey());
         if (null != cc)
         {
             return(cc);
         }
         throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.OWN_CONTEXT_404), this.GetType().FullName));
     } catch (NoCustomContextException e) {
         throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.OWN_CONTEXT_404), this.GetType().FullName), e);
     }
 }
Exemplo n.º 7
0
 public ServiceConstructor(ICacheContainer cacheContainer,
                           ICustomContext context,
                           string username,
                           Expression <Func <T, bool> > cacheLoadFilter = null,
                           Func <IQueryable <T>, IIncludableQueryable <T, object> > includeInCache = null,
                           int cacheTimeoutInMinutes = 10,
                           bool isSharedContext      = true)
 {
     CacheContainer           = cacheContainer;
     Context                  = context;
     IsSharedContext          = isSharedContext;
     CacheLoadFilter          = cacheLoadFilter;
     CacheTimoutInMinutes     = cacheTimeoutInMinutes;
     Username                 = username;
     IncludePropertiesInCache = includeInCache;
 }
Exemplo n.º 8
0
        public async Task <T> GetAndLoadCacheItemAsync <T>(ICustomContext context,
                                                           string cacheName,
                                                           Func <ICustomContext, Task <T> > reloadMethodAsync,
                                                           bool forceImmediateReload = false,
                                                           int timeoutInMinutes      = 10) where T : class
        {
            var cachedRec = await GetItemFromCache <T>(context, cacheName, forceImmediateReload);

            if (cachedRec != null)
            {
                return(cachedRec);
            }
            var data = await reloadMethodAsync(context);

            AddItemToCache(cacheName, data, reloadMethodAsync, forceImmediateReload, timeoutInMinutes);
            return(data);
        }
Exemplo n.º 9
0
        protected BaseService(IServiceConstructor <T> constructor)
        {
            CurrentUsername          = constructor.Username;
            Context                  = constructor.Context;
            IsSharedContext          = constructor.IsSharedContext;
            Repo                     = new GenericRepository <T, SqlParameter, int>(this.Context, CurrentUsername);
            CacheContainer           = constructor.CacheContainer;
            cacheLoadFilter          = constructor.CacheLoadFilter;
            cacheTimeoutInMinutes    = constructor.CacheTimoutInMinutes;
            includePropertiesInCache = constructor.IncludePropertiesInCache;
            reloadMethod             = async(context) =>
            {
                IGenericRepository <T, int> repo = new GenericRepository <T, SqlParameter, int>(context, "System");

                var data = await repo.GetAsync(cacheLoadFilter, includePropertiesInCache);

                var detachedData = data.Select(t => repo.CreateDetachedEntity(t)).ToList();
                return(detachedData);
            };
        }
Exemplo n.º 10
0
 public static void UpdateAllPropertiesToValue <TEntity, TEntityValue>(this ICustomContext context, TEntity entity, string propertyName, TEntityValue value) where TEntity : class
 {
     if (entity.GetType().GetProperty(propertyName) != null)
     {
         var propertyType = entity.GetType().GetProperty(propertyName).PropertyType;
         propertyType = Nullable.GetUnderlyingType(propertyType) ?? propertyType;
         if (propertyType != value.GetType())
         {
             throw new InvalidCastException($"The type doesn't match the property that is being inserted for {entity.GetType()} - {propertyName}.  {propertyType.ToString()} != {value.GetType().ToString()}");
         }
         entity.GetType().GetProperty(propertyName).SetValue(entity, value);
         if (context.Entry(entity).State != EntityState.Detached)
         {
             context.Entry(entity).Property(propertyName).IsModified = true;
         }
     }
     foreach (var property in entity.GetType().GetProperties())
     {
         if (property.PropertyType.IsClass && property.PropertyType.IsByRef)
         {
             UpdateAllPropertiesToValue(context, property, propertyName, value);
         }
         if (property.PropertyType.IsInterface && property.PropertyType.GetInterface(typeof(IEnumerable <>).FullName) != null)
         {
             var propValue = entity.GetType().GetProperty(property.Name).GetValue(entity);
             if (propValue == null)
             {
                 continue;
             }
             foreach (var propValueCollectionItem in (System.Collections.IEnumerable)propValue)
             {
                 UpdateAllPropertiesToValue(context, propValueCollectionItem, propertyName, value);
             }
         }
     }
 }
Exemplo n.º 11
0
        public static void SetFieldsAsNotModified <TEntity>(this ICustomContext context, TEntity entity, string[] excludedProperties = null) where TEntity : class
        {
            foreach (var property in entity.GetType().GetProperties())
            {
                if ((property.PropertyType.IsClass || property.PropertyType.IsPrimitive || property.PropertyType.IsValueType) &&
                    excludedProperties.Contains(property.Name))
                {
                    context.Entry(entity).Property(property.Name).IsModified = false;
                }

                else if (property.PropertyType.IsInterface && property.PropertyType.GetInterface(typeof(IEnumerable <>).FullName) != null)
                {
                    var propValue = entity.GetType().GetProperty(property.Name).GetValue(entity);
                    if (propValue == null)
                    {
                        continue;
                    }
                    foreach (var propValueCollectionItem in (System.Collections.IEnumerable)propValue)
                    {
                        SetFieldsAsNotModified(context, propValueCollectionItem);
                    }
                }
            }
        }
 public Actmgr_Actividades(ICustomContext context)
     : base(context)
 {
 }
Exemplo n.º 13
0
 public BaseContext(ICustomContext Contexto)
 {
     this.Contexto = Contexto;
 }
Exemplo n.º 14
0
 public StudentService(ICustomContext context, string currentUsername)
     : base(context, currentUsername)
 {
 }
Exemplo n.º 15
0
 public Business(ICustomContext context)
 {
     this.context = context;
 }
Exemplo n.º 16
0
        public async Task ReloadDataAsync(ICustomContext context)
        {
            _cachedData = await _reloadMethodAsync(context);

            Updated = DateTime.Now;
        }
Exemplo n.º 17
0
 public Actmgr_Proyectos(ICustomContext Contexto)
     : base(Contexto)
 {
 }
Exemplo n.º 18
0
 public CourseService(ICustomContext context, string currentUsername)
     : base(context, currentUsername)
 {
 }
Exemplo n.º 19
0
 public AttributeCommaSeparated()
 {
     _reflectionService = (ReflectionService)ServiceLocator.ServiceProvider.GetService(typeof(IReflectionService));
     _sitecoreService   = (ISitecoreService)ServiceLocator.ServiceProvider.GetService(typeof(ISitecoreService));
     _customContext     = (ICustomContext)ServiceLocator.ServiceProvider.GetService(typeof(ICustomContext));
 }
Exemplo n.º 20
0
 /**
  * Convenience method.
  * @param key the key to store the CustomContext for.
  * @param context the CustomContext to store.
  */
 virtual public void Put(String key, ICustomContext context)
 {
     mc[key] = context;
 }
Exemplo n.º 21
0
 protected GenericServiceContainer(ICustomContext context)
 {
     this.context = context;
 }
Exemplo n.º 22
0
 /**
  * Convenience method.
  * @param key the key to store the CustomContext for.
  * @param context the CustomContext to store.
  */
 virtual public void Put(String key, ICustomContext context) {
     mc[key] = context;
 }
Exemplo n.º 23
0
 public BaseService(ICustomContext context, string currentUsername)
 {
     Context         = context;
     CurrentUsername = currentUsername;
     Repo            = new GenericRepository <T, SqlParameter, int>(Context, CurrentUsername);
 }
Exemplo n.º 24
0
 public GenericRepositoryBase(ICustomContext context)
 {
     this.context = context;
     this.dbSet   = this.context.Set <T>();
 }
Exemplo n.º 25
0
 public GenericRepository(ICustomContext context, string currentUser, string parameterPrefix = "@")
     : base(context)
 {
     CurrentUser          = currentUser;
     this.parameterPrefix = parameterPrefix;
 }
Exemplo n.º 26
0
 public MvcContext(ISitecoreService sitecoreService, IReflectionService reflectionService, ICustomContext customContext)
 {
     SitecoreService    = sitecoreService;
     _reflectionService = reflectionService;
     _customContext     = customContext;
 }
Exemplo n.º 27
0
 public CustomRepository(ICustomContext context)
 {
     _context = context;
 }