Exemplo n.º 1
0
        private void OnPlaybackPlay()
        {
            PlayRequest request = (PlayRequest)RequestFactory.CreateRequest(MessageType.Play);

            if (_playlistForm.GetCurrent().Count.Equals(0))
            {
                MessageBox.Show("Playlist is empty. Nothing to play", "Information");
                return;
            }

            request.Tracks = _playlistForm.GetCurrent();

            AResponse response = _playerCommunicatorControl.SendRequest(request);

            try
            {
                // if success
                if (response.ResponseType == ServerResponseType.Success)
                {
                    // set controls state
                    _mediaInfo.Open(_playlistForm.GetCurrent()[0]);
                    _playbackControl.PlaybackStarted(_mediaInfo.GetDuration());
                    _mediaInfo.Close();

                    _addonsForm.PlaybackStarted();

                    // Set volume
                    OnPlaybackVolume(_playbackControl.Volume);
                }
            }
            catch (System.Exception)
            {
            }
        }
Exemplo n.º 2
0
        public async Task <AResponse> Register(RegistrationViewModel viewModel)
        {
            AResponse          response        = null;
            ApplicationUserDTO dtoRegistration = null;

            try
            {
                response = new AResponse();

                dtoRegistration = GetDtoObject(viewModel);
                var result = await(Repository as AccountRepository).InsertAsync(dtoRegistration);

                if (!result.Succeeded)
                {
                    response.Data = result;
                    throw new Exception();
                }

                response.StatusMessage  = "Record inserted successfully";
                response.ResponseStatus = ActionResponse.Success;
            }
            catch (Exception ex)
            {
                response.ResponseStatus = ActionResponse.DBInsertFailed;
                response.Exception      = ex;
                response.StatusMessage  = "Error occurred";
            }

            return(response);
        }
Exemplo n.º 3
0
        public async void Dispatch(Session session, Opcode opcode, int offset, byte[] messageBytes, AMessage message)
        {
            // gate session收到actor消息直接转发给actor自己去处理
            if (message is AActorMessage)
            {
                long       unitId     = session.GetComponent <SessionPlayerComponent>().Player.mBaseInfo.roleId;
                ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(unitId);
                actorProxy.Send(message);
                return;
            }

            // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
            if (message is AActorRequest aActorRequest)
            {
                long       unitId     = session.GetComponent <SessionPlayerComponent>().Player.mBaseInfo.roleId;
                ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(unitId);
                uint       rpcId      = aActorRequest.RpcId;
                AResponse  response   = await actorProxy.Call <AResponse>(aActorRequest);

                response.RpcId = rpcId;
                session.Reply(response);
                return;
            }

            if (message != null)
            {
                Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, message);
                return;
            }

            throw new Exception($"message type error: {message.GetType().FullName}");
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Login([FromBody] LoginViewModel credentials)
        {
            AResponse response = null;
            string    jwt      = String.Empty;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            response = await _accountsBL.Login(credentials);

            if (response.ResponseStatus != Enums.ActionResponse.Success)
            {
                if (response.Exception.GetType() == typeof(InvalidCredentialsException))
                {
                    return(BadRequest(Errors.AddErrorToModelState("login_failure", response.Exception.Message, ModelState)));
                }
                else if (response.Exception.GetType() == typeof(JwtGenerateException))
                {
                    return(BadRequest(Errors.AddErrorToModelState("jwt_exception", response.Exception.Message, ModelState)));
                }
                else
                {
                    return(BadRequest(Errors.AddErrorToModelState("errors", response.Exception.Message, ModelState)));
                }
            }

            jwt = (string)response.Data;

            return(new OkObjectResult(jwt));
        }
        public void Send(AResponse reponse)
        {
            MemoryStream stream = new MemoryStream();

            reponse.Write(new BinaryWriter(stream));
            byte [] payload = stream.ToArray();
            connection_writer.SendMessage(new Message(MessageType.MessagePayload, payload));
        }
Exemplo n.º 6
0
        public void RegisterHandler_TestFirstStyle()
        {
            ExampleApp app;
            Object     result;

            MyQuery.Response response;

            Scenario()
            .Given(app = new ExampleApp())
            .Given(() => app.RegisterHandler(new MyHandler()))
            .Given(result  = new Object())
            .When(response = app.Invoke(new MyQuery {
                ReturnMe = result
            }))
            .Then(ExpectThat(response), Is(AResponse.With().Result(result)));
        }
