public CommandStatus Call(CommandVerb verb, int bundleId, IEnumerable <string> arguments) { CommandStatus status; status = _client.Dispatch(new CommandServiceEventArgs(verb, bundleId, arguments)); return(status); }
private CommandVerb GetPhraseIntent(string phrase) { CommandVerb verb = CommandVerb.None; if (phrase.StartsWith("Add") || phrase.StartsWith("Create") || phrase.StartsWith("New")) { verb = CommandVerb.Create; } else if (phrase.StartsWith("Read")) { verb = CommandVerb.Read; } else if (phrase.StartsWith("Edit")) { verb = CommandVerb.Edit; } else if (phrase.StartsWith("Delete")) { verb = CommandVerb.Delete; } else if (phrase.StartsWith("Help") || phrase.StartsWith("What can I say")) { verb = CommandVerb.Help; } else if (phrase.StartsWith("Show")) { verb = CommandVerb.Show; } else { Debug.WriteLine("Phrase intent not recognized: {0}", phrase); } return(verb); }
private static CommandVerb ParseVerb(string userStatment) { CommandVerb verb = CommandVerb.Error; if (userStatment.StartsWith("look", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Look; } else if (userStatment.StartsWith("take", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Take; } else if (userStatment.StartsWith("get", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Take; } else if (userStatment.StartsWith("drop", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Drop; } else if (userStatment.StartsWith("open", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Open; } else if (userStatment.StartsWith("inv", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Inventory; } else if (userStatment.StartsWith("drink", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Drink; } else if (userStatment.StartsWith("wear", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Wear; } else if (userStatment.StartsWith("read", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Read; } else if (userStatment.StartsWith("wave", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Wave; } else if (userStatment.StartsWith("quit", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Quit; } else if (userStatment.StartsWith("show", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Show; } else if (userStatment.StartsWith("play", StringComparison.CurrentCultureIgnoreCase)) { verb = CommandVerb.Play; } return(verb); }
public CommandItem(CommandVerb verb, int bundleId, IEnumerable <string> arguments) { Verb = verb; BundleId = bundleId; List <string> args = new List <string>(); args.AddRange(arguments); Arguments = args; }
private static void CallService(CommandVerb verb, int batchId, IEnumerable <string> files) { CommandStatus status = Resolve.CommandService.Call(verb, batchId, files); if (status == CommandStatus.Success) { return; } OS.Current.ExitApplication(1); }
/// <summary> /// Initializes a new instance of the <see cref="PhraseRecognizedEventArgs"/> class. /// </summary> /// <param name="person">The Person who the note is addressed to.</param> /// <param name="phrase">The phrase provided by the speech recognizer.</param> /// <param name="speechRecognitionArgs">Event data from the speech recognizer.</param> public PhraseRecognizedEventArgs( Person person, string phrase, CommandVerb verb, SpeechContinuousRecognitionResultGeneratedEventArgs speechRecognitionArgs) { PhraseTargetPerson = person; PhraseText = phrase; Verb = verb; IsDictation = speechRecognitionArgs.Result.Constraint == null ? false : Verb == CommandVerb.Dictation; }
public IReactiveServiceCommandRemoting CreateCommand(CommandVerb verb, CommandNoun noun, string commandText) { var connection = Connection; if (connection == null) { throw new InvalidOperationException("Inner connection is not set. Did you configure and start the service?"); } return(new ReactiveServiceCommandService(connection.CreateCommand(verb, noun, commandText))); }
private string GetVerb(CommandVerb verb) { switch (verb) { case CommandVerb.Get: return("GET"); case CommandVerb.Post: return("POST"); default: throw new NotImplementedException("Verb " + verb + " is not implemented."); } }
public static Command Parse(string userStatement) { Command newCommand = null; Char[] split = new Char[1]; split[0] = ' '; String[] commands = userStatement.Split(split); CommandVerb verb = ParseVerb(commands[0]); if (commands.Length < 2) { newCommand = new Command(verb, String.Empty); } else { newCommand = new Command(verb, commands[1]); } return(newCommand); }
private static List <CommandItem> ParseArguments(IEnumerable <string> arguments) { List <CommandItem> _commandItems = new List <CommandItem>(); int bundleId = 0; CommandVerb fileVerb = CommandVerb.Unknown; OptionSetCollection options = new OptionSetCollection() { { "batch", var => bundleId = 0 }, { "bundle=", (int id) => bundleId = id }, { "files", var => fileVerb = CommandVerb.AddFiles }, { "encrypt", var => fileVerb = CommandVerb.Encrypt }, { "decrypt", var => fileVerb = CommandVerb.Decrypt }, { "wipe", var => fileVerb = CommandVerb.Wipe }, { "open", var => fileVerb = CommandVerb.Open }, { "rename", var => fileVerb = CommandVerb.RandomRename }, { "start", var => _commandItems.Add(new CommandItem(CommandVerb.Startup, bundleId, NoArguments)) }, { "show", var => _commandItems.Add(new CommandItem(CommandVerb.Show, bundleId, NoArguments)) }, { "exit", var => _commandItems.Add(new CommandItem(CommandVerb.Exit, bundleId, NoArguments)) }, { "signout", var => _commandItems.Add(new CommandItem(CommandVerb.SignOut, bundleId, NoArguments)) }, { "offline", var => _commandItems.Add(new CommandItem(CommandVerb.SetOfflineMode, bundleId, NoArguments)) }, { "use_application=", (string path) => _commandItems.Add(new CommandItem(CommandVerb.UseForOpen, bundleId, new string[] { path })) }, { "login="******"passphrase=", (string passphrase) => _commandItems.Add(new CommandItem(CommandVerb.SetPassphrase, bundleId, new string[] { passphrase })) }, { "key_file=", (string path) => _commandItems.Add(new CommandItem(CommandVerb.SetKeyFile, bundleId, new string[] { path })) }, { "about", var => _commandItems.Add(new CommandItem(CommandVerb.About, bundleId, NoArguments)) }, { "register", var => _commandItems.Add(new CommandItem(CommandVerb.Register, bundleId, NoArguments)) }, }; IList <string> argumentlist = options.Parse(arguments); if (fileVerb == CommandVerb.Unknown) { fileVerb = bundleId == 0 ? CommandVerb.Open : CommandVerb.AddFiles; } if (argumentlist.Count > 0 || bundleId != 0) { _commandItems.Add(new CommandItem(fileVerb, bundleId, argumentlist)); } return(_commandItems); }
public Command(CommandVerb verb, String subject) { this.Verb = verb; this.Subject = subject; }
public IReactiveServiceCommand CreateCommand(CommandVerb verb, CommandNoun noun, string commandText) { return(new ReactiveServiceCommandProxy(_connection.CreateCommand(verb, noun, commandText))); }
/// <summary> /// Handles the <see cref="SpeechManager.PhraseRecognized"/> event. /// </summary> /// <param name="sender">the <see cref="SpeechManager"/> that raised the event.</param> /// <param name="e">The event data.</param> private async void speechManager_PhraseRecognized(object sender, PhraseRecognizedEventArgs e) { Person person = e.PhraseTargetPerson; string phrase = e.PhraseText; CommandVerb verb = e.Verb; string msg = String.Format("Heard phrase: {0}", phrase); Debug.WriteLine(msg); switch (verb) { case CommandVerb.Dictation: { // The phrase came from dictation, so transition speech recognition // to listen for command phrases. await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { FocusedNote.NoteBusinessObject.NoteText = phrase; await _speechManager.SetRecognitionMode(SpeechRecognitionMode.CommandPhrases); }); break; } case CommandVerb.Create: { // A command for creating a note was recognized. await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { _activeNote = CreateNote(person); _activeNote.NoteText = "Dictate your note here!"; await _speechManager.SpeakAsync("Dictate your note", _media); await _speechManager.SetRecognitionMode(SpeechRecognitionMode.Dictation); }); break; } case CommandVerb.Read: { // The command for reading a note was recognized. bool focusedNoteAssigned = await FocusedNoteAssigned(); if (focusedNoteAssigned) { await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await _speechManager.SpeakAsync( FocusedNote.NoteBusinessObject.NoteText, _media); }); } break; } case CommandVerb.Edit: { // The command for editing a note was recognized. bool focusedNoteAssigned = await FocusedNoteAssigned(); if (focusedNoteAssigned) { await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await _speechManager.SpeakAsync("Dictate your note", _media); await _speechManager.SetRecognitionMode(SpeechRecognitionMode.Dictation); }); } break; } case CommandVerb.Delete: { // The command for deleting a note was recognized. bool focusedNoteAssigned = await FocusedNoteAssigned(); if (focusedNoteAssigned) { await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { FocusedNote.OnDeleteNoteEvent(); await _speechManager.SpeakAsync("Note deleted", _media); }); } break; } case CommandVerb.Show: { Debug.WriteLine("SpeechManager.PhraseRecognized handler: Show TBD"); break; } case CommandVerb.Help: { // A command for spoken help was recognized. await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await _speechManager.SpeakAsync(_helpString, _media); }); break; } default: { Debug.WriteLine("SpeechManager.PhraseRecognized handler: Couldn't determine phrase intent"); break; } } }
protected Command(CommandVerb verb, List <string> arguments) { Verb = verb; Arguments = arguments; }
private UserMessage RunSpecialCommand(CommandVerb verb, String subject, Point location) { UserMessage returnMessage = null; foreach (var item in currentInventory) { if (item.IsSpecialCommandSupported(verb)) { returnMessage = item.RunCommand(verb, subject, currentRoomIndex, location, FindItemInInventory); } } return returnMessage; }
public bool IsSpecialCommandSupported(CommandVerb verb) { if(SpecialCommandList.ContainsKey(verb)) { return true; } else { return false; } }
public CommandServiceEventArgs(CommandVerb verb, int bundleId, IEnumerable <string> arguments) { Verb = verb; BundleId = bundleId; Arguments = new List <string>(arguments); }
public CommandCompleteEventArgs(CommandVerb verb, IEnumerable <string> arguments) { Verb = verb; Arguments = arguments; }
public CommandServiceEventArgs(CommandVerb verb, int bundleId, params string[] arguments) { Verb = verb; BundleId = bundleId; Arguments = new List <string>(arguments); }
public UserMessage RunCommand(CommandVerb verb, String subject, int currentRoomIndex, Point location, FindItemInInventoryCb findItemInInventoryCb) { return SpecialCommandList[verb](subject, currentRoomIndex, location, findItemInInventoryCb); }
/// <summary> /// Handle events fired when a result is generated. This may include a garbage rule that fires when general room noise /// or side-talk is captured (this will have a confidence of Rejected typically, but may occasionally match a rule with /// low confidence). /// </summary> /// <param name="sender">The Recognition session that generated this result</param> /// <param name="args">Details about the recognized speech</param> /// <remarks> /// <para> This method raises the PhraseRecognized event. Keep in mind that the /// ContinuousRecognitionSession.ResultGenerated event is raised on an arbitrary thread /// from the thread pool. If a <see cref="SpeechManager"/> client has thread affinity, /// like in a XAML-based UI, you need to marshal the call to the client's thread. /// </para> /// <para>In a UWP app, use the <see cref="CoreDispatcher"/> to execute the call /// on the main UI thread.</para> /// </remarks> private void ContinuousRecognitionSession_ResultGenerated( SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args) { if (args.Result.Status != SpeechRecognitionResultStatus.Success) { #if VERBOSE_DEBUG Debug.WriteLine("SpeechManager: ResultGenerated: {0}", args.Result.Status); #endif return; } // Unpack event arg data. bool hasConstraint = args.Result.Constraint != null; var confidence = args.Result.Confidence; string phrase = args.Result.Text; // The garbage rule doesn't have a tag associated with it, and // the other rules return a string matching the tag provided // when the grammar was compiled. string tag = hasConstraint ? args.Result.Constraint.Tag : "unknown"; if (tag == "unknown") { #if VERBOSE_DEBUG Debug.WriteLine("SpeechManager: ResultGenerated: garbage rule hit"); #endif return; } else { #if VERBOSE_DEBUG string msg = String.Format("SpeechManager: ResultGenerated: {0}", phrase); Debug.WriteLine(msg); #endif } if (hasConstraint && args.Result.Constraint.Type == SpeechRecognitionConstraintType.List) { // The List constraint type represents speech from // a compiled grammar of commands. CommandVerb verb = GetPhraseIntent(phrase); // You may decide to use per-phrase confidence levels in order to // tune the behavior of your grammar based on testing. if (confidence == SpeechRecognitionConfidence.Medium || confidence == SpeechRecognitionConfidence.High) { Person person = null; if (PhraseToPersonDictionary.ContainsKey(phrase)) { person = PhraseToPersonDictionary[phrase]; } // Raise the PhraseRecognized event. Clients with thread affinity, // like in a XAML-based UI, need to marshal the call to the // client's thread. PhraseRecognizedEventArgs eventArgs = new PhraseRecognizedEventArgs( person, phrase, verb, args); OnPhraseRecognized(eventArgs); } } else if (hasConstraint && args.Result.Constraint.Type == SpeechRecognitionConstraintType.Topic) { // The Topic constraint type represents speech from dictation. // Raise the PhraseRecognized event. Clients with thread affinity, // like in a XAML-based UI, need to marshal the call to the // client's thread. PhraseRecognizedEventArgs eventArgs = new PhraseRecognizedEventArgs( null, phrase, CommandVerb.Dictation, args); OnPhraseRecognized(eventArgs); } }
/// <summary> /// Creates and returns an IReactiveServiceCommand object associated with the connection. /// </summary> /// <param name="verb">Command verb.</param> /// <param name="noun">Command noun.</param> /// <param name="commandText">Text command to run against the reactive service.</param> /// <returns>Command object associated with the connection.</returns> public IReactiveServiceCommand CreateCommand(CommandVerb verb, CommandNoun noun, string commandText) { return(new Command(this, verb, noun, commandText)); }
public CommandStatus Call(CommandVerb verb, int bundleId, params string[] arguments) { return(Call(verb, bundleId, new List <string>(arguments))); }