Пример #1
0
        private void InitializeServices()
        {
            // register our configuration service and initialize it
            SimpleIoc.Default.Register <ConfigurationService>();
            ConfigurationService configurationService = (ConfigurationService)SimpleIoc.Default.GetInstance <ConfigurationService>();

            if (null != configurationService)
            {
                // need this to start, so run this synchronously
                AsyncHelper.RunSync(() => configurationService.Initialize());
            }

            // register our localization service and initialize it
            SimpleIoc.Default.Register <LocalizationService>();
            LocalizationService localizationService = (LocalizationService)SimpleIoc.Default.GetInstance <LocalizationService>();

            if (null != localizationService)
            {
                // need this to start, so run sync
                AsyncHelper.RunSync(() => localizationService.Initialize());
            }

            // register the playlist service and initialize it
            SimpleIoc.Default.Register <PlaylistService>();
            PlaylistService playlistService = (PlaylistService)SimpleIoc.Default.GetInstance <PlaylistService>();

            if (null != playlistService)
            {
                //// need this to start, so run sync
                //AsyncHelper.RunSync(() =>  playlistService.Initialize());
                playlistService.Initialize();
            }

            // initialize the telemetry service
            SimpleIoc.Default.Register <TelemetryService>();
            TelemetryService telemetryService = (TelemetryService)SimpleIoc.Default.GetInstance <TelemetryService>();

            if (null != telemetryService)
            {
                if (null != configurationService)
                {
                    // DO NOT try to run this asynchronously; MetroLog hangs when invoked async
                    //AsyncHelper.RunSync(() => telemetryService.Initialize(configurationService.Configuration.TelemetryKey));
                    telemetryService.Initialize(configurationService.Configuration.IsTelemetryEnabled,
                                                configurationService.Configuration.TelemetryKey);

                    // log app start
                    TelemetryService.Current?.LogTelemetryEvent(TelemetryEvents.StartApplication);
                }
            }
        }
Пример #2
0
        public App()
        {
            // save a pointer to ourself
            App.Current = this;

            InitializeComponent();

            // app lifecycle event handlers
            EnteredBackground  += OnEnteredBackground;
            Suspending         += OnSuspending;
            Resuming           += OnResuming;
            UnhandledException += OnUnhandledException;

            // we want full screen, but leave this off during dev
            ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
            //ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;

            // we want landscape only
            DisplayOrientations orientations = DisplayOrientations.Landscape;

            DisplayInformation.AutoRotationPreferences = orientations;

            // Deferred execution until used. Check https://msdn.microsoft.com/library/dd642331(v=vs.110).aspx for further info on Lazy<T> class.
            _activationService = new Lazy <ActivationService>(CreateActivationService);

            // register our configuration service and initialize it
            SimpleIoc.Default.Register <ConfigurationService>();
            ConfigurationService configurationService = (ConfigurationService)SimpleIoc.Default.GetInstance <ConfigurationService>();

            if (null != configurationService)
            {
                // run this synchronously
                AsyncHelper.RunSync(() => configurationService.Initialize());
            }

            // register our localization service and initialize it
            SimpleIoc.Default.Register <LocalizationService>();
            LocalizationService localizationService = (LocalizationService)SimpleIoc.Default.GetInstance <LocalizationService>();

            if (null != localizationService)
            {
                // async here might lead to a race condition, but no signs so far
                //localizationService.Initialize();
                AsyncHelper.RunSync(() => localizationService.Initialize());
            }

            // initialize the telemetry service
            SimpleIoc.Default.Register <TelemetryService>();
            TelemetryService telemetryService = (TelemetryService)SimpleIoc.Default.GetInstance <TelemetryService>();

            if (null != telemetryService)
            {
                if (null != configurationService)
                {
                    // DO NOT try to run this asynchronously; MetroLog hangs when invoked async
                    //AsyncHelper.RunSync(() => telemetryService.Initialize(configurationService.Configuration.TelemetryKey));
                    telemetryService.Initialize(configurationService.Configuration.IsTelemetryEnabled,
                                                configurationService.Configuration.TelemetryKey);

                    // log app start
                    TelemetryService.Current?.LogTelemetryEvent(TelemetryEvents.StartApplication);
                }
            }
        }
Пример #3
0
        protected override void OnStartup(StartupEventArgs eventArgs)
        {
            base.OnStartup(eventArgs);

            TelemetryService.Initialize();
            TelemetryService.PublishUsage(Environment.MachineName, GetAppAssemblyVersion(), "OnStartup", Phase.Start);

            log4net.Config.XmlConfigurator.Configure();

            Uri uri = new Uri("_Resources/Icons.xaml", UriKind.Relative);
            ResourceDictionary dict = new ResourceDictionary {
                Source = uri
            };

            var mainView       = new MainView();
            var messageService = new MessageService(mainView);

            _appInstaller = new Installer(messageService);

            var toolbar         = new ToolbarViewModel();
            var profileManager  = new UserProfileManager();
            var activityManager = new InactiveTransactionsManager();
            var categoriesMap   = new CategoriesViewModel();
            var dataLoader      = new DataLoader(profileManager);

            var dateStateVm   = new DateStateViewModel();
            var auditor       = new Auditor(dataLoader, dateStateVm);
            var newAccountVm  = new NewAccountViewModel(dataLoader);
            var newCategoryVm = new NewCategoryViewModel();

            var accountsVm = new AccountsViewModel(dataLoader, auditor, dateStateVm);
            var incomeVm   = new IncomeViewModel(dataLoader, auditor, dateStateVm);
            var expensesVm = new ExpensesViewModel(dataLoader, auditor, dateStateVm, categoriesMap);
            var budgetVm   = new BudgetViewModel(dataLoader, auditor, dateStateVm, categoriesMap);

            var analysisVm = new AnalysisViewModel();
            var settingsVm = new SettingsViewModel();
            var mainVm     = new MainViewModel(dataLoader, toolbar, accountsVm, newAccountVm, newCategoryVm, budgetVm, dateStateVm);

            toolbar.Items.Add(new ToolboxItemViewModel("Accounts", dict["appbar_layer"] as Canvas, accountsVm, mainVm, true));
            toolbar.Items.Add(new ToolboxItemViewModel("Income", dict["appbar_graph_line_up"] as Canvas, incomeVm, mainVm));
            toolbar.Items.Add(new ToolboxItemViewModel("Expenses", dict["appbar_graph_line_down"] as Canvas, expensesVm, mainVm));
            toolbar.Items.Add(new ToolboxItemViewModel("Budget", dict["appbar_billing"] as Canvas, budgetVm, mainVm));
            toolbar.Items.Add(new ToolboxItemViewModel("Analysis", dict["appbar_graph_bar"] as Canvas, analysisVm, mainVm));
            toolbar.Items.Add(new ToolboxItemViewModel("Settings", dict["appbar_settings"] as Canvas, settingsVm, mainVm));

            mainView.DataContext = mainVm;
            mainView.Show();
            mainView.Closing += (s, e) =>
            {
                mainVm.Dispose();
                accountsVm.Dispose();
                expensesVm.Dispose();
                activityManager.Dispose();

                TelemetryService.PublishUsage(Environment.MachineName, GetAppAssemblyVersion(), "Closing", Phase.End);
            };

            dataLoader.LoadAsync();

            TelemetryService.PublishUsage(Environment.MachineName, GetAppAssemblyVersion(), "OnStartup", Phase.End);
        }