Exemplo n.º 7
0
        private void OnUpdateDisplayDeviceListEvent()
        {
            try
            {
                AResponse response = _playerCommunicatorControl.SendRequest(new DisplayDevicesInfoRequest());

                if (!response.Type.Equals(MessageType.DisplayDevicesInfo))
                {
                    throw new ApplicationException("Invalid response message");
                }

                _playbackWindowForm.DisplayDevices = ((DisplayDeviceInfoResponse)response).Devices;
            }
            catch (System.Exception e)
            {
                MessageBox.Show("Error. Could not retrieve monitor information\n" + e.Message);
            }
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Post([FromBody] RegistrationViewModel model)
        {
            AResponse response = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            response = await _accountsBL.Register(model);

            if (response.ResponseStatus != Enums.ActionResponse.Success)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState((IdentityResult)response.Data, ModelState)));
            }

            return(new OkObjectResult("Account created"));
        }
Exemplo n.º 9
0
        public AResponse Send(ARequest request)
        {
            string    messageToSend = request.ParseToString();
            AResponse response      = null;

            try
            {
                TcpClient client = new TcpClient();

                // connect to the server
                client.Connect(SettingsManager.Instance.PlayerSettings.Ip.ToString(), (int)_port);

                // Send stream
                Stream        stream           = client.GetStream();
                ASCIIEncoding encoding         = new ASCIIEncoding();
                byte[]        requestByteArray = encoding.GetBytes(messageToSend);

                // Transmitting data
                stream.Write(requestByteArray, 0, requestByteArray.Length);

                // Get response
                byte[] responseByteArray = new byte[500];
                int    responseLength    = stream.Read(responseByteArray, 0, 500);

                string responseMessage = string.Empty;
                for (int i = 0; i < responseLength; i++)
                {
                    responseMessage += Convert.ToChar(responseByteArray[i]);
                }

                // close connection to server
                client.Close();

                // get response
                response = ResponseFactory.Instance.CreateResponse(responseMessage);
            }
            catch (Exception e)
            {
                throw e;
            }


            return(response);
        }
Exemplo n.º 10
0
        private void OnSendPlayerQuitCallback(AResponse response)
        {
            G2C_PlayerQuit g2C_PlayerQuit = (G2C_PlayerQuit)response;

            if (g2C_PlayerQuit.Error != ErrorCode.ERR_Success)
            {
                Log.Error(g2C_PlayerQuit.Error.ToString());
                return;
            }

            //await Game.Scene.GetComponent<SceneChangeComponent>().ChangeSceneAsync(Model.SceneType.Init);

            //Hotfix.Scene.GetComponent<UIComponent>().Remove(UIType.UIBattle);
            //Hotfix.Scene.GetComponent<UIComponent>().Create(UIType.UILogin);

            //Game.Scene.RemoveComponent<SessionComponent>();
            //Game.Scene.RemoveComponent<HeartBeatComponent>();
            Application.Quit();
        }
Exemplo n.º 11
0
        private void LoginGateOk(AResponse response)
        {
            G2C_LoginGate g2CLoginGate = (G2C_LoginGate)response;

            if (g2CLoginGate.Error != ErrorCode.ERR_Success)
            {
                Log.Error(g2CLoginGate.Error.ToString());
                return;
            }

            Log.Info("登陆gate成功!");

            // 创建Player
            Player          player          = Model.EntityFactory.CreateWithId <Player>(g2CLoginGate.PlayerId);
            PlayerComponent playerComponent = Game.Scene.GetComponent <PlayerComponent>();

            playerComponent.MyPlayer = player;

            Hotfix.Scene.GetComponent <UIComponent>().Create(UIType.UILobby);
            Hotfix.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
        }
Exemplo n.º 12
0
        private void LoginOK(AResponse response)
        {
            R2C_Login r2CLogin = (R2C_Login)response;

            if (r2CLogin.Error != ErrorCode.ERR_Success)
            {
                Log.Error(r2CLogin.Error.ToString());
                return;
            }

            Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);

            Game.Scene.AddComponent <SessionComponent>().Session = gateSession;

            SessionComponent.Instance.Session.CallWithAction(new C2G_LoginGate()
            {
                Key = r2CLogin.Key
            },
                                                             (response2) => LoginGateOk(response2)
                                                             );
        }
Exemplo n.º 13
0
        public async Task <AResponse> Login(LoginViewModel viewModel)
        {
            AResponse          response = null;
            string             jwt      = String.Empty;
            ApplicationUserDTO dtoLogin;

            try
            {
                response = new AResponse();
                dtoLogin = GetDtoObject(viewModel);

                var identity = await(Repository as AccountRepository).GetClaimsIdentity(dtoLogin.Username, dtoLogin.Password);

                if (identity == null)
                {
                    throw new InvalidCredentialsException();
                }

                try
                {
                    jwt = await(Repository as AccountRepository).GenerateJwt(identity, dtoLogin.Username);
                }
                catch (Exception ex)
                {
                    throw new JwtGenerateException(dtoLogin.Username);
                }


                response.Data           = jwt;
                response.ResponseStatus = Enums.ActionResponse.Success;
            }
            catch (Exception ex)
            {
                response.ResponseStatus = ActionResponse.InvalidValues;
                response.Exception      = ex;
                response.StatusMessage  = "Error occurred";
            }

            return(response);
        }
