コード例 #1
0
ファイル: MaxLengthInfo.cs プロジェクト: TinOroz/Rhetos
        public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts)
        {
            var itemFilter = new ItemFilterInfo
            {
                Expression = String.Format("item => !String.IsNullOrEmpty(item.{0}) && item.{0}.Length > {1}", Property.Name, Length),
                FilterName = Property.Name + "_MaxLengthFilter",
                Source     = Property.DataStructure
            };
            var invalidData = new InvalidDataInfo
            {
                Source       = Property.DataStructure,
                FilterType   = itemFilter.FilterName,
                ErrorMessage = "Maximum allowed length of {0} is {1} characters."
            };
            var messageParameters = new InvalidDataMessageParametersConstantInfo
            {
                InvalidData       = invalidData,
                MessageParameters = CsUtility.QuotedString(Property.Name) + ", " + Length
            };
            var invalidProperty = new InvalidDataMarkProperty2Info
            {
                InvalidData  = invalidData,
                MarkProperty = Property
            };

            return(new IConceptInfo[] { itemFilter, invalidData, messageParameters, invalidProperty });
        }
コード例 #2
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (QueryInfo)conceptInfo;

            codeBuilder.InsertCode($"new KeyValuePair<string, Type>({CsUtility.QuotedString(info.Parameter)}, typeof({info.Parameter})),{Environment.NewLine}            ",
                                   RepositoryHelper.ReadParameterTypesTag, info.DataStructure);
        }
コード例 #3
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (UniqueReferenceInfo)conceptInfo;

            if (DslUtility.IsQueryable(info.Extension) && DslUtility.IsQueryable(info.Base))
            {
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Extension,
                                                                                          csPropertyName: "Base",
                                                                                          propertyType: "Common.Queryable." + info.Base.Module.Name + "_" + info.Base.Name,
                                                                                          additionalSetterCode: "ID = value != null ? value.ID : Guid.Empty;");
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Base,
                                                                                          csPropertyName: info.ExtensionPropertyName(),
                                                                                          propertyType: "Common.Queryable." + info.Extension.Module.Name + "_" + info.Extension.Name,
                                                                                          additionalSetterCode: null);
            }

            if (UniqueReferenceDatabaseDefinition.IsSupported(info) &&
                info.Extension is IOrmDataStructure &&
                info.Base is IWritableOrmDataStructure)
            {
                var    ormDataStructure          = (IOrmDataStructure)info.Extension;
                string systemMessage             = $"DataStructure:{info.Extension.FullName},Property:ID,Referenced:{info.Base.FullName}";
                string onDeleteInterpretSqlError = @"if (interpretedException is Rhetos.UserException && Rhetos.Utilities.MsSqlUtility.IsReferenceErrorOnDelete(interpretedException, "
                                                   + CsUtility.QuotedString(ormDataStructure.GetOrmSchema() + "." + ormDataStructure.GetOrmDatabaseObject()) + @", "
                                                   + CsUtility.QuotedString("ID") + @", "
                                                   + CsUtility.QuotedString(UniqueReferenceDatabaseDefinition.GetConstraintName(info)) + @"))
                        ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @";
                    ";
                codeBuilder.InsertCode(onDeleteInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.Base);
            }
        }
