示例#1
0
        public void TestCorrectConfig()
        {
            ConfigLoader cl = new ConfigLoader();

            cl.ParseConfig(StringToStreamReader(@"
[section1]
hoge = fuga
asdf =aassddff
[section2]
hoge = fuga asdf

[section3]
hoge=fuga ahoaho

[section4]
h = fuga
ho = fuga 
hog = fuga  
hoge = fuga   "));

            // セクションの取得
            List <string> sections = cl.GetSections();

            Assert.AreEqual(4, sections.Count);

            // note : 順序は保証されない
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "section1"); }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "section2"); }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "section3"); }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "section4"); }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return(s == "section5"); }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return(s == "section"); }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return(s == ""); }));

            // セクションから項目取得
            {
                Hashtable conf = cl.GetConfig("section1");
                Assert.AreEqual(2, conf.Count);
                Assert.AreEqual("fuga", (string)conf["hoge"]);
                Assert.AreEqual("aassddff", (string)conf["asdf"]);
            }
            {
                Hashtable conf = cl.GetConfig("section2");
                Assert.AreEqual(1, conf.Count);
                Assert.AreEqual("fuga asdf", (string)conf["hoge"]);
            }
            {
                Hashtable conf = cl.GetConfig("section3");
                Assert.AreEqual(1, conf.Count);
                Assert.AreEqual("fuga ahoaho", (string)conf["hoge"]);
            }
            {
                Hashtable conf = cl.GetConfig("section4");
                Assert.AreEqual(4, conf.Count);
                Assert.AreEqual("fuga", (string)conf["h"]);
                Assert.AreEqual("fuga", (string)conf["ho"]);
                Assert.AreEqual("fuga", (string)conf["hog"]);
                Assert.AreEqual("fuga", (string)conf["hoge"]);
            }
        }
示例#2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler.HandleUnhandledException);
            Application.ThreadException += new ThreadExceptionEventHandler(UnhandledExceptionHandler.HandleUnhandledThreadException);
            //Load configs
            ConfigLoader configLoader = new ConfigLoader();

            if (configLoader.LoadFailed())
            {
                return;
            }
            //Create the SettingsController
            SettingsController settingsController = new SettingsController(configLoader.GetSpeciesList(), configLoader.GetStyles(), configLoader.GetUserSettings());
            //Create the main window and controller
            TemtemTrackerUI trackerUI = new TemtemTrackerUI(settingsController);
            //Create the Luma Calculator
            LumaChanceCalculator lumaCalculator = new LumaChanceCalculator(settingsController, configLoader.GetConfig());
            //Create the TemtemTableController
            TemtemTableController tableController = new TemtemTableController(trackerUI, lumaCalculator, settingsController);
            //Create the SessionTimeController
            SessionTimeController sessionTimeController = new SessionTimeController(trackerUI);

            OCRController ocr = new OCRController(configLoader.GetConfig(), configLoader.GetSpeciesList());

            //Database controller
            DatabaseController dbcon = DatabaseController.Instance;

            DetectorLoop loop = new DetectorLoop(configLoader.GetConfig(), tableController, ocr, settingsController);
            //The timer controller
            TimerController timerController = new TimerController(tableController, sessionTimeController, loop, configLoader.GetConfig(), configLoader.GetUserSettings(), settingsController);

            timerController.StartTimers();
            //The hotkey controller
            HotkeyController hotkeyController = new HotkeyController(settingsController, trackerUI, tableController);

            //Add listeners to application exit
            trackerUI.FormClosing += new FormClosingEventHandler((object source, FormClosingEventArgs e) =>
            {
                //Prevent shutdown during close
                User32.ShutdownBlockReasonCreate(trackerUI.Handle, "Saving! Please wait!");
                //Remove timers after run is over
                timerController.DisposeTimers();
                //Unregister hotkeys
                hotkeyController.UnregisterHotkeys();
                //Save Config and stuff
                tableController.SaveTable();
                settingsController.SaveSettings();
                sessionTimeController.SaveOnAppClose();
                //Allow shutdown again
                User32.ShutdownBlockReasonDestroy(trackerUI.Handle);
            });
            //Run the app
            Application.Run(trackerUI);
        }
