private DynamicClassView GenerateView()
    {
        if (ObjectType == null || UserID == null)
        {
            throw new InvalidOperationException("Both ObjectType and UserID property must be specified");
        }
        var ot  = ObjectType.Value;
        var ui  = UserID.Value;
        var now = DateTime.Now;

        var permissions = ServerModel.DB.Load <TblPermissions>(PermissionsManager.GetPermissions(ot, ui, now, null));

        if (permissions.Count > 0)
        {
            Type pType   = typeof(TblPermissions);
            var  refProp = pType.GetProperty(ot.GetSecurityAtr().Name + "Ref");
            var  ids     = new List <int>(permissions.Select(p => refProp.GetValue(p, null)).NonNull().Cast <int>().Distinct());
            var  objs    =
                new DataObjectDictionary(
                    (IEnumerable)
                    DatabaseModel.LOAD_LIST_METHOD.MakeGenericMethod(new[] { ot.GetSecurityAtr().RuntimeClass }).
                    Invoke(ServerModel.DB, new[] { ids }));

            var possibleOps = PermissionsManager.GetPossibleOperations(ot);

            var view = new DynamicClassView(possibleOps.Count);
            view.DefineProperty("Name", typeof(string));
            view.DefineProperty("Date From", typeof(DateTime), false);
            view.DefineProperty("Date To", typeof(DateTime), false);
            foreach (var op in possibleOps)
            {
                view.DefineProperty(op.Name, typeof(bool));
            }

            foreach (ISecuredDataObject o in objs.Values)
            {
                var operations = PermissionsManager.GetOperationsForObject(ot, ui, o.ID, now);

                foreach (var op in operations)
                {
                    var d = view.Add();
                    foreach (var i in possibleOps)
                    {
                        d.AddProperty(i.Name, i.ID == op);
                    }
                    d.AddProperty("Name", o.Name);
                    // TODO: Implement datefrom and dateto retrieving
                    d.AddProperty("Date From", null);
                    d.AddProperty("Date To", null);

                    view.Add(d);
                }
            }

            return(view);
        }
        return(null);
    }
    private DynamicClassView GenerateView()
    {
        if (ObjectType == null || UserID == null)
        {
            throw new InvalidOperationException("Both ObjectType and UserID property must be specified");
        }
        var ot = ObjectType.Value;
        var ui = UserID.Value;
        var now = DateTime.Now;

        var permissions = ServerModel.DB.Load<TblPermissions>(PermissionsManager.GetPermissions(ot, ui, now, null));
        if (permissions.Count > 0)
        {
            Type pType = typeof (TblPermissions);
            var refProp = pType.GetProperty(ot.GetSecurityAtr().Name + "Ref");
            var ids = new List<int>(permissions.Select(p => refProp.GetValue(p, null)).NonNull().Cast<int>().Distinct());
            var objs =
                new DataObjectDictionary(
                    (IEnumerable)
                    DatabaseModel.LOAD_LIST_METHOD.MakeGenericMethod(new[] {ot.GetSecurityAtr().RuntimeClass}).
                        Invoke(ServerModel.DB, new[] {ids}));

            var possibleOps = PermissionsManager.GetPossibleOperations(ot);

            var view = new DynamicClassView(possibleOps.Count);
            view.DefineProperty("Name", typeof (string));
            view.DefineProperty("Date From", typeof (DateTime), false);
            view.DefineProperty("Date To", typeof (DateTime), false);
            foreach (var op in possibleOps)
            {
                view.DefineProperty(op.Name, typeof (bool));
            }

            foreach (ISecuredDataObject o in objs.Values)
            {
                var operations = PermissionsManager.GetOperationsForObject(ot, ui, o.ID, now);

                foreach (var op in operations)
                {
                    var d = view.Add();
                    foreach (var i in possibleOps)
                    {
                        d.AddProperty(i.Name, i.ID == op);
                    }
                    d.AddProperty("Name", o.Name);
                    // TODO: Implement datefrom and dateto retrieving
                    d.AddProperty("Date From", null);
                    d.AddProperty("Date To", null);

                    view.Add(d);
                }
            }

            return view;
        }
        return null;
    }
Esempio n. 3
0
        public void TestDynamicObject()
        {
            var view = new DynamicClassView();
            view.DefineProperty("prop1", typeof(string));
            view.DefineProperty("p2", typeof(int));
            var o = view.Add();

            var props1 = TypeDescriptor.GetProperties(o);
            Assert.AreEqual(2, props1.Count);

            var props2 = view.GetItemProperties(null);
            Assert.AreEqual(2, props2.Count);

            Assert.AreEqual(props1, props2);
        }
Esempio n. 4
0
        public void TestDynamicObject()
        {
            var view = new DynamicClassView();

            view.DefineProperty("prop1", typeof(string));
            view.DefineProperty("p2", typeof(int));
            var o = view.Add();

            var props1 = TypeDescriptor.GetProperties(o);

            Assert.AreEqual(2, props1.Count);

            var props2 = view.GetItemProperties(null);

            Assert.AreEqual(2, props2.Count);

            Assert.AreEqual(props1, props2);
        }