Beispiel #1
0
        public void HandleDeivce(Object obj)
        {
            TcpClient client = (TcpClient)obj;
            var       stream = client.GetStream();

            try
            {
                byte[] bufs = new byte[Notify._BUFFER_SIZE];
                int    i    = stream.Read(bufs, 0, bufs.Length);
                if (i > 36)
                {
                    NOTI_TYPE type = (NOTI_TYPE)bufs[0];
                    string    data = Encoding.UTF8.GetString(bufs, 1, i - 1);
                    if (data.Length > 36)
                    {
                        data = data.Substring(36);
                    }
                    Console.WriteLine("{0}\t\t\t={1}", type, data);
                    ___process_message(stream, type, data);
                }
                client.Close();
            }
            catch (Exception e)
            {
                client.Close();
            }
        }
Beispiel #2
0
        void ___process_message(NetworkStream stream, NOTI_TYPE type, string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            byte[]   buf;
            string[] a = data.Split('|');
            string   msg, s;

            switch (type)
            {
            case NOTI_TYPE.TOKEN_VALID:
                s = ___get_url(string.Format(URL_USER_GET_PROFILE_BY_TOKEN, a.Length > 1 ? a[1] : a[0]));
                if (s.Length > 0)
                {
                    //data = System.Web.HttpUtility.HtmlDecode(data);
                    buf = Convert.FromBase64String(data);
                    msg = Encoding.ASCII.GetString(buf);

                    stream.Write(buf, 0, buf.Length);
                    stream.Flush();
                }
                break;

            case NOTI_TYPE.TOKEN_RETURN_LOGIN_SUCCESS:
                s = ___get_url(string.Format(URL_USER_GET_TOKEN_BY_ID, a.Length > 1 ? a[1] : a[0]));
                if (s.Length > 0)
                {
                    buf = Encoding.UTF8.GetBytes(s);
                    msg = Convert.ToBase64String(buf);
                    buf = Encoding.UTF8.GetBytes(msg);

                    stream.Write(buf, 0, buf.Length);
                    stream.Flush();
                }
                break;
            }
        }
Beispiel #3
0
        /* Select count(*) from SGNotiInfo */
        public int SelectNotiInfoCount(NOTI_TYPE type, int groupId, string userSeq)
        {
            mut.WaitOne();
            int nCount;

            // Read
            if (type == NOTI_TYPE.ALL)
            {
                nCount = DBCtx.Notis
                         .Where(x => x.GroupId == groupId && x.UserSeq == userSeq)
                         .Count();
            }
            else
            {
                nCount = DBCtx.Notis
                         .Where(x => x.Type == type && x.GroupId == groupId && x.UserSeq == userSeq)
                         .Count();
            }
            Log.Information("Querying for a NotiInfo Count {nCount}", nCount);
            mut.ReleaseMutex();
            return(nCount);
        }
Beispiel #4
0
        /* Select group by count(*) from SGNotiInfo of CategoryId */
        public Dictionary <LSIDEBAR, int> SelectNotiInfoCategoryCount(NOTI_TYPE type, int groupId, string userSeq)
        {
            mut.WaitOne();
            Dictionary <LSIDEBAR, int> NotiDic;

            if (type == NOTI_TYPE.ALL)
            {
                NotiDic = DBCtx.Notis
                          .Where(x => x.GroupId == groupId && x.UserSeq == userSeq)
                          .GroupBy(x => x.CategoryId)
                          .Select(x => new
                {
                    CategoryId    = x.Key,
                    CategoryCount = x.Count()
                }
                                  )
                          .OrderBy(x => x.CategoryId)
                          .ToDictionary(x => x.CategoryId, x => x.CategoryCount);
            }
            else
            {
                NotiDic = DBCtx.Notis
                          .Where(x => x.Type == type && x.GroupId == groupId && x.UserSeq == userSeq)
                          .GroupBy(x => x.CategoryId)
                          .Select(x => new
                {
                    CategoryId    = x.Key,
                    CategoryCount = x.Count()
                }
                                  )
                          .OrderBy(x => x.CategoryId)
                          .ToDictionary(x => x.CategoryId, x => x.CategoryCount);
            }
            mut.ReleaseMutex();
            return(NotiDic);
        }
Beispiel #5
0
        /* Select * from SGNotiInfo */
        public List <SGNotiData> SelectNotiInfoLimit(NOTI_TYPE type, int groupId, string userSeq, int nLimit)
        {
            mut.WaitOne();
            List <SGNotiData> NotiList;

            // Read
            if (type == NOTI_TYPE.ALL)
            {
                NotiList = DBCtx.Notis
                           .Where(x => x.GroupId == groupId && x.UserSeq == userSeq)
                           .OrderByDescending(x => x.Time).Take(nLimit)
                           .ToList();
            }
            else
            {
                NotiList = DBCtx.Notis
                           .Where(x => x.Type == type && x.GroupId == groupId && x.UserSeq == userSeq)
                           .OrderByDescending(x => x.Time).Take(nLimit)
                           .ToList();
            }
            Log.Information("Querying for a NotiInfo Limit {nLimit}", nLimit);
            mut.ReleaseMutex();
            return(NotiList);
        }
Beispiel #6
0
 /* Insert to SGNotiInfo */
 public bool InsertNotiInfo(NOTI_TYPE type, int groupId, string userSeq, string seq, LSIDEBAR categoryId, string path, string iconImage, string head, string body)
 {
     // Create
     mut.WaitOne();
     Log.Information("Inserting a NotiInfo, {NotiHead}, {NotiBody}", head, body);
     DBCtx.Add(new SGNotiData
     {
         Id         = 0,
         Type       = type,
         GroupId    = groupId,
         UserSeq    = userSeq,
         Seq        = seq,
         CategoryId = categoryId,
         Path       = path,
         IconImage  = iconImage,
         Head       = head,
         Body       = body,
         Time       = DateTime.Now
     }
               );
     DBCtx.SaveChanges();
     mut.ReleaseMutex();
     return(true);
 }