예제 #1
0
        public void JMXObjectTest()
        {
            JMXSchemaProviderFactory.RegisterProvider <JMXSchemaProviderMemory>();
            IJMXSchemaProvider sp = JMXSchemaProviderFactory.GetProvider <JMXSchemaProviderMemory>();

            JMXSchemaProviderFactory.SetDefault(sp);
            using (FileLog _logger = new FileLog("ORMSchemaTest", new FileLogSettings()
            {
                DateFolderMask = "yyyy-MM-dd"
            }))
            {
                sp.SaveSchema(creaateTestSchema());

                JMXObject o = new JMXObject("SysCat.SysSchema")
                {
                    ["ID"] = 1
                };
                _logger.Debug(o.ToString());
                string s = o.ToString();
                o.ParseJson(s, null);
                _logger.Debug(o.ToString());
                o = JMXObject.CreateFrom(o.ToString());
                _logger.Debug(o.ToString());
            }
        }
예제 #2
0
        public void SerializeTest()
        {
            using (FileLog _logger = new FileLog("ORMSchemaTest", new FileLogSettings()
            {
                DateFolderMask = "yyyy-MM-dd"
            }))
            {
                JMXAttribute a = new JMXAttribute("ID")
                {
                    DataType   = MdbType.@int,
                    IsNullable = false
                };
                string sa = a.ToString();
                //_logger.Debug(sa);
                a = JsonConvert.DeserializeObject <JMXAttribute>(sa);
                //_logger.Debug(a.ToString());
                Assert.AreEqual(sa, a.ToString());
                JMXPrimaryKey pk  = new JMXPrimaryKey("PK_SomeObjects", "SomeAtt", "NextAtt");
                string        spk = pk.ToString();
                //_logger.Debug(spk);
                pk = JsonConvert.DeserializeObject <JMXPrimaryKey>(spk);
                Assert.AreEqual(spk, pk.ToString());
                JMXSchema s = new JMXSchema("SysSchemas")
                {
                    DbObjectName = new JMXObjectName("SysCat", "SysSchemas")
                };
                s.Attributes.Add(a);
                s.PrimaryKey = pk;
                s.Indexes.Add(new JMXIndex("IE1_SysSchemas", "ID"));
                var fk = new JMXForeignKey("FK1")
                {
                    RefObjectName   = "SysCat.SysArea",
                    RefDbObjectName = new JMXObjectName("SysCat", "SysAreas")
                };
                fk.AddKeyMember("AreaID");
                fk.AddRefKeyMember("ID");
                s.ForeignKeys.Add(fk);
                string ss = s.ToString();
                _logger.Debug(ss);
                s = JsonConvert.DeserializeObject <JMXSchema>(ss);
                Assert.AreEqual(ss, s.ToString());
                _logger.Debug("Start speed test fo JMXObject parse from json string");


                JMXSchemaProviderFactory.RegisterProvider <JMXSchemaProviderMemory>();
                JMXSchemaProviderFactory.SetDefault(JMXSchemaProviderFactory.GetProvider <JMXSchemaProviderMemory>());
                JMXSchemaProviderFactory.Default.SaveSchema(creaateTestSchema());
                JMXObject o = new JMXObject("SysCat.SysSchema");
                for (int i = 0; i < 1000; i++)
                {
                    o.ParseJson(ss, null);
                }
                _logger.Debug("Finish speed test");
                _logger.Debug(o.ToString());
                _logger.Debug("Start speed test fo JMXSchema serialize to json string");
                for (int i = 0; i < 1000; i++)
                {
                    ss = JsonConvert.SerializeObject(s);
                }
                _logger.Debug("Finish speed test");
                _logger.Debug("Start speed test fo JMXSchema ToString method to json string");
                for (int i = 0; i < 1000; i++)
                {
                    ss = s.ToString();
                }
                _logger.Debug("Finish speed test");
                _logger.Debug("Start speed test fo JMXSchema parse from json string");
                for (int i = 0; i < 1000; i++)
                {
                    s = JsonConvert.DeserializeObject <JMXSchema>(ss);
                }
                _logger.Debug("Finish speed test");

                //JMXObject o = new JMXObject(JObject.Parse(ss));
                //_logger.Debug((o as JObject).ToString());
                //JsonSerializer serializer = new JsonSerializer();
                //JMXObject o = (JMXObject)serializer.Deserialize(new JTokenReader(JObject.Parse(ss)), typeof(JMXObject));
                //JMXObject o = new JMXObject("Test");
            }
        }