public IndexResult UpdateGeneralIndex(GeneralDTO general, ICollection <GeneralField> changedFields) { if (general.GeneralID == null) { return(new IndexResult()); } IEnumerable <IDocumentIndex> indexes = _documentIndexProvider.GetOrCreateDocumentIndexes(_pluginContext.AccountName, DocumentIndexTypeToken.Entity, DocumentIndexTypeToken.EntityProject, DocumentIndexTypeToken.EntityType); if (!indexes.Any(i => changedFields.Any(f => i.Type.IsBelongedToIndexFields(f) || i.Type.IsBelongedToDocumentFields(f)))) { return(new IndexResult()); } IDocumentIndex entityIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.Entity); var document = entityIndex.FindDocumentByName <EntityDocument>(EntityDocument.CreateName(general.GeneralID)); 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 !!!", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.Name)); return(new IndexResult()); } if (changedFields.Any(f => entityIndex.Type.IsBelongedToDocumentFields(f))) { document.ProjectId = _documentIdFactory.CreateProjectId(general.ParentProjectID.GetValueOrDefault()); document.EntityTypeId = _documentIdFactory.CreateEntityTypeId(general.EntityTypeID.GetValueOrDefault()); entityIndex.SaveDocument(document, false); _log.Debug(string.Format("Updated {0} #{1} - '{2}':{3}{4}", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.Name, changedFields.Contains(GeneralField.ParentProjectID) ? string.Format(" Project - {0};", string.Join(",", general.ParentProjectName)) : string.Empty, changedFields.Contains(GeneralField.EntityTypeID) ? string.Format(" EntityType - {0};", string.Join(",", general.EntityTypeName)) : string.Empty)); } if (changedFields.Any(f => entityIndex.Type.IsBelongedToIndexFields(f))) { var text = _textOperations.Prepare(string.Format("{0} {1} ", general.Name, general.Description ?? string.Empty)); var indexResult = entityIndex.Update(document.FileName, text); _log.Debug(string.Format("Updated {0} #{1} - '{2}':{3}{4}", general.EntityTypeName, general.GeneralID.GetValueOrDefault(), general.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)) && document.DocNumber >= 0) { entityProjectIndex.Update(document.DocNumber, general.ParentProjectID.HasValue ? _documentIdFactory.EncodeProjectId(general.ParentProjectID.Value) : string.Empty); _localBus.SendLocal(new GeneralProjectChangedLocalMessage { GeneralId = general.GeneralID.Value, ProjectId = general.ParentProjectID }); } IDocumentIndex entityTypeIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.EntityType); if (changedFields.Any(f => entityTypeIndex.Type.IsBelongedToIndexFields(f)) && document.DocNumber >= 0) { entityTypeIndex.Index(document.DocNumber, general.EntityTypeName); } return(new IndexResult { DocNumber = document.DocNumber }); }
public EntityDocument CreateGeneral(GeneralDTO general) { string name = EntityDocument.CreateName(general.GeneralID); string text = _textOperations.Prepare(String.Format("{0} {1} ", general.Name, general.Description ?? String.Empty)); return(new EntityDocument(name, text) { ProjectId = _documentIdFactory.CreateProjectId(general.ParentProjectID.GetValueOrDefault()), EntityTypeId = _documentIdFactory.CreateEntityTypeId(general.EntityTypeID.GetValueOrDefault()), SquadId = _documentIdFactory.CreateSquadId(0), DocNumber = -1 }); }