Ejemplo n.º 1
0
        private static int GetFieldSerializeLen(StringBuilder code, PropertyConfig field)
        {
            int flen = 0;

            Trace.WriteLine(field.Caption);
            CppTypeHelper2.DoByCppType(field.Parent, field,
                                       (pro, len) =>
            {
                flen = 4;
            },
                                       (pro, type, len) =>
            {
                if (len > 1)
                {
                    flen = 4;
                }
            },
                                       (pro, type, len) =>
            {
                flen = 4;
                code.Append(" + " + GetEntitySerializeLen(type));
            },
                                       (pro, type, len) =>
            {
                Debug.Assert(len < 1);
            },
                                       (pro, type, len) =>
            {
                Debug.Assert(len < 1);
            }
                                       );
            return(flen);
        }
Ejemplo n.º 2
0
     public static void GetCsRandomValue(StringBuilder code, PropertyConfig field, string entityName)
     {
         CppTypeHelper2.DoByCppType(field.Parent, field,
                                    (pro, len) =>
         {
             int len2  = (len - 1) / 2;
             var value = TestLine[random.Next(TestLine.Length - 1)];
             if (value.Length > len2)
             {
                 value = value.Substring(0, len2);
             }
             code.Append($@"
 //{field.Caption}
 {entityName}.{field.Name}=""{value}"";");
         },
                                    (pro, type, len) =>
         {
             if (type == "tm")
             {
                 code.Append($@"
 //{field.Caption}
 {entityName}.{field.Name} = DateTime.Now;");
             }
             else if (len <= 0)
             {
                 code.Append($@"
 //{field.Caption}
 {entityName}.{field.Name} = {GetBaseTypeValue(type)};");
             }
             else
             {
                 code.Append($@"
 //{field.Caption}");
                 for (int idx = 0; idx < len; idx++)
                 {
                     code.Append($@"
 {entityName}.{field.Name}[{idx}] = {GetBaseTypeValue(type)};");
                 }
             }
         },
                                    (pro, en, len) =>
         {
             code.Append($@"
 //{field.Caption}
 {CreateCsEntityCode(en, $"{entityName}.{field.Name}", false)};");
         },
                                    (pro, type, len) =>
         {
         },
                                    (pro, enumcfg, len) =>
         {
             var value = enumcfg.Items[random.Next(enumcfg.Items.Count - 1)].Name;
             code.Append($@"
 //{field.Caption}
 {entityName}.{field.Name} ={enumcfg.Name}.{value};");
         });
     }
Ejemplo n.º 3
0
     public static void FieldCmp(StringBuilder code, PropertyConfig field)
     {
         CppTypeHelper2.DoByCppType(field.Parent, field,
                                    (pro, len) =>
         {
             code.Append($@"
 if(strcmp(field_org.{field.Name},field_dec.{field.Name}) != 0)
 {{
     succeed = false;
     cout << ""    {field.Caption}失败:"" << field_org.{field.Name} << ""***""<<field_dec.{field.Name}<<endl;
 }}");
         },
                                    (pro, type, len) =>
         {
             if (type == "tm" || len > 1)
             {
                 code.Append($@"
 if(memcmp(&field_org.{field.Name},&field_dec.{field.Name},sizeof(tm)) != 0)
 {{
     succeed = false;
     cout << ""    {field.Caption}失败:"" <<endl;
 }}");
             }
             else
             {
                 code.Append($@"
 if( field_org.{field.Name} != field_dec.{field.Name})
 {{
     succeed = false;
     cout << ""    {field.Caption}失败:"" << field_org.{field.Name} << ""***""<< field_dec.{field.Name}<<endl;
 }}");
             }
         },
                                    (pro, en, len) =>
         {
             code.Append($@"
 if(memcmp(&field_org.{field.Name},&field_dec.{field.Name},sizeof({en.Name})) != 0)
 {{
     succeed = false;
     cout << ""    {field.Caption}失败:"" <<endl;
 }}");
         },
                                    (pro, ty, len) =>
         {
             if (len > 1)
             {
                 code.Append($@"
 if(memcmp(&field_org.{field.Name},&field_dec.{field.Name},sizeof(tm)) != 0)
 {{
     succeed = false;
     cout << ""    {field.Caption}失败:"" <<endl;
 }}");
             }
             else
             {
                 code.Append($@"
 if( field_org.{field.Name} != field_dec.{field.Name})
 {{
     succeed = false;
     cout << ""    {field.Caption}失败:"" << field_org.{field.Name} << ""***""<< field_dec.{field.Name}<<endl;
 }}");
             }
         },
                                    (pro, em, len) =>
         {
             if (len > 1)
             {
                 code.Append($@"
 if(memcmp(&field_org.{field.Name},&field_dec.{field.Name},sizeof(tm)) != 0)
 {{
     succeed = false;
     cout << ""    {field.Caption}失败:"" <<endl;
 }}");
             }
             else
             {
                 code.Append($@"
 if( field_org.{field.Name} != field_dec.{field.Name})
 {{
     succeed = false;
     cout << ""    {field.Caption}失败:"" << field_org.{field.Name} << ""***""<< field_dec.{field.Name}<<endl;
 }}");
             }
         });
     }
Ejemplo n.º 4
0
     public static void GetRandomValue(StringBuilder code, PropertyConfig field, string entityName)
     {
         CppTypeHelper2.DoByCppType(field.Parent, field,
                                    (pro, len) =>
         {
             int len2  = (len - 1) / 2;
             var value = TestLine[random.Next(TestLine.Length - 1)];
             if (value.Length > len2)
             {
                 value = value.Substring(0, len2);
             }
             code.Append($@"
 //{field.Caption} -- char[{len}]
 strcpy_s({entityName}.{field.Name},""{value}"");");
         },
                                    (pro, type, len) =>
         {
             if (type == "tm")
             {
                 DateTime tm = DateTime.Now;
                 code.Append($@"
 //{field.Caption} -- {type}
 {entityName}.{field.Name}.tm_year = {tm.Year };
 {entityName}.{field.Name}.tm_mon = {tm.Month };
 {entityName}.{field.Name}.tm_mday = {tm.Day };
 {entityName}.{field.Name}.tm_hour = {tm.Hour};
 {entityName}.{field.Name}.tm_min = {tm.Minute};
 {entityName}.{field.Name}.tm_sec = {tm.Second};");
             }
             else if (len <= 0)
             {
                 code.Append($@"
 //{field.Caption} -- {type}
 {entityName}.{field.Name} = {GetBaseTypeValue(type)};");
             }
             else
             {
                 code.Append($@"
 //{field.Caption} -- {type}[{len}]");
                 for (int idx = 0; idx < len; idx++)
                 {
                     code.Append($@"
 {entityName}.{field.Name}[{idx}] = {GetBaseTypeValue(type)};");
                 }
             }
         },
                                    (pro, en, len) =>
         {
             code.Append($@"
 //{field.Caption} -- {en.Caption}
 {CreateEntityCode(en, $"{entityName}.{field.Name}", false)};");
         },
                                    (pro, type, len) =>
         {
             var value = type.Items.Values.ToArray()[random.Next(type.Items.Count - 1)].Value;
             if (value == "'")
             {
                 value = "'\\0'";
             }
             code.Append($@"
 //{field.Caption} -- {type}
 {entityName}.{field.Name} = {value};");
         },
                                    (pro, enumcfg, len) =>
         {
             var value = enumcfg.Items[random.Next(enumcfg.Items.Count - 1)].Name;
             code.Append($@"
 //{field.Caption} -- {enumcfg}
 {entityName}.{field.Name} = GBS::Futures::{enumcfg.Name}Classify::{value};");
         });
     }