Наследование: IMappingTemplate
        public void IsSubstring_True()
        {
            var column = "D(1-3)";

            var actual = MappingTemplate.IsSubstring(column);

            Assert.True(actual);
        }
        public void IsRegex_True()
        {
            var column = "E[(?<=WRAP ).*$]";

            var actual = MappingTemplate.IsRegex(column);

            Assert.True(actual);
        }
        public void GetRegex_HasRegex()
        {
            var column = "E[(?<=WRAP ).*$]";

            var actual = MappingTemplate.GetRegex(column);

            Assert.Equal("(?<=WRAP ).*$", actual);
        }
        public void GetSubStringIndex_NoSubstring()
        {
            var column = "D";

            var actual = MappingTemplate.GetSubStringIndexes(column);

            Assert.Empty(actual);
        }
        public void GetColumn_HasRegex()
        {
            var column = "D[(?<=WRAP ).*$]";

            var actual = MappingTemplate.GetColumn(column);

            Assert.Equal("D", actual);
        }
        public void GetColumn_HasSubstring()
        {
            var column = "D(1-3)";

            var actual = MappingTemplate.GetColumn(column);

            Assert.Equal("D", actual);
        }
        public void GetColumn_Basic()
        {
            var column = "D";

            var actual = MappingTemplate.GetColumn(column);

            Assert.Equal(column, actual);
            Assert.False(MappingTemplate.IsSubstring(column));
            Assert.False(MappingTemplate.IsRegex(column));
        }
        public void GetSubStringIndex_HasSubstring_DoubleDigit()
        {
            var column = "D(1-15)";

            var actual = MappingTemplate.GetSubStringIndexes(column);

            Assert.Equal(2, actual.Count);
            Assert.Equal(1, actual[0]);
            Assert.Equal(15, actual[1]);
        }
Пример #9
0
        protected internal override MappingWriter SerializeMapping(string type)
        {
            MappingTemplate template = MappingTemplate.TEMPLATES.get(type);

            if (template == null)
            {
                throw new WebApplicationException(Response.status(Response.Status.NOT_ACCEPTABLE).entity("Cannot represent \"" + type + "\" as html").build());
            }
            return(new HtmlMap(template));
        }
Пример #10
0
        public void RenderMappingFile(List <MappingModel> models, List <EntityModel> eModels)
        {
            if (!Directory.Exists(_outputPath + "Mappings\\" + NormalizeTableName + "\\"))
            {
                Directory.CreateDirectory(_outputPath + "Mappings\\" + NormalizeTableName + "\\");
            }
            var outputPath      = _outputPath + "Mappings\\" + NormalizeTableName + "\\" + NormalizeTableName + "Mapping.cs";
            var mappingTemplate = new MappingTemplate(models, eModels, _projectName, _tableName);
            var output          = mappingTemplate.TransformText();

            File.WriteAllText(outputPath, output);
        }
Пример #11
0
        private List <int> GetCommissionIndexes()
        {
            var commissionTypeIndexes = new List <int>();

            if (string.IsNullOrWhiteSpace(_sheet.Config.CommissionTypes.MappingTemplate))
            {
                return(commissionTypeIndexes);
            }

            return(MappingTemplate.Parse(_sheet.Config.CommissionTypes.MappingTemplate)
                   .Select(c => ExcelUtils.ColumnToIndex(c))
                   .ToList());
        }
