public async Task SendAuthClientGrant(AuthRequestRemoteMessage authRequest) { this.ClientID = authRequest.ClientID; this.ClientName = authRequest.DeviceInfo; this.ClientAuthExpiration = authRequest.Expiration; await Send(new AuthClientGrantRemoteMessage() { SessionID = this.SessionID, Boards = ChannelSession.Settings.RemoteBoards.Select(b => b.ToSimpleModel()).ToList() }); }
private async void RemoteService_OnAuthRequest(object sender, AuthRequestRemoteMessage authRequest) { this.RemoteEventsTextBlock.Text += "Device Authorization Requested: " + authRequest.DeviceInfo + Environment.NewLine; await this.Window.RunAsyncOperation(async() => { if (await MessageBoxHelper.ShowConfirmationDialog("The following device would like to connect:" + Environment.NewLine + Environment.NewLine + authRequest.DeviceInfo + Environment.NewLine + Environment.NewLine + "Would you like to approve this device?")) { await this.remoteService.SendAuthClientGrant(authRequest); this.RemoteEventsTextBlock.Text += "Device Authorization Approved: " + authRequest.DeviceInfo + Environment.NewLine; } else { await this.remoteService.SendAuthClientDeny(); this.RemoteEventsTextBlock.Text += "Device Authorization Denied: " + authRequest.DeviceInfo + Environment.NewLine; } }); }
protected override async Task ProcessReceivedPacket(string packetJSON) { try { if (!string.IsNullOrEmpty(packetJSON)) { dynamic jsonObject = JsonConvert.DeserializeObject(packetJSON); if (jsonObject["Type"] != null) { MessageType type = (MessageType)((int)jsonObject["Type"]); switch (type) { case MessageType.HEARTBEAT: await ReceiveHeartbeat(packetJSON); break; case MessageType.DISCONNECT_REQ: break; case MessageType.MESSAGE_FAILED: break; case MessageType.SESSION_NEW: //Host Receive -> Server Send NewSessionRemoteMessage newSessionPacket = JsonConvert.DeserializeObject <NewSessionRemoteMessage>(packetJSON); this.SessionID = newSessionPacket.SessionID; this.AccessCode = newSessionPacket.AccessCode; this.AccessCodeExpiration = newSessionPacket.Expiration; break; case MessageType.ACCESS_CODE_NEW: //Host Receive -> Server Send AccessCodeNewRemoteMessage newRemotePacket = JsonConvert.DeserializeObject <AccessCodeNewRemoteMessage>(packetJSON); this.AccessCode = newRemotePacket.AccessCode; this.AccessCodeExpiration = newRemotePacket.Expiration; this.SendEvent(packetJSON, this.OnNewAccessCode); break; case MessageType.AUTH_REQ: AuthRequestRemoteMessage authRequestPacket = JsonConvert.DeserializeObject <AuthRequestRemoteMessage>(packetJSON); if (ChannelSession.Settings.RemoteSavedDevices.Any(d => d.ID.Equals(authRequestPacket.ClientID))) { await this.SendAuthClientGrant(authRequestPacket); } else { this.SendEvent(packetJSON, this.OnAuthRequest); } break; case MessageType.BOARD_REQ: BoardRequestRemoteMessage boardRequestPacket = JsonConvert.DeserializeObject <BoardRequestRemoteMessage>(packetJSON); RemoteBoardModel board = ChannelSession.Settings.RemoteBoards.FirstOrDefault(b => b.ID.Equals(boardRequestPacket.BoardID)); if (board != null) { await this.SendBoardDetail(board); if (this.OnBoardRequest != null) { this.OnBoardRequest(this, board); } } break; case MessageType.ACTION_REQ: ActionRequestRemoteMessage actionRequestPacket = JsonConvert.DeserializeObject <ActionRequestRemoteMessage>(packetJSON); RemoteCommand command = ChannelSession.Settings.RemoteCommands.FirstOrDefault(c => c.ID.Equals(actionRequestPacket.ItemID)); if (command != null) { await command.Perform(); if (this.OnActionRequest != null) { this.OnActionRequest(this, command); } } break; } } } } catch (Exception ex) { Logger.Log(ex); } }