private static CodeTypeDeclaration CreateCore(TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var classType = new CodeTypeDeclaration();

            classType.Attributes      = MemberAttributes.Public;
            classType.Name            = tableInfo.GetClassName();
            classType.IsClass         = true;
            classType.TypeAttributes |= TypeAttributes.Sealed;
            classType.BaseTypes.Add("base", "CremaTable", tableInfo.GetRowCodeType());
            if (generationInfo.OmitComment == false)
            {
                classType.Comments.AddSummary(tableInfo.Comment);
            }
            if (generationInfo.OmitSignatureDate == false)
            {
                classType.Comments.Add(CremaCodeGenerator.Creator, tableInfo.CreationInfo.ID);
                classType.Comments.Add(CremaCodeGenerator.CreatedDateTime, tableInfo.CreationInfo.DateTime);
                classType.Comments.Add(CremaCodeGenerator.Modifier, tableInfo.ModificationInfo.ID);
                classType.Comments.Add(CremaCodeGenerator.ModifiedDateTime, tableInfo.ModificationInfo.DateTime);
                classType.Comments.Add(CremaCodeGenerator.ContentsModifier, tableInfo.ContentsInfo.ID);
                classType.Comments.Add(CremaCodeGenerator.ContentsModifiedDateTime, tableInfo.ContentsInfo.DateTime);
            }

            CreateChildFields(classType, tableInfo, generationInfo);
            CreateChildProperties(classType, tableInfo, generationInfo);
            CreateCreateFromTableMethod(classType, tableInfo, generationInfo);
            CreateCreateFromRowsMethod(classType, tableInfo, generationInfo);

            CreateReadFromRowsMethod(classType, tableInfo);
            CreateFindMethod(classType, tableInfo, generationInfo);
            CreateCreateRowInstanceMethod(classType, tableInfo, generationInfo);
            CreateReadFromTableMethod(classType, tableInfo, generationInfo);

            return(classType);
        }
 public static void Create(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo)
 {
     foreach (var item in generationInfo.GetTables())
     {
         Create(codeNamespace, item, generationInfo);
     }
 }
Exemple #3
0
        public void Generate(string outputPath, GenerationSet metaData, CodeGenerationSettings settings)
        {
            var generationInfo = new CodeGenerationInfo(outputPath, metaData, settings);

            if (settings.Options.HasFlag(CodeGenerationOptions.OmitCode) == false)
            {
                var codes = this.GenerateCodes(generationInfo);

                foreach (var item in codes)
                {
                    var codePath = FileUtility.WriteAllText(item.Value, Encoding.UTF8, outputPath, item.Key);
                    this.PrintResult(codePath);
                }
            }

            if (settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == false)
            {
                var codes = this.GenerateBaseCodes(generationInfo);

                foreach (var item in codes)
                {
                    var codePath = FileUtility.WriteAllText(item.Value, Encoding.UTF8, outputPath, item.Key);
                    this.PrintResult(codePath);
                }
            }
        }
Exemple #4
0
        public void Compile(string outputPath, GenerationSet metaData, CodeGenerationSettings settings, string target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            var generationInfo = new CodeGenerationInfo(outputPath, metaData, settings);

            var codes1 = this.GenerateCodes(generationInfo);
            var codes2 = this.GenerateBaseCodes(generationInfo);
            var codes3 = codes1.Concat(codes2).ToDictionary(item => item.Key, item => item.Value);

            var codes = TypeScriptCompiler.Compile(codes3, target == string.Empty ? "ES5" : target);

            if (Directory.Exists(outputPath) == false)
            {
                Directory.CreateDirectory(outputPath);
            }

            foreach (var item in codes)
            {
                string codePath = Path.Combine(outputPath, item.Key);

                using (StreamWriter sw = new StreamWriter(codePath, false, Encoding.UTF8))
                {
                    sw.WriteLine(item.Value);
                    this.PrintResult(codePath);
                }
            }
        }
        public static void Create(CodeNamespace codeNamespace, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var classType = new CodeTypeDeclaration();

            classType.Attributes      = MemberAttributes.Public;
            classType.Name            = tableInfo.GetRowClassName();
            classType.IsClass         = true;
            classType.TypeAttributes |= TypeAttributes.Sealed;
            classType.BaseTypes.Add("base", "CremaRow");

            CreateStaticChildEmptyFields(classType, tableInfo, generationInfo);
            CreateTableField(classType, tableInfo);
            CreateColumnFields(classType, tableInfo, generationInfo);
            CreateChildFields(classType, tableInfo, generationInfo);

            CreateConstructor(classType, tableInfo, generationInfo);

            CreateSetChildsMethod(classType, tableInfo, generationInfo);
            CreateColumnProperties(classType, tableInfo, generationInfo);
            CreateChildProperties(classType, tableInfo, generationInfo);
            CreateTableProperty(classType, tableInfo);
            CreateParentProperty(classType, tableInfo);

            codeNamespace.Types.Add(classType);
        }