示例#3
0
        void TestLoadingMulticonfig()
        {
            ConfigLoader cl = new ConfigLoader();

            cl.ParseConfig(StringToStreamReader(@"
[section1]
hoge = fuga
asdf =aassddff
[section2]
hoge = fuga asdf

[section3]
hoge=fuga ahoaho

[section4]
h = fuga
ho = fuga 
hog = fuga  
hoge = fuga   

"));
            cl.ParseConfig(StringToStreamReader(@"
[addedsection]
hoku = hoku
poka = poka

"));

            // セクションの取得
            List <string> sections = cl.GetSections();

            Assert.AreEqual(5, sections.Count);

            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "section1"); }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "section2"); }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "section3"); }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "section4"); }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return(s == "addedsection"); }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return(s == "section5"); }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return(s == "section"); }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return(s == ""); }));

            // セクションから項目取得
            {
                Hashtable conf = cl.GetConfig("section1");
                Assert.AreEqual(2, conf.Count);
                Assert.AreEqual("fuga", (string)conf["hoge"]);
                Assert.AreEqual("aassddff", (string)conf["asdf"]);
            }
            {
                Hashtable conf = cl.GetConfig("addedsection");
                Assert.AreEqual(2, conf.Count);
                Assert.AreEqual("hoku", (string)conf["hoku"]);
                Assert.AreEqual("poka", (string)conf["poka"]);
            }
        }
示例#4
0
 public Config()
 {
     if (_configContainer == null)
     {
         var loader = new ConfigLoader();
         _configContainer = loader.GetConfig(_basePath, _configFileName);
     }
 }
示例#5
0
        private void InitServer()
        {
            var config = ConfigLoader.GetConfig();
            var host   = IPAddress.Parse(config.Host);

            _listener = new TcpListener(host, config.Port);
            Console.WriteLine("Server init");
        }
示例#6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler.HandleUnhandledException);
            Application.ThreadException += new ThreadExceptionEventHandler(UnhandledExceptionHandler.HandleUnhandledThreadException);
            //Load configs
            ConfigLoader configLoader = new ConfigLoader();

            if (configLoader.LoadFailed())
            {
                return;
            }
            //Create the SettingsController
            SettingsController settingsController = new SettingsController(configLoader.GetSpeciesList(), configLoader.GetStyles(), configLoader.GetUserSettings());
            //Create the main window and controller
            TemtemTrackerUI trackerUI = new TemtemTrackerUI(settingsController);
            //Create the Luma Calculator
            LumaChanceCalculator lumaCalculator = new LumaChanceCalculator(settingsController, configLoader.GetConfig());
            //Create the TemtemTableController
            TemtemTableController tableController = new TemtemTableController(trackerUI, lumaCalculator, settingsController);
            OCRController         ocr             = new OCRController(configLoader.GetConfig(), configLoader.GetSpeciesList());
            DetectorLoop          loop            = new DetectorLoop(configLoader.GetConfig(), tableController, ocr);
            //The timer controller
            TimerController timerController = new TimerController(tableController, loop, configLoader.GetConfig(), configLoader.GetUserSettings(), settingsController);

            timerController.StartTimers();
            //The hotkey controller
            HotkeyController hotkeyController = new HotkeyController(settingsController, trackerUI, tableController);

            //Add listeners to application exit
            Application.ApplicationExit += new EventHandler((Object source, EventArgs args) => {
                //Remove timers after run is over
                timerController.DisposeTimers();
                //Unregister hotkeys
                hotkeyController.UnregisterHotkeys();
                //Save Config and stuff
                tableController.SaveTable();
                settingsController.SaveSettings();
            });

            //Run the app
            Application.Run(trackerUI);
        }