コード例 #4
0
        private static string CheckLockedPropertySnippet(LockPropertyInfo info)
        {
            string propertyName = info.Source.Name;

            if (info.Source is ReferencePropertyInfo)
            {
                propertyName += "ID";
            }

            return(string.Format(
                       @"if (updatedNew.Count() > 0 || deletedIds.Count() > 0)
            {{
                {0}[] changedItems = updated.Zip(updatedNew, (i, j) => ({4})
                    ? i : null).Where(x => x != null).ToArray();

                if (changedItems != null && changedItems.Length > 0)
                {{
                    var lockedItems = _domRepository.{0}.Filter(this.Query(changedItems.Select(item => item.ID)), new {1}());
                    if (lockedItems.Count() > 0)
                        throw new Rhetos.UserException({2}, ""DataStructure:{0},ID:"" + lockedItems.First().ID.ToString() + "",Property:{3}"");
                }}
            }}
            ",
                       info.Source.DataStructure.GetKeyProperties(),
                       info.FilterType,
                       CsUtility.QuotedString(info.Title),
                       propertyName,
                       CompareValuePropertySnippet(propertyName)));
        }
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (RegisteredInterfaceImplementationInfo)conceptInfo;

            var interfaceType = Type.GetType(info.InterfaceAssemblyQualifiedName);

            if (interfaceType == null)
            {
                throw new DslSyntaxException(conceptInfo, "Could not find type '" + info.InterfaceAssemblyQualifiedName + "'.");
            }

            // TODO: Remove IQueryableRepository registration.  IQueryableRepository should be cast from repository object in Rhetos.Dom.DefaultConcepts.GenericRepositories class.
            string registerRepository = string.Format(
                @"builder.RegisterType<{0}._Helper.{1}_Repository>().As<IQueryableRepository<{2}>>().InstancePerLifetimeScope();
            ",
                info.DataStructure.Module.Name,
                info.DataStructure.Name,
                interfaceType.FullName);

            codeBuilder.InsertCode(registerRepository, ModuleCodeGenerator.CommonAutofacConfigurationMembersTag);

            string registerImplementationName = string.Format(
                @"{{ typeof({0}), {1} }},
            ",
                interfaceType.FullName,
                CsUtility.QuotedString(
                    info.DataStructure.Module.Name
                    + "." + info.DataStructure.Name));

            codeBuilder.InsertCode(registerImplementationName, ModuleCodeGenerator.RegisteredInterfaceImplementationNameTag);
        }
コード例 #6
0
        public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts)
        {
            var itemFilter = new ItemFilterInfo
            {
                Expression = String.Format("item => item.{0} != null && item.{1} != null && item.{0} > item.{1}", PropertyFrom.Name, PropertyTo.Name),
                FilterName = PropertyFrom.Name + "_" + PropertyTo.Name + "_RangeFilter",
                Source     = PropertyFrom.DataStructure
            };
            var invalidData = new InvalidDataInfo
            {
                Source       = PropertyFrom.DataStructure,
                FilterType   = itemFilter.FilterName,
                ErrorMessage = "Value of {0} has to be less than or equal to {1}."
            };
            var messageParameters = new InvalidDataMessageParametersConstantInfo
            {
                InvalidData       = invalidData,
                MessageParameters = CsUtility.QuotedString(PropertyFrom.Name) + ", " + CsUtility.QuotedString(PropertyTo.Name)
            };
            var invalidProperty = new InvalidDataMarkProperty2Info
            {
                InvalidData  = invalidData,
                MarkProperty = PropertyFrom
            };

            return(new IConceptInfo[] { itemFilter, invalidData, messageParameters, invalidProperty });
        }
コード例 #7
0
        public IEnumerable <IConceptInfo> CreateNewConcepts(ChangesOnReferencedInfo conceptInfo, IDslModel existingConcepts)
        {
            var reference = DslUtility.GetPropertyByPath(conceptInfo.Computation, conceptInfo.ReferencePath, existingConcepts).Value;

            if (!(reference is ReferencePropertyInfo))
            {
                throw new DslSyntaxException(conceptInfo, $"The given path '{conceptInfo.ReferencePath}' should end with a reference property, instead of the {reference.GetUserDescription()}.");
            }
            var referenced = ((ReferencePropertyInfo)reference).Referenced;

            var computationDependencies = new List <Tuple <DataStructureInfo, string> >();

            if (referenced is IWritableOrmDataStructure)
            {
                computationDependencies.Add(Tuple.Create(referenced, "item => item.ID"));
            }
            else if (referenced is PolymorphicInfo)
            {
                AddPolymorphicImplementations(computationDependencies, (PolymorphicInfo)referenced, existingConcepts, conceptInfo);
            }

            string referencePathWithGuid = ChangeReferenceToGuid(conceptInfo.ReferencePath);

            return(computationDependencies.Select(dep =>
                                                  new ChangesOnChangedItemsInfo
            {
                Computation = conceptInfo.Computation,
                DependsOn = dep.Item1,
                FilterType = "FilterCriteria",
                FilterFormula = $@"changedItems => new FilterCriteria({CsUtility.QuotedString(referencePathWithGuid)}, ""In"","
                                + $" _domRepository.Common.FilterId.CreateQueryableFilterIds(changedItems.Select({dep.Item2})))"
            }));
        }