Exemple #6
0
        private string GenerateReader(CodeGenerationInfo generationInfo)
        {
            var sb = new StringBuilder();

            this.AppendLint(sb, generationInfo);
            var text = this.GetResourceString("Reader.crema-reader.ts");

            sb.Append(text);
            return(sb.ToString());
        }
Exemple #7
0
        private static void CreateRevisionField(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmf = new CodeMemberField();

            cmf.Attributes = MemberAttributes.Private;
            cmf.Name       = "_revision";
            cmf.Type       = new CodeTypeReference(typeof(long));

            classType.Members.Add(cmf);
        }
Exemple #8
0
        private static void CreateTagsHashValueField(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmf = new CodeMemberField();

            cmf.Attributes = MemberAttributes.Private;
            cmf.Name       = "_tags";
            cmf.Type       = new CodeTypeReference(typeof(string));

            classType.Members.Add(cmf);
        }
Exemple #9
0
        private IDictionary <string, string> GenerateBaseCodes(CodeGenerationInfo generationInfo)
        {
            var codes      = new Dictionary <string, string>();
            var baseCode   = GenerateBase(generationInfo);
            var readerCode = GenerateReader(generationInfo);

            codes.Add($"{generationInfo.RelativePath}{generationInfo.Namespace}-base.ts", baseCode);
            codes.Add($"{generationInfo.RelativePath}{generationInfo.Namespace}-reader.ts", readerCode);

            return(codes);
        }
Exemple #10
0
        private string GenerateBase(CodeGenerationInfo generationInfo)
        {
            var sb = new StringBuilder();

            this.AppendLint(sb, generationInfo);
            var text  = this.GetResourceString("Reader.crema-base.ts");
            var text2 = text.Replace("./crema-reader", string.Format("./{0}-reader", generationInfo.Namespace));

            sb.Append(text2);
            return(sb.ToString());
        }
Exemple #11
0
        private static void CreateTagsProperty(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberProperty();

            cmm.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            cmm.Name       = "tags";
            cmm.HasGet     = true;
            cmm.Type       = new CodeTypeReference(typeof(string));
            cmm.GetStatements.AddMethodReturn(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "_tags"));

            classType.Members.Add(cmm);
        }
Exemple #12
0
        private static void CreateTableFields(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetTables(true))
            {
                var cmf = new CodeMemberField();
                cmf.Attributes = MemberAttributes.Private;
                cmf.Name       = item.GetFieldName();
                cmf.Type       = item.GetCodeType();

                classType.Members.Add(cmf);
            }
        }
Exemple #13
0
 private void AppendLint(StringBuilder sb, CodeGenerationInfo generationInfo)
 {
     if (generationInfo.TSLintDisable != null)
     {
         if (generationInfo.TSLintDisable == string.Empty)
         {
             sb.AppendLine($"// tslint:disable");
         }
         else
         {
             sb.AppendLine($"// tslint:disable: {generationInfo.TSLintDisable}");
         }
         sb.AppendLine();
     }
 }
Exemple #14
0
        public static void CreateTypes(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo)
        {
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"dataBase: {generationInfo.DataBaseName}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"revision: {generationInfo.Revision}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"requested revision: {generationInfo.RequestedRevision}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"devmode: {generationInfo.IsDevmode}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"hash value: {generationInfo.TypesHashValue}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"tags: {generationInfo.Tags}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));

            foreach (var item in generationInfo.Types)
            {
                CreateType(codeNamespace, item, generationInfo);
            }
        }
