Exemple #1
0
 public async Task SendBoardDetail(RemoteBoardModel board)
 {
     await Send(new BoardDetailRemoteMessage()
     {
         Board = board
     });
 }
Exemple #2
0
        private async void BoardDeleteButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.BoardNameComboBox.SelectedIndex >= 0)
            {
                await this.Window.RunAsyncOperation(async() =>
                {
                    if (await MessageBoxHelper.ShowConfirmationDialog("Are you sure you wish to delete this board?"))
                    {
                        RemoteBoardModel board = (RemoteBoardModel)this.BoardNameComboBox.SelectedItem;
                        ChannelSession.Settings.RemoteBoards.Remove(board);
                        await ChannelSession.SaveSettings();

                        this.RefreshBoardsView();
                    }
                });
            }
        }
Exemple #3
0
        private async void BoardEditButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.BoardNameComboBox.SelectedIndex >= 0)
            {
                RemoteBoardModel board = (RemoteBoardModel)this.BoardNameComboBox.SelectedItem;
                await this.Window.RunAsyncOperation(async() =>
                {
                    string name = await MessageBoxHelper.ShowTextEntryDialog("Board Name", board.Name);
                    if (!string.IsNullOrEmpty(name))
                    {
                        board.Name = name;
                        await ChannelSession.SaveSettings();

                        this.RefreshBoardsView();
                    }
                });
            }
        }
 public async Task SendBoard(RemoteBoardModel profileBoard)
 {
     await this.AsyncWrapper(this.signalRConnection.Send(SendBoardMethodName, profileBoard));
 }
        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;
            });
        }
Exemple #6
0
        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); }
        }
Exemple #7
0
 private void RemoteService_OnBoardRequest(object sender, RemoteBoardModel board)
 {
     this.RemoteEventsTextBlock.Text += "Board Requested: " + board.Name + Environment.NewLine;
 }
        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;
            });
        }
Exemple #9
0
 public RemoteFolderItemModel(int xPosition, int yPosition)
     : base(xPosition, yPosition)
 {
     this.Board = new RemoteBoardModel(isSubBoard: true);
 }