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; }); }