Exemple #15
0
        private static void CreateTableProperties(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetTables(true))
            {
                var cmp = new CodeMemberProperty();
                cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                cmp.Name       = item.Name;
                cmp.Type       = item.GetCodeType();
                cmp.HasGet     = true;
                cmp.HasSet     = false;
                cmp.Comments.AddSummary(item.Comment);
                cmp.GetStatements.AddMethodReturn(item.GetFieldExpression());

                classType.Members.Add(cmp);
            }
        }
        public static void Create(CodeNamespace codeNamespace, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                if (item.TemplatedParent != string.Empty)
                {
                    continue;
                }

                Create(codeNamespace, item, generationInfo);
            }

            CremaRowClassCreator.Create(codeNamespace, tableInfo, generationInfo);
            var classType = CreateCore(tableInfo, generationInfo);

            codeNamespace.Types.Add(classType);
        }
Exemple #17
0
        public static void Create(CodeNamespace codeNamespace, CodeGenerationInfo generationInfo)
        {
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"dataBase: {generationInfo.DataBaseName}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"revision: {generationInfo.Revision}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"requested revision: {generationInfo.RequestedRevision}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"devmode: {generationInfo.IsDevmode}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"hash value: {generationInfo.TablesHashValue}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"tags: {generationInfo.Tags}"));
            codeNamespace.Comments.Add(new CodeCommentStatement($"------------------------------------------------------------------------------"));

            foreach (var item in generationInfo.GetTables())
            {
                CremaTableClassCreator.Create(codeNamespace, item, generationInfo);
            }

            var classType = new CodeTypeDeclaration();

            classType.Attributes      = MemberAttributes.Public;
            classType.Name            = generationInfo.ClassName;
            classType.IsClass         = true;
            classType.TypeAttributes |= TypeAttributes.Sealed;
            classType.BaseTypes.Add("base", "CremaData");

            CreateNameField(classType, generationInfo);
            CreateRevisionField(classType, generationInfo);
            CreateTypesHashValueField(classType, generationInfo);
            CreateTablesHashValueField(classType, generationInfo);
            CreateTagsHashValueField(classType, generationInfo);
            CreateNameProperty(classType, generationInfo);
            CreateRevisionProperty(classType, generationInfo);
            CreateTypesHashValueProperty(classType, generationInfo);
            CreateTablesHashValueProperty(classType, generationInfo);
            CreateTagsProperty(classType, generationInfo);
            CreateTableFields(classType, generationInfo);
            CreateCreateFromDataSetMethod(classType, generationInfo);
            CreateCreateFromFileMethod(classType, generationInfo);
            CreateTableProperties(classType, generationInfo);
            CreateReadFromDataSetMethod(classType, generationInfo);
            CreateReadFromFileMethod(classType, generationInfo);

            codeNamespace.Types.Add(classType);
        }
Exemple #18
0
        private static void CreateReadFromFileMethod(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberMethod();

            cmm.Attributes = MemberAttributes.Public;
            cmm.Name       = "readFromFile";
            cmm.Parameters.Add(typeof(string), "filename");
            cmm.Parameters.Add(typeof(bool), "verifyRevision");

            var filename        = new CodeVariableReferenceExpression("filename");
            var verifyRevision  = new CodeVariableReferenceExpression("verifyRevision");
            var cremaReader     = new CodeTypeReferenceExpression(Utility.GenerateCodeType("reader", "CremaReader"));
            var readFromFile    = new CodeMethodInvokeExpression(cremaReader, "readFromFile", filename);
            var readFromDataSet = new CodeMethodInvokeExpression(thisRef, "readFromDataSet", readFromFile, verifyRevision);

            cmm.Statements.Add(readFromDataSet);

            classType.Members.Add(cmm);
        }
