/// <summary>
        /// Examines the context changes from the ChangeTracker
        /// and returns a collection of LuceneIndexChanges
        /// </summary>
        /// <returns>LuceneIndexChangeset - collection of entity changes converted to LuceneIndexChanges</returns>
        private LuceneIndexChangeset GetChangeset()
        {
            LuceneIndexChangeset changes = new LuceneIndexChangeset();

            foreach (var entity in contextInterface.ChangeTracker.Entries().Where(x => x.State != EntityState.Unchanged))
            {
                Type entityType = entity.Entity.GetType();
                bool implementsILuceneIndexable = typeof(ILuceneIndexable).IsAssignableFrom(entityType);
                if (implementsILuceneIndexable == true)
                {
                    MethodInfo method = entityType.GetMethod("ToDocument");
                    if (method != null)
                    {
                        LuceneIndexChange change = new LuceneIndexChange(entity.Entity as ILuceneIndexable);

                        // If the entity doesn't have a guid IndexId, then add one in
                        if ((change.Entity.IndexId == Guid.Empty || change.Entity.IndexId == null) &&
                            (change.State == LuceneIndexState.Added || change.State == LuceneIndexState.Updated))
                        {
                            change.Entity.IndexId = Guid.NewGuid();
                        }

                        switch (entity.State)
                        {
                        case EntityState.Added:
                            change.State = LuceneIndexState.Added;
                            break;

                        case EntityState.Deleted:
                            change.State = LuceneIndexState.Removed;
                            break;

                        case EntityState.Modified:
                            change.State = LuceneIndexState.Updated;
                            break;

                        default:
                            change.State = LuceneIndexState.Unchanged;
                            break;
                        }
                        changes.Entries.Add(change);
                    }
                }
            }

            return(changes);
        }
Exemple #2
0
        /// <summary>
        /// Update a single LuceneIndexChange
        /// </summary>
        /// <param name="change">The change to make</param>
        /// <param name="optimize">Whether to optimize afterwards</param>
        public void Update(LuceneIndexChange change, bool optimize = false)
        {
            LuceneIndexChangeset changeset = new LuceneIndexChangeset(change, optimize);

            Update(changeset);
        }
 public LuceneIndexChangeset(LuceneIndexChange change, bool optimize = false)
 {
     Entries = new List <LuceneIndexChange>();
     Entries.Add(change);
     Optimize = optimize;
 }