コード例 #1
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        /// <summary>
        /// Event fired when a data is received from the Alchemy Websockets server instance.
        /// Parses data as JSON and calls the appropriate message or sends an error message.
        /// </summary>
        /// <param name="context">The user's connection context</param>
        public void OnReceive(UserContext context)
        {
            try
            {
                var json = context.DataFrame.ToString();
                RequestToTossServer    obj = JsonConvert.DeserializeObject <RequestToTossServer>(json);
                ResponseFromTossServer r;

                switch (obj.Type)
                {
                case CommandType.RegisterReq:
                    Register(obj.userIdentity, context);
                    break;

                case CommandType.HeartBeatReq:
                    var user = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single();
                    r = new ResponseFromTossServer()
                    {
                        Type = CommandType.HeartBeatRes
                    };
                    user.Context.Send(JsonConvert.SerializeObject(r));
                    break;

                default:
                    break;
                }
            }
            catch (Exception e) // Bad JSON! For shame.
            {
                var r = new ResponseFromTossServer {
                    Type = CommandType.Error, Data = new { e.Message }
                };
                context.Send(JsonConvert.SerializeObject(r));
            }
        }
コード例 #2
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        void cdrSrv_RequestCDREvent(object sender, int cmd, string caller, string callee, int result)
        {
            Clean c = new Clean() { caller = caller, callee = callee, result = result };

            var u = OnlineUsers.Keys.FirstOrDefault();

            ResponseFromTossServer r = null;

            Debug.WriteLine("ToossServer callee: " + callee);

            switch (callee)
            {
                case "0001":
                    // Make up room request
                    r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomReq, Data = c };
                    break;
                case "0002":
                    // Make up room done
                    r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomDone, Data = c };
                    break;
                case "0003":
                    // DnD 요청
                    r = new ResponseFromTossServer() { Type = CommandType.DnDReq, Data = c };
                    break;
                case "0004":
                    // DnD 취소
                    r = new ResponseFromTossServer() { Type = CommandType.DnDCancel, Data = c };
                    break;
                case "0005":
                    // 세탁 요청
                    r = new ResponseFromTossServer() { Type = CommandType.LaundaryReq, Data = c };
                    break;
                case "0006":
                    // 세탁 취소
                    r = new ResponseFromTossServer() { Type = CommandType.LaundaryCancel, Data = c };
                    break;
                case "0007":
                    // make up room confirm
                    r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomConfirm, Data = c };
                    break;
                case "0008":
                    // 방청소 확인
                    r = new ResponseFromTossServer() { Type = CommandType.MakeupRoomConfirm, Data = c };
                    break;
                default:
                    switch (caller)
                    {
                        case "morning":
                            r = new ResponseFromTossServer() { Type = CommandType.MorningCall, Data = c };
                            break;
                        default:
                            return;
                    }
                    break;
            }

            if (u != null)
                u.Context.Send(JsonConvert.SerializeObject(r));
        }
コード例 #3
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        /// <summary>
        /// Broadcasts an error message to the client who caused the error
        /// </summary>
        /// <param name="errorMessage">Details of the error</param>
        /// <param name="context">The user's connection context</param>
        private static void SendError(string errorMessage, UserContext context)
        {
            var r = new ResponseFromTossServer {
                Type = CommandType.Error, Data = new { Message = errorMessage }
            };

            context.Send(JsonConvert.SerializeObject(r));
        }
コード例 #4
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        void pmsSrv_ReqPMSSetEvent(PMSServer sender, _pms_data_type pmsdata)
        {
            //var user = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single();
            var u = OnlineUsers.Keys.FirstOrDefault();
            ResponseFromTossServer r = new ResponseFromTossServer()
            {
                Type = CommandType.Message, Data = pmsdata
            };

            if (u != null)
            {
                u.Context.Send(JsonConvert.SerializeObject(r));
            }
        }
コード例 #5
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        /// <summary>
        /// Register a user's context for the first time with a username, and add it to the list of online users
        /// </summary>
        /// <param name="name">The name to register the user under</param>
        /// <param name="context">The user's connection context</param>
        private void Register(string identify, UserContext context)
        {
            var json = context.DataFrame.ToString();
            RequestToTossServer obj = JsonConvert.DeserializeObject <RequestToTossServer>(json);

            var u = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single();

            u.Identity = obj.userIdentity;
            //OnlineUsers[u] = obj.userIdentity;

            ResponseFromTossServer r = new ResponseFromTossServer()
            {
                Type = CommandType.RegisterRes
            };
            var sjson = JsonConvert.SerializeObject(r);

            context.Send(sjson);
        }
コード例 #6
0
ファイル: PMS.xaml.cs プロジェクト: step4u/CallService
        void wsClient_OnConnectedEvent(Object sender, UserContext context)
        {
            if (loginstates)
                return;

            ResponseFromTossServer data = new ResponseFromTossServer() { Type = Com.Huen.Sockets.CommandType.HeartBeatReq, Data = new _pms_data_type() };
            wsClient.Send(JsonConvert.SerializeObject(data));
        }