Exemple #19
0
        private IDictionary <string, string> GenerateCodes(CodeGenerationInfo generationInfo)
        {
            var codes           = new Dictionary <string, string>();
            var codeDomProvider = new CodeDom.TypeScriptCodeProvider();
            var options         = new CodeGeneratorOptions()
            {
                BlankLinesBetweenMembers = true,
            };

            var cremaTypes  = GenerateTypes(codeDomProvider, options, generationInfo);
            var cremaTables = GenerateTables(codeDomProvider, options, generationInfo);
            var cremaDecl   = GenerateDeclaration(codeDomProvider, options, generationInfo);

            codes.Add($"{generationInfo.Namespace}-{generationInfo.Prefix}types{generationInfo.Postfix}.ts", cremaTypes);
            codes.Add($"{generationInfo.Namespace}-{generationInfo.Prefix}tables{generationInfo.Postfix}.ts", cremaTables);
            if (generationInfo.OmitDeclaration == false)
            {
                codes.Add($"{generationInfo.Namespace}.d.ts", cremaDecl);
            }

            return(codes);
        }
        private static void CreateConstructor(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor();

            cc.Attributes = MemberAttributes.Public;
            cc.Parameters.Add("reader", "IRow", "row");
            cc.Parameters.Add(tableInfo.GetCodeType(), "table");
            cc.BaseConstructorArgs.AddVariableReference("row");

            // assign table field
            {
                var tableField = tableInfo.GetFieldExpression();
                var table      = new CodeVariableReferenceExpression("table");
                cc.Statements.AddAssign(tableField, table);
            }

            // assign column fields
            {
                var index = 0;
                foreach (var item in tableInfo.Columns)
                {
                    var cas = new CodeAssignStatement();
                    cas.Left  = item.GetFieldExpression();
                    cas.Right = item.GetGetValueMethodExpression(index, false);

                    if (item.IsKey == false)
                    {
                        var ccs = new CodeConditionStatement(item.GetHasValueMethodExpression(index, false));
                        ccs.TrueStatements.Add(cas);
                        var tst = CremaDataClassCreator.CreateTryCatchStatement(classType, ccs, false);
                        cc.Statements.Add(tst);
                    }
                    else
                    {
                        cc.Statements.Add(cas);
                    }
                    index++;
                }
            }

            // invoke setKey
            {
                var setKey       = new CodeMethodReferenceExpression(thisRef, "setKey");
                var invokeSetKey = new CodeMethodInvokeExpression(setKey);

                foreach (var item in tableInfo.Columns)
                {
                    if (item.IsKey == true)
                    {
                        invokeSetKey.Parameters.Add(item.GetFieldExpression());
                    }
                }
                cc.Statements.Add(invokeSetKey);
            }

            classType.Members.Add(cc);
        }
        private static void CreateChildProperties(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                var cmp = new CodeMemberProperty();
                cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                cmp.Name       = item.GetPropertyName();
                cmp.Type       = item.GetCodeType();
                cmp.HasGet     = true;
                cmp.HasSet     = false;

                // check null and return defaultField
                {
                    var state     = new CodeConditionStatement();
                    var condition = new CodeBinaryOperatorExpression(item.GetFieldExpression(), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(null));
                    state.Condition = condition;

                    var staticField = new CodeFieldReferenceExpression(tableInfo.GetRowCodeTypeExpression(), item.GetFieldName() + "Empty");
                    state.TrueStatements.AddMethodReturn(staticField);

                    cmp.GetStatements.Add(state);
                }

                // return field;
                {
                    var fieldExp = item.GetFieldExpression();
                    cmp.GetStatements.AddMethodReturn(fieldExp);
                }

                classType.Members.Add(cmp);
            }
        }
        private static void CreateColumnProperties(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in tableInfo.Columns)
            {
                var cmp = new CodeMemberProperty();
                cmp.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                cmp.Name       = item.Name;
                cmp.Type       = item.GetCodeType();

                if (generationInfo.OmitComment == false)
                {
                    cmp.Comments.AddSummary(item.Comment);
                }
                if (generationInfo.OmitSignatureDate == false)
                {
                    cmp.Comments.Add(CremaCodeGenerator.Creator, item.CreationInfo.ID);
                    cmp.Comments.Add(CremaCodeGenerator.CreatedDateTime, item.CreationInfo.DateTime);
                    cmp.Comments.Add(CremaCodeGenerator.Modifier, item.ModificationInfo.ID);
                    cmp.Comments.Add(CremaCodeGenerator.ModifiedDateTime, item.ModificationInfo.DateTime);
                }
                cmp.HasGet = true;
                cmp.HasSet = false;

                // return field;
                {
                    var field = item.GetFieldExpression();
                    cmp.GetStatements.AddMethodReturn(field);
                }

                classType.Members.Add(cmp);
            }
        }
        private static void CreateStaticChildEmptyFields(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                var cmf = new CodeMemberField();
                cmf.Attributes     = MemberAttributes.Private | MemberAttributes.Static;
                cmf.Name           = item.GetFieldName() + "Empty";
                cmf.Type           = item.GetCodeType();
                cmf.InitExpression = new CodeObjectCreateExpression(item.GetCodeType());

                classType.Members.Add(cmf);
            }
        }
        private static void CreateColumnFields(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in tableInfo.Columns)
            {
                var cmf = new CodeMemberField();
                cmf.Attributes = MemberAttributes.Private;
                cmf.Name       = item.GetFieldName();
                cmf.Type       = item.GetCodeType();

                classType.Members.Add(cmf);
            }
        }
        private static void CreateSetChildsMethod(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            foreach (var item in generationInfo.GetChilds(tableInfo))
            {
                var cmm = new CodeMemberMethod();
                cmm.Attributes = MemberAttributes.FamilyAndAssembly | MemberAttributes.Static;
                cmm.Name       = "Set" + item.TableName;
                cmm.Parameters.Add(tableInfo.GetRowCodeType(), "target");
                cmm.Parameters.Add(typeof(string), "childName");
                cmm.Parameters.Add(item.GetRowCodeType(), 1, "childs");

                // invoke setParent
                {
                    var target    = new CodeVariableReferenceExpression("target");
                    var childs    = new CodeVariableReferenceExpression("childs");
                    var setParent = new CodeMethodReferenceExpression(tableInfo.GetRowCodeTypeExpression(), "setParent");
                    setParent.TypeArguments.Add(tableInfo.GetRowCodeType());
                    setParent.TypeArguments.Add(item.GetRowCodeType());
                    var invokeSetParent = new CodeMethodInvokeExpression(setParent, target, childs);

                    cmm.Statements.AddExpression(invokeSetParent);
                }

                // create and assign child table
                {
                    var target               = new CodeVariableReferenceExpression("target");
                    var childName            = new CodeVariableReferenceExpression("childName");
                    var childs               = new CodeVariableReferenceExpression("childs");
                    var field                = item.GetFieldExpression(target);
                    var createFromRows       = new CodeMethodReferenceExpression(item.GetCodeTypeExpression(), "createFromRows");
                    var InvokeCreateFromRows = new CodeMethodInvokeExpression(createFromRows, childName, childs);

                    cmm.Statements.AddAssign(field, InvokeCreateFromRows);
                }

                classType.Members.Add(cmm);
            }
        }
