コード例 #1
0
        private void ProcessTaxonomyTerms(ExportImportJob importJob, ImportDto importDto,
                                          IList <TaxonomyVocabulary> otherVocabularies, IList <TaxonomyTerm> otherTaxonomyTerms)
        {
            var dataService = Util.GetDataService();
            //var vocabularyController = new VocabularyController();
            var localTaxonomyTerms = GetTaxonomyTerms(importDto.PortalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null);

            foreach (var other in otherTaxonomyTerms)
            {
                var createdBy  = Common.Util.GetUserIdByName(importJob, other.CreatedByUserID, other.CreatedByUserName);
                var modifiedBy = Common.Util.GetUserIdByName(importJob, other.LastModifiedByUserID, other.LastModifiedByUserName);

                var vocabulary   = otherVocabularies.FirstOrDefault(v => v.VocabularyID == other.VocabularyID);
                var vocabularyId = vocabulary?.LocalId ?? 0;
                var local        = localTaxonomyTerms.FirstOrDefault(t => t.Name == other.Name && t.VocabularyID == vocabularyId);

                if (local != null)
                {
                    other.LocalId = local.TermID;
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Ignore:
                        Result.AddLogEntry("Ignored taxonomy", other.Name);
                        break;

                    case CollisionResolution.Overwrite:
                        var parent = other.ParentTermID.HasValue
                                ? otherTaxonomyTerms.FirstOrDefault(v => v.TermID == other.ParentTermID.Value)
                                : null;
                        var term = new Term(other.Name, other.Description, vocabularyId)
                        {
                            TermId       = local.TermID,
                            ParentTermId = parent?.LocalId,
                            Weight       = other.Weight,
                        };

                        if (term.ParentTermId.HasValue)
                        {
                            dataService.UpdateHeirarchicalTerm(term, modifiedBy);
                        }
                        else
                        {
                            dataService.UpdateSimpleTerm(term, modifiedBy);
                        }
                        DataCache.ClearCache(string.Format(DataCache.TermCacheKey, term.TermId));
                        Result.AddLogEntry("Updated taxonomy", other.Name);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                else
                {
                    var parent = other.ParentTermID.HasValue
                        ? otherTaxonomyTerms.FirstOrDefault(v => v.TermID == other.ParentTermID.Value)
                        : null;
                    var term = new Term(other.Name, other.Description, vocabularyId)
                    {
                        ParentTermId = parent?.LocalId,
                        Weight       = other.Weight,
                    };


                    other.LocalId = term.ParentTermId.HasValue
                        ? dataService.AddHeirarchicalTerm(term, createdBy)
                        : dataService.AddSimpleTerm(term, createdBy);
                    Result.AddLogEntry("Added taxonomy", other.Name);
                }
            }
        }
コード例 #2
0
        private void ProcessVocabularies(ExportImportJob importJob, ImportDto importDto,
                                         IList <TaxonomyScopeType> otherScopeTypes, IEnumerable <TaxonomyVocabulary> otherVocabularies)
        {
            var changed           = false;
            var dataService       = Util.GetDataService();
            var localVocabularies = GetTaxonomyVocabularies(importDto.PortalId, DateUtils.GetDatabaseUtcTime().AddYears(1), null);

            foreach (var other in otherVocabularies)
            {
                var createdBy  = Common.Util.GetUserIdByName(importJob, other.CreatedByUserID, other.CreatedByUserName);
                var modifiedBy = Common.Util.GetUserIdByName(importJob, other.LastModifiedByUserID, other.LastModifiedByUserName);
                var local      = localVocabularies.FirstOrDefault(t => t.Name == other.Name);
                var scope      = otherScopeTypes.FirstOrDefault(s => s.ScopeTypeID == other.ScopeTypeID);

                var scopeId = other.ScopeID ?? Null.NullInteger;
                if (scope != null && scope.ScopeType.Equals("Application", StringComparison.InvariantCultureIgnoreCase))
                {
                    scopeId = Null.NullInteger;
                }
                else if (scope != null && scope.ScopeType.Equals("Portal", StringComparison.InvariantCultureIgnoreCase))
                {
                    scopeId = importDto.PortalId;
                }

                if (local != null)
                {
                    other.LocalId = local.VocabularyID;
                    switch (importDto.CollisionResolution)
                    {
                    case CollisionResolution.Ignore:
                        Result.AddLogEntry("Ignored vocabulary", other.Name);
                        break;

                    case CollisionResolution.Overwrite:
                        var vocabulary = new Vocabulary(other.Name, other.Description)
                        {
                            IsSystem    = other.IsSystem,
                            Weight      = other.Weight,
                            ScopeId     = scopeId,
                            ScopeTypeId = scope?.LocalId ?? other.ScopeTypeID,
                        };
                        dataService.UpdateVocabulary(vocabulary, modifiedBy);
                        Result.AddLogEntry("Updated vocabulary", other.Name);
                        changed = true;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(importDto.CollisionResolution.ToString());
                    }
                }
                else
                {
                    var vocabulary = new Vocabulary(other.Name, other.Description, (VocabularyType)other.VocabularyTypeID)
                    {
                        IsSystem    = other.IsSystem,
                        Weight      = other.Weight,
                        ScopeId     = scopeId,
                        ScopeTypeId = scope?.LocalId ?? other.ScopeTypeID,
                    };
                    other.LocalId = dataService.AddVocabulary(vocabulary, createdBy);
                    Result.AddLogEntry("Added vocabulary", other.Name);
                    changed = true;
                }
            }
            if (changed)
            {
                DataCache.ClearCache(DataCache.VocabularyCacheKey);
            }
        }