Example #1
0
        public override async Task <ICacheControlFeature> GetCacheControlFeature(
            CacheControlAttribute directive)
        {
            if (directive == null)
            {
                throw new ArgumentNullException(nameof(directive));
            }

            if (directive is PrivateCacheControlAttribute attr)
            {
                var key        = GetCacheControlKey(attr.AdditionalVaryHeaders);
                var validators = await base.TryGetCacheControlValidators(key);

                var headers = new Dictionary <string, StringValues>()
                {
                    { HeaderNames.CacheControl, new[]
                      { "private", $"max-age={attr.MaxAge}" } },
                    { HeaderNames.Vary, base.GetVaryHeaders(attr.AdditionalVaryHeaders) }
                };

                return(CacheControlFeature.CacheEnabled(key, validators, headers));
            }

            return(await base.GetCacheControlFeature(directive));
        }
        public virtual async Task <ICacheControlFeature> GetCacheControlFeature(
            CacheControlAttribute descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            return(nextValidator == null?CacheControlFeature.CacheUnsupported(GetCacheControlKey()) : await nextValidator.GetCacheControlFeature(descriptor));
        }
Example #3
0
        public override Task <ICacheControlFeature> GetCacheControlFeature(
            CacheControlAttribute directive)
        {
            if (directive == null)
            {
                throw new ArgumentNullException(nameof(directive));
            }

            if (directive is DisableCacheControlAttribute _)
            {
                var key = base.GetCacheControlKey();

                var headers = new Dictionary <string, StringValues>()
                {
                    { HeaderNames.CacheControl, new[] { "no-store" } }
                };

                var feature = CacheControlFeature.CacheDisabled(key, headers);

                return(Task.FromResult(feature));
            }

            return(base.GetCacheControlFeature(directive));
        }
Example #4
0
        /// <summary>
        /// Δημιουργεί ένα νέο αντικείμενο μεταδεδομένων οντότητας
        /// </summary>
        /// <param name="EntityType">Ο τύπος της κλάσης που έχει μαρκαριστεί ως οντότητα</param>
        public ClassMetadata(Type EntityType)
        {
            this.EntityType = EntityType ?? throw new ArgumentNullException(nameof(EntityType));
            if (!IsEntity(this.EntityType))
            {
                throw MetadataException.InvalidEntity(this.EntityType);
            }

            EntityName = this.EntityType.Name;
            CacheKey   = GetCacheKey(this.EntityType);
            TableName  = GetTableName(this.EntityType);
            Columns    = GetColumns(this.EntityType);
            try
            {
                //Εαν η οντότητα δεν έχει καμία στηλή με το IdentifierAttribute, η παρακάτω
                //γραμμή θα σκάσει και θα μας πάρει στο λαιμό της. Εξ ού και το try-catch
                IdentifierColumn = Columns
                                   .Select(c => c.Value)
                                   .First(c => c.IsIdentifier).ColumnName;
            } catch (Exception)
            {
                throw MetadataException.MissingIdentifierAttribute(EntityName);
            }

            //Σε αντίθεση με παραπάνω, οι οντότητες δεν είναι υποχρεωμένες να έχουν
            //παραμετρικά πεδία ή (πιο κάτω) στήλη Guid, οπότε εδώ αρκούν απλοί έλεγχοι
            //για την ύπαρξη παραμετρικών ή στήλης Guid
            if (HasCustomColumns())
            {
                CustomTable = Columns
                              .Select(c => c.Value)
                              .FirstOrDefault(c => c.IsCustomColumn)
                              ?.CustomFieldTable ?? string.Empty;
                CustomReferenceColumn = Columns
                                        .Select(c => c.Value)
                                        .FirstOrDefault(c => c.IsCustomColumn)
                                        ?.CustomFieldReference ?? string.Empty;
            }

            if (HasGuidColumn())
            {
                GuidColumn = Columns
                             .Select(c => c.Value)
                             .FirstOrDefault(c => c.IsRowGuid)
                             ?.ColumnName ?? string.Empty;
            }

            CacheControlAttribute cacheAttr = this.EntityType.GetCustomAttribute <CacheControlAttribute>();

            if (cacheAttr != null)
            {
                CacheDuration = cacheAttr.Duration;
                NoCache       = cacheAttr.NoCache;
            }

            SupportsOptimisticLocking = Columns
                                        .Select(c => c.Value)
                                        .Any(c => c.IsVersion);
            if (SupportsOptimisticLocking)
            {
                VersionColumn = Columns
                                .Select(c => c.Value)
                                .FirstOrDefault(c => c.IsVersion)
                                ?.ColumnName ?? string.Empty;
            }
        }