private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var messageType    = (string)args.Request.Message[MessageKeys.Type];
            var messageContent = (string)args.Request.Message[MessageKeys.Content];

            if (messageType == nameof(CreateTerminalRequest))
            {
                var deferral = args.GetDeferral();

                var request = JsonConvert.DeserializeObject <CreateTerminalRequest>(messageContent);

                Logger.Instance.Debug("Received CreateTerminalRequest: {@request}", request);

                var response = _terminalsManager.CreateTerminal(request);

                Logger.Instance.Debug("Sending CreateTerminalResponse: {@response}", response);

                await args.Request.SendResponseAsync(CreateMessage(response));

                deferral.Complete();
            }
            else if (messageType == nameof(ResizeTerminalRequest))
            {
                var request = JsonConvert.DeserializeObject <ResizeTerminalRequest>(messageContent);

                _terminalsManager.ResizeTerminal(request.TerminalId, request.NewSize);
            }
            else if (messageType == nameof(SetToggleWindowKeyBindingsRequest))
            {
                var request = JsonConvert.DeserializeObject <SetToggleWindowKeyBindingsRequest>(messageContent);

                _toggleWindowService.SetHotKeys(request.KeyBindings);
            }
            else if (messageType == nameof(WriteDataRequest))
            {
                var request = JsonConvert.DeserializeObject <WriteDataRequest>(messageContent);
                _terminalsManager.Write(request.TerminalId, request.Data);
            }
            else if (messageType == nameof(TerminalExitedRequest))
            {
                var request = JsonConvert.DeserializeObject <TerminalExitedRequest>(messageContent);
                _terminalsManager.CloseTerminal(request.TerminalId);
            }
            else if (messageType == nameof(GetAvailablePortRequest))
            {
                var deferral = args.GetDeferral();

                var response = new GetAvailablePortResponse {
                    Port = Utilities.GetAvailablePort().Value
                };

                await args.Request.SendResponseAsync(CreateMessage(response));

                deferral.Complete();
            }
        }
        private async Task HandleGetAvailablePortRequest(AppServiceRequestReceivedEventArgs args)
        {
            var deferral = args.GetDeferral();
            var response = new GetAvailablePortResponse {
                Port = Utilities.GetAvailablePort().Value
            };
            await args.Request.SendResponseAsync(CreateMessage(response));

            deferral.Complete();
        }