コード例 #1
0
ファイル: IOChannel.cs プロジェクト: chenyilyang/Azusa
        public IOChannel(string name, string enginePath, string arg = "", bool win = false)
        {
            try
            {
                Name = name;
                //specifies the way the recognizer is run
                Engine           = new Process();
                Engine.StartInfo = new ProcessStartInfo(enginePath, arg);
                if (!win)
                {
                    Engine.StartInfo.UseShellExecute = false;
                    Engine.StartInfo.CreateNoWindow  = true;
                    Engine.StartInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                }


                //port I/O to allow communication
                Engine.StartInfo.RedirectStandardOutput = true;
                Engine.StartInfo.RedirectStandardInput  = true;
            }
            catch
            {
                Notifier.ErrorMsg("Unable to load engine at " + enginePath + ".");
            }
        }
コード例 #2
0
ファイル: Configuration.cs プロジェクト: chenyilyang/Azusa
        static public void Import(string filePath)
        {
            try
            {
                int      numLine = 1;
                string[] entry;
                foreach (string line in File.ReadAllLines(filePath))
                {
                    try
                    {
                        if (line.Trim() != "" && !line.StartsWith("#"))
                        {
                            entry = line.Trim().Split('=');
                            Set(entry[0].Trim(), entry[1].Trim());
                        }
                    }
                    catch
                    {
                        Notifier.ErrorMsg("Ill-formatted setting in line " + numLine.ToString() + "of " + filePath);
                    }

                    numLine++;
                }
            }
            catch
            {
                Notifier.ErrorMsg("Unable to import settings from " + filePath);
            }
        }
コード例 #3
0
        //add a command to the list
        static public void Add(string name, string vname, string exec)
        {
            try
            {
                Command newcmd;
                newcmd.Name = name;
                newcmd.Exec = exec;

                if (GetExec(name) != null)
                {
                    CmdList.Add(newcmd);
                }
                else //the command already exist, treat as an update
                {
                    //first locate the existing command
                    Command result = CmdList.Find(x => x.Name == name);

                    //update the entry
                    Update(result.Name, result.Exec, name, exec);
                }
            }
            catch
            {
                Notifier.ErrorMsg("Error when trying to add the command \"" + name + "\"");
            }
        }
コード例 #4
0
ファイル: Configuration.cs プロジェクト: chenyilyang/Azusa
        static public void Set(string property, string value)
        {
            try
            {
                switch (property)
                {
                //BEHAVIOR

                case "frmDraggable":
                    draggable = Convert.ToBoolean(value);
                    break;

                case "dbgMode":
                    debugging = true;
                    break;

                case "showIcon":
                    showicon = Convert.ToBoolean(value);
                    break;

                case "culture":
                    culture = value;
                    break;

                case "frameInterval":
                    aniRate = Convert.ToInt32(value);
                    break;

                //APPEARANCE

                //settings for the main form
                case "frmHeight":
                    frmHeight = Convert.ToInt32(value);
                    break;

                case "frmWidth":
                    frmWidth = Convert.ToInt32(value);
                    break;

                case "frmPosX":
                    frmPosX = Convert.ToInt32(value);
                    break;

                case "frmPosY":
                    frmPosY = Convert.ToInt32(value);
                    break;


                //user-defined parameter
                default:
                    usrDef.Add(property, value);
                    break;
                }
            }
            catch {
                Notifier.ErrorMsg("Unable to set \"" + property + "\" to \"" + value + "\".");
            }
        }
コード例 #5
0
 //get the exec for a give command, the name may come from text input or voice input
 static public string GetExec(string name)
 {
     try
     {
         Command result = CmdList.Find(x => x.Name == name);
         return(result.Exec);
     }
     catch
     {
         Notifier.ErrorMsg("Error when trying to look for the command \"" + name + "\"");
         return(null);
     }
 }
コード例 #6
0
ファイル: IOChannel.cs プロジェクト: chenyilyang/Azusa
 public void Start()
 {
     try
     {
         Engine.Start();
         Engine.BeginOutputReadLine();
         Engine.OutputDataReceived += new DataReceivedEventHandler(Recognizer_OutputDataReceived);
         Scripting.ProcessServer.RegisterProcess(Engine);
     }
     catch
     {
         Notifier.ErrorMsg("Unable to start the engine " + Name + ".");
     }
 }
コード例 #7
0
ファイル: IOChannel.cs プロジェクト: chenyilyang/Azusa
 public void Stop()
 {
     try
     {
         Engine.CancelOutputRead();
         Engine.Kill();
         Engine.Dispose();
         Engine = null;
     }
     catch
     {
         Notifier.ErrorMsg("Unable to stop the engine \"" + Name + "\".");
     }
 }
コード例 #8
0
        //import command list from a text file
        static public void Import(string filePath)
        {
            string[] db = {};

            try
            {
                db = File.ReadAllLines(filePath);
            }
            catch
            {
                Notifier.ErrorMsg("Unable to read the command list located at " + filePath + ". It might be corrupted.");
                return;
            }

            string[] parsed;
            int      lineNum = 1;

            foreach (string line in db)
            {
                try
                {
                    //This allows some formatting and commenting in the text file
                    if (line.Trim() != "" && !line.StartsWith("#"))
                    {
                        parsed = line.Split(',');

                        Command entry;
                        entry.Name = parsed[0];
                        entry.Exec = parsed[1];

                        CmdList.Add(entry);
                    }
                }
                catch
                {
                    Notifier.ErrorMsg("Ill-formatted command entry in command list at line " + lineNum.ToString());
                    return;
                }

                lineNum++;
            }
        }
