/// <summary>
        /// Get the details for searchers
        /// </summary>
        /// <returns></returns>
        public IEnumerable <ExamineSearcherModel> GetSearcherDetails()
        {
            var model = new List <ExamineSearcherModel>(
                ExamineManager.Instance.SearchProviderCollection.Cast <BaseSearchProvider>().Select(searcher =>
            {
                var indexerModel = new ExamineSearcherModel()
                {
                    Name = searcher.Name
                };
                var props = TypeHelper.CachedDiscoverableProperties(searcher.GetType(), mustWrite: false)
                            //ignore these properties
                            .Where(x => new[] { "Description" }.InvariantContains(x.Name) == false)
                            .OrderBy(x => x.Name);
                foreach (var p in props)
                {
                    indexerModel.ProviderProperties.Add(p.Name, p.GetValue(searcher, null).ToString());
                }
                return(indexerModel);
            }).OrderBy(x =>
            {
                //order by name , but strip the "Searcher" from the end if it exists
                return(x.Name.TrimEnd("Searcher"));
            }));

            return(model);
        }
        private ExamineIndexerModel CreateModel(BaseIndexProvider indexer)
        {
            var indexerModel = new ExamineIndexerModel()
            {
                IndexCriteria = indexer.IndexerData,
                Name          = indexer.Name
            };
            var props = TypeHelper.CachedDiscoverableProperties(indexer.GetType(), mustWrite: false)
                        //ignore these properties
                        .Where(x => !new[] { "IndexerData", "Description", "WorkingFolder" }.InvariantContains(x.Name))
                        .OrderBy(x => x.Name);

            foreach (var p in props)
            {
                indexerModel.ProviderProperties.Add(p.Name, p.GetValue(indexer, null).ToString());
            }

            var luceneIndexer = indexer as LuceneIndexer;

            if (luceneIndexer != null && luceneIndexer.IndexExists())
            {
                indexerModel.IsLuceneIndex = true;
                indexerModel.DocumentCount = luceneIndexer.GetIndexDocumentCount();
                indexerModel.FieldCount    = luceneIndexer.GetIndexDocumentCount();
                indexerModel.IsOptimized   = luceneIndexer.IsIndexOptimized();
                indexerModel.DeletionCount = luceneIndexer.GetDeletedDocumentsCount();
            }
            return(indexerModel);
        }
