Esempio n. 1
0
        public List <ColumnMetaData> GetColumnsMetaData(List <ColumnHeader> columnHeaders)
        {
            List <ColumnMetaData> metaDataAllList = null;

            lock (thisLock)
            {
                metaDataAllList = _cache.Get <List <ColumnMetaData> >(CacheKeys.TitleMetaData.ToString());
                if (metaDataAllList == null || metaDataAllList.Count == 0)
                {
                    metaDataAllList = _metaDataRepository.GetColumnsMetaData();
                    _cache.Set(CacheKeys.TitleMetaData.ToString(), metaDataAllList, new MemoryCacheEntryOptions
                    {
                        Priority           = CacheItemPriority.High,
                        AbsoluteExpiration = DateTimeOffset.Now.AddDays(4)
                    });
                }
            }
            var result = new List <ColumnMetaData>();

            foreach (var columnHeader in columnHeaders)
            {
                var metaData = metaDataAllList.FirstOrDefault(m => m.Key == columnHeader.ColumnName.Trim());
                if (metaData == null)
                {
                    metaData = new ColumnMetaData {
                        Key = columnHeader.ColumnName, Name = columnHeader.ColumnName, Title = ""
                    };
                }
                if (string.IsNullOrEmpty(metaData.Name))
                {
                    metaData.Name = columnHeader.ColumnName;
                }
                metaData.Field = columnHeader.Field;
                //if (!result.Any(fn => fn.ColumnName == metaData.ColumnName && fn.Field == metaData.Field))
                result.Add(metaData);
            }
            return(result);
        }