コード例 #1
0
        public TranslationDefinitions(IResolveManager resolveManager,
                                      ITranslationPrimitives translationPrimitives,
                                      ITranslationUnitOfWork unitOfWork,
                                      TranslationDirection directionDefinition,
                                      IVersioningManager versioningManager,
                                      Type typeToInstantiate = null,
                                      TOut predefinedTarget  = null,
                                      Guid?requestlanguageId = null,
                                      TranslationPolicy translationPolicies = TranslationPolicy.Defaults)
        {
            this.resolveManager            = resolveManager;
            this.translationPrimitives     = translationPrimitives;
            this.directionDefinition       = directionDefinition;
            this.typeToInstantiate         = typeToInstantiate ?? typeof(TOut);
            this.unitOfWork                = unitOfWork;
            this.targetInstance            = predefinedTarget;
            this.requestlanguageIdAssigned = requestlanguageId;
            var cacheManager = resolveManager.Resolve <ICacheManager>();

            this.languageCache         = cacheManager.LanguageCache;
            this.publishingStatusCache = cacheManager.PublishingStatusCache;
            this.versioningManager     = versioningManager;
            this.translationPolicies   = translationPolicies;
            this.entityOutSet          = unitOfWork?.GetSet <TOut>() as IQueryable <TOut>;
            if (this.unitOfWork != null && this.targetInstance != null)
            {
                var cached = unitOfWork.TranslationCloneCache.GetFromCachedSet <TOut>();
                clonedTargetApplied = cached.Any(i => i.ClonedEntity == this.targetInstance);
            }
        }
コード例 #2
0
        public ITranslationDefinitions <TIn, TOut> AddCollectionWithRemove <TInProperty, TOutProperty>(Func <TIn, IEnumerable <TInProperty> > fromProperty,
                                                                                                       Expression <Func <TOut, IEnumerable <TOutProperty> > > toProperty, Action <DefinitionDeepClause <TOutProperty> > deepConditions) where TInProperty : class where TOutProperty : class
        {
            TranslationPolicy translationPolicy = TranslationPolicy.Defaults;

            AddCollectionInternal <TInProperty, TOutProperty>(fromProperty, toProperty, keepUntouchedAndMerge: translationPolicy.HasFlag(TranslationPolicy.MergeOutputCollections), fetchData: translationPolicy.HasFlag(TranslationPolicy.FetchData), deepConditionsRemove: deepConditions);
            return(this);
        }
コード例 #3
0
        public ITranslationDefinitions <TIn, TOut> UseVersioning <TOutVersioned, TOutRoot>(Expression <Func <TOut, TOutVersioned> > versioned, VersioningMode versioningMode = VersioningMode.Standard, Func <TIn, bool> versioningCondition = null) where TOutRoot : class, IVersionedRoot, new()  where TOutVersioned : class, TOut, IVersionedVolume <TOutRoot>, new()
        {
            if (unitOfWork == null)
            {
                return(this);
            }
            if (sourceInstance == null)
            {
                return(this);
            }
            if (targetInstance == null)
            {
                throw new Exception(CoreMessages.TranslatorWrongVersioningUsage);
            }
            if ((versioningCondition != null) && (!versioningCondition(sourceInstance)))
            {
                return(this);
            }
            var tracked = targetInstance as IVersionedTrackedEntity;

            if (tracked?.VersioningApplied == true)
            {
                return(this);
            }
            var versionedEntity = versioned.Compile()(targetInstance);
            var newTarget       = versioningManager.CreateEntityVersion(unitOfWork, versionedEntity, versioningMode);

            clonedTargetApplied = newTarget != versionedEntity;
            versionedEntity     = newTarget;
            versioningManager.EnsureUnificRoot(versionedEntity);
            targetInstance = versionedEntity;
            tracked.SafeCall(i => i.VersioningApplied = true);
            if (clonedTargetApplied)
            {
                translationPolicies |= TranslationPolicy.MergeOutputCollections;
                unitOfWork.TranslationCloneCache.MarkAsProcessedByTranslator(newTarget);
                if (requestLanguageExplicitlySet)
                {
                    ApplyMarkAsKept <ILocalizable>(i => i.LocalizationId != requestlanguageId);
                }
            }
            return(this);
        }
コード例 #4
0
 public void SetTranslationPolicy(TranslationPolicy translationPolicy)
 {
     this.translationPolicies = translationPolicy;
 }
コード例 #5
0
 public ITranslationDefinitions <TIn, TOut> AddCollectionWithRemove <TInProperty, TOutProperty>(Func <TIn, IEnumerable <TInProperty> > fromProperty,
                                                                                                Expression <Func <TOut, IEnumerable <TOutProperty> > > toProperty, TranslationPolicy translationPolicy, Func <TOutProperty, bool> whatRemoveSelector) where TInProperty : class where TOutProperty : class
 {
     AddCollectionInternal <TInProperty, TOutProperty>(fromProperty, toProperty, keepUntouchedAndMerge: translationPolicy.HasFlag(TranslationPolicy.MergeOutputCollections), fetchData: translationPolicy.HasFlag(TranslationPolicy.FetchData), mergeAndKeepTheseSelector: null, whatToRemoveSelector: whatRemoveSelector);
     return(this);
 }
コード例 #6
0
 public ITranslationDefinitions <TIn, TOut> AddCollection <TInProperty, TOutProperty>(Func <TIn, IEnumerable <TInProperty> > fromProperty,
                                                                                      Expression <Func <TOut, IEnumerable <TOutProperty> > > toProperty, TranslationPolicy translationPolicy) where TInProperty : class where TOutProperty : class
 {
     AddCollectionInternal <TInProperty, TOutProperty>(fromProperty, toProperty, keepUntouchedAndMerge: translationPolicy.HasFlag(TranslationPolicy.MergeOutputCollections), fetchData: translationPolicy.HasFlag(TranslationPolicy.FetchData));
     return(this);
 }