Пример #12
0
        internal BuildCustomResourceStack(Construct scope, string id = "Image-Recognition-4-Custom-Stack", IStackProps props = null) : base(scope, id, props)
        {
            try{
                string appSyncName = Fn.ImportValue(BuildAppSyncStack.GRAPHQL_API_ID_EXPORT);
                var    graphqlAPI  = GraphqlApi.FromGraphqlApiAttributes(this, "Existing-Graph-API", new GraphqlApiAttributes {
                    GraphqlApiId = appSyncName
                });

                var sfnProxyDataSource = graphqlAPI.AddHttpDataSource
                                         (
                    "SfnProxyDataSource",
                    "https://states." + Region + ".amazonaws.com/",
                    new HttpDataSourceOptions {
                    AuthorizationConfig = new AwsIamConfig()
                    {
                        SigningRegion      = Region,
                        SigningServiceName = "states"
                    }
                }
                                         );

                PolicyStatement sfnPolicy = new PolicyStatement(new PolicyStatementProps {
                    Effect    = Effect.ALLOW,
                    Actions   = new string[] { "states:StartExecution", "states:DescribeExecution" },
                    Resources = new string[] { "*" }
                });


                sfnProxyDataSource.GrantPrincipal.AddToPrincipalPolicy(sfnPolicy);

                sfnProxyDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Mutation",
                    FieldName = "startSfnExecution",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Mutation.startSfnExecution.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Mutation.startSfnExecution.res.vtl"),
                });


                sfnProxyDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Query",
                    FieldName = "checkSfnStatus",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Query.checkSfnStatus.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Query.checkSfnStatus.res.vtl"),
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #13
0
        private void Initialize()
        {
            if (_inialized)
            {
                return;
            }
            var scope = new Scope(this);

            _updateurl      = new Uri(UpdateUrlTemplate.Interpolate(scope));
            _mappingquery   = MappingTemplate.Interpolate(scope);
            _nextquery      = NextQueryTemplate.Interpolate(scope);
            _mappingurl     = new Uri(MappingUrlTemplate.Interpolate(scope));
            _geturl         = new Uri(GetUrlTemplate.Interpolate(scope));
            _indexexistsurl = new Uri(IndexExistsUrlTemplate.Interpolate(scope));
            _http           = new HttpClient();
            EnsureIndex();
            _inialized = true;
        }
Пример #14
0
        public CommissionTypesValidator()
        {
            RuleFor(t => t.MappingTemplate)
            .Must(HaveValidExcelColumnIdentifiers)
            .When(t => !string.IsNullOrEmpty(t.MappingTemplate))
            .WithMessage("'Mapping Template' contains invalid excel column identifiers");

            RuleFor(t => t.DefaultCommissionTypeCode).NotEmpty().WithName("Default Commission Type");

            RuleForEach(t => t.Types).SetValidator(new CommissionTypeValidator());
            RuleForEach(t => t.Types)
            .Custom((type, context) =>
            {
                var mappingTemplate = ((CommissionTypes)context.ParentContext.InstanceToValidate).MappingTemplate;
                if (!MappingTemplate.EqualLength(mappingTemplate, type.Value))
                {
                    var failure = new ValidationFailure($"{context.PropertyName}.Value", "Invalid Value", type.Value);
                    context.AddFailure(failure);
                }
            });
        }
