Ejemplo n.º 1
0
        public IndexResult RemoveAssignableIndex(AssignableDTO assignable)
        {
            if (assignable.AssignableID == null)
            {
                return(new IndexResult());
            }
            var entityIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.Entity);
            var doc         = entityIndex.FindDocumentByName <EntityDocument>(EntityDocument.CreateName(assignable.AssignableID));

            if (doc == null)
            {
                _log.Error(string.Format("CANNOT PROCESS UPDATE '{0}DeletedMessage' FOR ENTITY #{1} - '{2}'. ENTITY WAS NOT ADDED DURING PROFILE INITIALIZATION OR ENTITY CREATION !!!", assignable.EntityTypeName, assignable.AssignableID.GetValueOrDefault(), assignable.Name));
                return(new IndexResult());
            }
            var indexResult = entityIndex.Rebuild(CreateEmptyEntityDocument(doc.DocNumber, EntityDocument.CreateName(assignable.AssignableID)));

            _log.Debug(string.Format("Removed {0} #{1} - '{2}'", assignable.EntityTypeName, assignable.AssignableID.GetValueOrDefault(), assignable.Name));
            if (doc.DocNumber >= 0)
            {
                IDocumentIndex projectContextIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityProject);
                projectContextIndex.Update(doc.DocNumber, string.Empty);
                IDocumentIndex entityTypeIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityType);
                entityTypeIndex.Update(doc.DocNumber, string.Empty);
                IDocumentIndex entityStateIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityState);
                entityStateIndex.Update(doc.DocNumber, string.Empty);
                IDocumentIndex entitySquadIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntitySquad);
                entitySquadIndex.Update(doc.DocNumber, string.Empty);
            }
            return(indexResult);
        }
        private void UpdateAssignableIndex(AssignableDTO assignableDto, ICollection <AssignableField> changedAssignableFields)
        {
            if (!changedAssignableFields.Any(
                    f => f == AssignableField.Description || f == AssignableField.Name || f == AssignableField.EntityStateID ||
                    f == AssignableField.ProjectID || f == AssignableField.EntityTypeID || f == AssignableField.SquadID))
            {
                return;
            }

            _entityIndexer.UpdateAssignableIndex(assignableDto, changedAssignableFields, isIndexing: false);
            _entityIndexer.OptimizeAssignableIndex();
        }
        public EntityDocument CreateAssignable(AssignableDTO assignable)
        {
            var name = EntityDocument.CreateName(assignable.AssignableID);
            var text = _textOperations.Prepare(string.Format("{0} {1} ", assignable.Name, assignable.Description ?? string.Empty));

            return(new EntityDocument(name, text)
            {
                ProjectId = _documentIdFactory.CreateProjectId(assignable.ProjectID.GetValueOrDefault()),
                EntityTypeId = _documentIdFactory.CreateEntityTypeId(assignable.EntityTypeID.GetValueOrDefault()),
                SquadId = _documentIdFactory.CreateSquadId(assignable.SquadID.GetValueOrDefault()),
                DocNumber = -1
            });
        }
