public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts)
        {
            var newConcepts = new List<IConceptInfo>();

            var persisted = new EntityInfo { Module = Polymorphic.Module, Name = Polymorphic.Name + "_Materialized" };
            newConcepts.Add(persisted);

            var computedFrom = new EntityComputedFromInfo { Target = persisted, Source = Polymorphic };
            newConcepts.Add(computedFrom);

            newConcepts.Add(new KeepSynchronizedInfo
            {
                EntityComputedFrom = computedFrom,
                FilterSaveExpression = ""
            });

            // Optimized filter by subtype allows efficient queryies on the polymophic's view,
            // but it does not need to use the subtype name (and persist it) when querying the materialized data.
            newConcepts.Add(new FilterByInfo
            {
                Source = persisted,
                Parameter = "Rhetos.Dom.DefaultConcepts.FilterSubtype",
                Expression = @"(repository, parameter) => Filter(parameter.Ids)"
            });

            return newConcepts;
        }
        public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts)
        {
            var newConcepts = new List <IConceptInfo>();

            var persisted = new EntityInfo {
                Module = Polymorphic.Module, Name = Polymorphic.Name + "_Materialized"
            };

            newConcepts.Add(persisted);

            var computedFrom = new EntityComputedFromInfo {
                Target = persisted, Source = Polymorphic
            };

            newConcepts.Add(computedFrom);

            newConcepts.Add(new KeepSynchronizedInfo
            {
                EntityComputedFrom   = computedFrom,
                FilterSaveExpression = ""
            });

            // Optimized filter by subtype allows efficient queryies on the polymophic's view,
            // but it does not need to use the subtype name (and persist it) when querying the materialized data.
            newConcepts.Add(new FilterByInfo
            {
                Source     = persisted,
                Parameter  = "Rhetos.Dom.DefaultConcepts.FilterSubtype",
                Expression = @"(repository, parameter) => Filter(parameter.Ids)"
            });

            return(newConcepts);
        }
Example #3
0
 public void InitializeNonparsableProperties(out IEnumerable <IConceptInfo> createdConcepts)
 {
     InternalCheck();
     Dependency_EntityComputedFrom = new EntityComputedFromInfo {
         Target = (EntityInfo)Target.DataStructure, Source = Source.DataStructure
     };
     createdConcepts = new[] { Dependency_EntityComputedFrom };
 }
        private static string CodeSnippet(EntityComputedFromInfo info)
        {
            return string.Format(
        @"private class {2}_KeyComparer : IComparer<{0}>
        {{
            public int Compare({0} x, {0} y)
            {{
                int diff;
                {6}
                return diff;
            }}
        }}

        public IEnumerable<{0}> {2}(object filterLoad = null, Func<IEnumerable<{0}>, IEnumerable<{0}>> filterSave = null)
        {{
            {7}
            filterLoad = filterLoad ?? new FilterAll();
            filterSave = filterSave ?? (x => x);

            var sourceRepository = _executionContext.GenericRepositories.GetGenericRepository<{1}>();
            var sourceItems = sourceRepository.Load(filterLoad);
            var newItems = sourceItems.Select(sourceItem => new {0} {{
                ID = sourceItem.ID,
                {4} }}).ToList();

            var destinationRepository = _executionContext.GenericRepositories.GetGenericRepository<{0}>();
            destinationRepository.InsertOrUpdateOrDelete(
                newItems,
                sameRecord: new {2}_KeyComparer(),
                sameValue: (x, y) =>
                {{
                    {3}
                    return true;
                }},
                filterLoad: filterLoad,
                assign: (destination, source) =>
                {{
                    {5}
                }},
                beforeSave: (ref IEnumerable<{0}> toInsert, ref IEnumerable<{0}> toUpdate, ref IEnumerable<{0}> toDelete) =>
                {{
                    toInsert = filterSave(toInsert);
                    toUpdate = filterSave(toUpdate);
                    toDelete = filterSave(toDelete);
                }});
            return newItems;
        }}

        ",
            info.Target.GetKeyProperties(),
            info.Source.GetKeyProperties(),
            RecomputeFunctionName(info),
            CompareValuePropertyTag.Evaluate(info),
            ClonePropertyTag.Evaluate(info),
            AssignPropertyTag.Evaluate(info),
            CompareKeyPropertyTag.Evaluate(info),
            OverrideDefaultFiltersTag.Evaluate(info));
        }
 public static string RecomputeFunctionName(EntityComputedFromInfo info)
 {
     return "RecomputeFrom" + DslUtility.NameOptionalModule(info.Source, info.Target.Module);
 }
