Example #1
0
 public Instructions()
 {
     instructions["ST"]   = new ST();
     instructions["LD"]   = new LD();
     instructions["ADD"]  = new ADD();
     instructions["SUB"]  = new SUB();
     instructions["JMP"]  = new JMP();
     instructions["JN"]   = new JN();
     instructions["JP"]   = new JP();
     instructions["JZ"]   = new JZ();
     instructions["JNZ"]  = new JNZ();
     instructions["HALT"] = new HALT();
     //Second architecture functions.
     instructions["LD2"] = new LD2();
     instructions["LD3"] = new LD3();
     instructions["ST2"] = new ST2();
     instructions["ST3"] = new ST3();
     instructions["POS"] = new POS();
     instructions["PXL"] = new PXL();
     instructions["RND"] = new RND();
     instructions["CLR"] = new CLR();
     instructions["COS"] = new COS();
     instructions["SIN"] = new SIN();
     instructions["IN"]  = new IN();
 }
Example #2
0
        public void ItParsesNull()
        {
            var parser = JP.Null().CreateAbstractValuedParser();

            parser.Parse("null");
            Assert.True(parser.Success);
            Assert.AreEqual(typeof(JsonNull), parser.Value.GetType());

            parser = JP.Null().CreateAbstractValuedParser();
            parser.Parse("foo");
            Assert.False(parser.Success);
        }
Example #3
0
        public void TestMethodMediator_Example()
        {
            UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil();
            TW c1 = new TW(UNSC);
            JP c2 = new JP(UNSC);

            UNSC.colleague1 = c1;
            UNSC.colleague2 = c2;

            c1.Declare("YA");
            c2.Declare("I love TW");
        }
Example #4
0
        public static JsonEntity ReadJson(string json)
        {
            var parser = JP.Entity().CreateAbstractValuedParser();

            parser.Parse(json);

            if (!parser.Success)
            {
                throw parser.Exception;
            }

            return(parser.Value);
        }
Example #5
0
        public void ItParsesBoolean()
        {
            var parser = JP.Boolean().CreateAbstractValuedParser();

            parser.Parse("true");
            Assert.True(parser.Success);
            Assert.True(parser.Value.Value);

            parser = JP.Boolean().CreateAbstractValuedParser();
            parser.Parse("false");
            Assert.True(parser.Success);
            Assert.False(parser.Value.Value);

            parser = JP.Boolean().CreateAbstractValuedParser();
            parser.Parse("bar");
            Assert.False(parser.Success);
        }
Example #6
0
 public void SetUp()
 {
     parser = JP.Object().CreateAbstractValuedParser();
 }
 public JPDetailPage(JP jp)
 {
     InitializeComponent();
     BindingContext = ViewModel = new JPDetailsViewModel();
     ViewModel.SetData(jp);
 }
