protected static string CodeSnippet(PersistedDataStructureInfo info)
        {
            return(string.Format(
                       @"public IEnumerable<{0}> Recompute(object filterLoad = null, Func<IEnumerable<{0}>, IEnumerable<{0}>> filterSave = null)
        {{
            return {2}(filterLoad, filterSave);
        }}

        ",
                       info.GetKeyProperties(),
                       info.Source.GetKeyProperties(),
                       EntityComputedFromCodeGenerator.RecomputeFunctionName(new EntityComputedFromInfo {
                Source = info.Source, Target = info
            })));
        }
        private static string FilterAndRecomputeAfterSave(KeepSynchronizedOnChangedItemsInfo info, string uniqueName)
        {
            string recomputeCall;

            if (FilterIsEnumerableGuid(info.UpdateOnChange.FilterType))
            {
                recomputeCall =
                    @"_domRepository.{1}.{2}.{5}(filteredNew.Union(filterKeepSynchronizedOnChangedItems{0}Old).ToList());";
            }
            else if (info.UpdateOnChange.FilterType == "Rhetos.Dom.DefaultConcepts.FilterSubtype")
            {
                recomputeCall =
                    @"_domRepository.{1}.{2}.{5}(new Rhetos.Dom.DefaultConcepts.FilterSubtype
                    {{
                        Ids = filteredNew.Ids.Union(filterKeepSynchronizedOnChangedItems{0}Old.Ids).ToList(),
                        Subtype = filteredNew.Subtype,
                        ImplementationName = filteredNew.ImplementationName
                    }});";
            }
            else if (info.UpdateOnChange.FilterType == "FilterAll" || info.UpdateOnChange.FilterType == "Rhetos.Dom.DefaultConcepts.FilterAll")
            {
                recomputeCall =
                    @"_domRepository.{1}.{2}.{5}(new Rhetos.Dom.DefaultConcepts.FilterAll());";
            }
            else
            {
                recomputeCall =
                    @"_domRepository.{1}.{2}.{5}(filterKeepSynchronizedOnChangedItems{0}Old);
                    _domRepository.{1}.{2}.{5}(filteredNew);";
            }

            return(string.Format(
                       OverrideRecomputeTag(info) + @"
                {{
                    var filteredNew = filterLoadKeepSynchronizedOnChangedItems{0}(inserted.Concat(updated));
                    " + recomputeCall + @"
                }}

                ",
                       uniqueName,
                       info.KeepSynchronized.EntityComputedFrom.Target.Module.Name,
                       info.KeepSynchronized.EntityComputedFrom.Target.Name,
                       info.UpdateOnChange.DependsOn.Module.Name,
                       info.UpdateOnChange.DependsOn.Name,
                       EntityComputedFromCodeGenerator.RecomputeFunctionName(info.KeepSynchronized.EntityComputedFrom)));
        }
        private static string RecomputeForNewItemsSnippet(ComputeForNewItemsInfo info, string uniqueSuffix)
        {
            DataStructureInfo hookOnSave = info.EntityComputedFrom.Target;
            EntityInfo        updatePersistedComputation = info.EntityComputedFrom.Target;

            return(string.Format(
                       @"            if (inserted.Count() > 0)
            {{
                var filter = inserted.Select(item => item.ID).ToArray();
                {4}(filter{3});
            }}
",
                       hookOnSave.Module.Name,
                       hookOnSave.Name,
                       uniqueSuffix,
                       !string.IsNullOrWhiteSpace(info.FilterSaveExpression) ? (", _filterSaveComputeForNewItems_" + uniqueSuffix) : "",
                       EntityComputedFromCodeGenerator.RecomputeFunctionName(info.EntityComputedFrom)));
        }