Exemple #26
0
        private static void CreateCreateFromDataSetMethod(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberMethod();

            cmm.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            cmm.Name       = "createFromDataSet";
            cmm.Parameters.Add("reader", "IDataSet", "dataSet");
            cmm.Parameters.Add(typeof(bool), "verifyRevision");
            cmm.ReturnType = new CodeTypeReference(generationInfo.ClassName);

            // create instance
            {
                var create = new CodeObjectCreateExpression(cmm.ReturnType);
                cmm.Statements.AddVariableDeclaration(cmm.ReturnType.BaseType, "instance", create);
            }

            // invoke readFromDataSet
            {
                var instance        = new CodeVariableReferenceExpression("instance");
                var dataSet         = new CodeVariableReferenceExpression("dataSet");
                var verifyRevision  = new CodeVariableReferenceExpression("verifyRevision");
                var readFromDataSet = new CodeMethodReferenceExpression(instance, "readFromDataSet");
                cmm.Statements.Add(new CodeMethodInvokeExpression(readFromDataSet, dataSet, verifyRevision));
            }

            // return instance;
            {
                var instance = new CodeVariableReferenceExpression("instance");
                cmm.Statements.AddMethodReturn(instance);
            }

            classType.Members.Add(cmm);
        }
Exemple #27
0
        private static CodeStatement CreateCompareTablesHashValueStatement(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var ccs = new CodeConditionStatement();

            var left  = new CodePrimitiveExpression(generationInfo.TablesHashValue);
            var right = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("dataSet"), "tablesHashValue");

            ccs.Condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityInequality, right);

            var message   = string.Format("테이블 해시값이 '{0}'이 아닙니다.", generationInfo.TablesHashValue);
            var exception = new CodeObjectCreateExpression("Error", new CodePrimitiveExpression(message));

            ccs.TrueStatements.Add(new CodeThrowExceptionStatement(exception));

            return(ccs);
        }