Example #8
0
 public void SetUp()
 {
     parser = JP.Number().CreateAbstractValuedParser();
 }
 public void SetData(JP finalsession)
 {
     JP = finalsession;
 }
        public string Save(string token)
        {
            token = TokenManager.readToken(HttpContext.Current.Request);
            string message = "";
            var    strP    = TokenManager.GetPrincipal(token);

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                string              obj        = "";
                int                 branchId   = 0;
                string              objectName = "";
                string              prefix     = "";
                int                 userId     = 0;
                int                 posId      = 0;
                notification        Object     = null;
                IEnumerable <Claim> claims     = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "itemObject")
                    {
                        obj    = c.Value.Replace("\\", string.Empty);
                        obj    = obj.Trim('"');
                        Object = JsonConvert.DeserializeObject <notification>(obj, new IsoDateTimeConverter {
                            DateTimeFormat = "dd/MM/yyyy"
                        });
                        //break;
                    }
                    else if (c.Type == "branchId")
                    {
                        branchId = int.Parse(c.Value);
                    }
                    else if (c.Type == "objectName")
                    {
                        objectName = c.Value;
                    }
                    else if (c.Type == "prefix")
                    {
                        prefix = c.Value;
                    }
                    else if (c.Type == "userId")
                    {
                        userId = int.Parse(c.Value);
                    }
                    else if (c.Type == "posId")
                    {
                        posId = int.Parse(c.Value);
                    }
                }
                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        Object.ncontent   = prefix + ":" + Object.ncontent;
                        Object.isActive   = 1;
                        Object.createDate = DateTime.Now;
                        Object.updateDate = DateTime.Now;

                        var          notEntity = entity.Set <notification>();
                        notification not       = notEntity.Add(Object);
                        entity.SaveChanges();

                        #region pos notifications
                        if (posId != 0)
                        {
                            var notUserEntity        = entity.Set <notificationUser>();
                            notificationUser notUser = new notificationUser()
                            {
                                notId        = not.notId,
                                posId        = posId,
                                isRead       = false,
                                createDate   = DateTime.Now,
                                updateDate   = DateTime.Now,
                                createUserId = Object.createUserId,
                                updateUserId = Object.createUserId,
                            };
                            notUserEntity.Add(notUser);
                        }
                        #endregion
                        else if (userId == 0)
                        {
                            var users = (from u in entity.users.Where(x => x.isActive == 1)
                                         join b in entity.branchesUsers on u.userId equals b.userId
                                         where b.branchId == branchId
                                         select new UserModel()
                            {
                                userId = u.userId
                            }
                                         ).ToList();

                            foreach (UserModel user in users)
                            {
                                var groupObjects = (from GO in entity.groupObject
                                                    join U in entity.users on GO.groupId equals U.groupId
                                                    join G in entity.groups on GO.groupId equals G.groupId
                                                    join O in entity.objects on GO.objectId equals O.objectId
                                                    join POO in entity.objects on O.parentObjectId equals POO.objectId into JP

                                                    from PO in JP.DefaultIfEmpty()
                                                    where U.userId == user.userId
                                                    select new
                                {
                                    //group object
                                    GO.id,
                                    GO.groupId,
                                    GO.objectId,
                                    GO.addOb,
                                    GO.updateOb,
                                    GO.deleteOb,
                                    GO.showOb,
                                    GO.reportOb,
                                    GO.levelOb,
                                    //group
                                    GroupName = G.name,
                                    //object
                                    ObjectName = O.name,
                                    O.parentObjectId,
                                    O.objectType,
                                    parentObjectName = PO.name,
                                }).ToList();

                                var element = groupObjects.Where(X => X.ObjectName == objectName).FirstOrDefault();
                                if (element.showOb == 1)
                                {
                                    // add notification to users
                                    var notUserEntity        = entity.Set <notificationUser>();
                                    notificationUser notUser = new notificationUser()
                                    {
                                        notId        = not.notId,
                                        userId       = user.userId,
                                        isRead       = false,
                                        createDate   = DateTime.Now,
                                        updateDate   = DateTime.Now,
                                        createUserId = Object.createUserId,
                                        updateUserId = Object.createUserId,
                                    };
                                    notUserEntity.Add(notUser);
                                }
                            }
                        }
                        else // add notification to one user whose id = userId
                        {
                            var notUserEntity        = entity.Set <notificationUser>();
                            notificationUser notUser = new notificationUser()
                            {
                                notId        = not.notId,
                                userId       = userId,
                                isRead       = false,
                                createDate   = DateTime.Now,
                                updateDate   = DateTime.Now,
                                createUserId = Object.createUserId,
                                updateUserId = Object.createUserId,
                            };
                            notUserEntity.Add(notUser);
                        }
                        entity.SaveChanges();
                    }
                    message = "1";
                    return(TokenManager.GenerateToken(message));
                }
                catch
                {
                    message = "0";
                    return(TokenManager.GenerateToken(message));
                }
            }
        }
        public void addNotifications(string objectName, string notificationObj, int branchId, string itemName)
        {
            notificationObj = notificationObj.Replace("\\", string.Empty);
            notificationObj = notificationObj.Trim('"');
            notification Object = JsonConvert.DeserializeObject <notification>(notificationObj, new JsonSerializerSettings {
                DateParseHandling = DateParseHandling.None
            });

            //try
            //{
            using (incposdbEntities entity = new incposdbEntities())
            {
                var users = (from u in entity.users.Where(x => x.isActive == 1 && x.isAdmin == false)
                             join b in entity.branchesUsers on u.userId equals b.userId
                             where b.branchId == branchId
                             select new UserModel()
                {
                    userId = u.userId
                }
                             ).ToList();

                Object.ncontent   = itemName + ":" + Object.ncontent;
                Object.isActive   = 1;
                Object.createDate = DateTime.Now;
                Object.updateDate = DateTime.Now;

                var          notEntity = entity.Set <notification>();
                notification not       = notEntity.Add(Object);

                entity.SaveChanges();
                notificationUser notUser;
                var notUserEntity = entity.Set <notificationUser>();
                foreach (UserModel user in users)
                {
                    var groupObjects = (from GO in entity.groupObject
                                        join U in entity.users on GO.groupId equals U.groupId
                                        join G in entity.groups on GO.groupId equals G.groupId
                                        join O in entity.objects on GO.objectId equals O.objectId
                                        join POO in entity.objects on O.parentObjectId equals POO.objectId into JP

                                        from PO in JP.DefaultIfEmpty()
                                        where U.userId == user.userId
                                        select new
                    {
                        //group object
                        GO.id,
                        GO.groupId,
                        GO.objectId,
                        GO.addOb,
                        GO.updateOb,
                        GO.deleteOb,
                        GO.showOb,
                        GO.reportOb,
                        GO.levelOb,
                        //group
                        GroupName = G.name,
                        //object
                        ObjectName = O.name,
                        O.parentObjectId,
                        O.objectType,
                        parentObjectName = PO.name,
                    }).ToList();

                    var element = groupObjects.Where(X => X.ObjectName == objectName).FirstOrDefault();
                    if (element != null)
                    {
                        if (element.showOb == 1)
                        {
                            // add notification to users
                            notUser = new notificationUser()
                            {
                                notId        = not.notId,
                                userId       = user.userId,
                                isRead       = false,
                                createDate   = DateTime.Now,
                                updateDate   = DateTime.Now,
                                createUserId = Object.createUserId,
                                updateUserId = Object.createUserId,
                            };
                            notUserEntity.Add(notUser);
                        }
                    }
                }
                var admins = (from u in entity.users.Where(x => x.isActive == 1 && x.isAdmin == true)
                              select new UserModel()
                {
                    userId = u.userId
                }
                              ).ToList();
                foreach (UserModel user in admins)
                {
                    notUser = new notificationUser()
                    {
                        notId        = not.notId,
                        userId       = user.userId,
                        isRead       = false,
                        createDate   = DateTime.Now,
                        updateDate   = DateTime.Now,
                        createUserId = Object.createUserId,
                        updateUserId = Object.createUserId,
                    };
                    notUserEntity.Add(notUser);
                }
                entity.SaveChanges();
            }
        }