Exemplo n.º 14
0
        private void LoginOK(Session loginSession, AResponse response)
        {
            loginSession.Dispose();
            R2C_Login r2CLogin = (R2C_Login)response;

            if (r2CLogin.Error != ErrorCode.ERR_Success)
            {
                Log.Error(r2CLogin.Error.ToString());
                return;
            }

            IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
            Session    gateSession    = Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);

            Game.Scene.AddComponent <SessionComponent>().Session = gateSession;

            SessionComponent.Instance.Session.CallWithAction(new C2G_LoginGate()
            {
                Key = r2CLogin.Key
            },
                                                             (response2) => LoginGateOk(response2)
                                                             );
        }
Exemplo n.º 15
0
        public AResponse SendRequest(ARequest request)
        {
            byte[] payload = null;
            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    request.Write(writer);
                    payload = stream.ToArray();
                }
            }
            connection.SendMessage(new Message(MessageType.MessagePayload, payload));

            Message response_message = message_queue.Take();

            using (MemoryStream stream = new MemoryStream(response_message.Payload))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    return(AResponse.Read(reader));
                }
            }
        }
Exemplo n.º 16
0
        public AResponse SendRequest(ARequest request)
        {
            AResponse response = null;

            try
            {
                _historyControl.WriteToLog("Request: " + request.ParseToString());

                response = _client.Send(request);

                _historyControl.WriteToLog("Response: " + response.ResponseType.ToString());

                // update status
                SuccessPanel.BackColor = _statusColors[response.ResponseType];
            }
            catch (System.Exception e)
            {
                _historyControl.WriteToLog("Error:" + e.Message);
                SuccessPanel.BackColor = _statusColors[ServerResponseType.Bad];
            }

            return(response);
        }
Exemplo n.º 17
0
        public AResponse CreateResponse(string responseData)
        {
            AResponse response = null;

            try
            {
                // validate length
                if (responseData.Length < Protocol.Instance.HeaderLength)
                {
                    throw new ParserException("invalid responseData length");
                }

                // get the header
                string header = responseData.Substring(0, (int)Protocol.Instance.HeaderLength);

                switch (_messageHeaderMapper[header])
                {
                case MessageType.DisplayDevicesInfo:
                    response = new DisplayDeviceInfoResponse();
                    break;

                case MessageType.Pause:
                    response = new PauseResponse();
                    break;

                case MessageType.Play:
                    response = new PlayResponse();
                    break;

                case MessageType.Resume:
                    response = new ResumeResponse();
                    break;

                case MessageType.Seek:
                    response = new SeekResponse();
                    break;

                case MessageType.SetImage:
                    response = new SetImageResponse();
                    break;

                case MessageType.SetText:
                    response = new SetTextResponse();
                    break;

                case MessageType.RemoveAddon:
                    response = new RemoveAddonResponse();
                    break;

                case MessageType.Stop:
                    response = new StopResponse();
                    break;

                case MessageType.Termination:
                    response = new TerminationResponse();
                    break;

                case MessageType.VideoLayout:
                    response = new VideoLayoutResponse();
                    break;

                case MessageType.Volume:
                    response = new VolumeResponse();
                    break;

                case MessageType.WindowLayout:
                    response = new WindowLayoutResponse();
                    break;

                case MessageType.SoundFx:
                    response = new SoundFxResponse();
                    break;

                case MessageType.Sound3d:
                    response = new Sound3dResponse();
                    break;

                case MessageType.MidiProperties:
                    response = new MidiPropertiesResponse();
                    break;

                case MessageType.MidiOutputPortInfo:
                    response = new MidiOutputPortInfoResponse();
                    break;

                case MessageType.SetMidiOutputPort:
                    response = new SetMidiOutputPortResponse();
                    break;

                case MessageType.SetDls:
                    response = new SetDlsResponse();
                    break;

                case MessageType.SetFrequency:
                    response = new SetFrequencyResponse();
                    break;

                case MessageType.SetRate:
                    response = new SetRateResponse();
                    break;

                case MessageType.SetPlayerType:
                    response = new SetPlayerTypeResponse();
                    break;

                default:
                    throw new ParserException("invalid message header");
                }
                response.ParseFromString(responseData);
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(response);
        }