Пример #1
0
        public ReplyData Heartbeat(IPAddress remoteIP, int remotePort, List <string> arguments, string body, string method, Dictionary <string, string> Headers)
        {
            ReplyData _reply = new ReplyData();

            Heartbeat_Memory mem = Heartbeat_Memory.GetHeartbeat();

            if (mem.Contains(remoteIP.ToString()))
            {
                mem.Set(remoteIP.ToString(), Guid.NewGuid().ToString());
            }
            else
            {
                mem.Add(remoteIP.ToString(), Guid.NewGuid().ToString());
            }
            heartbeat_ReplyData hbrd = new heartbeat_ReplyData();

            hbrd.status = "success";
            hbrd.data   = new Dictionary <string, string>();
            hbrd.data.Add("session_id", mem.Get(remoteIP.ToString()));
            _reply.Status = 200;
            _reply.Body   = JsonConvert.SerializeObject(hbrd);

            Console.WriteLine("====> heartbeat reply: " + _reply.Body);

            return(_reply);
        }
Пример #2
0
        public RESTReplyData Heartbeat(RESTRequestData pReq, List <string> pArgs)
        {
            RESTReplyData _reply = new RESTReplyData();

            Heartbeat_Memory mem = Heartbeat_Memory.GetHeartbeat();

            if (mem.Contains(pReq.RemoteUser.ToString()))
            {
                mem.Set(pReq.RemoteUser.ToString(), Guid.NewGuid().ToString());
            }
            else
            {
                mem.Add(pReq.RemoteUser.ToString(), Guid.NewGuid().ToString());
            }
            heartbeat_ReplyData hbrd = new heartbeat_ReplyData();

            hbrd.status = "success";
            hbrd.data   = new Dictionary <string, string>();
            hbrd.data.Add("session_id", mem.Get(pReq.RemoteUser.ToString()));
            _reply.Status = 200;
            _reply.Body   = JsonConvert.SerializeObject(hbrd);


            return(_reply);
        }
Пример #3
0
        public static Heartbeat_Memory GetHeartbeat()
        {
            if (!File.Exists("presence.json"))
            {
                Heartbeat_Memory hm = new Heartbeat_Memory();
                return(hm);
            }
            string js = File.ReadAllText("presence.json");

            return((Heartbeat_Memory)JsonConvert.DeserializeObject <Heartbeat_Memory>(js));
        }
Пример #4
0
        public RESTReplyData user_activity(RESTRequestData pReq, List <string> pArgs)
        {
            Heartbeat_Memory    hbmem = new Heartbeat_Memory();
            user_activity_input uai   = pReq.RequestBodyObject <user_activity_input>();
            RESTReplyData       rd    = new RESTReplyData();

            rd.Status = 404;
            rd.Body   = "{\"status\":\"notfound\"}";
            if (uai.action_name == "quit")
            {
                if (hbmem.Contains(pReq.RemoteUser.ToString()))
                {
                    hbmem.Rem(pReq.RemoteUser.ToString());
                }
                rd        = new RESTReplyData();
                rd.Status = 200;
                user_activities_reply uar = new user_activities_reply();
                uar.status = "success";
                rd.Body    = JsonConvert.SerializeObject(uar);
                Console.WriteLine("=====> user_action: quit; " + pReq.RemoteUser.ToString());
                return(rd);
            }
            return(rd);
        }
Пример #5
0
        public ReplyData user_activity(IPAddress remoteIP, int remotePort, List <string> arguments, string body, string method, Dictionary <string, string> Headers)
        {
            Heartbeat_Memory    hbmem = new Heartbeat_Memory();
            user_activity_input uai   = (user_activity_input)JsonConvert.DeserializeObject <user_activity_input>(body);
            ReplyData           rd    = new ReplyData();

            rd.Status = 404;
            rd.Body   = "{\"status\":\"notfound\"}";
            if (uai.action_name == "quit")
            {
                if (hbmem.Contains(remoteIP.ToString()))
                {
                    hbmem.Rem(remoteIP.ToString());
                }
                rd        = new ReplyData();
                rd.Status = 200;
                user_activities_reply uar = new user_activities_reply();
                uar.status = "success";
                rd.Body    = JsonConvert.SerializeObject(uar);
                Console.WriteLine("=====> user_action: quit; " + remoteIP.ToString());
                return(rd);
            }
            return(rd);
        }