Exemplo n.º 1
0
        private async void Application_Startup(object sender, StartupEventArgs e)
        {
            //set up sqlite
            SQLitePCL.Batteries.Init();

            //Load settings
            var settings = SettingsUtils.LoadSettings();

            //initialize logging
            InitializeLogging(settings);

            //Log unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException;

            //db
            var contextFactory = new DbContextFactory(() => new QpasDbContext());

            InitializeDb(contextFactory);

            //check for empty account fields and load preferences
            using (var dbContext = contextFactory.Get())
            {
                if (dbContext.EquitySummaries.Any(x => x.AccountID == null))
                {
                    App.Splash.LoadComplete();
                    var accountMigrationWindow = new AccountMigrationWindow();
                    accountMigrationWindow.ShowDialog();
                }
            }

            var data = await DataLoader.LoadData(contextFactory);

            var qdmsSource = new ExternalDataSources.QDMS(settings, data.DatasourcePreferences.ToList());
            var ds         = new DataSourcer(contextFactory, qdmsSource, data, settings.AllowExternalDataSource);

            var window = new MainWindow(data, settings, contextFactory, ds);
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            //make sure we have a database connection and stuff, otherwise show the dialog to set db settings
            try
            {
                DBUtils.CheckDBConnection();
            }
            catch
            {
                App.Splash.LoadComplete();
                var dbDetailsWindow = new DBPicker();
                dbDetailsWindow.ShowDialog();
            }

            //initialize logging
            InitializeLogging();

            //Log unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException;

            //set the connection string
            DBUtils.SetConnectionString();

            Context = new DBContext();

            //create db if it doesn't exist
            Context.Database.Initialize(false);

            //check for any currencies, seed the db with initial values if nothing is found
            if (!Context.Currencies.Any())
            {
                Seed.DoSeed();
            }

            //check for empty account fields
            if (Context.EquitySummaries.Any(x => x.AccountID == null))
            {
                App.Splash.LoadComplete();
                var accountMigrationWindow = new AccountMigrationWindow();
                accountMigrationWindow.ShowDialog();
            }

            var qdmsSource = new ExternalDataSources.QDMS();

            Datasourcer = new DataSourcer(Context, qdmsSource);

            TradesRepository = new TradesRepository(Context, Datasourcer);

            IDialogService dialogService = new DialogService(this);

            ViewModel = new MainViewModel(Context, Datasourcer, dialogService);

            /////////////////////////////////////////////////////////
            InitializeComponent();
            /////////////////////////////////////////////////////////

            DataContext = ViewModel;

            //Create the load statement menus using the loaded plugins
            PopulateStatementMenus();

            //Restore column ordering, widths, and sorting
            LoadDataGridLayouts();

            //A hack to force the heavy stuff to load,
            //providing snappier navigation at the expense of longer startup time
#if !DEBUG
            ViewModel.TradesPageViewModel.Refresh();
            TradesGrid.Measure(new Size(500, 500));

            ViewModel.OrdersPageViewModel.Refresh();
            OrdersGrid.Measure(new Size(500, 500));

            ViewModel.CashTransactionsPageViewModel.Refresh();
            CashTransactionsGrid.Measure(new Size(500, 500));
#endif
            //hiding the tab headers
            Style s = new Style();
            s.Setters.Add(new Setter(VisibilityProperty, Visibility.Collapsed));
            MainTabCtl.ItemContainerStyle = s;

            //load the open positions page data
            ViewModel.RefreshCurrentPage();

            //close the slash screen
            App.Splash.LoadComplete();

            ShowChangelog();
        }
Exemplo n.º 3
0
        public MainWindow()
        {
            //make sure we have a database connection and stuff, otherwise show the dialog to set db settings
            try
            {
                DBUtils.CheckDBConnection();
            }
            catch
            {
                App.Splash.LoadComplete();
                var dbDetailsWindow = new DBPicker();
                dbDetailsWindow.ShowDialog();
            }

            //initialize logging
            InitializeLogging();

            //Log unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException;

            //set the connection string
            DBUtils.SetConnectionString();

            //set EF configuration, necessary for MySql to work
            DBUtils.SetDbConfiguration();

            Context = new DBContext();

            //create db if it doesn't exist
            Context.Database.Initialize(false);

            //check for any currencies, seed the db with initial values if nothing is found
            if (!Context.Currencies.Any())
            {
                Seed.DoSeed();
            }

            //check for empty account fields
            if(Context.EquitySummaries.Any(x => x.AccountID == null))
            {
                App.Splash.LoadComplete();
                var accountMigrationWindow = new AccountMigrationWindow();
                accountMigrationWindow.ShowDialog();
            }

            var qdmsSource = new ExternalDataSources.QDMS();
            Datasourcer = new DataSourcer(Context, qdmsSource, Properties.Settings.Default.allowExternalDataSource);

            TradesRepository = new TradesRepository(Context, Datasourcer, Properties.Settings.Default.optionsCapitalUsageMultiplier);

            ViewModel = new MainViewModel(Context, Datasourcer, DialogCoordinator.Instance);

            //Load user scripts
            ScriptLoader.LoadUserScriptTypes();

            /////////////////////////////////////////////////////////
            InitializeComponent();
            /////////////////////////////////////////////////////////

            DataContext = ViewModel;

            //Create the load statement menus using the loaded plugins
            PopulateStatementMenus();

            //Restore column ordering, widths, and sorting
            LoadDataGridLayouts();

            //A hack to force the heavy stuff to load, 
            //providing snappier navigation at the expense of longer startup time
#if !DEBUG
            ViewModel.TradesPageViewModel.Refresh();
            TradesGrid.Measure(new Size(500, 500));

            ViewModel.OrdersPageViewModel.Refresh();
            OrdersGrid.Measure(new Size(500, 500));

            ViewModel.CashTransactionsPageViewModel.Refresh();
            CashTransactionsGrid.Measure(new Size(500, 500));
#endif
            //hiding the tab headers
            Style s = new Style();
            s.Setters.Add(new Setter(VisibilityProperty, Visibility.Collapsed));
            MainTabCtl.ItemContainerStyle = s;

            //load the open positions page data
            ViewModel.RefreshCurrentPage();

            //close the slash screen
            App.Splash.LoadComplete();

            ShowChangelog();
        }