示例#1
0
        public static IDictionary <DocumentIndexTypeToken, DocumentIndexType> Load()
        {
            IDictionary <DocumentIndexTypeToken, IndexFileName> typeDescriptions = EnumServices.Load <DocumentIndexTypeToken, IndexFileName>();
            var documentIndexAttribute = typeof(DocumentIndexType).GetCustomAttribute <DocumentIndexAttribute>()
                                         .FailIfNothing(() => new InvalidOperationException("DocumentIndexType type should have DocumentIndexAttribute"));
            var accSource = Enum.GetValues(typeof(DocumentIndexTypeToken))
                            .Cast <DocumentIndexTypeToken>()
                            .ToDictionary(x => x, _ => new DocumentIndexTypeTokenMetadata());

            return(documentIndexAttribute.IndexAttributeTypes.Concat(documentIndexAttribute.DocumentAttributeTypes).Concat(new[] { documentIndexAttribute.VersionAttributeType })
                   .Select(EnumServices.Load <DocumentIndexTypeToken>)
                   .Aggregate(accSource, (acc, x) =>
            {
                foreach (KeyValuePair <DocumentIndexTypeToken, Attribute> p in x)
                {
                    var indexableFieldsProvider = p.Value as IIndexFieldsProvider;
                    if (indexableFieldsProvider != null)
                    {
                        acc[p.Key].AddIndexFields(indexableFieldsProvider.IndexFields);
                    }
                    var documentFieldsProvider = p.Value as IDocumentFieldsProvider;
                    if (documentFieldsProvider != null)
                    {
                        acc[p.Key].AddDocumentFields(documentFieldsProvider.DocumentFields);
                    }
                    var maybeVersion = p.Value as DocumentIndexVersionAttribute;
                    if (maybeVersion != null)
                    {
                        acc[p.Key].Version = maybeVersion.Version;
                    }
                }
                return acc;
            }).ToDictionary(p => p.Key, p => new DocumentIndexType(p.Key, typeDescriptions[p.Key].FileName, p.Value.IndexFields, p.Value.DocumentFields, p.Value.Version)));
        }
        private static IDictionary <IndexTypeToken, DocumentIndexType> Load(DocumentIndexDataTypeServiceFactory documentIndexDataTypeServiceFactory)
        {
            IDictionary <DocumentIndexTypeToken, IndexFileName> typeDescriptions = EnumServices.Load <DocumentIndexTypeToken, IndexFileName>();
            var documentIndexAttribute = typeof(DocumentIndexType).GetCustomAttribute <DocumentIndexAttribute>()
                                         .GetOrThrow(() => new InvalidOperationException("DocumentIndexType type should have DocumentIndexAttribute"));
            var accSource = Enum.GetValues(typeof(DocumentIndexTypeToken))
                            .Cast <DocumentIndexTypeToken>()
                            .ToDictionary(x => x, _ => new DocumentIndexTypeTokenMetadata());

            return(documentIndexAttribute.IndexAttributeTypes.Concat(documentIndexAttribute.DocumentAttributeTypes)
                   .Concat(new[] { documentIndexAttribute.VersionAttributeType, documentIndexAttribute.DataTypeTokenAttributeType })
                   .Select(EnumServices.Load <DocumentIndexTypeToken>)
                   .Aggregate(accSource, (acc, x) =>
            {
                foreach (KeyValuePair <DocumentIndexTypeToken, Attribute> p in x)
                {
                    var metadata = acc[p.Key];
                    var indexableFieldsProvider = p.Value as IIndexFieldsProvider;
                    if (indexableFieldsProvider != null)
                    {
                        metadata.AddIndexFields(indexableFieldsProvider.IndexFields);
                    }
                    var documentFieldsProvider = p.Value as IDocumentFieldsProvider;
                    if (documentFieldsProvider != null)
                    {
                        metadata.AddDocumentFields(documentFieldsProvider.DocumentFields);
                    }
                    var maybeVersion = p.Value as DocumentIndexVersionAttribute;
                    if (maybeVersion != null)
                    {
                        metadata.Version = maybeVersion.Version;
                    }
                    var maybeDataToken = p.Value as DocumentIndexDataTypeAttribute;
                    if (maybeDataToken != null)
                    {
                        metadata.AddDataTypeToken(maybeDataToken.Tokens);
                    }
                }
                return acc;
            })
                   .SelectMany(p => p.Value.DataTypeTokens.Select(d => new DocumentIndexType(p.Key, d, typeDescriptions[p.Key].FileName, p.Value.IndexFields, p.Value.DocumentFields, p.Value.Version, documentIndexDataTypeServiceFactory.Create(d), new FileService())))
                   .ToDictionary(x => new IndexTypeToken {
                Type = x.TypeToken, DataType = x.DataTypeToken
            }, _ => _));
        }
        public EnumDescriptions()
        {
            var loaded = EnumServices.Load <TEnum, DescriptionAttribute>();

            _descriptions = loaded.ToDictionary(x => x.Key, x => x.Value.Description);
        }