Beispiel #1
0
        public void Reload()
        {
            string          filePath = "Reload.xml";
            XmlConfigSource source   = new XmlConfigSource();

            IConfig petConfig = source.AddConfig("Pets");

            petConfig.Set("cat", "Muffy");
            petConfig.Set("dog", "Rover");
            IConfig weatherConfig = source.AddConfig("Weather");

            weatherConfig.Set("skies", "cloudy");
            weatherConfig.Set("precipitation", "rain");
            source.Save(filePath);

            Assert.AreEqual(2, petConfig.GetKeys().Length);
            Assert.AreEqual("Muffy", petConfig.Get("cat"));
            Assert.AreEqual(2, source.Configs.Count);

            XmlConfigSource newSource = new XmlConfigSource(filePath);

            IConfig compareConfig = newSource.Configs["Pets"];

            Assert.AreEqual(2, compareConfig.GetKeys().Length);
            Assert.AreEqual("Muffy", compareConfig.Get("cat"));
            Assert.IsTrue(compareConfig == newSource.Configs["Pets"],
                          "References before are not equal");

            // Set the new values to source
            source.Configs["Pets"].Set("cat", "Misha");
            source.Configs["Pets"].Set("lizard", "Lizzy");
            source.Configs["Pets"].Set("hampster", "Surly");
            source.Configs["Pets"].Remove("dog");
            source.Configs.Remove(weatherConfig);
            source.Save();              // saves new value

            // Reload the new source and check for changes
            newSource.Reload();
            Assert.IsTrue(compareConfig == newSource.Configs["Pets"],
                          "References after are not equal");
            Assert.AreEqual(1, newSource.Configs.Count);
            Assert.AreEqual(3, newSource.Configs["Pets"].GetKeys().Length);
            Assert.AreEqual("Lizzy", newSource.Configs["Pets"].Get("lizard"));
            Assert.AreEqual("Misha", newSource.Configs["Pets"].Get("cat"));
            Assert.IsNull(newSource.Configs["Pets"].Get("dog"));

            File.Delete(filePath);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException;

            logger.Info("Чтение конфигурационного файла...");
            IConfig serviceConfig;
            IConfig kassaConfig;

            IConfig[] cashboxesConfig;

            try {
                XmlConfigSource confFile = new XmlConfigSource(configFile);
                confFile.Reload();
                serviceConfig = confFile.Configs["Service"];
                kassaConfig   = confFile.Configs["ModulKassa"];

                cashboxesConfig = new[] {
                    confFile.Configs["RetailPointSosnovcev"],
                    confFile.Configs["RetailPointVodovozSouth"],
                    confFile.Configs["RetailPointVodovozNorth"]
                };

                IConfig mysqlConfig = confFile.Configs["Mysql"];
                mysqlServerHostName = mysqlConfig.GetString("mysql_server_host_name");
                mysqlServerPort     = mysqlConfig.GetString("mysql_server_port", "3306");
                mysqlUser           = mysqlConfig.GetString("mysql_user");
                mysqlPassword       = mysqlConfig.GetString("mysql_password");
                mysqlDatabase       = mysqlConfig.GetString("mysql_database");
            }
            catch (Exception ex) {
                logger.Fatal(ex, "Ошибка чтения конфигурационного файла.");
                return;
            }

            logger.Info("Настройка подключения к БД...");
            try {
                var conStrBuilder = new MySqlConnectionStringBuilder {
                    Server   = mysqlServerHostName,
                    Port     = UInt32.Parse(mysqlServerPort),
                    Database = mysqlDatabase,
                    UserID   = mysqlUser,
                    Password = mysqlPassword,
                    SslMode  = MySqlSslMode.None
                };

                var dbConfig = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard
                               .ConnectionString(conStrBuilder.GetConnectionString(true));

                OrmConfig.ConfigureOrm(
                    dbConfig,
                    new[] {
                    System.Reflection.Assembly.GetAssembly(typeof(QS.Banks.Domain.Bank)),
                    System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.HistoryLog.HistoryMain)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.Project.Domain.UserBase))
                }
                    );

                QS.HistoryLog.HistoryMain.Enable();
            }
            catch (Exception ex) {
                logger.Fatal(ex, "Ошибка в настройке подключения к БД.");
                return;
            }

            try {
                ReceiptServiceStarter.StartService(serviceConfig, kassaConfig, cashboxesConfig);

                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    UnixSignal[] signals =
                    {
                        new UnixSignal(Signum.SIGINT),
                        new UnixSignal(Signum.SIGHUP),
                        new UnixSignal(Signum.SIGTERM)
                    };
                    UnixSignal.WaitAny(signals);
                }
                else
                {
                    Console.ReadLine();
                }
            }
            catch (Exception e) {
                logger.Fatal(e);
            }
            finally {
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    Thread.CurrentThread.Abort();
                }
                Environment.Exit(0);
            }
        }