示例#1
0
        public void Load(string path, bool clean)
        {
            SARAH.GetInstance().Log("ConfigManager", "Loading: " + path);
            var parser = new FileIniDataParser();
            var conf   = parser.ReadFile(path);

            //SARAH.GetInstance().Log("ConfigManager", conf.ToString());
            if (clean)
            {
                foreach (var section in conf.Sections)
                {
                    section.LeadingComments.Clear();
                    section.TrailingComments.Clear();
                    foreach (var keydata in section.Keys)
                    {
                        keydata.Comments.Clear();
                    }
                }
            }
            if (Config == null)
            {
                Config = conf;
            }
            else
            {
                Config.Merge(conf);
            }
        }
示例#2
0
 protected String Find(string section, string key, string def)
 {
     try { return(Config[section][key]); } catch (Exception) {
         if (!"enable".Equals(key))
         {
             SARAH.GetInstance().Log("Missing config : " + section + "." + key);
         }
         return(def);
     }
 }
示例#3
0
    public static SARAH GetInstance() {
      if (sarah == null) {
        sarah = new SARAH();

        var path = "bootlog.txt";
        if (File.Exists(path)) {
          File.Delete(path);
        }
        var bootlog = new System.Diagnostics.TextWriterTraceListener(File.CreateText(path));
        System.Diagnostics.Debug.Listeners.Add(bootlog);

        sarah.Log("==========================================");
      }
      return sarah;
    }
示例#4
0
        public static SARAH GetInstance()
        {
            if (sarah == null)
            {
                sarah = new SARAH();

                var path = "bootlog.txt";
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                var bootlog = new System.Diagnostics.TextWriterTraceListener(File.CreateText(path));
                System.Diagnostics.Debug.Listeners.Add(bootlog);

                sarah.Log("==========================================");
            }
            return(sarah);
        }
示例#5
0
        static void Main(string[] args)
        {
            // Create SARAH
            var sarah = SARAH.GetInstance();

            try {
                // Start Process
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.ApplicationExit += new EventHandler(OnApplicationExit);

                // Start SARAH backend
                thread = new Thread(delegate() {
                    sarah.Start();
                    sarah.Setup();
                    Application.Run();
                });
                thread.Start();

                // Wait for ready state
                while (!sarah.Ready())
                {
                    Thread.Sleep(100);
                }

                // Build System Tray
                using (MenuTray tray = new MenuTray()) {
                    tray.Display();
                    sarah.Log("SARAH", "==========================================");
                    Application.Run();
                }
            }
            catch (Exception ex) {
                sarah.Error("CATCH_ALL", ex);
                sarah.Error("CATCH_ALL", ex.StackTrace);
            }
        }
示例#6
0
        // ==========================================
        //  CALLBACK
        // ==========================================

        void Exit_Click(object sender, EventArgs e)
        {
            SARAH.GetInstance().Dispose();
            Application.Exit();
        }
 protected void Error(Exception ex)
 {
     SARAH.GetInstance().Error(Name + "|" + Device, ex);
 }
 protected void Error(string msg)
 {
     SARAH.GetInstance().Error(Name + "|" + Device, msg);
 }
 protected void Debug(string msg)
 {
     SARAH.GetInstance().Debug(Name + "|" + Device, msg);
 }
示例#10
0
        // -------------------------------------------
        //  IPLUGIN HOST (called by addon)
        // -------------------------------------------

        public void Log(IAddOn addon, string msg)
        {
            SARAH.GetInstance().Log("AddOnManager][" + addon.Name, msg);
        }
示例#11
0
        private void Load(string path, bool IsAddOn)
        {
            if (File.Exists(path))
            {
                return;
            }
            SARAH.GetInstance().Log("AddOnManager", "Searching: " + path);

            // Recursive with folders
            string[] folders = Directory.GetDirectories(path);
            foreach (string folder in folders)
            {
                Load(folder, IsAddOn);
            }

            // Retrieve all .dll files
            string[] dll = Directory.GetFiles(path, "*.dll");

            // Load Assemblies from files
            ICollection <Assembly> assemblies = new List <Assembly>(dll.Length);

            foreach (string file in dll)
            {
                var name = Path.GetFileNameWithoutExtension(file);
                if (IsAddOn && !ConfigManager.GetInstance().Find(name + ".enable", false))
                {
                    continue;
                }
                if (!IsAddOn && !name.StartsWith("Emgu"))
                {
                    continue;
                }                                               // Hack

                try {
                    AssemblyName an       = AssemblyName.GetAssemblyName(file);
                    Assembly     assembly = Assembly.Load(an);
                    if (IsAddOn)
                    {
                        assemblies.Add(assembly);
                    }
                } catch (Exception ex) {
                    SARAH.GetInstance().Error("AddOnManager", ex.Message);
                }
            }

            Type addonType = typeof(IAddOn);

            foreach (Assembly assembly in assemblies)
            {
                if (assembly == null)
                {
                    continue;
                }
                ICollection <Type> addonTypes = new List <Type>();

                // Retrieve AddOn's type
                Type[] types = assembly.GetTypes();
                foreach (Type type in types)
                {
                    if (type.IsInterface || type.IsAbstract)
                    {
                        continue;
                    }
                    if (type.GetInterface(addonType.FullName) == null)
                    {
                        continue;
                    }
                    addonTypes.Add(type);
                }

                // Instanciate AddOns
                foreach (Type type in addonTypes)
                {
                    var addon = (IAddOn)Activator.CreateInstance(type);
                    addon.Host = this;
                    AddOns.Add(addon);
                    SARAH.GetInstance().Log("AddOnManager", "Loading addon \"" + addon.Name + "\" v" + addon.Version);
                }
            }
        }
示例#12
0
        // -------------------------------------------
        //  UTILITY
        // ------------------------------------------

        protected void Debug(string msg)
        {
            SARAH.GetInstance().Debug("SpeechToText", msg);
        }