Пример #15
0
        private bool HaveValidExcelColumnIdentifiers(string mappingTemplate)
        {
            foreach (var part in MappingTemplate.Parse(mappingTemplate))
            {
                try
                {
                    var column = MappingTemplate.GetColumn(part);

                    if (MappingTemplate.IsSubstring(part))
                    {
                        var subStringIndex = MappingTemplate.GetSubStringIndexes(part);

                        if (subStringIndex.Count != 0 && subStringIndex.Count != 2)
                        {
                            return(false);
                        }

                        if (subStringIndex.Count == 2)
                        {
                            if (subStringIndex[0] >= subStringIndex[1])
                            {
                                return(false);
                            }
                        }
                    }

                    if (!Utils.IsValidExcelColumn((column)) && column != CommissionTypes.GROUP_COMMISSION_TYPE)
                    {
                        return(false);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #16
0
        static void Main(string[] args)
        {
            string dir  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).Replace("\\bin\\Debug", "").Replace("\\bin", "");
            string path = Path.Combine(dir, "data.xml");

            string dataProjectDir   = dir.Replace(".T4", ".Data");
            string webProjectDir    = dir.Replace(".T4", ".Admin");
            string clientProjectDir = dir.Replace(".T4", "");

            DatabaseInfo databaseInfo = new DatabaseInfo();

            var serializer = new XmlSerializer(databaseInfo.GetType());

            using (StreamReader reader = new StreamReader(path))
            {
                databaseInfo = (DatabaseInfo)serializer.Deserialize(reader);
            }

            foreach (ModelInfo model in databaseInfo.Models)
            {
                //preparing FK collection names
                model.CollectionModel = databaseInfo.Models.Where(m => m.Fields.Any(f => f.FkSingular == model.Singular)).ToList();

                //angular project

                //AngularControllerTemplate acTemplate = new AngularControllerTemplate();
                //acTemplate.Model = model;
                //string acContent = acTemplate.TransformText();
                //File.WriteAllText(Path.Combine(clientProjectDir, "Scripts\\modules\\stolarus\\controllers", model.Plural.ToLower() + ".js"), acContent);

                //AngularItemTemplate aiTemplate = new AngularItemTemplate();
                //aiTemplate.Model = model;
                //string aiContent = aiTemplate.TransformText();
                //File.WriteAllText(Path.Combine(clientProjectDir, "WebPages", model.Singular + "ListItem.html"), aiContent);


                //data project

                ModelTemplate modelTemplate = new ModelTemplate();
                modelTemplate.Model         = model;
                modelTemplate.RootNamespace = databaseInfo.RootNamespace;
                string modelContent = modelTemplate.TransformText();
                File.WriteAllText(Path.Combine(dataProjectDir, "Models", model.Singular + ".cs"), modelContent);

                MappingTemplate mapTemplate = new MappingTemplate();
                mapTemplate.Model         = model;
                mapTemplate.RootNamespace = databaseInfo.RootNamespace;
                string mapContent = mapTemplate.TransformText();
                File.WriteAllText(Path.Combine(dataProjectDir, "Models\\Mapping", model.Singular + "Map.cs"), mapContent);

                RepositoryTemplate repositoryTemplate = new RepositoryTemplate();
                repositoryTemplate.Model         = model;
                repositoryTemplate.RootNamespace = databaseInfo.RootNamespace;
                string repositoryContent = repositoryTemplate.TransformText();
                File.WriteAllText(Path.Combine(dataProjectDir, "Repository", model.Plural + "Repository.cs"), repositoryContent);

                ContractTemplate contractTemplate = new ContractTemplate();
                contractTemplate.Model         = model;
                contractTemplate.RootNamespace = databaseInfo.RootNamespace;
                string contractContent = contractTemplate.TransformText();
                File.WriteAllText(Path.Combine(dataProjectDir, "Contracts", "I" + model.Plural + "Repository.cs"), contractContent);

                //web project

                //ModelBinderTemplate modelBinderTemplate = new ModelBinderTemplate();
                //modelBinderTemplate.Model = model;
                //modelBinderTemplate.RootNamespace = databaseInfo.RootNamespace;
                //string modelBinderContent = modelBinderTemplate.TransformText();
                //File.WriteAllText(Path.Combine(webProjectDir, "ModelBinding", model.Plural + "FilterModelBinder.cs"), modelBinderContent);

                //ControllerTemplate controllerTemplate = new ControllerTemplate();
                //controllerTemplate.Model = model;
                //controllerTemplate.RootNamespace = databaseInfo.RootNamespace;
                //string controllerContent = controllerTemplate.TransformText();
                //File.WriteAllText(Path.Combine(webProjectDir, "Controllers", model.Plural + "Controller.cs"), controllerContent);

                //EditorTemplate editorTemplate = new EditorTemplate();
                //editorTemplate.Model = model;
                //editorTemplate.RootNamespace = databaseInfo.RootNamespace;
                //string editorContent = editorTemplate.TransformText();
                //File.WriteAllText(Path.Combine(webProjectDir, "Views\\Shared\\EditorTemplates", "_" + model.Singular + ".cshtml"), editorContent);

                ////client web project

                //ApiControllerTemplate apiControllerTemplate = new ApiControllerTemplate();
                //apiControllerTemplate.Model = model;
                //apiControllerTemplate.RootNamespace = databaseInfo.RootNamespace;
                //string apiControllerContent = apiControllerTemplate.TransformText();
                //File.WriteAllText(Path.Combine(clientProjectDir, "Controllers\\Api", model.Plural + "Controller.cs"), apiControllerContent);
            }

            //ContextTemplate contextTemplate = new ContextTemplate();
            //contextTemplate.RootNamespace = databaseInfo.RootNamespace;
            //contextTemplate.Models = databaseInfo.Models;
            //string contextContent = contextTemplate.TransformText();
            //File.WriteAllText(Path.Combine(dataProjectDir, "Models", databaseInfo.RootNamespace + "Context.cs"), contextContent);

            //RegisterModelBindersTemplate registerModelBindersTemplate = new RegisterModelBindersTemplate();
            //registerModelBindersTemplate.Models = databaseInfo.Models;
            //registerModelBindersTemplate.RootNamespace = databaseInfo.RootNamespace;
            //string registerModelBindersContent = registerModelBindersTemplate.TransformText();
            //File.WriteAllText(Path.Combine(webProjectDir, "App_Start", "ModelBindersConfig.cs"), registerModelBindersContent);

            //RegisterUnityTemplate registerUnityTemplate1 = new RegisterUnityTemplate();
            //registerUnityTemplate1.RootNamespace = databaseInfo.RootNamespace + ".Admin";
            //registerUnityTemplate1.Models = databaseInfo.Models;
            //string registerUnityContent1 = registerUnityTemplate1.TransformText();
            //File.WriteAllText(Path.Combine(webProjectDir, "App_Start", "UnityConfig.custom.cs"), registerUnityContent1);

            //RegisterUnityTemplate registerUnityTemplate2 = new RegisterUnityTemplate();
            //registerUnityTemplate2.RootNamespace = databaseInfo.RootNamespace;
            //registerUnityTemplate2.Models = databaseInfo.Models;
            //string registerUnityContent2 = registerUnityTemplate2.TransformText();
            //File.WriteAllText(Path.Combine(clientProjectDir, "App_Start", "UnityConfig.custom.cs"), registerUnityContent2);

            //MiscTemplate miscTemplate = new MiscTemplate();
            //miscTemplate.Models = databaseInfo.Models;
            //string miscContent = miscTemplate.TransformText();
            //File.WriteAllText(Path.Combine(webProjectDir, "Misc.txt"), miscContent);
        }
Пример #17
0
 internal HtmlMap(MappingTemplate template) : base(new Dictionary <string, object>(), true)
 {
     this.Template = template;
 }
Пример #18
0
        public void GenerateDataServiceProject(DomainDataService dataService, string outputFolder)
        {
            outputFolder = Path.Combine(outputFolder, $"{dataService.Solution.NamespacePrefix}.{dataService.Name}.DataService");
            var interfacesFolder  = Path.Combine(outputFolder, "Interfaces");
            var mappingsFolder    = Path.Combine(outputFolder, "Mappings");
            var recordTypesFolder = Path.Combine(outputFolder, "RecordTypes");
            var validatorsFolder  = Path.Combine(outputFolder, "Validators");

            ReplaceDirectories(interfacesFolder, mappingsFolder, recordTypesFolder, validatorsFolder);

            var session = new Dictionary <string, object>();

            session.Add("DomainDataService", dataService);

            DataServiceProjectTemplate projectTemplate = new DataServiceProjectTemplate();

            projectTemplate.Session = session;
            projectTemplate.Initialize();
            string content = projectTemplate.TransformText();

            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Solution.NamespacePrefix}.{dataService.Name}.DataService.csproj"), content);

            IRepositoryTemplate repositoryInterfaceTemplate = new IRepositoryTemplate();

            repositoryInterfaceTemplate.Session = session;
            repositoryInterfaceTemplate.Initialize();
            content = repositoryInterfaceTemplate.TransformText();
            File.WriteAllText(Path.Combine(interfacesFolder, $"I{dataService.Name}DataServiceRespository.cs"), content);

            IDataServiceTemplate dataServiceInterfaceTemplate = new IDataServiceTemplate();

            dataServiceInterfaceTemplate.Session = session;
            dataServiceInterfaceTemplate.Initialize();
            content = dataServiceInterfaceTemplate.TransformText();
            File.WriteAllText(Path.Combine(interfacesFolder, $"I{dataService.Name}DataService.cs"), content);

            RepositoryTemplate repositoryTemplate = new RepositoryTemplate();

            repositoryTemplate.Session = session;
            repositoryTemplate.Initialize();
            content = repositoryTemplate.TransformText();
            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}DataServiceRespository.cs"), content);

            DataServiceTemplate dataServiceTemplate = new DataServiceTemplate();

            dataServiceTemplate.Session = session;
            dataServiceTemplate.Initialize();
            content = dataServiceTemplate.TransformText();
            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}DataService.cs"), content);

            KernelManipulationsTemplate kernelManipulationsTemplate = new KernelManipulationsTemplate();

            kernelManipulationsTemplate.Session = session;
            kernelManipulationsTemplate.Initialize();
            content = kernelManipulationsTemplate.TransformText();
            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}KernelManipulations.cs"), content);

            StartupTaskTemplate startupTaskTemplate = new StartupTaskTemplate();

            startupTaskTemplate.Session = session;
            startupTaskTemplate.Initialize();
            content = startupTaskTemplate.TransformText();
            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}Startup.cs"), content);

            if (!(dataService.Schemas is null))
            {
                foreach (var domainObject in dataService.Schemas.SelectMany(s => s.Objects))
                {
                    session["CurrentObject"] = domainObject;

                    MappingTemplate mappingTemplate = new MappingTemplate();
                    mappingTemplate.Session = session;
                    mappingTemplate.Initialize();
                    content = mappingTemplate.TransformText();
                    File.WriteAllText(Path.Combine(mappingsFolder, $"{domainObject.ObjectName}Mapping.cs"), content);

                    RecordTypeTemplate recordTypeTemplate = new RecordTypeTemplate();
                    recordTypeTemplate.Session = session;
                    recordTypeTemplate.Initialize();
                    content = recordTypeTemplate.TransformText();
                    File.WriteAllText(Path.Combine(recordTypesFolder, $"{domainObject.ObjectName}RecordType.cs"), content);

                    if (domainObject.SupportsIHaveId())
                    {
                        var modelValidatorsFolder = Path.Combine(validatorsFolder, domainObject.ObjectName);
                        ReplaceDirectories(modelValidatorsFolder);

                        ValidatorTemplate validatorTemplate = new ValidatorTemplate();
                        validatorTemplate.Session = session;
                        validatorTemplate.Initialize();
                        content = validatorTemplate.TransformText();
                        File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}Validator.cs"), content);

                        DeleteValidatorTemplate deleteValidatorTemplate = new DeleteValidatorTemplate();
                        deleteValidatorTemplate.Session = session;
                        deleteValidatorTemplate.Initialize();
                        content = deleteValidatorTemplate.TransformText();
                        File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}DeleteValidator.cs"), content);

                        BatchValidatorTemplate batchValidatorTemplate = new BatchValidatorTemplate();
                        batchValidatorTemplate.Session = session;
                        batchValidatorTemplate.Initialize();
                        content = batchValidatorTemplate.TransformText();
                        File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}BatchValidator.cs"), content);
                    }
                }
            }
        }
        internal BuildAlbumStack(Construct scope, string id = "Image-Recognition-2-Album-Stack", IStackProps props = null) : base(scope, id, props)
        {
            try{
                var albumTable = new Table(this, "AlbumTable", new TableProps {
                    PartitionKey = new Attribute {
                        Name = "id", Type = AttributeType.STRING
                    },
                    BillingMode   = BillingMode.PAY_PER_REQUEST,
                    RemovalPolicy = RemovalPolicy.DESTROY,
                    Stream        = StreamViewType.NEW_AND_OLD_IMAGES
                });

                string appSyncName = Fn.ImportValue(BuildAppSyncStack.GRAPHQL_API_ID_EXPORT);
                var    graphqlAPI  = GraphqlApi.FromGraphqlApiAttributes(this, "Existing-Graph-API", new GraphqlApiAttributes {
                    GraphqlApiId = appSyncName
                });

                var albumTableDataSource = graphqlAPI.AddDynamoDbDataSource("AlbumTable", albumTable);

                albumTableDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Query",
                    FieldName = "getAlbum",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Query.getAlbum.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Query.getAlbum.res.vtl"),
                });

                albumTableDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Query",
                    FieldName = "listAlbums",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Query.listAlbums.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Query.listAlbums.res.vtl"),
                });

                albumTableDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Mutation",
                    FieldName = "createAlbum",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Mutation.createAlbum.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Mutation.createAlbum.res.vtl"),
                });

                albumTableDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Mutation",
                    FieldName = "updateAlbum",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Mutation.updateAlbum.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Mutation.updateAlbum.res.vtl"),
                });

                albumTableDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Mutation",
                    FieldName = "deleteAlbum",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Mutation.deleteAlbum.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Mutation.deleteAlbum.res.vtl"),
                });

                albumTableDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Subscription",
                    FieldName = "onCreateAlbum",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Subscription.onCreateAlbum.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Subscription.onCreateAlbum.res.vtl"),
                });

                albumTableDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Subscription",
                    FieldName = "onUpdateAlbum",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Subscription.onUpdateAlbum.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Subscription.onUpdateAlbum.res.vtl"),
                });

                albumTableDataSource.CreateResolver(new ResolverProps {
                    TypeName  = "Subscription",
                    FieldName = "onDeleteAlbum",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Subscription.onDeleteAlbum.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Subscription.onDeleteAlbum.res.vtl"),
                });

                albumTableDataSource.CreateResolver(new ExtendedResolverProps {
                    TypeName  = "Photo",
                    FieldName = "album",
                    RequestMappingTemplate  = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Photo.album.req.vtl"),
                    ResponseMappingTemplate = MappingTemplate.FromFile("src/ImageRecognitionInfrastructure/API/resolvers/Photo.album.res.vtl")
                });

                new CfnOutput(this, "AlbumTableStreamArn", new CfnOutputProps {
                    Value      = albumTable.TableStreamArn,
                    ExportName = ALBUM_TABLE_STREAM_ARN_EXPORT
                });

                new CfnOutput(this, "AlbumTableDataSourceName", new CfnOutputProps {
                    Value      = albumTableDataSource.Name,
                    ExportName = ALBUM_TABLE_DATASOURCE_NAME_EXPORT
                });

                new CfnOutput(this, "AlbumTableName", new CfnOutputProps {
                    Value      = albumTable.TableName,
                    ExportName = ALBUM_TABLE_NAME_EXPORT
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #20
0
        public void Select_WithTwoForeignObject_ShouldReturnComplete()
        {
            // Arrange

            MappingTemplate template1 = new MappingTemplate()
            {
                Name = "t1"
            };
            MappingTemplate template2 = new MappingTemplate()
            {
                Name = "t2"
            };
            MappingField mappingField11 = new MappingField()
            {
                Name = "f1t1", MappingTemplate = template1
            };
            MappingField mappingField21 = new MappingField()
            {
                Name = "f2t1", MappingTemplate = template1
            };
            MappingField mappingField12 = new MappingField()
            {
                Name = "f1t2", MappingTemplate = template2
            };
            MappingField mappingField22 = new MappingField()
            {
                Name = "f2t2", MappingTemplate = template2
            };
            Mapping m1 = new Mapping()
            {
                MappingFieldSource = mappingField11, MappingFieldDest = mappingField12
            };
            Mapping m2 = new Mapping()
            {
                MappingFieldSource = mappingField21, MappingFieldDest = mappingField22
            };

            using (Dao dao = new Dao(transaction, options))
            {
                dao.Options.Schema = "dbo";
                dao.Insert(template1);
                dao.Insert(template2);
                dao.Insert(mappingField11);
                dao.Insert(mappingField21);
                dao.Insert(mappingField12);
                dao.Insert(mappingField22);
                dao.Insert(m1);
                dao.Insert(m2);
            }

            IList <Mapping> result;

            // Act

            using (Dao dao = new Dao(transaction, options))
            {
                dao.Options.Schema = "dbo";

                result = dao.Select <Mapping>(Where("MappingFieldSource.MappingTemplate.Id", template1.Id)
                                              .And("MappingFieldDest.MappingTemplate.Id", template2.Id));
            }

            // Assert

            Assert.Equal("t1", result.First().MappingFieldSource.MappingTemplate.Name);
            Assert.Equal("t2", result.Last().MappingFieldDest.MappingTemplate.Name);
        }
Пример #21
0
 internal CompactJsonWriter(MappingTemplate template) : base(new Dictionary <string, object>(), true)
 {
     this.Template = template;
 }
        public static string GetCommissionTypeValue(IExcelDataReader reader, SheetConfig config, List <GroupValue> groupValues)
        {
            var parts = MappingTemplate.Parse(config.CommissionTypes.MappingTemplate);

            if (!parts.Any())
            {
                return(config.CommissionTypes.DefaultCommissionTypeCode);
            }

            var values = new List <string>();

            foreach (var part in parts)
            {
                string value = "";
                if (part == CommissionTypes.GROUP_COMMISSION_TYPE)
                {
                    value = GetGroupValue(groupValues, GroupFieldNames.CommissionType);
                }
                else
                {
                    var column = MappingTemplate.GetColumn(part);

                    var index = ExcelUtils.ColumnToIndex(column);
                    value = Utils.GetValue(reader, index);

                    //Update value is substring is defined
                    if (MappingTemplate.IsSubstring(part))
                    {
                        try
                        {
                            var subStringIndex = MappingTemplate.GetSubStringIndexes(part);

                            var startIndex = subStringIndex[0] - 1;
                            var length     = subStringIndex[1] - subStringIndex[0] + 1;
                            value = value.Substring(startIndex, length);
                        }
                        catch { }
                    }

                    //Update value is regex is defined
                    if (MappingTemplate.IsRegex(part))
                    {
                        try
                        {
                            var regex = MappingTemplate.GetRegex(part);

                            var match = Regex.Match(value, regex, RegexOptions.IgnoreCase);
                            if (match.Success)
                            {
                                value = match.Value;
                            }
                            else
                            {
                                value = "";
                            }
                        }
                        catch { }
                    }
                }

                values.Add(value);
            }

            return(MappingTemplate.Format(values));
        }