Exemple #28
0
        private static CodeStatement CreateCompareRevisionStatement(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var ccs = new CodeConditionStatement();

            var left1  = new CodeVariableReferenceExpression("verifyRevision");
            var right1 = new CodePrimitiveExpression(true);
            var left   = new CodeBinaryOperatorExpression(left1, CodeBinaryOperatorType.IdentityEquality, right1);

            var left2  = new CodeCastExpression(typeof(int), new CodePrimitiveExpression(generationInfo.Revision));
            var right2 = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("dataSet"), "revision");
            var right  = new CodeBinaryOperatorExpression(left2, CodeBinaryOperatorType.IdentityInequality, right2);

            ccs.Condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.BooleanAnd, right);

            var message   = string.Format("데이터의 리비전 코드 리비전({0})과 다릅니다.", generationInfo.Revision);
            var exception = new CodeObjectCreateExpression("Error", new CodePrimitiveExpression(message));

            ccs.TrueStatements.Add(new CodeThrowExceptionStatement(exception));

            return(ccs);
        }
        private static CodeStatement CreateCompareTypeStatement(CodeTypeDeclaration classType, TableInfo tableInfo, CodeGenerationInfo generationInfo)
        {
            var table   = new CodeVariableReferenceExpression("table");
            var version = new CodePropertyReferenceExpression(table, "hashValue");

            var state = new CodeConditionStatement();

            state.Condition = new CodeBinaryOperatorExpression(version, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(tableInfo.HashValue));

            var message   = string.Format("{0} 테이블과 데이터의 형식이 맞지 않습니다.", tableInfo.Name);
            var exception = new CodeObjectCreateExpression("Error", new CodePrimitiveExpression(message));

            state.TrueStatements.Add(new CodeThrowExceptionStatement(exception));

            return(state);
        }
Exemple #30
0
        private static void CreateReadFromDataSetMethod(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cmm = new CodeMemberMethod();

            cmm.Attributes = MemberAttributes.Public;
            cmm.Name       = "readFromDataSet";
            cmm.Parameters.Add("reader", "IDataSet", "dataSet");
            cmm.Parameters.Add(typeof(bool), "verifyRevision");

            var dataSet = new CodeVariableReferenceExpression("dataSet");

            {
                var ccs = CreateCompareDataBaseStatement(classType, generationInfo);
                var tst = CreateTryCatchStatement(classType, ccs, generationInfo.IsDevmode);
                cmm.Statements.Add(tst);
            }

            {
                var ccs = CreateCompareTypesHashValueStatement(classType, generationInfo);
                var tst = CreateTryCatchStatement(classType, ccs, generationInfo.IsDevmode);
                cmm.Statements.Add(tst);
            }

            {
                var ccs = CreateCompareTablesHashValueStatement(classType, generationInfo);
                var tst = CreateTryCatchStatement(classType, ccs, generationInfo.IsDevmode);
                cmm.Statements.Add(tst);
            }

            {
                var ccs = CreateCompareRevisionStatement(classType, generationInfo);
                var tst = CreateTryCatchStatement(classType, ccs, generationInfo.IsDevmode);
                cmm.Statements.Add(tst);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_name");
                var property = new CodePropertyReferenceExpression(dataSet, "name");
                cmm.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_revision");
                var property = new CodePropertyReferenceExpression(dataSet, "revision");
                cmm.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_typesHashValue");
                var property = new CodePropertyReferenceExpression(dataSet, "typesHashValue");
                cmm.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_tablesHashValue");
                var property = new CodePropertyReferenceExpression(dataSet, "tablesHashValue");
                cmm.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_tags");
                var property = new CodePropertyReferenceExpression(dataSet, "tags");
                cmm.Statements.AddAssign(field, property);
            }

            foreach (var item in generationInfo.GetTables(true))
            {
                var tableName  = new CodePrimitiveExpression(item.Name);
                var tablesProp = new CodePropertyReferenceExpression(dataSet, "tables");
                var table      = new CodePropertyReferenceExpression(tablesProp, item.Name);

                var field           = item.GetFieldExpression();
                var createFromTable = new CodeMethodReferenceExpression(item.GetCodeTypeExpression(), "createFromTable");
                var invoke          = new CodeMethodInvokeExpression(createFromTable, table);
                var assignStatement = new CodeAssignStatement(field, invoke);

                var tryStatement = CreateTryCatchStatement(classType, assignStatement, generationInfo.IsDevmode);
                cmm.Statements.Add(tryStatement);
            }

            classType.Members.Add(cmm);
        }