コード例 #1
0
        public async Task <object> Get(string datonKey)
        {
            //authenticate; for demo purposes we will assume the user, but for a real app you would check the authentication
            //header and look up the user in a cache or databse
            var user = UserCache.Buffy_The_Admin;

            //get the daton, with permissions enforced (so it may be missing some rows and columns depending on the user)
            var key        = DatonKey.Parse(datonKey);
            var loadResult = await Globals.Retroverse.GetDaton(key, user);

            if (loadResult.Daton == null)
            {
                return(null);                          //could check loadResult.Errors here too
            }
            //return as json
            string json = Retrovert.ToWire(Globals.Retroverse.DataDictionary, loadResult.Daton, true);

            return(Content(json, "application/json"));
        }
コード例 #2
0
        public void ToCompatibleWire()
        {
            var jill = new Employee
            {
                EmpId     = 9,
                FirstName = "Jill",
                Key       = new PersistonKey("Employee", "9", false),
                Version   = "v2"
            };
            var elist = new EmployeeList
            {
                Key      = new ViewonKey("EmployeeList"),
                Version  = "v2",
                Employee = new List <EmployeeList.TopRow>
                {
                    new EmployeeList.TopRow
                    {
                        EmpId     = 9,
                        FirstName = "Jill"
                                    //last name missing
                    }
                }
            };
            var ddict = new DataDictionary();

            ddict.AddDatonUsingClassAnnotation(typeof(Employee));
            ddict.AddDatonUsingClassAnnotation(typeof(EmployeeList));

            string json = Retrovert.ToWire(ddict, jill, true);
            //expected has single quotes so the source code is more readable
            string expected = "{'key':'Employee|=9','version':'v2','employee':{'empId':9,'firstName':'Jill'}}";

            Assert.AreEqual(expected.Replace('\'', '"'), json);

            json = Retrovert.ToWire(ddict, elist, true);
            //expected has single quotes so the source code is more readable
            expected = "{'key':'EmployeeList','version':'v2','employee':[{'empId':9,'firstName':'Jill','lastName':null,'supervisorId':0,'supervisorLastName':null}]}";
            Assert.AreEqual(expected.Replace('\'', '"'), json);
        }
コード例 #3
0
        public void ToDenseWire()
        {
            var jill = new Employee
            {
                EmpId     = 9,
                FirstName = "Jill",
                Key       = new PersistonKey("Employee", "9", false),
                Version   = "v2"
            };
            var elist = new EmployeeList
            {
                Key      = new ViewonKey("EmployeeList"),
                Version  = "v2",
                Employee = new List <EmployeeList.TopRow>
                {
                    new EmployeeList.TopRow
                    {
                        EmpId     = 9,
                        FirstName = "Jill"
                                    //last name missing
                    }
                }
            };
            var emily = new Ogre()
            {
                Name          = "Emily",
                Key           = new PersistonKey("Ogre", "3", false),
                Version       = "v2",
                Money         = 2,
                OgreId        = 3,
                PaymentMethod = new List <Ogre.PaymentMethodRow>
                {
                    new Ogre.PaymentMethodRow {
                        Method = "THUMP", Notes = "n1"
                    },
                    new Ogre.PaymentMethodRow {
                        Method = "BOP", Notes = null
                    }
                }
            };

            var ddict = new DataDictionary();

            ddict.AddDatonUsingClassAnnotation(typeof(Employee));
            ddict.AddDatonUsingClassAnnotation(typeof(EmployeeList));
            ddict.AddDatonUsingClassAnnotation(typeof(Ogre));

            string json = Retrovert.ToWire(ddict, jill, false);
            //expected has single quotes so the source code is more readable
            string expected = "{'key':'Employee|=9','version':'v2','content':[[9,'Jill']]}";

            Assert.AreEqual(expected.Replace('\'', '"'), json);

            json = Retrovert.ToWire(ddict, elist, false);
            //expected has single quotes so the source code is more readable
            expected = "{'key':'EmployeeList','version':'v2','content':[[9,'Jill',null,0,null]]}";
            Assert.AreEqual(expected.Replace('\'', '"'), json);

            json = Retrovert.ToWire(ddict, emily, false);
            //expected has single quotes so the source code is more readable
            expected = "{'key':'Ogre|=3','version':'v2','content':[[3,'Emily',2,null,[[0,'THUMP','n1',null],[0,'BOP',null,null]]]]}";
            Assert.AreEqual(expected.Replace('\'', '"'), json);
        }