Ejemplo n.º 4
0
        public IndexResult AddAssignableIndex(AssignableDTO assignable)
        {
            if (assignable.AssignableID == null)
            {
                return(new IndexResult());
            }
            if (Exists <EntityDocument>(assignable.AssignableID.Value, DocumentIndexTypeToken.Entity))
            {
                if (_profile.Initialized)
                {
                    _log.WarnFormat("CANNOT PROCESS '{0}CreatedMessage' FOR ENTITY #{1} - '{2}'. ENTITY HAS ALREADY BEEN ADDED ON PROFILE INITIALIZATION OR ENTITY CREATION !!!", assignable.EntityTypeName, assignable.AssignableID.GetValueOrDefault(), assignable.Name);
                }
                else
                {
                    _log.ErrorFormat("CANNOT PROCESS '{0}CreatedMessage' FOR ENTITY #{1} - '{2}'. ENTITY HAS ALREADY BEEN ADDED !!!", assignable.EntityTypeName, assignable.AssignableID.GetValueOrDefault(), assignable.Name);
                }
                return(new IndexResult());
            }
            IDocumentIndex entityIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.Entity);
            EntityDocument doc         = _documentFactory.CreateAssignable(assignable);
            var            indexResult = doc == null ? new IndexResult() : entityIndex.Index(doc, false);

            if (indexResult.DocNumber != -1)
            {
                IDocumentIndex entityProjectIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityProject);
                entityProjectIndex.Index(indexResult.DocNumber, _documentIdFactory.EncodeProjectId(assignable.ProjectID));
                Maybe <string> maybeEntityTypeName = _entityTypeProvider.GetEntityTypeName(assignable.EntityTypeID);
                string         entityTypeName      = maybeEntityTypeName.FailIfNothing(() => new ApplicationException("Entity type name was not found {0}".Fmt(assignable.EntityTypeID)));
                IDocumentIndex entityTypeIndex     = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityType);
                entityTypeIndex.Index(indexResult.DocNumber, entityTypeName);
                if (assignable.EntityStateID != null)
                {
                    IDocumentIndex entityStateIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityState);
                    entityStateIndex.Index(indexResult.DocNumber, _documentIdFactory.EncodeEntityStateId(assignable.EntityStateID.Value));
                }
                IDocumentIndex squadIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntitySquad);
                squadIndex.Index(indexResult.DocNumber, _documentIdFactory.EncodeSquadId(assignable.SquadID));
            }
            _log.Debug(string.Format("Added {0} #{1} - '{2}':{3}", assignable.EntityTypeName, assignable.AssignableID.GetValueOrDefault(), assignable.Name, indexResult.WordsAdded.Any() ? string.Format(" added words - {0};", string.Join(",", indexResult.WordsAdded.Keys)) : " NO WORDS ADDED;"));
            return(indexResult);
        }
 private void RemoveAssignableIndex(AssignableDTO assignableDto)
 {
     RebuildOrAction(() => _entityIndexer.RemoveAssignableIndex(assignableDto, DocumentIndexOptimizeSetup.DeferredOptimize));
 }
 private void UpdateAssignableIndex(AssignableDTO assignableDto, ICollection <AssignableField> changedAssignableFields)
 {
     RebuildOrAction(() => _entityIndexer.UpdateAssignableIndex(assignableDto, changedAssignableFields, false, DocumentIndexOptimizeSetup.DeferredOptimize));
 }
 private void RemoveAssignableIndex(AssignableDTO assignableDto)
 {
     _entityIndexer.RemoveAssignableIndex(assignableDto);
 }
 private void AddAssignableIndex(AssignableDTO assignableDto)
 {
     _entityIndexer.AddAssignableIndex(assignableDto);
     _entityIndexer.OptimizeAssignableIndex();
 }
