Exemplo n.º 1
0
        static void Main()
        {
            if (!SingleInstance.Exists())
            {
                Application.CurrentCulture = new CultureInfo("en-US");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string configFilePath = Path.Combine(AppPath, "AppConfig.json");

                IKernel    kernel = new StandardKernel(new InjectionModules());
                IAppConfig config = kernel.Get <IAppConfig>();

                try
                {
                    config.LoadConfig(configFilePath);
                }
                catch (FileNotFoundException)
                {
                    config.SaveConfig();
                }
                catch (Exception ex)
                {
                    config.SaveConfig();
                    MessageBox.Show("Error loading configuration file. The configuration file has become corrupt and will be reset to the default settings.", "Error Loading Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    config.AppPath = AppPath;
                }

                var mainForm = kernel.Get <MainForm>();
                (kernel.Get <IFsdManger>() as IEventBus).Register();
                (kernel.Get <ISoundManager>() as IEventBus).Register();
                (kernel.Get <IAfvManager>() as IEventBus).Register();
                (kernel.Get <IXplaneConnectionManager>() as IEventBus).Register();
                (kernel.Get <IVersionCheck>() as IEventBus).Register();
                (kernel.Get <IUserAircraftManager>() as IEventBus).Register();
                (kernel.Get <ISelcalGenerator>() as IEventBus).Register();
                (kernel.Get <INetworkAircraftManager>() as IEventBus).Register();
                (kernel.Get <IPttManager>() as IEventBus).Register();
                (kernel.Get <IControllerManager>() as IEventBus).Register();
                (kernel.Get <IControllerAtisManager>() as IEventBus).Register();
                Application.Run(mainForm);
                kernel.Dispose();
            }
        }