Ejemplo n.º 1
0
        public MainWindow()
        {
            var model = this.InitViewModels();

            this.DataContext = model;
            this.InitializeComponent();
            var databaseBasePath         = ConfigurationLoader.GetAppSettingsValue("DatabasePath");
            var databasepathwithoutslash = databaseBasePath.Replace('\\', '_');

            singleton = new Mutex(true, databasepathwithoutslash);
            if (!singleton.WaitOne(TimeSpan.Zero, true))
            {
                //there is already another instance running!
                Log.Error($"En annen prosess kjører allerede på samme konfigurasjon {databaseBasePath}");
                System.Windows.Forms.MessageBox.Show($"En annen prosess kjører allerede på samme konfigurasjon {databaseBasePath}. Bare en instans kan kjøre samtidig", "FEIL. En annen prosess kjører allerede", System.Windows.Forms.MessageBoxButtons.OK);
                Application.Current.Shutdown();
            }

            var logfile = ConfigurationLoader.GetAppSettingsValue("LogFile");

            var Skytterlag = ConfigurationLoader.GetAppSettingsValue("Skytterlag");
            var Lisens     = ConfigurationLoader.GetAppSettingsValue("Lisens");

            var           LoggingLevelsString = ConfigurationLoader.GetAppSettingsValue("LoggingLevels");
            LoggingLevels enumLowestTrace     = LoggingLevels.Info;

            if (!string.IsNullOrEmpty(LoggingLevelsString))
            {
                if (!Enum.TryParse(LoggingLevelsString, true, out enumLowestTrace))
                {
                    enumLowestTrace = LoggingLevels.Info;
                }
            }

            var fileAppsender = new FileAppender(logfile, enumLowestTrace, LoggingLevels.Trace);

            Log.AddAppender(fileAppsender);
            if (!LisensChecker.Validate(Skytterlag, DateTime.Now, Lisens))
            {
                Log.Error("Lisens not valid for {0}", Skytterlag);
                System.Windows.Forms.MessageBox.Show($"Lisens ikke gyldig for {Skytterlag}", "FEIL. Lisenssjekk", System.Windows.Forms.MessageBoxButtons.OK);
                Application.Current.Shutdown();
            }

            Log.Info("FeltAdmin started");

            model.DisableDb += model_DisableDb;
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += CurrentDomainUnhandledException;
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            var lisens = LisensChecker.GenerateLisens("Bodø-Østre Skytterlag", new DateTime(2030, 06, 30));

            Assert.IsTrue(LisensChecker.Validate("Bodø-Østre Skytterlag", DateTime.Now, lisens));
        }