private void TransformRequest() { var transformRequest = new RemoteRequest(RobotPacket.PacketID.OpenTransform); transformRequest.ProcessSuccessfully += (data) => { ViewModel.State = RobotTransformButtonModel.ButtonState.Untransform; Dispatcher.BeginInvoke((Action)delegate { Cursor = Cursors.Arrow; OnUpdateParentControl(null); }); }; transformRequest.ProcessError += (errorCode, msg) => { Dispatcher.BeginInvoke((Action)delegate { Cursor = Cursors.Arrow; Cursor = Cursors.Arrow; switch (errorCode) { case RobotRequest.ErrorCode.SetupConnection: case RobotRequest.ErrorCode.WrongSessionID: OnUpdateParentControl("MustReconnect"); break; } }); Debug.Fail(msg, Enum.GetName(typeof(RobotRequest.ErrorCode), errorCode)); }; GlobalVariables.RobotWorker.AddJob(transformRequest); }
protected override void ClickProcess() { var stopRequest = new RemoteRequest(RobotPacket.PacketID.Stop); stopRequest.ProcessSuccessfully += (data) => { }; stopRequest.ProcessError += (data, msg) => Debug.Fail(msg); GlobalVariables.RobotWorker.AddJob(stopRequest); }
protected override void ClickProcess() { var index = GlobalVariables.CurrentRobotState.MotionIndex; if (index == GlobalVariables.CurrentListMotion.Count - 1) { index = 0; GlobalVariables.CurrentRobotState.MotionIndex = 0; } else { index++; GlobalVariables.CurrentRobotState.MotionIndex++; } if (index < 0 || index >= GlobalVariables.CurrentListMotion.Count) { Request = null; return; } ulong nextMotionID = GlobalVariables.CurrentListMotion[index].MotionID; Console.WriteLine("Next track: {0}:{1}", GlobalVariables.CurrentRobotState.MotionIndex, nextMotionID); Request = new RemoteRequest(RobotPacket.PacketID.SelectMotionToPlay, -1, nextMotionID); }
// This method raises the CopyMotion event private void TransferButton_Click(object sender, RoutedEventArgs e) { if (!GlobalVariables.RoboOnline) { var title = string.Format("{0}!", TryFindResource("ConnectToRobotText")); WPFMessageBox.Show(StaticMainWindow.Window, "", title, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); } else { if (CheckExistInRobot(GlobalVariables.CurrentListMotion, MotionID)) { var titleRecopy = (string)TryFindResource("ExistInRobotText"); var msgRecopy = (string)TryFindResource("WantRecopyMotionText"); var recopyResult = WPFMessageBox.Show(StaticMainWindow.Window, msgRecopy, titleRecopy, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (recopyResult == MessageBoxResult.No) { return; } } if (GlobalVariables.CurrentRobotState.MusicState == RobotState.MusicStates.MusicPlaying) { var titleStop = (string)TryFindResource("StopDanceToCopyText"); var msgStop = (string)TryFindResource("WantToStopDanceText"); var result = WPFMessageBox.Show(StaticMainWindow.Window, msgStop, titleStop, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes); if (result == MessageBoxResult.Yes) { var musicStopRequest = new RemoteRequest(RobotPacket.PacketID.Stop); musicStopRequest.ProcessSuccessfully += (data) => { Dispatcher.BeginInvoke((Action)delegate { var transferRequest = new TransferMotionToRobot(MotionID); var transferWindow = new Windows.TransferWindow(transferRequest, MotionID.ToString()); if (transferWindow.ShowDialog(StaticMainWindow.Window) == true) { var newEventArgs = new RoutedEventArgs(CopyMotionEvent); RaiseEvent(newEventArgs); } }); }; musicStopRequest.ProcessError += (data, msg) => Debug.Fail(msg); GlobalVariables.RobotWorker.AddJob(musicStopRequest); } } else { var transferRequest = new TransferMotionToRobot(MotionID); var transferWindow = new Windows.TransferWindow(transferRequest, MotionID.ToString()); if (transferWindow.ShowDialog(StaticMainWindow.Window) == true) { var newEventArgs = new RoutedEventArgs(CopyMotionEvent); RaiseEvent(newEventArgs); } } } }
private void PlayRequest() { RobotState state = GlobalVariables.CurrentRobotState; RemoteRequest playRequest = null; if (state.MusicState == RobotState.MusicStates.MusicIdled) { playRequest = state.MotionID > 2 ? new RemoteRequest(RobotPacket.PacketID.SelectMotionToPlay, -1, state.MotionID) : new RemoteRequest(RobotPacket.PacketID.SelectMotionToPlay, -1, GlobalVariables.CurrentListMotion[0].MotionID); } else playRequest = new RemoteRequest(RobotPacket.PacketID.Play); playRequest.ProcessSuccessfully += (data) => { ViewModel.StateButton = PlayPauseButtonModel.ButtonState.Pause; Dispatcher.BeginInvoke((Action)GetState); }; playRequest.ProcessError += (errorCode, msg) => { Dispatcher.BeginInvoke((Action)delegate { Cursor = Cursors.Arrow; switch (errorCode) { case RobotRequest.ErrorCode.SetupConnection: case RobotRequest.ErrorCode.WrongSessionID: OnUpdateParentControl("MustReconnect"); break; } }); Debug.Fail(msg, Enum.GetName(typeof(RobotRequest.ErrorCode), errorCode)); }; GlobalVariables.RobotWorker.AddJob(playRequest); }
private void PauseRequest() { var pauseRequest = new RemoteRequest(RobotPacket.PacketID.Pause); pauseRequest.ProcessSuccessfully += (data) => { ViewModel.StateButton = PlayPauseButtonModel.ButtonState.Play; Dispatcher.BeginInvoke((Action)GetState); }; pauseRequest.ProcessError += (errorCode, msg) => { Dispatcher.BeginInvoke((Action)delegate { Cursor = Cursors.Arrow; switch (errorCode) { case RobotRequest.ErrorCode.SetupConnection: case RobotRequest.ErrorCode.WrongSessionID: OnUpdateParentControl("MustReconnect"); break; } }); Debug.Fail(msg); }; GlobalVariables.RobotWorker.AddJob(pauseRequest); }
private void ConnectMrobo(bool reconnect = false) { //Cursor = Cursors.Wait; var helloRequest = new RemoteRequest(RobotPacket.PacketID.Hello); helloRequest.ProcessSuccessfully += (data) => { Dispatcher.BeginInvoke((Action)delegate { if (!reconnect) { var title = (string)TryFindResource("ConnectToRobotSuccesfullyText"); WPFMessageBox.Show(StaticMainWindow.Window, "", title, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK); } UnconnectedTextBox.Visibility = Visibility.Hidden; //Cursor = Cursors.Arrow; //TransformButton.ViewModel.State = RobotTransformButtonModel.ButtonState.Transform; GetListMotion(); GetState(); //GetState(NullMethod, 0); }); GlobalVariables.RoboOnline = true; }; helloRequest.ProcessError += (errorCode, msg) => { Debug.Fail(msg, Enum.GetName((typeof(RobotRequest.ErrorCode)), errorCode)); Dispatcher.BeginInvoke((Action)delegate { if (!reconnect) { var titleError = (string)TryFindResource("ConnectToRobotErrorText"); var msgError = (string)TryFindResource("CheckDefaultErrorText"); WPFMessageBox.Show(StaticMainWindow.Window, msgError, titleError, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } UnconnectedTextBox.Visibility = Visibility.Visible; Cursor = Cursors.Arrow; }); }; GlobalVariables.RobotWorker.AddJob(helloRequest); }
private void UpdateVolume(int value) { var volumeRequest = new RemoteRequest(RobotPacket.PacketID.SetVolumeLevel, value); volumeRequest.ProcessSuccessfully += (reply) => Dispatcher.BeginInvoke((Action)UpdateRemoteControl); volumeRequest.ProcessError += (reply, msg) => { if (reply == null) Debug.Fail(msg); Debug.Fail(reply.ToString(), msg); }; GlobalVariables.StoreWorker.AddRequest(volumeRequest); }
private void Play(ulong motionID) { //if (GlobalVariables.CurrentRobotState.TransformState != RobotState.TransformStates.Opened) //{ // string msgTransform = string.Empty; // string titleTransform = string.Empty; // switch (GlobalVariables.CurrentRobotState.TransformState) // { // case RobotState.TransformStates.Closed: // msgTransform = (string)TryFindResource("MustTransformToPlayText"); // titleTransform = (string)TryFindResource("PleaseTransformText"); // break; // case RobotState.TransformStates.Openning: // case RobotState.TransformStates.Closing: // msgTransform = (string)TryFindResource("RobotTransformingText"); // titleTransform = (string)TryFindResource("WaitToTransformedText"); // break; // } // WPFMessageBox.Show(StaticMainWindow.Window, titleTransform, // msgTransform, MessageBoxButton.OK, // MessageBoxImage.Information, MessageBoxResult.OK); // RemoteListBox.SelectedIndex = -1; // return; //} Cursor = Cursors.Wait; var playRequest = new RemoteRequest(RobotPacket.PacketID.SelectMotionToPlay, -1, motionID); playRequest.ProcessSuccessfully += (data) => Dispatcher.BeginInvoke((Action)(() => GetState(NullMethod, 0))); playRequest.ProcessError += (errorCode, msg) => { Dispatcher.BeginInvoke((Action)delegate { Cursor = Cursors.Arrow; switch (errorCode) { case RobotRequest.ErrorCode.SetupConnection: case RobotRequest.ErrorCode.WrongSessionID: var result = WPFMessageBox.Show(StaticMainWindow.Window, "Your connection to robot is lost", "Do you want to reconnect", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes); if (result == MessageBoxResult.Yes) { ConnectMrobo(); } else { GlobalVariables.RoboOnline = false; UnconnectedTextBox.Visibility = Visibility.Visible; } break; } }); Debug.Fail(msg); }; GlobalVariables.RobotWorker.AddJob(playRequest); }
private void MotionTitleItem_DeleteMotion(ulong motionID) { if (GlobalVariables.CurrentRobotState.MusicState == RobotState.MusicStates.MusicPlaying) { var titleStop = (string)TryFindResource("StopDanceToDeleteText"); var msgStop = (string)TryFindResource("WantToStopDanceText"); var result = WPFMessageBox.Show(StaticMainWindow.Window, msgStop, titleStop, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes); if (result == MessageBoxResult.Yes) { var musicStopRequest = new RemoteRequest(RobotPacket.PacketID.Stop); musicStopRequest.ProcessSuccessfully += (data) => Dispatcher.BeginInvoke((Action)(() => DeleteMotionInRobot(motionID))); musicStopRequest.ProcessError += (data, msg) => Debug.Fail(msg); GlobalVariables.RobotWorker.AddJob(musicStopRequest); } } else { DeleteMotionInRobot(motionID); } }
private void DeleteMotionInRobot(ulong motionID) { var delRequest = new RemoteRequest(RobotPacket.PacketID.DeleteMotion, -1, motionID); delRequest.ProcessSuccessfully += (reply) => Dispatcher.BeginInvoke((Action)delegate { GetListMotion(); RemoteListBox.SelectedIndex = 0; }); delRequest.ProcessError += (errorCode, msg) => Debug.Fail(errorCode.ToString(), msg); GlobalVariables.RobotWorker.AddJob(delRequest); }