private static string TryExtractShortName(string typeName, FilterByInfo filter)
 {
     var removablePrefixes = _defaultNamespaces.Concat(new[] { filter.Source.Module.Name + "." });
     var removablePrefix = removablePrefixes.FirstOrDefault(prefix => typeName.StartsWith(prefix));
     if (removablePrefix != null)
         return typeName.Substring(removablePrefix.Length);
     return null;
 }
예제 #2
0
        private static string FilterImplementationSnippet(FilterByInfo info)
        {
            return string.Format(
        @"public global::{0}[] Filter({1} filter_Parameter)
        {{
            Func<Common.DomRepository, {1}{3}, {0}[]> filter_Function =
                {2};
            return filter_Function(_domRepository, filter_Parameter{4});
        }}

        ",
            info.Source.GetKeyProperties(),
            info.Parameter,
            info.Expression,
            AdditionalParametersTypeTag.Evaluate(info),
            AdditionalParametersArgumentTag.Evaluate(info));
        }
        private static string CodeSnippet(FilterByInfo info)
        {
            var fullTypeName = info.Parameter;
            if (System.CodeDom.Compiler.CodeGenerator.IsValidLanguageIndependentIdentifier(fullTypeName))
                fullTypeName = info.Source.Module.Name + "." + fullTypeName;

            string result = String.Format(
            @"Tuple.Create(""{0}"", typeof({0})),
                ", fullTypeName);

            var shortName = TryExtractShortName(fullTypeName);
            if (shortName != null)
                result += String.Format(
            @"Tuple.Create(""{0}"", typeof({1})),
                ", shortName, fullTypeName);

            return result;
        }
예제 #4
0
        private static string FilterImplementationSnippet(FilterByInfo info)
        {
            return string.Format(
            @"        private static readonly Func<Common.DomRepository, {1}{4}, {0}[]> {2} =
            {3};

            public global::{0}[] Filter({1} parameter)
            {{
            return {2}(_domRepository, parameter{5});
            }}

            ",
            info.Source.GetKeyProperties(),
            info.Parameter,
            FilterExpressionPropertyName(info),
            info.Expression,
            AdditionalParametersTypeTag.Evaluate(info),
            AdditionalParametersArgumentTag.Evaluate(info));
        }
예제 #5
0
        public IEnumerable <IConceptInfo> CreateNewConcepts(IsSubtypeOfInfo conceptInfo, IDslModel existingConcepts)
        {
            var newConcepts = new List <IConceptInfo>();

            // Add a subtype reference (for each subtype) to the supertype data structure:

            var subtypeReference = new PolymorphicSubtypeReferenceInfo
            {
                DataStructure = conceptInfo.Supertype,
                Referenced    = conceptInfo.Subtype,
                Name          = conceptInfo.GetSubtypeReferenceName()
            };

            newConcepts.Add(subtypeReference);
            newConcepts.Add(new PolymorphicPropertyInfo {
                Property = subtypeReference
            });                                                                           // Minor optimization to reduce the number of macro evaluations.

            // Append subtype implementation to the supertype union:

            newConcepts.Add(new SubtypeExtendPolymorphicInfo
            {
                IsSubtypeOf = conceptInfo,
                SubtypeImplementationView = conceptInfo.GetImplementationViewPrototype(),
                PolymorphicUnionView      = conceptInfo.Supertype.GetUnionViewPrototype()
            });

            var filterBySubtypePrototype = new FilterByInfo {
                Source = conceptInfo.Supertype, Parameter = "Rhetos.Dom.DefaultConcepts.FilterSubtype"
            };

            newConcepts.Add(new SubtypeExtendFilterInfo
            {
                IsSubtypeOf     = conceptInfo,
                FilterBySubtype = filterBySubtypePrototype
            });

            // Add metadata for supertype computation (union):

            foreach (DataStructureInfo dependsOn in DslUtility.GetBaseChangesOnDependency(conceptInfo.Subtype, existingConcepts))
            {
                newConcepts.Add(new ChangesOnChangedItemsInfo
                {
                    Computation   = conceptInfo.Supertype,
                    DependsOn     = dependsOn,
                    FilterType    = "Rhetos.Dom.DefaultConcepts.FilterSubtype",
                    FilterFormula = @"changedItems => new Rhetos.Dom.DefaultConcepts.FilterSubtype
                        {
                            Ids = changedItems.Select(" + GetComputeHashIdSelector(conceptInfo) + @").ToArray(),
                            Subtype = " + CsUtility.QuotedString(conceptInfo.Subtype.Module.Name + "." + conceptInfo.Subtype.Name) + @",
                            ImplementationName = " + CsUtility.QuotedString(conceptInfo.ImplementationName) + @"
                        }"
                });
            }

            // Add metadata for subtype implementation:

            PersistedSubtypeImplementationIdInfo subtypeImplementationColumn = null;

            if (conceptInfo.SupportsPersistedSubtypeImplementationColum())
            {
                subtypeImplementationColumn = new PersistedSubtypeImplementationIdInfo {
                    Subtype = conceptInfo.Subtype, ImplementationName = conceptInfo.ImplementationName
                };
                newConcepts.Add(subtypeImplementationColumn);
            }

            // Automatic interface implementation:

            var implementationView = (SqlViewInfo)existingConcepts.FindByKey(conceptInfo.GetImplementationViewPrototype().GetKey());

            if (implementationView == null)
            {
                implementationView = new ExtensibleSubtypeSqlViewInfo {
                    IsSubtypeOf = conceptInfo
                };
                newConcepts.Add(implementationView);

                if (subtypeImplementationColumn != null)
                {
                    newConcepts.Add(new SqlDependsOnSqlObjectInfo
                    {
                        // The subtype implementation view will use the PersistedSubtypeImplementationColumn.
                        DependsOn = subtypeImplementationColumn.GetSqlObjectPrototype(),
                        Dependent = implementationView
                    });
                }
            }

            // Redirect the developer-provided SQL dependencies from the "Is" concept to the implementation view:

            newConcepts.AddRange(DslUtility.CopySqlDependencies(conceptInfo, implementationView, existingConcepts));

            return(newConcepts);
        }
예제 #6
0
 private static string FilterInterfaceSnippet(FilterByInfo info)
 {
     return "IFilterRepository<" + info.Parameter + ", " + info.Source.GetKeyProperties() + ">";
 }
예제 #7
0
 private static string FilterExpressionPropertyName(FilterByInfo info)
 {
     return "_filterExpression_" + CsUtility.TextToIdentifier(info.Parameter);
 }