public CommandComponent() { _onError = new ErrorCommandGroup(); _onExecute = new CommandGroup(); _command = new _Command(); _icommand = _command; }
/// <summary> /// Kann zu Designzwecken verwendet werden. /// </summary> public LearnContext() { // Define buttons ClearConfiguration = new _Command(() => true, () => { }); ClearKeySequences = new _Command(() => true, () => { }); SaveConfiguration = new _Command(() => true, () => { }); AddNewSequence = new _Command(() => true, () => { }); Exit = new _Command(() => true, () => { }); // Load defaults Path = new FileInfo(@"c:\temp\test.xml"); Configuration = new RCSettings(); // Finish CurrentKey = AllKeys[0]; }
/// <summary> /// Erzeugt eine neue Arbeitsumgebung. /// </summary> /// <param name="path">Die zu verwendende Konfigurationsdatei.</param> /// <param name="exitAction">Wird beim Beenden aufgerufen.</param> private LearnContext( FileInfo path, Action exitAction ) { // Reset the whole configuration ClearConfiguration = new _Command( () => Configuration.Mappings.Length > 0, () => { // Process Configuration.Mappings = null; // We changed m_Changed = true; // Refresh nearly all RefreshButtons( ClearConfiguration, ClearKeySequences, SaveConfiguration ); } ); // Reset the configuration of a single key ClearKeySequences = new _Command( () => Configuration.Mappings.Any( m => m.Meaning == m_CurrentKey ), () => { // Process Configuration.Mappings = Configuration.Mappings.Where( m => m.Meaning != m_CurrentKey ).ToArray(); // We changed m_Changed = true; // Refresh RefreshButtons( ClearConfiguration, ClearKeySequences, SaveConfiguration ); } ); // Save the configuration and leave SaveConfiguration = new _Command( () => m_Changed, () => { // Safe process try { // Send to disk Configuration.Save( Path.FullName ); // Done Exit.Execute( null ); } catch (Exception e) { // Show error MessageBox.Show( e.Message, Properties.Resources.RC_Learn_SaveError ); } } ); // Register a new sequence AddNewSequence = new _Command( () => m_Sequence.Count > 0, () => { // Test for add if (m_Sequence.Count > 0) { // Create mapping var mapping = new InputMapping { Meaning = m_CurrentKey }; // Fill sequence mapping.Items.AddRange( m_Sequence ); // Add if not already there if (Configuration.Add( mapping )) { // Now we changed m_Changed = true; } } // Reset RegisterSequence( null ); // Refresh RefreshButtons( ClearKeySequences, ClearConfiguration, SaveConfiguration ); } ); // Other buttons Exit = new _Command( () => true, exitAction ); // Remember Path = path; // Load configuration if (path.Exists) Configuration = RCSettings.Load( path.FullName ); else Configuration = new RCSettings(); // Finish CurrentKey = AllKeys[0]; }
/// <summary> /// Kann zu Designzwecken verwendet werden. /// </summary> public LearnContext() { // Define buttons ClearConfiguration = new _Command( () => true, () => { } ); ClearKeySequences = new _Command( () => true, () => { } ); SaveConfiguration = new _Command( () => true, () => { } ); AddNewSequence = new _Command( () => true, () => { } ); Exit = new _Command( () => true, () => { } ); // Load defaults Path = new FileInfo( @"c:\temp\test.xml" ); Configuration = new RCSettings(); // Finish CurrentKey = AllKeys[0]; }
/// <summary> /// Erzeugt eine neue Arbeitsumgebung. /// </summary> /// <param name="path">Die zu verwendende Konfigurationsdatei.</param> /// <param name="exitAction">Wird beim Beenden aufgerufen.</param> private LearnContext(FileInfo path, Action exitAction) { // Reset the whole configuration ClearConfiguration = new _Command(() => Configuration.Mappings.Length > 0, () => { // Process Configuration.Mappings = null; // We changed m_Changed = true; // Refresh nearly all RefreshButtons(ClearConfiguration, ClearKeySequences, SaveConfiguration); }); // Reset the configuration of a single key ClearKeySequences = new _Command(() => Configuration.Mappings.Any(m => m.Meaning == m_CurrentKey), () => { // Process Configuration.Mappings = Configuration.Mappings.Where(m => m.Meaning != m_CurrentKey).ToArray(); // We changed m_Changed = true; // Refresh RefreshButtons(ClearConfiguration, ClearKeySequences, SaveConfiguration); }); // Save the configuration and leave SaveConfiguration = new _Command(() => m_Changed, () => { // Safe process try { // Send to disk Configuration.Save(Path.FullName); // Done Exit.Execute(null); } catch (Exception e) { // Show error MessageBox.Show(e.Message, Properties.Resources.RC_Learn_SaveError); } }); // Register a new sequence AddNewSequence = new _Command(() => m_Sequence.Count > 0, () => { // Test for add if (m_Sequence.Count > 0) { // Create mapping var mapping = new InputMapping { Meaning = m_CurrentKey }; // Fill sequence mapping.Items.AddRange(m_Sequence); // Add if not already there if (Configuration.Add(mapping)) { // Now we changed m_Changed = true; } } // Reset RegisterSequence(null); // Refresh RefreshButtons(ClearKeySequences, ClearConfiguration, SaveConfiguration); }); // Other buttons Exit = new _Command(() => true, exitAction); // Remember Path = path; // Load configuration if (path.Exists) { Configuration = RCSettings.Load(path.FullName); } else { Configuration = new RCSettings(); } // Finish CurrentKey = AllKeys[0]; }
//Event raise on connection received a message private void Con_MessageReceived(object sender, StringEventArgs e) { listBoxKey.Items.Insert(0, e.Message); if (e.Message.All(char.IsDigit)) { int command = int.Parse(e.Message); switch ((_Command)command) { case _Command.Stop: { car.Stop(); break; } case _Command.Avant: { car.Forward(); break; } case _Command.Avant_Gauche: { car.ForwardLeft(); break; } case _Command.Avant_Droite: { car.ForwardRight(); break; } case _Command.Arriere: { car.Backward(); break; } case _Command.Arriere_Gauche: { car.BackwardLeft(); break; } case _Command.Arriere_Droite: { car.BackwardRight(); break; } case _Command.Servo_Gauche: { car.servoTurnLeft(); break; } case _Command.Servo_Droite: { car.servoTurnRight(); break; } default: { break; } } } //check if string contains space and continue using the _Command enum for setspeed etc... else if (e.Message.Split(' ').Length == 2 || e.Message.Split(' ')[0].All(char.IsDigit)) { string[] fullCommand = e.Message.Split(' '); _Command command = (_Command)int.Parse(fullCommand[0]); int param = int.Parse(fullCommand[1]); switch (command) { case _Command.Set_Speed: car.setSpeed(param); break; case _Command.Set_Left_Speed: break; case _Command.Set_Right_Speed: break; default: break; } } }