Exemplo n.º 1
0
 private static void CreateFieldsTable(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
 {
     foreach (var item in generationInfo.GetTables(true))
     {
         var cmf = new CodeMemberField
         {
             Attributes = MemberAttributes.Public,
             Name       = item.Name,
             Type       = item.GetCodeType(CodeType.Pointer | CodeType.Const)
         };
         classType.Members.Add(cmf);
     }
 }
Exemplo n.º 2
0
        private static void CreateDestructor(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeDestructor
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Override
            };

            foreach (var item in generationInfo.GetTables())
            {
                var field  = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name);
                var delete = new CodeObjectDeleteExpression(field);

                cc.Statements.Add(delete);
            }

            classType.Members.Add(cc);
        }
Exemplo n.º 3
0
        private static void CreateConstructor(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeConstructor
            {
                Attributes = MemberAttributes.Public
            };

            cc.Parameters.Add(generationInfo.ReaderNamespace, "idataset&", "dataSet");
            cc.Parameters.Add(new CodeTypeReference(typeof(bool)), "verifyRevision");

            foreach (var item in generationInfo.GetTables(true))
            {
                var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name);
                cc.Statements.AddAssign(field, new CodePrimitiveExpression(null));
            }

            var methodInvokeExp = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Load", new CodeVariableReferenceExpression("dataSet"), new CodeVariableReferenceExpression("verifyRevision"));

            cc.Statements.Add(methodInvokeExp);

            classType.Members.Add(cc);
        }
Exemplo n.º 4
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($"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();

            codeNamespace.Types.Add(classType);
            classType.Name    = generationInfo.ClassName;
            classType.IsClass = true;
            classType.BaseTypes.Add(generationInfo.BaseNamespace, "CremaData");

            CreateNameField(classType, generationInfo);
            CreateRevisionField(classType, generationInfo);
            CreateTypesHashValueField(classType, generationInfo);
            CreateTablesHashValueField(classType, generationInfo);
            CreateTagsField(classType, generationInfo);
            CreateNameMethod(classType, generationInfo);
            CreateRevisionMethod(classType, generationInfo);
            CreateTypesHashValueMethod(classType, generationInfo);
            CreateTablesHashValueMethod(classType, generationInfo);
            CreateTagsMethod(classType, generationInfo);
            CreateFieldsTable(classType, generationInfo);
            CreateConstructor(classType, generationInfo);
            CreateConstructorFromFile(classType, generationInfo);
            CreateLoadFromFile(classType, generationInfo);
            CreateLoad(classType, generationInfo);
            CreateDestructor(classType, generationInfo);
        }
Exemplo n.º 5
0
        private static void CreateLoad(CodeTypeDeclaration classType, CodeGenerationInfo generationInfo)
        {
            var cc = new CodeMemberMethod
            {
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Name       = "Load"
            };

            cc.Parameters.Add(generationInfo.ReaderNamespace, "idataset&", "dataSet");
            cc.Parameters.Add(new CodeTypeReference(typeof(bool)), "verifyRevision");

            var dataSet = new CodeVariableReferenceExpression("dataSet");

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

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

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

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

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

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

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_typesHashValue");
                var property = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "types_hash_value"));
                cc.Statements.AddAssign(field, property);
            }

            {
                var field    = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_tablesHashValue");
                var property = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "tables_hash_value"));
                cc.Statements.AddAssign(field, property);
            }

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

            foreach (var item in generationInfo.GetTables(true))
            {
                var field       = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name);
                var operatorExp = new CodeBinaryOperatorExpression(field, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
                var ccs         = new CodeConditionStatement(operatorExp);
                var delete      = new CodeObjectDeleteExpression(field);
                ccs.TrueStatements.Add(delete);
                cc.Statements.Add(ccs);

                var tableName  = new CodePrimitiveExpression(item.Name);
                var tablesProp = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(dataSet, "tables"));
                var table      = new CodeIndexerExpression(tablesProp, tableName);

                //var field = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), item.Name);
                var instance = new CodeObjectCreateExpression(item.GetCodeType(generationInfo.Namespace, CodeType.None), table);

                cc.Statements.AddAssign(field, instance);
            }

            classType.Members.Add(cc);
        }