/// <summary>
        /// Gets the lookup table for the property from a lookup cache using <see cref="TableType"/>.
        /// </summary>
        /// <param name="cachedOnly">True to return only the cached lookup table, False to try to load it, if it's not cached.</param>
        /// <param name="row">Data row for which to get the lookup table, or null if the property is not in a data list object.</param>
        /// <returns>The lookup table to be used for the property.</returns>
        protected virtual LookupTable GetLookupTable(bool cachedOnly = false, DataRow row = null)
        {
            LookupCache cache = row?.GetLookupCache(this) ?? LocalCacheLoader?.LocalCache ??
                                LookupCache.Get(parent?.ServiceProvider ?? DI.DefaultServiceProvider, CacheType);

            return(cache?.GetLookupTable(TableType, cachedOnly));
        }
Beispiel #2
0
        public ActionResult <LookupTable> Get(string id)
        {
            LookupTable  tbl      = globalCache.GetLookupTable(id);
            ObjectResult response = tbl != null ? (ObjectResult)Ok(tbl) :
                                    NotFound(string.Format(resMgr.GetString(Messages.LookupTableNotFound), id));

            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the lookup table for the property. The default implementation uses the <see cref="EnumType"/>
        /// to find the lookup table in the lookup cache specified by the <see cref="CacheType"/>.
        /// </summary>
        /// <returns>The lookup table to be used for the property.</returns>
        protected virtual LookupTable GetLookupTable()
        {
            if (LocalLookupTable != null)
            {
                return(LocalLookupTable);
            }
            LookupCache cache = LookupCache.Get(parent != null ? parent.ServiceProvider : DI.DefaultServiceProvider, CacheType);

            LookupCache.LookupTableReady onReady = null;
            return(cache == null ? null : cache.GetLookupTable(EnumType, onReady));
        }
Beispiel #4
0
        public HttpResponseMessage Get(string id)
        {
            LookupTable tbl      = globalCache.GetLookupTable(id);
            var         response = tbl == null?
                                   Request.CreateResponse <string>(HttpStatusCode.NotFound,
                                                                   string.Format("Lookup table '{0}' is not found in the global lookup cache.", id)) :
                                       Request.CreateResponse <LookupTable>(HttpStatusCode.OK, tbl);

            response.Headers.CacheControl = new CacheControlHeaderValue()
            {
                Public = true,
                MaxAge = new TimeSpan(0, 0, 30)
            };
            return(response);
        }
Beispiel #5
0
        /// <summary>
        /// Validates the specified list of values using the current <see cref="ValidationContext"/>.
        /// </summary>
        /// <param name="values">The list of values to validate.</param>
        /// <param name="validationContext">The validation context to use.</param>
        /// <returns><see cref="ValidationResult.Success"/> if all the values in the list are valid,
        /// and a <see cref="ValidationResult"/> with the localized error otherwise.</returns>
        protected ValidationResult IsValidList(ICollection values, ValidationContext validationContext)
        {
            if (ValidationType == LookupValidationType.None)
            {
                return(ValidationResult.Success);
            }

            IServiceProvider svcProvider = (validationContext?.GetService(typeof(ResourceManager)) != null) ? validationContext : DI.DefaultServiceProvider;
            ResourceManager  rm          = (ResourceManager)svcProvider?.GetService(typeof(ResourceManager)) ?? Messages.ResourceManager;
            LookupCache      cache       = LookupCache.Get(svcProvider, CacheType);
            LookupTable      table       = cache?.GetLookupTable(LookupTable);

            if (table == null)
            {
                throw new InvalidOperationException(
                          string.Format(rm.GetString(Messages.Validation_InvalidLookupTable), validationContext.DisplayName, LookupTable));
            }
            string[]      memberNames   = validationContext.MemberName != null ? new string[] { validationContext.MemberName } : null;
            List <string> invalidValues = new List <string>();

            foreach (object val in values)
            {
                string strVal = val?.ToString();
                if (val is bool)
                {
                    strVal = strVal.ToLower();
                }
                if (string.IsNullOrEmpty(strVal))
                {
                    continue;
                }
                Header h = table.LookupById(strVal);
                if (h == null || ValidationType == LookupValidationType.ActiveItem && !h.IsActive)
                {
                    invalidValues.Add("'" + strVal + "'");
                }
            }
            if (invalidValues.Count == 0)
            {
                return(ValidationResult.Success);
            }
            string errMsg = invalidValues.Count > 1 ? Messages.Validation_LookupValues : Messages.Validation_LookupValue;

            return(new ValidationResult(string.Format(rm.GetString(errMsg), validationContext.DisplayName, LookupTable, string.Join(", ", invalidValues)), memberNames));
        }