Esempio n. 4
0
        public string RepositoryRecomputeFromMethodName(string sourceDataStructure)
        {
            var entityModuleName = DataStructureUtility.SplitModuleName(_entityName);
            var sourceModuleName = DataStructureUtility.SplitModuleName(sourceDataStructure);
            var computedConcept  = new EntityComputedFromInfo
            {
                Source = new DataStructureInfo {
                    Module = new ModuleInfo {
                        Name = sourceModuleName.Item1
                    }, Name = sourceModuleName.Item2
                },
                Target = new EntityInfo {
                    Module = new ModuleInfo {
                        Name = entityModuleName.Item1
                    }, Name = entityModuleName.Item2
                }
            };

            return(EntityComputedFromCodeGenerator.RecomputeFunctionName(computedConcept));
        }
        private static string RecomputeForNewItemsSnippet(ComputeForNewBaseItemsInfo info, string uniqueSuffix)
        {
            DataStructureInfo hookOnSave = info.Dependency_Extends.Base;
            EntityInfo        updatePersistedComputation = info.EntityComputedFrom.Target;

            return(string.Format(
                       @"            if (inserted.Count() > 0)
            {{
                IEnumerable<{0}.{1}> changedItems = inserted;
                var filter = _filterComputeForNewBaseItems_{2}(changedItems);
                _domRepository.{3}.{4}.{6}(filter{5});
            }}
",
                       hookOnSave.Module.Name,
                       hookOnSave.Name,
                       uniqueSuffix,
                       updatePersistedComputation.Module.Name,
                       updatePersistedComputation.Name,
                       !string.IsNullOrWhiteSpace(info.FilterSaveExpression) ? (", _filterSaveComputeForNewBaseItems_" + uniqueSuffix) : "",
                       EntityComputedFromCodeGenerator.RecomputeFunctionName(info.EntityComputedFrom)));
        }
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info         = (ComputeForNewBaseItemsInfo)conceptInfo;
            var baseDS       = info.Dependency_Extends.Base;
            var uniqueSuffix = DslUtility.NameOptionalModule(info.EntityComputedFrom.Source, baseDS.Module)
                               + DslUtility.NameOptionalModule(info.EntityComputedFrom.Target, baseDS.Module);

            string saveFilterArgument;

            if (!string.IsNullOrWhiteSpace(info.FilterSaveExpression))
            {
                string saveFilterMethodName = $"FilterSaveComputeForNewBaseItems_{uniqueSuffix}";
                var    extensionDS          = info.Dependency_Extends.Extension;

                var    parsedExpression = new ParsedExpression(info.FilterSaveExpression, new[] { $"IEnumerable<{extensionDS.FullName}>" }, info);
                string filterSaveMethod = $@"private IEnumerable<{extensionDS.FullName}> {saveFilterMethodName}{parsedExpression.MethodParametersAndBody}

        ";

                codeBuilder.InsertCode(filterSaveMethod, RepositoryHelper.RepositoryMembers, baseDS);

                saveFilterArgument = $", {saveFilterMethodName}";
            }
            else
            {
                saveFilterArgument = "";
            }


            string callRecomputeOnSave = $@"if (insertedNew.Any())
                {{
                    Guid[] insertedIds = insertedNew.Select(item => item.ID).ToArray();
                    _domRepository.{info.EntityComputedFrom.Target.FullName}.{EntityComputedFromCodeGenerator.RecomputeFunctionName(info.EntityComputedFrom)}(insertedIds{saveFilterArgument});
                }}
                ";

            codeBuilder.InsertCode(callRecomputeOnSave, WritableOrmDataStructureCodeGenerator.OnSaveTag1, baseDS);
        }
        private static string FilterAndRecomputeAfterSave(KeepSynchronizedOnChangedItemsInfo info, string filterType, string uniqueName)
        {
            string recomputeMethodName =
                info.KeepSynchronized.EntityComputedFrom.Target.Module.Name
                + "." + info.KeepSynchronized.EntityComputedFrom.Target.Name
                + "." + EntityComputedFromCodeGenerator.RecomputeFunctionName(info.KeepSynchronized.EntityComputedFrom);

            return
                ($@"{OverrideRecomputeTag(info)}
                {{
                    var filteredNew = filterLoadKeepSynchronizedOnChangedItems{uniqueName}(inserted.Concat(updated));
                    {filterType} optimizedFilter;
                    if (KeepSynchronizedHelper.OptimizeFiltersUnion(filteredNew, filterKeepSynchronizedOnChangedItems{uniqueName}Old, out optimizedFilter))
                        _domRepository.{recomputeMethodName}(optimizedFilter);
                    else
                    {{
                        _domRepository.{recomputeMethodName}(filterKeepSynchronizedOnChangedItems{uniqueName}Old);
                        _domRepository.{recomputeMethodName}(filteredNew);
                    }}
                }}

                ");
        }
Esempio n. 8
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (AlternativeKeyComparerInfo)conceptInfo;

            string targetEntity          = info.EntityComputedFrom.Target.GetKeyProperties();
            string recomputeFunctionName = EntityComputedFromCodeGenerator.RecomputeFunctionName(info.EntityComputedFrom);
            string keyComparerName       = recomputeFunctionName + "_KeyComparer";
            string keyComparerSnippet    =
                $@"private class {keyComparerName} : IComparer<{targetEntity}>
        {{
            public int Compare({targetEntity} x, {targetEntity} y)
            {{
                int diff;
                {CompareKeyPropertyTag.Evaluate(info)}
                return diff;
            }}
        }}

        ";

            codeBuilder.InsertCode(keyComparerSnippet, RepositoryHelper.RepositoryMembers, info.EntityComputedFrom.Target);
            codeBuilder.InsertCode($"new {keyComparerName}(), //", EntityComputedFromCodeGenerator.OverrideKeyComparerTag, info.EntityComputedFrom);
        }