示例#3
0
        private ExamineIndexerModel CreateModel(BaseIndexProvider indexer)
        {
            var indexerModel = new ExamineIndexerModel()
            {
                IndexCriteria = indexer.IndexerData,
                Name          = indexer.Name
            };
            var props = TypeHelper.CachedDiscoverableProperties(indexer.GetType(), mustWrite: false)
                        //ignore these properties
                        .Where(x => new[] { "IndexerData", "Description", "WorkingFolder" }.InvariantContains(x.Name) == false)
                        .OrderBy(x => x.Name);

            foreach (var p in props)
            {
                var val = p.GetValue(indexer, null);
                if (val == null)
                {
                    LogHelper.Warn <ExamineManagementApiController>("Property value was null when setting up property on indexer: " + indexer.Name + " property: " + p.Name);
                    val = string.Empty;
                }
                indexerModel.ProviderProperties.Add(p.Name, val.ToString());
            }

            var luceneIndexer = indexer as LuceneIndexer;

            if (luceneIndexer != null)
            {
                indexerModel.IsLuceneIndex = true;

                if (luceneIndexer.IndexExists())
                {
                    indexerModel.DocumentCount = luceneIndexer.GetIndexDocumentCount();
                    indexerModel.FieldCount    = luceneIndexer.GetIndexFieldCount();
                    indexerModel.IsOptimized   = luceneIndexer.IsIndexOptimized();
                    indexerModel.DeletionCount = luceneIndexer.GetDeletedDocumentsCount();
                }
                else
                {
                    indexerModel.DocumentCount = 0;
                    indexerModel.FieldCount    = 0;
                    indexerModel.IsOptimized   = true;
                    indexerModel.DeletionCount = 0;
                }
            }
            return(indexerModel);
        }
        private ExamineIndexerModel CreateModel(BaseIndexProvider indexer)
        {
            var indexerModel = new ExamineIndexerModel()
            {
                IndexCriteria = indexer.IndexerData,
                Name          = indexer.Name
            };

            var props = TypeHelper.CachedDiscoverableProperties(indexer.GetType(), mustWrite: false)
                        //ignore these properties
                        .Where(x => new[] { "IndexerData", "Description", "WorkingFolder" }.InvariantContains(x.Name) == false)
                        .OrderBy(x => x.Name);

            foreach (var p in props)
            {
                var val = p.GetValue(indexer, null);
                if (val == null)
                {
                    // Do not warn for new new attribute that is optional
                    if (string.Equals(p.Name, "DirectoryFactory", StringComparison.InvariantCultureIgnoreCase) == false)
                    {
                        LogHelper.Warn <ExamineManagementApiController>("Property value was null when setting up property on indexer: " + indexer.Name + " property: " + p.Name);
                    }

                    val = string.Empty;
                }
                indexerModel.ProviderProperties.Add(p.Name, val.ToString());
            }

            var luceneIndexer = indexer as LuceneIndexer;

            if (luceneIndexer != null)
            {
                indexerModel.IsLuceneIndex = true;

                if (luceneIndexer.IndexExists())
                {
                    Exception indexError;
                    indexerModel.IsHealthy = luceneIndexer.IsHealthy(out indexError);

                    if (indexerModel.IsHealthy == false)
                    {
                        //we cannot continue at this point
                        indexerModel.Error = indexError.ToString();
                        return(indexerModel);
                    }

                    indexerModel.DocumentCount = luceneIndexer.GetIndexDocumentCount();
                    indexerModel.FieldCount    = luceneIndexer.GetIndexFieldCount();
                    indexerModel.IsOptimized   = luceneIndexer.IsIndexOptimized();
                    indexerModel.DeletionCount = luceneIndexer.GetDeletedDocumentsCount();
                }
                else
                {
                    indexerModel.DocumentCount = 0;
                    indexerModel.FieldCount    = 0;
                    indexerModel.IsOptimized   = true;
                    indexerModel.DeletionCount = 0;
                }
            }
            return(indexerModel);
        }
        public PreValueEditor()
        {
            var fields = new List <PreValueField>();

            //the ctor checks if we have PreValueFieldAttributes applied and if so we construct our fields from them
            var props = TypeHelper.CachedDiscoverableProperties(GetType())
                        .Where(x => x.Name != "Fields");

            foreach (var p in props)
            {
                var att = p.GetCustomAttributes(typeof(PreValueFieldAttribute), false).OfType <PreValueFieldAttribute>().SingleOrDefault();
                if (att != null)
                {
                    if (att.PreValueFieldType != null)
                    {
                        //try to create it
                        try
                        {
                            var instance = (PreValueField)Activator.CreateInstance(att.PreValueFieldType);
                            //overwrite values if they are assigned
                            if (!att.Key.IsNullOrWhiteSpace())
                            {
                                instance.Key = att.Key;
                            }
                            //if the key is still empty then assign it to be the property name
                            if (instance.Key.IsNullOrWhiteSpace())
                            {
                                instance.Key = p.Name;
                            }

                            if (!att.Name.IsNullOrWhiteSpace())
                            {
                                instance.Name = att.Name;
                            }
                            if (!att.View.IsNullOrWhiteSpace())
                            {
                                instance.View = att.View;
                            }
                            if (!att.Description.IsNullOrWhiteSpace())
                            {
                                instance.Description = att.Description;
                            }
                            if (att.HideLabel)
                            {
                                instance.HideLabel = att.HideLabel;
                            }

                            //add the custom field
                            fields.Add(instance);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.WarnWithException <PreValueEditor>("Could not create an instance of " + att.PreValueFieldType, ex);
                        }
                    }
                    else
                    {
                        fields.Add(MapAttributeToField(att, p));
                    }
                }
            }

            Fields = fields;
        }
        /// <summary>
        /// Discovers fields from configuration properties marked with the field attribute.
        /// </summary>
        private static List <ConfigurationField> DiscoverFields(IIOHelper ioHelper)
        {
            var fields     = new List <ConfigurationField>();
            var properties = TypeHelper.CachedDiscoverableProperties(typeof(TConfiguration));

            foreach (var property in properties)
            {
                var attribute = property.GetCustomAttribute <ConfigurationFieldAttribute>(false);
                if (attribute == null)
                {
                    continue;
                }

                ConfigurationField field;

                var attributeView = ioHelper.ResolveRelativeOrVirtualUrl(attribute.View);
                // if the field does not have its own type, use the base type
                if (attribute.Type == null)
                {
                    field = new ConfigurationField
                    {
                        // if the key is empty then use the property name
                        Key          = string.IsNullOrWhiteSpace(attribute.Key) ? property.Name : attribute.Key,
                        Name         = attribute.Name,
                        PropertyName = property.Name,
                        PropertyType = property.PropertyType,
                        Description  = attribute.Description,
                        HideLabel    = attribute.HideLabel,
                        View         = attributeView
                    };

                    fields.Add(field);
                    continue;
                }

                // if the field has its own type, instantiate it
                try
                {
                    field = (ConfigurationField)Activator.CreateInstance(attribute.Type);
                }
                catch (Exception ex)
                {
                    throw new Exception($"Failed to create an instance of type \"{attribute.Type}\" for property \"{property.Name}\" of configuration \"{typeof(TConfiguration).Name}\" (see inner exception).", ex);
                }

                // then add it, and overwrite values if they are assigned in the attribute
                fields.Add(field);

                field.PropertyName = property.Name;
                field.PropertyType = property.PropertyType;

                if (!string.IsNullOrWhiteSpace(attribute.Key))
                {
                    field.Key = attribute.Key;
                }

                // if the key is still empty then use the property name
                if (string.IsNullOrWhiteSpace(field.Key))
                {
                    field.Key = property.Name;
                }

                if (!string.IsNullOrWhiteSpace(attribute.Name))
                {
                    field.Name = attribute.Name;
                }

                if (!string.IsNullOrWhiteSpace(attribute.View))
                {
                    field.View = attributeView;
                }

                if (!string.IsNullOrWhiteSpace(attribute.Description))
                {
                    field.Description = attribute.Description;
                }

                if (attribute.HideLabelSettable.HasValue)
                {
                    field.HideLabel = attribute.HideLabel;
                }
            }

            return(fields);
        }