Example #12
0
 public void SetUp()
 {
     parser = JP.String().CreateAbstractValuedParser();
 }
        public string GetUserpermission(string token)
        {
            //public string GetByGroupId(string token)int userId
            //{


            token = TokenManager.readToken(HttpContext.Current.Request);
            var strP = TokenManager.GetPrincipal(token);

            if (strP != "0") //invalid authorization
            {
                return(TokenManager.GenerateToken(strP));
            }
            else
            {
                int userId = 0;


                IEnumerable <Claim> claims = TokenManager.getTokenClaims(token);
                foreach (Claim c in claims)
                {
                    if (c.Type == "userId")
                    {
                        userId = int.Parse(c.Value);
                    }
                }

                // DateTime cmpdate = DateTime.Now.AddDays(newdays);
                try
                {
                    using (incposdbEntities entity = new incposdbEntities())
                    {
                        var list = (from GO in entity.groupObject
                                    join U in entity.users on GO.groupId equals U.groupId
                                    join G in entity.groups on GO.groupId equals G.groupId
                                    join O in entity.objects on GO.objectId equals O.objectId
                                    join POO in entity.objects on O.parentObjectId equals POO.objectId into JP

                                    from PO in JP.DefaultIfEmpty()
                                    where U.userId == userId
                                    select new
                        {
                            //group object
                            GO.id,
                            GO.groupId,
                            GO.objectId,
                            GO.addOb,
                            GO.updateOb,
                            GO.deleteOb,
                            GO.showOb,
                            GO.reportOb,
                            GO.levelOb,
                            //group
                            GroupName = G.name,
                            //object
                            ObjectName = O.name,
                            O.parentObjectId,
                            O.objectType,
                            parentObjectName = PO.name,
                        }).ToList();


                        return(TokenManager.GenerateToken(list));
                    }
                }
                catch
                {
                    return(TokenManager.GenerateToken("0"));
                }
            }

            //    var re = Request;
            //var headers = re.Headers;
            //string token = "";

            //if (headers.Contains("APIKey"))
            //{
            //    token = headers.GetValues("APIKey").First();
            //}

            //Validation validation = new Validation();
            //bool valid = validation.CheckApiKey(token);

            //if (valid)
            //{
            //    using (incposdbEntities entity = new incposdbEntities())
            //    {
            //        var list = (from GO in entity.groupObject
            //                    join U in entity.users on GO.groupId equals U.groupId
            //                    join G in entity.groups on GO.groupId equals G.groupId
            //                    join O in entity.objects on GO.objectId equals O.objectId
            //                    join POO in entity.objects on O.parentObjectId equals POO.objectId into JP

            //                    from PO in JP.DefaultIfEmpty()
            //                    where U.userId == userId
            //                    select new
            //                    {
            //                        //group object
            //                        GO.id,
            //                        GO.groupId,
            //                        GO.objectId,
            //                        GO.addOb,
            //                        GO.updateOb,
            //                        GO.deleteOb,
            //                        GO.showOb,
            //                        GO.reportOb,
            //                        GO.levelOb,
            //                        //group
            //                        GroupName = G.name,
            //                        //object
            //                        ObjectName = O.name,
            //                        O.parentObjectId,
            //                        O.objectType,
            //                        parentObjectName = PO.name,

            //                    }).ToList();


            //        if (list == null)
            //            return NotFound();
            //        else
            //            return Ok(list);

            //    }
            //}
            //else
            //    return NotFound();
        }