public override async Task <bool> RemoveClient(RemoteConnectionModel hostConnection, RemoteConnectionModel clientConnection) { return(await this.AsyncWrapper <bool>(async() => { return await this.GetAsync <bool>(string.Format("authentication/removeclient?hostID={0}&clientID={1}", hostConnection.ID, clientConnection.ID)); })); }
public override async Task <RemoteConnectionModel> ApproveClient(RemoteConnectionModel connection, string clientShortCode, bool rememberClient = false) { return(await this.AsyncWrapper <RemoteConnectionAuthenticationTokenModel>(async() => { return await this.GetAsync <RemoteConnectionAuthenticationTokenModel>(string.Format("authentication/approveclient?hostID={0}&shortCode={1}&rememberClient={2}", connection.ID, clientShortCode, rememberClient)); })); }
public RemoteConnectionUIViewModel(RemoteSettingsControlViewModel parent, RemoteConnectionModel connection) { this.parent = parent; this.Connection = connection; this.DeleteCommand = this.CreateCommand(async(parameter) => { await ChannelSession.Services.RemoteService.RemoveClient(ChannelSession.Settings.RemoteHostConnection, this.Connection); ChannelSession.Settings.RemoteClientConnections.Remove(this.Connection); this.parent.RefreshList(); }); }
public abstract Task <bool> RemoveClient(RemoteConnectionModel hostConnection, RemoteConnectionModel clientConnection);
public abstract Task <RemoteConnectionModel> ApproveClient(RemoteConnectionModel connection, string clientShortCode, bool rememberClient = false);
public override async Task <bool> InitializeConnection(RemoteConnectionAuthenticationTokenModel connection) { if (!this.IsConnected) { if (!await this.ValidateConnection(connection)) { return(false); } this.AuthenticationToken = connection; this.ListenForRequestProfiles(async(clientID) => { try { RemoteConnectionModel clientConnection = ChannelSession.Settings.RemoteClientConnections.FirstOrDefault(c => c.ID.Equals(clientID)); if (clientConnection != null) { await this.SendProfiles(ChannelSession.Settings.RemoteProfiles.Where(p => !p.IsStreamer || clientConnection.IsStreamer)); ChannelSession.Services.Telemetry.TrackRemoteSendProfiles(connection.ID); } } catch (Exception ex) { Logger.Log(ex); } }); this.ListenForRequestBoard(async(clientID, profileID, boardID) => { try { RemoteConnectionModel clientConnection = ChannelSession.Settings.RemoteClientConnections.FirstOrDefault(c => c.ID.Equals(clientID)); if (clientConnection != null) { if (ChannelSession.Settings.RemoteProfileBoards.ContainsKey(profileID) && ChannelSession.Settings.RemoteProfileBoards[profileID].Boards.ContainsKey(boardID)) { await this.SendBoard(ChannelSession.Settings.RemoteProfileBoards[profileID].Boards[boardID]); ChannelSession.Services.Telemetry.TrackRemoteSendBoard(connection.ID, profileID, boardID); } else { await this.SendBoard(null); } } } catch (Exception ex) { Logger.Log(ex); } }); this.ListenForSendCommand(async(clientID, commandID) => { try { RemoteConnectionModel clientConnection = ChannelSession.Settings.RemoteClientConnections.FirstOrDefault(c => c.ID.Equals(clientID)); if (clientConnection != null) { CommandBase command = ChannelSession.AllEnabledCommands.FirstOrDefault(c => c.ID.Equals(commandID)); if (command != null) { await command.Perform(); } } } catch (Exception ex) { Logger.Log(ex); } }); await this.Connect(); await this.Authenticate(connection.ID, ChannelSession.Services.Secrets.GetSecret("RemoteHostSecret"), connection.AccessToken); await Task.Delay(3000); if (this.IsConnected) { ChannelSession.Services.Telemetry.TrackRemoteAuthentication(connection.ID); } return(this.IsConnected); } return(true); }
public RemoteMainControlViewModel(MainWindowViewModel windowViewModel) : base(windowViewModel) { this.AddProfileCommand = this.CreateCommand(async(x) => { string name = await DialogHelper.ShowTextEntry($"{MixItUp.Base.Resources.NameOfProfile}:"); if (!string.IsNullOrEmpty(name)) { if (ChannelSession.Settings.RemoteProfiles.Any(p => p.Name.Equals(name))) { await DialogHelper.ShowMessage("A profile with the same name already exists"); return; } RemoteProfileModel profile = new RemoteProfileModel(name.ToString()); ChannelSession.Settings.RemoteProfiles.Add(profile); ChannelSession.Settings.RemoteProfileBoards[profile.ID] = new RemoteProfileBoardsModel(profile.ID); this.RefreshProfiles(); this.ProfileSelected(this.Profiles.FirstOrDefault(p => p.ID.Equals(profile.ID))); } }); this.DeleteProfileCommand = this.CreateCommand(async(x) => { if (this.Profile != null) { if (await DialogHelper.ShowConfirmation("Are you sure you want to delete this profile?")) { ChannelSession.Settings.RemoteProfiles.Remove(this.Profile.GetModel()); ChannelSession.Settings.RemoteProfileBoards.Remove(this.profile.ID); this.RefreshProfiles(); this.ProfileSelected(null); this.Item = null; } } }); this.ConnectDeviceCommand = this.CreateCommand(async(parameter) => { if (ChannelSession.Settings.RemoteHostConnection == null || (!await ChannelSession.Services.RemoteService.ValidateConnection(ChannelSession.Settings.RemoteHostConnection))) { //ChannelSession.Settings.RemoteHostConnection = await ChannelSession.Services.RemoteService.NewHost(ChannelSession.MixerChannel.token); ChannelSession.Settings.RemoteClientConnections.Clear(); } if (ChannelSession.Settings.RemoteHostConnection != null) { if (!ChannelSession.Services.RemoteService.IsConnected) { if (!await ChannelSession.Services.RemoteService.InitializeConnection(ChannelSession.Settings.RemoteHostConnection)) { await DialogHelper.ShowMessage("Could not connect to Remote service, please try again"); return; } } string shortCode = await DialogHelper.ShowTextEntry("Device 6-Digit Code:"); if (!string.IsNullOrEmpty(shortCode)) { if (shortCode.Length != 6) { await DialogHelper.ShowMessage("The code entered is not valid"); return; } RemoteConnectionModel clientConnection = await ChannelSession.Services.RemoteService.ApproveClient(ChannelSession.Settings.RemoteHostConnection, shortCode, rememberClient: true); if (clientConnection != null) { if (!clientConnection.IsTemporary) { ChannelSession.Settings.RemoteClientConnections.Add(clientConnection); } await DialogHelper.ShowMessage(string.Format("The device {0} has been approved." + Environment.NewLine + Environment.NewLine + "To configure it, head to Settings -> Remote.", clientConnection.Name)); } else { await DialogHelper.ShowMessage("A client device could not be found with the specified code"); return; } } } else { await DialogHelper.ShowMessage("Could not connect to Remote service, please try again"); } }); this.DownloadAppleCommand = this.CreateCommand((x) => { ProcessHelper.LaunchLink("https://itunes.apple.com/us/app/mix-it-up-remote/id1459364145"); return(Task.FromResult(0)); }); this.DownloadAndroidCommand = this.CreateCommand((x) => { ProcessHelper.LaunchLink("https://play.google.com/store/apps/details?id=com.MixItUpApp.Remote.Beta"); return(Task.FromResult(0)); }); MessageCenter.Register <RemoteCommandItemViewModel>(RemoteEmptyItemControlViewModel.NewRemoteCommandEventName, this, (command) => { if (this.Board != null) { this.Board.AddItem(command); this.RefreshBoardItem(command.XPosition, command.YPosition); this.Item = this.GetItem(command.XPosition, command.YPosition); } }); MessageCenter.Register <RemoteFolderItemViewModel>(RemoteEmptyItemControlViewModel.NewRemoteFolderEventName, this, async(folder) => { if (this.NavigationNames.Count() > 2) { await DialogHelper.ShowMessage("Boards can only be up to 2 layers deep"); return; } if (this.Board != null) { RemoteBoardModel newBoard = new RemoteBoardModel(isSubBoard: true); folder.BoardID = newBoard.ID; ChannelSession.Settings.RemoteProfileBoards[this.Profile.ID].Boards[folder.BoardID] = newBoard; this.Board.AddItem(folder); this.RefreshBoardItem(folder.XPosition, folder.YPosition); this.Item = this.GetItem(folder.XPosition, folder.YPosition); } }); MessageCenter.Register <RemoteCommandItemControlViewModel>(RemoteCommandItemControlViewModel.RemoteCommandDetailsEventName, this, (command) => { this.Item = command; }); MessageCenter.Register <RemoteFolderItemControlViewModel>(RemoteFolderItemControlViewModel.RemoteFolderDetailsEventName, this, (folder) => { this.Item = folder; }); MessageCenter.Register <RemoteFolderItemViewModel>(RemoteFolderItemControlViewModel.RemoteFolderNavigationEventName, this, (folder) => { if (ChannelSession.Settings.RemoteProfileBoards[this.Profile.ID].Boards.ContainsKey(folder.BoardID)) { this.Board = new RemoteBoardViewModel(ChannelSession.Settings.RemoteProfileBoards[this.Profile.ID].Boards[folder.BoardID], this.Board); this.RefreshBoard(); this.AddRemoveNavigationName(folder.Name); this.Item = null; } }); MessageCenter.Register <RemoteBoardViewModel>(RemoteBackItemControlViewModel.RemoteBackNavigationEventName, this, (board) => { this.Board = board; this.RefreshBoard(); this.AddRemoveNavigationName(null); this.Item = null; }); MessageCenter.Register <RemoteItemViewModelBase>(RemoteItemControlViewModelBase.RemoteDeleteItemEventName, this, (item) => { this.Board.RemoveItem(item.XPosition, item.YPosition); this.RefreshBoardItem(item.XPosition, item.YPosition); this.Item = null; }); }
public RemoteMainControlViewModel(MainWindowViewModel windowViewModel) : base(windowViewModel) { this.AddProfileCommand = this.CreateCommand(async(x) => { string name = await DialogHelper.ShowTextEntry(MixItUp.Base.Resources.NameOfProfileHeader); if (!string.IsNullOrEmpty(name)) { if (ChannelSession.Settings.RemoteProfiles.Any(p => p.Name.Equals(name))) { await DialogHelper.ShowMessage(Resources.DuplicateProfileName); return; } RemoteProfileModel profile = new RemoteProfileModel(name.ToString()); ChannelSession.Settings.RemoteProfiles.Add(profile); ChannelSession.Settings.RemoteProfileBoards[profile.ID] = new RemoteProfileBoardsModel(profile.ID); this.RefreshProfiles(); this.ProfileSelected(this.Profiles.FirstOrDefault(p => p.ID.Equals(profile.ID))); } }); this.DeleteProfileCommand = this.CreateCommand(async(x) => { if (this.Profile != null) { if (await DialogHelper.ShowConfirmation(Resources.DeleteProfilePrompt)) { ChannelSession.Settings.RemoteProfiles.Remove(this.Profile.GetModel()); ChannelSession.Settings.RemoteProfileBoards.Remove(this.profile.ID); this.RefreshProfiles(); this.ProfileSelected(null); this.Item = null; } } }); this.ConnectDeviceCommand = this.CreateCommand(async(parameter) => { if (ChannelSession.Settings.RemoteHostConnection == null || (!await ChannelSession.Services.RemoteService.ValidateConnection(ChannelSession.Settings.RemoteHostConnection))) { //ChannelSession.Settings.RemoteHostConnection = await ChannelSession.Services.RemoteService.NewHost(ChannelSession.MixerChannel.token); ChannelSession.Settings.RemoteClientConnections.Clear(); } if (ChannelSession.Settings.RemoteHostConnection != null) { if (!ChannelSession.Services.RemoteService.IsConnected) { if (!await ChannelSession.Services.RemoteService.InitializeConnection(ChannelSession.Settings.RemoteHostConnection)) { await DialogHelper.ShowMessage(Resources.RemoteServicesFailed); return; } } string shortCode = await DialogHelper.ShowTextEntry(Resources.DeviceCodeHeader); if (!string.IsNullOrEmpty(shortCode)) { if (shortCode.Length != 6) { await DialogHelper.ShowMessage(Resources.DeviceCodeInvalid); return; } RemoteConnectionModel clientConnection = await ChannelSession.Services.RemoteService.ApproveClient(ChannelSession.Settings.RemoteHostConnection, shortCode, rememberClient: true); if (clientConnection != null) { if (!clientConnection.IsTemporary) { ChannelSession.Settings.RemoteClientConnections.Add(clientConnection); } await DialogHelper.ShowMessage(string.Format(Resources.DeviceApprovedLine1 + Environment.NewLine + Environment.NewLine + Resources.DeviceApprovedLine2, clientConnection.Name)); } else { await DialogHelper.ShowMessage(Resources.DeviceNoCode); return; } } } else { await DialogHelper.ShowMessage(Resources.RemoteFailed); } }); this.DownloadAppleCommand = this.CreateCommand((x) => { ProcessHelper.LaunchLink("https://itunes.apple.com/us/app/mix-it-up-remote/id1459364145"); return(Task.FromResult(0)); }); this.DownloadAndroidCommand = this.CreateCommand((x) => { ProcessHelper.LaunchLink("https://play.google.com/store/apps/details?id=com.MixItUpApp.Remote.Beta"); return(Task.FromResult(0)); }); MessageCenter.Register <RemoteCommandItemViewModel>(RemoteEmptyItemControlViewModel.NewRemoteCommandEventName, this, (command) => { if (this.Board != null) { this.Board.AddItem(command); this.RefreshBoardItem(command.XPosition, command.YPosition); this.Item = this.GetItem(command.XPosition, command.YPosition); } }); MessageCenter.Register <RemoteFolderItemViewModel>(RemoteEmptyItemControlViewModel.NewRemoteFolderEventName, this, async(folder) => { if (this.NavigationNames.Count() > 2) { await DialogHelper.ShowMessage(Resources.RemoteTwoLayersMax); return; } if (this.Board != null) { RemoteBoardModel newBoard = new RemoteBoardModel(isSubBoard: true); folder.BoardID = newBoard.ID; ChannelSession.Settings.RemoteProfileBoards[this.Profile.ID].Boards[folder.BoardID] = newBoard; this.Board.AddItem(folder); this.RefreshBoardItem(folder.XPosition, folder.YPosition); this.Item = this.GetItem(folder.XPosition, folder.YPosition); } }); MessageCenter.Register <RemoteCommandItemControlViewModel>(RemoteCommandItemControlViewModel.RemoteCommandDetailsEventName, this, (command) => { this.Item = command; }); MessageCenter.Register <RemoteFolderItemControlViewModel>(RemoteFolderItemControlViewModel.RemoteFolderDetailsEventName, this, (folder) => { this.Item = folder; }); MessageCenter.Register <RemoteFolderItemViewModel>(RemoteFolderItemControlViewModel.RemoteFolderNavigationEventName, this, (folder) => { if (ChannelSession.Settings.RemoteProfileBoards[this.Profile.ID].Boards.ContainsKey(folder.BoardID)) { this.Board = new RemoteBoardViewModel(ChannelSession.Settings.RemoteProfileBoards[this.Profile.ID].Boards[folder.BoardID], this.Board); this.RefreshBoard(); this.AddRemoveNavigationName(folder.Name); this.Item = null; } }); MessageCenter.Register <RemoteBoardViewModel>(RemoteBackItemControlViewModel.RemoteBackNavigationEventName, this, (board) => { this.Board = board; this.RefreshBoard(); this.AddRemoveNavigationName(null); this.Item = null; }); MessageCenter.Register <RemoteItemViewModelBase>(RemoteItemControlViewModelBase.RemoteDeleteItemEventName, this, (item) => { this.Board.RemoveItem(item.XPosition, item.YPosition); this.RefreshBoardItem(item.XPosition, item.YPosition); this.Item = null; }); }