Example #6
0
 public void InitializeNonparsableProperties(out IEnumerable<IConceptInfo> createdConcepts)
 {
     InternalCheck();
     EntityComputedFrom = new EntityComputedFromInfo { Target = (EntityInfo) Target.DataStructure, Source = Source.DataStructure };
     createdConcepts = new[] { EntityComputedFrom };
 }
        protected static string CodeSnippet(EntityComputedFromInfo info)
        {
            return string.Format(
            @"        public void {4}()
            {{
            {4}<FilterAll>(null);
            }}

            public void {4}<T>(T filterLoad)
            {{
            {4}(filterLoad, x => x);
            }}

            public void {4}<T>(T filterLoad, Func<IEnumerable<{0}>, IEnumerable<{0}>> filterSave)
            {{
            var delete = new List<{0}>();
            var insert = new List<{0}>();
            var update = new List<{0}>();

            var sourceRepository = (IFilterRepository<T, {1}>)_domRepository.{1};
            var destRepository = (IFilterRepository<T, {0}>)_domRepository.{0};

            {1}[] sourceArray = sourceRepository.Filter(filterLoad);
            {0}[] destArray = destRepository.Filter(filterLoad);

            Array.Sort(sourceArray, (a, b)=>a.ID.CompareTo(b.ID));
            Array.Sort(destArray, (a, b) => a.ID.CompareTo(b.ID));

            IEnumerator<{1}> sourceEnum = sourceArray.AsEnumerable().GetEnumerator();
            IEnumerator<{0}> destEnum = destArray.AsEnumerable().GetEnumerator();

            try
            {{
                bool sourceExists = sourceEnum.MoveNext();
                bool destExists = destEnum.MoveNext();

                while (true)
                {{
                    int keyDiff;

                    if (sourceExists)
                        if (destExists)
                            keyDiff = sourceEnum.Current.ID.CompareTo(destEnum.Current.ID);
                        else
                            keyDiff = -1;
                    else
                        if (destExists)
                            keyDiff = 1;
                        else
                            break;

                    if (keyDiff == 0)
                    {{
                        bool same = true;
            {2}

                        if (!same)
                        {{
                            _executionContext.NHibernateSession.Evict(destEnum.Current);
                            {5}
                            update.Add(destEnum.Current);
                        }}

                        sourceExists = sourceEnum.MoveNext();
                        destExists = destEnum.MoveNext();
                    }}
                    else if (keyDiff < 0)
                    {{
                        insert.Add(new {0}
                                {{
                                    ID = sourceEnum.Current.ID{3}
                                }});

                        sourceExists = sourceEnum.MoveNext();
                    }}
                    else
                    {{
                        delete.Add(destEnum.Current);
                        destExists = destEnum.MoveNext();
                    }}
                }}
            }}
            finally
            {{
                sourceEnum.Dispose();
                destEnum.Dispose();
            }}

            _domRepository.{0}.Save(filterSave(insert).ToArray(), filterSave(update).ToArray(), filterSave(delete).ToArray());
            }}

            ",
            info.Target.GetKeyProperties(),
            info.Source.GetKeyProperties(),
            ComparePropertyTag.Evaluate(info),
            ClonePropertyTag.Evaluate(info),
            EntityComputedFromInfo.RecomputeFunctionName(info),
            AssignPropertyTag.Evaluate(info));
        }