コード例 #7
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        void cdrSrv_RequestCDREvent(object sender, int cmd, string caller, string callee, int result)
        {
            Clean c = new Clean()
            {
                caller = caller, callee = callee, result = result
            };

            var u = OnlineUsers.Keys.FirstOrDefault();

            ResponseFromTossServer r = null;

            Debug.WriteLine("ToossServer callee: " + callee);

            switch (callee)
            {
            case "0001":
                // Make up room request
                r = new ResponseFromTossServer()
                {
                    Type = CommandType.MakeupRoomReq, Data = c
                };
                break;

            case "0002":
                // Make up room done
                r = new ResponseFromTossServer()
                {
                    Type = CommandType.MakeupRoomDone, Data = c
                };
                break;

            case "0003":
                // DnD 요청
                r = new ResponseFromTossServer()
                {
                    Type = CommandType.DnDReq, Data = c
                };
                break;

            case "0004":
                // DnD 취소
                r = new ResponseFromTossServer()
                {
                    Type = CommandType.DnDCancel, Data = c
                };
                break;

            case "0005":
                // 세탁 요청
                r = new ResponseFromTossServer()
                {
                    Type = CommandType.LaundaryReq, Data = c
                };
                break;

            case "0006":
                // 세탁 취소
                r = new ResponseFromTossServer()
                {
                    Type = CommandType.LaundaryCancel, Data = c
                };
                break;

            case "0007":
                // make up room confirm
                r = new ResponseFromTossServer()
                {
                    Type = CommandType.MakeupRoomConfirm, Data = c
                };
                break;

            case "0008":
                // 방청소 확인
                r = new ResponseFromTossServer()
                {
                    Type = CommandType.MakeupRoomConfirm, Data = c
                };
                break;

            default:
                switch (caller)
                {
                case "morning":
                    r = new ResponseFromTossServer()
                    {
                        Type = CommandType.MorningCall, Data = c
                    };
                    break;

                default:
                    return;
                }
                break;
            }

            if (u != null)
            {
                u.Context.Send(JsonConvert.SerializeObject(r));
            }
        }
コード例 #8
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        /// <summary>
        /// Broadcasts an error message to the client who caused the error
        /// </summary>
        /// <param name="errorMessage">Details of the error</param>
        /// <param name="context">The user's connection context</param>
        private static void SendError(string errorMessage, UserContext context)
        {
            var r = new ResponseFromTossServer { Type = CommandType.Error, Data = new { Message = errorMessage } };

            context.Send(JsonConvert.SerializeObject(r));
        }
コード例 #9
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        /// <summary>
        /// Register a user's context for the first time with a username, and add it to the list of online users
        /// </summary>
        /// <param name="name">The name to register the user under</param>
        /// <param name="context">The user's connection context</param>
        private void Register(string identify, UserContext context)
        {
            var json = context.DataFrame.ToString();
            RequestToTossServer obj = JsonConvert.DeserializeObject<RequestToTossServer>(json);

            var u = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single();
            u.Identity = obj.userIdentity;
            //OnlineUsers[u] = obj.userIdentity;

            ResponseFromTossServer r = new ResponseFromTossServer() { Type = CommandType.RegisterRes };
            var sjson = JsonConvert.SerializeObject(r);
            context.Send(sjson);
        }
コード例 #10
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
        /// <summary>
        /// Event fired when a data is received from the Alchemy Websockets server instance.
        /// Parses data as JSON and calls the appropriate message or sends an error message.
        /// </summary>
        /// <param name="context">The user's connection context</param>
        public void OnReceive(UserContext context)
        {
            try
            {
                var json = context.DataFrame.ToString();
                RequestToTossServer obj = JsonConvert.DeserializeObject<RequestToTossServer>(json);
                ResponseFromTossServer r;

                switch (obj.Type)
                {
                    case CommandType.RegisterReq:
                        Register(obj.userIdentity, context);
                        break;
                    case CommandType.HeartBeatReq:
                        var user = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single();
                        r = new ResponseFromTossServer() { Type = CommandType.HeartBeatRes };
                        user.Context.Send(JsonConvert.SerializeObject(r));
                        break;
                    default:
                        break;
                }
            }
            catch (Exception e) // Bad JSON! For shame.
            {
                var r = new ResponseFromTossServer { Type = CommandType.Error, Data = new { e.Message } };
                context.Send(JsonConvert.SerializeObject(r));
            }
        }
コード例 #11
0
ファイル: TossServer.cs プロジェクト: step4u/CallService
 void pmsSrv_ReqPMSSetEvent(PMSServer sender, _pms_data_type pmsdata)
 {
     //var user = OnlineUsers.Keys.Where(o => o.Context.ClientAddress == context.ClientAddress).Single();
     var u = OnlineUsers.Keys.FirstOrDefault();
     ResponseFromTossServer r = new ResponseFromTossServer() { Type = CommandType.Message, Data = pmsdata };
     if (u != null)
         u.Context.Send(JsonConvert.SerializeObject(r));
 }