コード例 #8
0
        public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts)
        {
            string filterName = "SystemRequired" + Property.Name;

            var filter = new ItemFilterInfo
            {
                Source     = Property.DataStructure,
                FilterName = filterName,
                Expression = "item => item." + Property.Name + " == null"
            };
            var invalidData = new InvalidDataInfo
            {
                Source       = Property.DataStructure,
                FilterType   = filterName,
                ErrorMessage = "System required property {0} is not set."
            };
            var messageParameters = new InvalidDataMessageParametersConstantInfo
            {
                InvalidData       = invalidData,
                MessageParameters = CsUtility.QuotedString(Property.GetUserDescription())
            };
            var invalidProperty = new InvalidDataMarkProperty2Info
            {
                InvalidData  = invalidData,
                MarkProperty = Property
            };

            return(new IConceptInfo[] { filter, invalidData, messageParameters, invalidProperty });
        }
コード例 #9
0
 private static string ImplementationCodeSnippet(RegExMatchInfo info)
 {
     return(string.Format(@"[RegularExpression({0}, ErrorMessage = {1})]
 ",
                          CsUtility.QuotedString(info.RegularExpression),
                          CsUtility.QuotedString(info.ErrorMessage)));
 }
コード例 #10
0
ファイル: RegExMatchInfo.cs プロジェクト: tjakopovic/Rhetos
        public IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts)
        {
            var filterParameter = new ParameterInfo
            {
                Module = Property.DataStructure.Module,
                Name   = Property.Name + "_RegExMatchFilter",
            };

            string filterExpression = string.Format(@"(source, repository, parameter) =>
                {{
                    var items = source.Where(item => !string.IsNullOrEmpty(item.{0})).Select(item => new {{ item.ID, item.{0} }}).ToList();
                    var regex = new System.Text.RegularExpressions.Regex({1});
                    var invalidItemIds = items.Where(item => !regex.IsMatch(item.{0})).Select(item => item.ID).ToList();
                    return Filter(source, invalidItemIds);
                }}",
                                                    Property.Name,
                                                    CsUtility.QuotedString("^" + RegularExpression + "$"));

            var itemFilterRegExMatchProperty = new ComposableFilterByInfo
            {
                Expression = filterExpression,
                Parameter  = filterParameter.Module.Name + "." + filterParameter.Name,
                Source     = Property.DataStructure
            };

            var invalidDataRegExMatchProperty = new InvalidDataMarkPropertyInfo
            {
                DependedProperty = Property,
                FilterType       = itemFilterRegExMatchProperty.Parameter,
                ErrorMessage     = ErrorMessage,
                Source           = Property.DataStructure
            };

            return(new IConceptInfo[] { filterParameter, itemFilterRegExMatchProperty, invalidDataRegExMatchProperty });
        }
コード例 #11
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (InvalidDataErrorMetadataInfo)conceptInfo;

            codeBuilder.InsertCode(
                $"metadata[{CsUtility.QuotedString(info.Key)}] = {CsUtility.QuotedString(info.Value)};\r\n            ",
                InvalidDataCodeGenerator.ErrorMetadataTag, info.InvalidData);
        }
コード例 #12
0
 protected static string AddFilterSnippet(ApplyFilterOnClientReadInfo info)
 {
     return(string.Format(
                @"{{ {0}, {1} }},
     ",
                CsUtility.QuotedString(info.DataStructure.GetKeyProperties()),
                CsUtility.QuotedString(info.FilterName)));
 }
コード例 #13
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (RowPermissionsInheritWriteSameMemberInfo)conceptInfo;

            codeBuilder.InsertCode(
                "Tuple.Create(" + CsUtility.QuotedString(info.DerivedMemberName) + ", " + CsUtility.QuotedString(info.BaseMemberName) + "), ",
                RowPermissionsInheritWriteCodeGenerator.SameMembersTag,
                info.InheritWrite);
        }
コード例 #14
0
 private static string KeepSynchronizedMetadataSnippet(KeepSynchronizedInfo info)
 {
     return(string.Format(
                @"new Common.KeepSynchronizedMetadata {{ Target = {0}, Source = {1}, Context = {2} }},
     ",
                CsUtility.QuotedString(info.EntityComputedFrom.Target.GetKeyProperties()),
                CsUtility.QuotedString(info.EntityComputedFrom.Source.GetKeyProperties()),
                CsUtility.QuotedString(GetKeepSynchronizedContext(info))));
 }