Ejemplo n.º 9
0
        public IndexResult UpdateAssignableIndex(AssignableDTO assignable, ICollection <AssignableField> changedFields, bool isIndexing)
        {
            var indexResult = new IndexResult();

            if (assignable.AssignableID == null)
            {
                return(new IndexResult());
            }
            IEnumerable <IDocumentIndex> indexes = _documentIndexProvider.GetOrCreateDocumentIndexes(_pluginContext.AccountName, DocumentIndexTypeToken.Entity, DocumentIndexTypeToken.EntityProject, DocumentIndexTypeToken.EntityType, DocumentIndexTypeToken.EntityState, DocumentIndexTypeToken.EntitySquad);

            if (!changedFields.Any(f => indexes.Any(i => i.Type.IsBelongedToDocumentFields(f) || i.Type.IsBelongedToIndexFields(f))))
            {
                return(new IndexResult());
            }
            var entityIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.Entity);
            var document    = entityIndex.FindDocumentByName <EntityDocument>(EntityDocument.CreateName(assignable.AssignableID));

            if (document == null)
            {
                _log.Error(string.Format("CANNOT PROCESS UPDATE '{0}UpdatedMessage' FOR ENTITY #{1} - '{2}'. ENTITY WAS NOT ADDED DURING PROFILE INITIALIZATION OR ENTITY CREATION !!!",
                                         assignable.EntityTypeName, assignable.AssignableID.GetValueOrDefault(), assignable.Name));
                return(indexResult);
            }
            if (changedFields.Any(f => entityIndex.Type.IsBelongedToDocumentFields(f)))
            {
                document.ProjectId    = _documentIdFactory.CreateProjectId(assignable.ProjectID.GetValueOrDefault());
                document.SquadId      = _documentIdFactory.CreateSquadId(assignable.SquadID.GetValueOrDefault());
                document.EntityTypeId = _documentIdFactory.CreateEntityTypeId(assignable.EntityTypeID.GetValueOrDefault());
                entityIndex.SaveDocument(document, false);
                _log.Debug(string.Format("Updated {0} #{1} - '{2}':{3}{4}{5}", assignable.EntityTypeName,
                                         assignable.AssignableID.GetValueOrDefault(), assignable.Name,
                                         changedFields.Contains(AssignableField.ProjectID) ? string.Format(" Project - {0};", string.Join(",", assignable.ProjectName)) : string.Empty,
                                         changedFields.Contains(AssignableField.EntityTypeID) ? string.Format(" EntityType - {0};", string.Join(",", assignable.EntityTypeName)) : string.Empty,
                                         changedFields.Contains(AssignableField.EntityStateID) ? string.Format(" EntityState - {0};", string.Join(",", assignable.EntityStateName)) : string.Empty));
            }
            if (document.DocNumber >= 0)
            {
                if (changedFields.Any(f => entityIndex.Type.IsBelongedToIndexFields(f)))
                {
                    var text = _textOperations.Prepare(string.Format("{0} {1} ", assignable.Name, assignable.Description ?? string.Empty));
                    indexResult = entityIndex.Update(document.DocNumber, text);
                    _log.Debug(string.Format("Updated {0} #{1} - '{2}':{3}{4}", assignable.EntityTypeName,
                                             assignable.AssignableID.GetValueOrDefault(), assignable.Name,
                                             indexResult.WordsAdded.Any() ? string.Format(" added words - {0};", string.Join(",", indexResult.WordsAdded.Keys)) : " NO WORDS ADDED;",
                                             indexResult.WordsRemoved.Any() ? string.Format(" removed words - {0}; ", string.Join(",", indexResult.WordsRemoved)) : " NO WORDS REMOVED;"));
                }
                IDocumentIndex entityProjectIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityProject);
                if (changedFields.Any(f => entityProjectIndex.Type.IsBelongedToIndexFields(f)))
                {
                    entityProjectIndex.Update(document.DocNumber, _documentIdFactory.EncodeProjectId(assignable.ProjectID));
                    if (!isIndexing)
                    {
                        _localBus.SendLocal(new GeneralProjectChangedLocalMessage {
                            GeneralId = assignable.AssignableID.Value, ProjectId = assignable.ProjectID
                        });
                    }
                }
                if (assignable.EntityTypeID != null)
                {
                    IDocumentIndex entityTypeIndices = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityType);
                    if (changedFields.Any(f => entityTypeIndices.Type.IsBelongedToIndexFields(f)))
                    {
                        entityTypeIndices.Update(document.DocNumber, assignable.EntityTypeName);
                    }
                }
                if (assignable.EntityStateID != null)
                {
                    IDocumentIndex entityStateIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityState);
                    if (changedFields.Any(f => entityStateIndex.Type.IsBelongedToIndexFields(f)))
                    {
                        entityStateIndex.Update(document.DocNumber, _documentIdFactory.EncodeEntityStateId(assignable.EntityStateID.Value));
                    }
                }
                IDocumentIndex entitySquadIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntitySquad);
                if (changedFields.Any(f => entitySquadIndex.Type.IsBelongedToIndexFields(f)))
                {
                    entitySquadIndex.Update(document.DocNumber, _documentIdFactory.EncodeSquadId(assignable.SquadID));
                    if (!isIndexing)
                    {
                        _localBus.SendLocal(new AssignableSquadChangedLocalMessage {
                            AssignableId = assignable.AssignableID.Value, SquadId = assignable.SquadID
                        });
                    }
                }
            }
            return(indexResult);
        }