コード例 #9
0
        //modify a command
        static public void Update(string name, string exec, string newname, string newexec)
        {
            try
            {
                Command target;
                target.Name = name;
                target.Exec = exec;

                Command newcmd;
                newcmd.Name = newname;
                newcmd.Exec = newexec;

                int index = CmdList.IndexOf(target);

                CmdList[index] = newcmd;
            }
            catch
            {
                Notifier.ErrorMsg("Error when trying to update the command \"" + name + "\"");
            }
        }
コード例 #10
0
        //emport command list to a text file
        static public void Emport(string filePath)
        {
            StreamWriter sw;

            try
            {
                sw = new StreamWriter(filePath, false);
            }
            catch
            {
                Notifier.ErrorMsg("Unable to access " + filePath + ".");
                return;
            }


            foreach (Command cmd in CmdList)
            {
                try
                {
                    sw.WriteLine(cmd.Name + "," + cmd.Exec);
                }
                catch
                {
                    Notifier.ErrorMsg("Unable to write the command \"" + cmd.Name + "\".\n" + cmd.Exec);
                    return;
                }
            }

            try
            {
                sw.Flush();
            }
            catch
            {
                Notifier.ErrorMsg("Unable to flush command table to " + filePath + ".");
            }

            sw.Close();
        }
コード例 #11
0
ファイル: IOChannel.cs プロジェクト: chenyilyang/Azusa
        void Recognizer_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            //The engine seems to be throwing unreadable output when it exits
            //Thus we need to make sure that the engine is still up and running
            DbgOutput.Write(e.Data);
            if (e.Data != null)
            {
                try
                {
                    switch (e.Data.Trim())
                    {
                    case "STATUS?":
                        Engine.StandardInput.WriteLine(StatusMonitor.CurrentStatus);
                        break;

                    case "PosX?":
                        Engine.StandardInput.WriteLine(Scripting.ScriptEngine.GetParent().Location.X);
                        break;

                    case "PosY?":
                        Engine.StandardInput.WriteLine(Scripting.ScriptEngine.GetParent().Location.Y);
                        break;

                    case "Width?":
                        Engine.StandardInput.WriteLine(Scripting.ScriptEngine.GetParent().Size.Width);
                        break;

                    case "Height?":
                        Engine.StandardInput.WriteLine(Scripting.ScriptEngine.GetParent().Size.Height);
                        break;

                    //time variables
                    case "s?":
                        //Engine.StandardInput.WriteLine(DateTime.Now.ToString("s",new CultureInfo(Configuration.culture)));
                        Engine.StandardInput.WriteLine(DateTime.Now.Second.ToString());
                        break;

                    case "m?":
                        Engine.StandardInput.WriteLine(DateTime.Now.Minute.ToString());
                        break;

                    case "h?":
                        Engine.StandardInput.WriteLine(DateTime.Now.ToString("hh", new CultureInfo(Configuration.culture)));
                        break;

                    case "t?":
                        Engine.StandardInput.WriteLine(DateTime.Now.ToString("tt", new CultureInfo(Configuration.culture)));
                        break;

                    case "D?":
                        Engine.StandardInput.WriteLine(DateTime.Now.ToString("dd", new CultureInfo(Configuration.culture)));
                        break;

                    case "M?":
                        Engine.StandardInput.WriteLine(DateTime.Now.ToString("MMMM", new CultureInfo(Configuration.culture)));
                        break;

                    case "Y?":
                        Engine.StandardInput.WriteLine(DateTime.Now.ToString("yyy", new CultureInfo(Configuration.culture)));
                        break;

                    case "d?":
                        Engine.StandardInput.WriteLine(DateTime.Now.ToString("dddd", new CultureInfo(Configuration.culture)));
                        break;

                    default:
                        //check if asking for a response, search user defined variables first and return if any, otherwise try parsing as an condition and return true/false.
                        //otherwise run as a script
                        if (e.Data.Trim().EndsWith("?"))
                        {
                            if (Configuration.usrDef.ContainsKey(e.Data.Trim().Trim('?')))
                            {
                                Engine.StandardInput.WriteLine(Configuration.usrDef[e.Data.Trim().Trim('?')]);
                            }
                            else
                            {
                                try
                                {
                                    if (Scripting.ConditionParser.Parse(e.Data.Trim().Trim('?')))
                                    {
                                        Engine.StandardInput.WriteLine("true");
                                    }
                                    else
                                    {
                                        Engine.StandardInput.WriteLine("false");
                                    }
                                }
                                catch { }
                            }
                        }
                        else
                        {
                            Scripting.ScriptEngine.Run("*" + e.Data.Trim());
                        }
                        break;
                    }
                }
                catch
                {
                    Notifier.ErrorMsg("Unable to run script: " + e.Data + "\n Engine: " + Name);
                }
            }
        }