コード例 #15
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (RowPermissionsInheritExtensionWriteInfo)conceptInfo;

            codeBuilder.InsertCode(
                ", " + CsUtility.QuotedString(info.Extends.ExtensionPropertyName()),
                RowPermissionsInheritWriteCodeGenerator.ExtensionReferenceTag,
                info.InheritWrite);
        }
コード例 #16
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            ReferencePropertyInfo info = (ReferencePropertyInfo)conceptInfo;

            var referenceGuid = new PropertyInfo {
                DataStructure = info.DataStructure, Name = info.Name + "ID"
            };

            PropertyHelper.GenerateCodeForType(referenceGuid, codeBuilder, "Guid?");
            PropertyHelper.GenerateStorageMapping(referenceGuid, codeBuilder, "System.Data.SqlDbType.UniqueIdentifier");

            if (DslUtility.IsQueryable(info.DataStructure) && DslUtility.IsQueryable(info.Referenced))
            {
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.DataStructure,
                                                                                          csPropertyName: info.Name,
                                                                                          propertyType: "Common.Queryable." + info.Referenced.Module.Name + "_" + info.Referenced.Name,
                                                                                          additionalSetterCode: info.Name + "ID = value != null ? (Guid?)value.ID : null;");
            }

            if (ReferencePropertyDbConstraintInfo.IsSupported(info) &&
                info.DataStructure is IOrmDataStructure &&
                info.Referenced is IOrmDataStructure)
            {
                var    ormDataStructure           = (IOrmDataStructure)info.DataStructure;
                var    referencedOrmDataStructure = (IOrmDataStructure)info.Referenced;
                string systemMessage = $"DataStructure:{info.DataStructure.FullName},Property:{info.Name}ID,Referenced:{info.Referenced.FullName}";

                if (info.DataStructure is IWritableOrmDataStructure)
                {
                    string onEnterInterpretSqlError = @"if (interpretedException is Rhetos.UserException && Rhetos.Utilities.MsSqlUtility.IsReferenceErrorOnInsertUpdate(interpretedException, "
                                                      + CsUtility.QuotedString(referencedOrmDataStructure.GetOrmSchema() + "." + referencedOrmDataStructure.GetOrmDatabaseObject()) + @", "
                                                      + CsUtility.QuotedString("ID") + @", "
                                                      + CsUtility.QuotedString(ReferencePropertyConstraintDatabaseDefinition.GetConstraintName(info)) + @"))
                        ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @";
                    ";
                    codeBuilder.InsertCode(onEnterInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.DataStructure);

                    if (info.Referenced == info.DataStructure)
                    {
                        codeBuilder.InsertCode($@"if (entity.{info.Name}ID != null && entity.{info.Name}ID != entity.ID) yield return entity.{info.Name}ID.Value;
            ", WritableOrmDataStructureCodeGenerator.PersistenceStorageMapperDependencyResolutionTag, info.DataStructure);
                    }
                }

                if (info.Referenced is IWritableOrmDataStructure)
                {
                    string onDeleteInterpretSqlError = @"if (interpretedException is Rhetos.UserException && Rhetos.Utilities.MsSqlUtility.IsReferenceErrorOnDelete(interpretedException, "
                                                       + CsUtility.QuotedString(ormDataStructure.GetOrmSchema() + "." + ormDataStructure.GetOrmDatabaseObject()) + @", "
                                                       + CsUtility.QuotedString(info.GetSimplePropertyName()) + @", "
                                                       + CsUtility.QuotedString(ReferencePropertyConstraintDatabaseDefinition.GetConstraintName(info)) + @"))
                        ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @";
                    ";
                    codeBuilder.InsertCode(onDeleteInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.Referenced);
                }
            }
        }
コード例 #17
0
        private static string CallFromModuleRepostiorySnippet(DataStructureInfo info)
        {
            return(string.Format(
                       @"private {0}_Repository _{0}_Repository;
        public {0}_Repository {0} {{ get {{ return _{0}_Repository ?? (_{0}_Repository = ({0}_Repository)Rhetos.Extensibility.NamedPluginsExtensions.GetPlugin(_repositories, {1})); }} }}

        ",
                       info.Name,
                       CsUtility.QuotedString(info.Module.Name + "." + info.Name)));
        }
