コード例 #1
0
        private async Task <ChangesResult <TDbEntity, TParseModelEntity> > GetChangesAsync <TDbEntity, TParseModelEntity>(
            int trainingProviderId,
            IEnumerable <TDbEntity> existingEntities,
            Dictionary <IUrlNameNaturalKey, TParseModelEntity> processingEntitiesContainer,
            IChangesDetector <TDbEntity, TParseModelEntity> changesDetector,
            Func <int, TParseModelEntity, Task <TDbEntity> > entityMapper,
            Action <TDbEntity, TParseModelEntity> keyAssignAction)
            where TParseModelEntity : IUrlNameNaturalKey
            where TDbEntity : IUrlNameNaturalKey
        {
            var unmodifiedEntities = new List <EntityPair <TDbEntity, TParseModelEntity> >();
            var modifiedEntities   = new List <EntityPair <TDbEntity, TParseModelEntity> >();
            var deletedEntities    = new List <TDbEntity>();

            foreach (var existingEntity in existingEntities)
            {
                TParseModelEntity processingEntity;
                if (processingEntitiesContainer.TryGetValue(existingEntity, out processingEntity))
                {
                    // assign identity key of the existing entity to the processing entity
                    if (keyAssignAction != null)
                    {
                        keyAssignAction.Invoke(existingEntity, processingEntity);
                    }

                    if (changesDetector.IsDifferent(existingEntity, processingEntity))
                    {
                        modifiedEntities.Add(new EntityPair <TDbEntity, TParseModelEntity>(existingEntity, processingEntity));
                    }
                    else
                    {
                        unmodifiedEntities.Add(new EntityPair <TDbEntity, TParseModelEntity>(existingEntity, processingEntity));
                    }

                    // need to detect new entities
                    processingEntitiesContainer.Remove(existingEntity);
                }
                else
                {
                    deletedEntities.Add(existingEntity);
                }
            }

            var newEntities = new List <EntityPair <TDbEntity, TParseModelEntity> >();

            foreach (var parseModelEntity in processingEntitiesContainer.Values)
            {
                var mappedEntity = await entityMapper.Invoke(trainingProviderId, parseModelEntity);

                newEntities.Add(new EntityPair <TDbEntity, TParseModelEntity>(mappedEntity, parseModelEntity));
            }

            var changesResult = new ChangesResult <TDbEntity, TParseModelEntity>(unmodifiedEntities, modifiedEntities,
                                                                                 newEntities, deletedEntities);

            return(changesResult);
        }
コード例 #2
0
 /// <exception cref="UpdateProcessorException"></exception>
 protected virtual async Task UpdateCategoriesAsync(ChangesResult <Category, TCategoryParseModel> categoriesChanges)
 {
     try
     {
         ProcessModifiedCategories(categoriesChanges.ModifiedEntities);
         ProcessDeletedCategories(categoriesChanges.DeletedEntities);
         await ProcessNewCategories(categoriesChanges.NewEntities);
     }
     catch (Exception ex)
     {
         throw new UpdateProcessorException(Resources.UpdateProcessorException_CategoriesUpdate_Message, ex);
     }
 }
コード例 #3
0
 /// <exception cref="UpdateProcessorException"></exception>
 protected virtual async Task UpdateCoursesAsync(ChangesResult <Course, TCourseParseModel> coursesChanges, List <AuthorResolve> authorResolves)
 {
     try
     {
         ProcessCategoryAndAuthorsChangesForUnmodifiedCourses(coursesChanges.UnmodifiedEntities, authorResolves);
         ProcessModifiedCourses(coursesChanges.ModifiedEntities, authorResolves);
         ProcessDeletedCourses(coursesChanges.DeletedEntities);
         await ProcessNewCourses(coursesChanges.NewEntities, authorResolves);
     }
     catch (Exception ex)
     {
         throw new UpdateProcessorException(Resources.UpdateProcessorException_CoursesUpdate_Message, ex);
     }
 }
コード例 #4
0
        /// <exception cref="UpdateProcessorException"></exception>
        protected virtual async Task UpdateAuthorsAsync(ChangesResult <TrainingProviderAuthor, TAuthorParseModel> authorsChanges, List <AuthorResolve> authorResolves)
        {
            try
            {
                ProcessModifiedAuthors(authorsChanges.ModifiedEntities);
                ProcessDeletedAuthors(authorsChanges.DeletedEntities, authorResolves);

                await ProcessNewAuthors(authorsChanges.NewEntities);
            }
            catch (Exception ex)
            {
                throw new UpdateProcessorException(Resources.UpdateProcessorException_AuthorsUpdate_Message, ex);
            }
        }