public void Reload()
 {
     SpeechResponderConfiguration configuration = SpeechResponderConfiguration.FromFile();
     Personality personality = Personality.FromName(configuration.Personality);
     if (personality == null)
     {
         Logging.Warn("Failed to find named personality; falling back to default");
         personality = Personality.Default();
         configuration.Personality = personality.Name;
         configuration.ToFile();
     }
     scriptResolver = new ScriptResolver(personality.Scripts);
     Logging.Info("Reloaded " + ResponderName() + " " + ResponderVersion());
 }
 public SpeechResponder()
 {
     SpeechResponderConfiguration configuration = SpeechResponderConfiguration.FromFile();
     Personality personality = null;
     if (configuration != null && configuration.Personality != null)
     {
         personality = Personality.FromName(configuration.Personality);
     }
     if (personality == null)
     { 
         personality = Personality.Default();
     }
     scriptResolver = new ScriptResolver(personality.Scripts);
     Logging.Info("Initialised " + ResponderName() + " " + ResponderVersion());
 }
        private void testButtonClick(object sender, RoutedEventArgs e)
        {
            // Splice the new script in to the existing scripts
            Dictionary<string, Script> newScripts = new Dictionary<string, Script>(scripts);
            Script testScript = new Script(ScriptName, ScriptDescription, false, ScriptValue);
            newScripts.Remove(ScriptName);
            newScripts.Add(ScriptName, testScript);

            SpeechResponder responder = new SpeechResponder();
            responder.Start();

            // See if we have a sample
            Event sampleEvent;
            object sample = Events.SampleByName(script.Name);
            if (sample == null)
            {
                sampleEvent = null;
            }
            else if (sample.GetType() == typeof(string))
            {
                // It's as tring so a journal entry.  Parse it
                sampleEvent = JournalMonitor.ParseJournalEntry((string)sample);
            }
            else if (sample.GetType() == typeof(Event))
            {
                // It's a direct event
                sampleEvent = (Event)sample;
            }
            else
            {
                Logging.Warn("Unknown sample type " + sample.GetType());
                sampleEvent = null;
            }

            ScriptResolver scriptResolver = new ScriptResolver(newScripts);
            responder.Say(scriptResolver, ScriptName, sampleEvent, 3, false);
        }
        private void testScript(object sender, RoutedEventArgs e)
        {
            Script script = ((KeyValuePair<string, Script>)((Button)e.Source).DataContext).Value;
            SpeechResponder responder = new SpeechResponder();
            responder.Start();
            // See if we have a sample
            Event sampleEvent;
            object sample = Events.SampleByName(script.Name);
            if (sample == null)
            {
                sampleEvent = null;
            }
            else if (sample.GetType() == typeof(string))
            {
                // It's as tring so a journal entry.  Parse it
                sampleEvent = JournalMonitor.ParseJournalEntry((string)sample);
            }
            else if (sample.GetType() == typeof(Event))
            {
                // It's a direct event
                sampleEvent = (Event)sample;
            }
            else
            {
                Logging.Warn("Unknown sample type " + sample.GetType());
                sampleEvent = null;
            }

            ScriptResolver scriptResolver = new ScriptResolver(Personality.Scripts);
            responder.Say(scriptResolver, script.Name, sampleEvent);
        }
 public void TestResolverSimple()
 {
     Dictionary<string, Script> scripts = new Dictionary<string, Script>();
     scripts.Add("test", new Script("test", null, false, "Hello {name}"));
     ScriptResolver resolver = new ScriptResolver(scripts);
     Dictionary<string, Cottle.Value> dict = new Dictionary<string, Cottle.Value>();
     dict["name"] = "world";
     string result = resolver.resolve("test", dict);
     Assert.AreEqual("Hello world", result);
 }
 // Say something with a custom resolver
 public void Say(ScriptResolver resolver, string scriptName, Event theEvent = null, int? priority = null, bool? wait = null)
 {
     Dictionary<string, Cottle.Value> dict = createVariables(theEvent);
     string script = resolver.resolve(scriptName, dict);
     if (script != null)
     {
         SpeechService.Instance.Say(EDDI.Instance.Ship, script, (wait == null ? true : (bool)wait), (priority == null ? resolver.priority(scriptName) : (int)priority));
     }
 }