コード例 #18
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (InvalidDataInfo)conceptInfo;

            // Using nonstandard naming of variables to avoid name clashes with injected code.
            string errorMessageMethod =
                $@"public IEnumerable<InvalidDataMessage> {info.GetErrorMessageMethodName()}(IEnumerable<Guid> invalidData_Ids)
        {{
            IDictionary<string, object> metadata = new Dictionary<string, object>();
            {ErrorMetadataTag.Evaluate(info)}
            {CustomValidationResultTag.Evaluate(info)}
        }}

        ";

            codeBuilder.InsertCode(errorMessageMethod, RepositoryHelper.RepositoryMembers, info.Source);
            codeBuilder.AddReferencesFromDependency(typeof(InvalidDataMessage));

            // HACK: Using IDslModel as a cleaner alternative to ConceptMetadata (which is not saved with DslModel).
            // We could remove InvalidDataMessageInfo and InvalidDataAllowSaveInfo concepts,
            // add a base validation concept for InvalidData that does not have these features (default validation result and DenySave),
            // and make InvalidData a macro that adds the features, but the result would not be fully backward compatible.
            bool hasCustomValidationMessage = _dslModel.FindByKey($"{nameof(InvalidDataMessageInfo)} {info.GetKeyProperties()}") != null;

            if (!hasCustomValidationMessage)
            {
                string defaultValidationResult =
                    $@"
            return invalidData_Ids.Select(id => new InvalidDataMessage
            {{
                ID = id,
                Message = {CsUtility.QuotedString(info.ErrorMessage)},
                Metadata = metadata
            }});";
                codeBuilder.InsertCode(defaultValidationResult, CustomValidationResultTag, info);
            }

            codeBuilder.InsertCode(
                "metadata[\"Validation\"] = " + CsUtility.QuotedString(info.FilterType) + ";\r\n            ",
                ErrorMetadataTag, info);

            bool allowSave = _dslModel.FindByKey($"{nameof(InvalidDataAllowSaveInfo)} {info.GetKeyProperties()}") != null;

            string validationSnippet =
                $@"if ({(allowSave ? "!" : "")}onSave)
            {{
                var errorIds = this.Filter(this.Query(ids), new {info.FilterType}()).Select(item => item.ID).ToArray();
                if (errorIds.Count() > 0)
                    foreach (var error in {info.GetErrorMessageMethodName()}(errorIds))
                        yield return error;
            }}
            ";

            codeBuilder.InsertCode(validationSnippet, WritableOrmDataStructureCodeGenerator.OnSaveValidateTag, info.Source);
        }
コード例 #19
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (UniqueReferenceInfo)conceptInfo;

            if (DslUtility.IsQueryable(info.Extension) && DslUtility.IsQueryable(info.Base))
            {
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Extension,
                                                                                          csPropertyName: "Base",
                                                                                          propertyType: "Common.Queryable." + info.Base.Module.Name + "_" + info.Base.Name,
                                                                                          additionalSetterCode: "ID = value != null ? value.ID : Guid.Empty;");
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Base,
                                                                                          csPropertyName: info.ExtensionPropertyName(),
                                                                                          propertyType: "Common.Queryable." + info.Extension.Module.Name + "_" + info.Extension.Name,
                                                                                          additionalSetterCode: null);
            }

            if (info.Extension is IOrmDataStructure && info.Base is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().HasRequired(t => t.Base).WithOptional(t => t.{2});\r\n            ",
                                  info.Extension.Module.Name, info.Extension.Name, info.ExtensionPropertyName()),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.Extension is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.Base);\r\n            ",
                                  info.Extension.Module.Name, info.Extension.Name),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.Base is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.{2});\r\n            ",
                                  info.Base.Module.Name, info.Base.Name, info.ExtensionPropertyName()),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }

            if (UniqueReferenceDatabaseDefinition.IsSupported(info) &&
                info.Extension is IOrmDataStructure &&
                info.Base is IWritableOrmDataStructure)
            {
                var    ormDataStructure          = (IOrmDataStructure)info.Extension;
                string systemMessage             = "DataStructure:" + info.Extension + ",Property:ID,Referenced:" + info.Base;
                string onDeleteInterpretSqlError = @"if (interpretedException is Rhetos.UserException && Rhetos.Utilities.MsSqlUtility.IsReferenceErrorOnDelete(interpretedException, "
                                                   + CsUtility.QuotedString(ormDataStructure.GetOrmSchema() + "." + ormDataStructure.GetOrmDatabaseObject()) + @", "
                                                   + CsUtility.QuotedString("ID") + @", "
                                                   + CsUtility.QuotedString(UniqueReferenceDatabaseDefinition.GetConstraintName(info)) + @"))
                    ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @";
                ";
                codeBuilder.InsertCode(onDeleteInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.Base);
            }
        }
コード例 #20
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (RegExMatchInfo)conceptInfo;

            var regexString = string.Format(@"""regex"":{{ ""Pattern"": {0}, 
            ""ErrorMessage"": {1} }},
",
                                            CsUtility.QuotedString(info.RegularExpression).Replace("@", ""),
                                            CsUtility.QuotedString(info.ErrorMessage).Replace("@", ""));

            codeBuilder.InsertCode(regexString, SimplePropertyCodeGenerator.AdditionalPropertiesTag, info.Property);
        }
コード例 #21
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (ApplyFilterOnClientReadWhereInfo)conceptInfo;

            string dataStructureSnippet = CsUtility.QuotedString(info.DataStructure.GetKeyProperties());
            string filterNameSnippet    = CsUtility.QuotedString(info.FilterName);
            string whereSnippet         = string.IsNullOrEmpty(info.Where) ? "" : (", " + info.Where);

            string snippet = $"{{ {dataStructureSnippet}, {filterNameSnippet}{whereSnippet} }},\r\n            ";

            codeBuilder.InsertCode(snippet, ModuleCodeGenerator.ApplyFiltersOnClientReadTag);
        }
コード例 #22
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (KeepSynchronizedInfo)conceptInfo;

            string metadata = string.Format(
                @"new Common.KeepSynchronizedMetadata {{ Target = {0}, Source = {1}, Context = {2} }},
            ",
                CsUtility.QuotedString(info.EntityComputedFrom.Target.GetKeyProperties()),
                CsUtility.QuotedString(info.EntityComputedFrom.Source.GetKeyProperties()),
                CsUtility.QuotedString(GetRecomputeContext(info.EntityComputedFrom.Source)));

            codeBuilder.InsertCode(metadata, KeepSynchronizedRecomputeOnDeployInfrastructureCodeGenerator.AddKeepSynchronizedMetadataTag);
        }
コード例 #23
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (SubtypeExtendFilterInfo)conceptInfo;

            string snippet = string.Format(
                @"if (parameter.Subtype == {0} && parameter.ImplementationName == {1})
                        filterExpression = item => item.{2}ID != null;
                    ",
                CsUtility.QuotedString(info.IsSubtypeOf.Subtype.Module.Name + "." + info.IsSubtypeOf.Subtype.Name),
                CsUtility.QuotedString(info.IsSubtypeOf.ImplementationName),
                info.IsSubtypeOf.GetSubtypeReferenceName());

            codeBuilder.InsertCode(snippet, PolymorphicMacro.SetFilterExpressionTag, info.IsSubtypeOf.Supertype);
        }
コード例 #24
0
        private static string GetReportDataSnippet(ReportDataSourceInfo info)
        {
            return(string.Format(@"
	        {{
                var dataSourceRepositiory = _domRepository.{1};
                var data = dataSourceRepositiory.Load(parameter);
                var order = {2};
	            reportData.Add(order, data);
            }}
",
                                 info.Report.GetKeyProperties(),
                                 info.DataSource.GetKeyProperties(),
                                 CsUtility.QuotedString(info.Order)));
        }
コード例 #25
0
        public void QuotedString()
        {
            string stringConstant = "\r\nabc \" \\ \\\" 123 \\\"\" \\\\\"\"\r\n\t\t \rx\nx ";

            string code = string.Format(
                @"using System;
                namespace GeneratedModuleQuotedString
                {{
                    public class C
                    {{
                        public static string F1()
                        {{
                            return {0};
                        }}
                        public static string F2()
                        {{
                            return {1};
                        }}
                    }}
                }}",
                CsUtility.QuotedString(stringConstant),
                CsUtility.QuotedString(null));

            Console.WriteLine(code);
            CSharpCodeProvider provider = new CSharpCodeProvider();
            CompilerResults    results  = provider.CompileAssemblyFromSource(new CompilerParameters(new string[] { }, "GeneratedQuotedStringAssembly"), code);

            foreach (CompilerError error in results.Errors)
            {
                Console.WriteLine(error);
            }
            Assert.AreEqual(0, results.Errors.Count, "Compiler errors");

            Console.WriteLine("CompiledAssembly: " + results.CompiledAssembly.Location);
            Type generatedClass = results.CompiledAssembly.GetType("GeneratedModuleQuotedString.C");

            {
                MethodInfo generatedMethod     = generatedClass.GetMethod("F1");
                string     generatedCodeResult = (string)generatedMethod.Invoke(null, new object[] { });
                Assert.AreEqual(stringConstant, generatedCodeResult);
            }

            {
                MethodInfo generatedMethod     = generatedClass.GetMethod("F2");
                string     generatedCodeResult = (string)generatedMethod.Invoke(null, new object[] { });
                Assert.IsNull(generatedCodeResult);
            }
        }
コード例 #26
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (InvalidDataMessageParametersConstantInfo)conceptInfo;

            string setMessages =
                $@"
            return invalidData_Ids.Select(id => new InvalidDataMessage
            {{
                ID = id,
                Message = {CsUtility.QuotedString(info.InvalidData.ErrorMessage)},
                MessageParameters = new object[] {{ {info.MessageParameters} }},
                Metadata = metadata
            }});";

            codeBuilder.InsertCode(setMessages, InvalidDataCodeGenerator.CustomValidationResultTag, info.InvalidData);
        }
コード例 #27
0
        private static string CheckInvalidItemsSnippet(InvalidDataInfo info)
        {
            return(string.Format(
                       @"            if (insertedNew.Count() > 0 || updatedNew.Count() > 0)
            {{
                {0}[] changedItems = inserted.Concat(updated).ToArray();
                var invalidItems = _domRepository.{0}.Filter(this.Query(changedItems.Select(item => item.ID)), new {1}());
                if (invalidItems.Count() > 0)
                    throw new Rhetos.UserException({2}, ""DataStructure:{0},ID:"" + invalidItems.First().ID.ToString(){3});
            }}
",
                       info.Source.GetKeyProperties(),
                       info.FilterType,
                       CsUtility.QuotedString(info.ErrorMessage),
                       UserMessageAppend.Evaluate(info)));
        }
コード例 #28
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (AutoCodeForEachInfo)conceptInfo;

            // The groupSelector value format must be compatible with T-SQL data formatting,
            // because it will be used is a generated SQL query to filter the records within the same group.
            string groupSelector   = SnippetSqlFormat(info.Group);
            string groupingSnippet = ", " + groupSelector;

            codeBuilder.InsertCode(groupingSnippet, AutoCodePropertyCodeGenerator.GroupingTag, info);

            string groupColumnName         = info.Group.Name + (info.Group is ReferencePropertyInfo ? "ID" : "");
            string groupQuoted             = SnippetSqlQuoted(info.Group) ? "true" : "false";
            string groupingMetadataSnippet = $",\r\n                {CsUtility.QuotedString(groupColumnName)}, {groupQuoted}";

            codeBuilder.InsertCode(groupingMetadataSnippet, AutoCodePropertyCodeGenerator.GroupColumnMetadataTag, info);
        }
コード例 #29
0
        public new IEnumerable <IConceptInfo> CreateNewConcepts(IEnumerable <IConceptInfo> existingConcepts)
        {
            var newConcepts = new List <IConceptInfo>();

            newConcepts.AddRange(base.CreateNewConcepts(existingConcepts));

            var invalidData       = newConcepts.OfType <InvalidDataInfo>().Single();
            var messageParameters = new InvalidDataMessageParametersConstantInfo
            {
                InvalidData       = invalidData,
                MessageParameters = CsUtility.QuotedString(Property.Name)
            };

            newConcepts.Add(messageParameters);

            return(newConcepts);
        }
コード例 #30
0
        private static string CheckLockedItemsSnippet(LockItemsInfo info)
        {
            return(string.Format(
                       @"if (updatedNew.Count() > 0 || deletedIds.Count() > 0)
            {{
                {0}[] changedItems = updated.Concat(deleted).ToArray();

                var lockedItems = _domRepository.{0}.Filter(this.Query(changedItems.Select(item => item.ID)), new {1}());
                if (lockedItems.Count() > 0)
                    throw new Rhetos.UserException({2}, ""DataStructure:{0},ID:"" + lockedItems.First().ID.ToString(){3});
            }}
            ",
                       info.Source.GetKeyProperties(),
                       info.FilterType,
                       CsUtility.QuotedString(info.Title),
                       ClientMessageTag.Evaluate(info)));
        }