Exemplo n.º 1
0
        public async Task SetupAsync()
        {
            if (!this.isBackgroundSyncEnabled)
            {
                return;
            }

            var cryptoService   = Ioc.RegisterInstance <ICryptoService, WinCryptoService>(new WinCryptoService());
            var vercorsService  = new VercorsService();
            var platformService = new PlatformService(
                ApplicationVersion.GetAppVersion(),
                this.workbook.Settings.GetValue <string>(CoreSettings.DeviceId),
                () => string.Empty);

            this.synchronizationManager = new SynchronizationManager(platformService, this.trackingManager, "win", true);

            Ioc.RegisterInstance <ISynchronizationManager, SynchronizationManager>(this.synchronizationManager);

            await SynchronizationManagerBootstraper.InitializeAsync(this.workbook, this.synchronizationManager, cryptoService, vercorsService, true);
        }
Exemplo n.º 2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;

            if (details != null && !string.IsNullOrWhiteSpace(details.Argument))
            {
                var persistenceLayer = new WinPersistenceLayer(automaticSave: false);
                var workbook         = persistenceLayer.Open(tryUpgrade: true);
                workbook.Initialize();

                var platformService = new PlatformService(
                    ApplicationVersion.GetAppVersion(),
                    workbook.Settings.GetValue <string>(CoreSettings.DeviceId),
                    () => string.Empty);

                // important: load alarm manager so that we update reminders properly is a recurring task is created
                var alarmManager = new AlarmManager(workbook);

                LaunchArgumentDescriptor descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(workbook, details.Argument);
                if (descriptor.Task != null && descriptor.Type == LaunchArgumentType.CompleteTask)
                {
                    descriptor.Task.IsCompleted = true;
                    persistenceLayer.Save();

                    UpdateSyncMetadata(workbook, platformService, descriptor);

                    var tileManager = new TileManager(workbook, new TrackingManager(false, DeviceFamily.Unkown), null, true);
                    tileManager.LoadSecondaryTilesAsync().Wait(500);
                    tileManager.UpdateTiles();

                    // signal changes (usefull if app is currently running)
                    waitHandle.Set();
                }
            }

            taskInstance.GetDeferral().Complete();
        }
Exemplo n.º 3
0
        public override async Task <IWorkbook> ConfigureAsync(Frame rootFrame)
        {
            if (rootFrame == null)
            {
                throw new ArgumentNullException(nameof(rootFrame));
            }

            bool sendAnalytics = WinSettings.Instance.GetValue <bool>(CoreSettings.SendAnalytics);

            string deviceId = "n/a";

            try
            {
                var settings = WinSettings.Instance;
                if (!settings.HasValue(CoreSettings.DeviceId) || settings.GetValue <string>(CoreSettings.DeviceId) == "N/A")
                {
                    string id = this.ComputeDeviceId();
                    settings.SetValue(CoreSettings.DeviceId, id);
                }

                deviceId = settings.GetValue <string>(CoreSettings.DeviceId);
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, "Error while setting device id");
            }

            var platformService = new PlatformService(this.version, deviceId, () => CrashHandler.GetDiagnosticsInformation());

            Ioc.RegisterInstance <IPlatformService, PlatformService>(platformService);

            TrackingManager trackingManager = new TrackingManager(sendAnalytics, platformService.DeviceFamily);

            Ioc.RegisterInstance <ITrackingManager, TrackingManager>(trackingManager);

            HttpClientHandler.Setup();

            ResourcesLocator.Initialize("ms-appx://", UriKind.Absolute);
            if (!WinSettings.Instance.GetValue <bool>(CoreSettings.UseDarkTheme))
            {
                ResourcesLocator.UpdateTheme(true);
            }

            var persistence = Ioc.RegisterInstance <IPersistenceLayer, WinPersistenceLayer>(new WinPersistenceLayer(automaticSave: true));

            LogService.Log("Bootstraper", string.Format("Version: {0}", ApplicationVersion.GetAppVersion()));

            var navigationService = new NavigationService(rootFrame, platformService);

            Ioc.RegisterInstance <INavigationService, NavigationService>(navigationService);

            var messageBoxService = new MessageBoxService(navigationService);

            Ioc.RegisterInstance <IMessageBoxService, MessageBoxService>(messageBoxService);

            Ioc.RegisterInstance <ISpeechService, SpeechService>(new SpeechService(messageBoxService));

            var workbook = this.InitializeWorkbook(persistence, platformService);

            // we just read the latest value of data from the DB, so even if there was a background sync
            // we now have the latest version, so we remove the background sync flag here
            workbook.Settings.SetValue(CoreSettings.SyncBackgroundOccured, false);

            this.keyboardShortcutManager = new KeyboardShortcutManager(workbook, rootFrame, navigationService, trackingManager);

            var backgroundTaskManager = new BackgroundTaskManager(workbook);

            backgroundTaskManager.InitializeAsync();
            Ioc.RegisterInstance <IBackgroundTaskManager, BackgroundTaskManager>(backgroundTaskManager);

            var notificationService = new NotificationService();

            Ioc.RegisterInstance <INotificationService, NotificationService>(notificationService);

            var startupManager = Ioc.Build <StartupManager>();

            Ioc.RegisterInstance <IStartupManager, StartupManager>(startupManager);

            Ioc.RegisterInstance <IAlarmManager, AlarmManager>(new AlarmManager(workbook));

            var tileManager = new TileManager(workbook, trackingManager, notificationService, false);

            tileManager.LoadSecondaryTilesAsync();
            Ioc.RegisterInstance <ITileManager, TileManager>(tileManager);

            var synchronizationManager = await InitializeSyncAsync(workbook, platformService, trackingManager);

            // it is important to remove old task after sync is initialized otherwise changes would not
            // tracked and put in the changelog for the next sync
            workbook.RemoveOldTasks();

            var cortanaService = new CortanaRuntimeService(workbook);

            // no need to await this call because it can runs in the background
            Task.Run(() =>
            {
                JumpListManager.SetupJumpListAsync();
                cortanaService.SetupDefinitionsAsync();
            });
            Ioc.RegisterInstance <ICortanaRuntimeService, CortanaRuntimeService>(cortanaService);

            return(workbook);
        }
Exemplo n.º 4
0
        private async Task BootstrapFrame(LaunchActivatedEventArgs launchActivatedEventArgs, IActivatedEventArgs activatedEventArgs, string addTaskTitle = null)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                try
                {
                    ApplicationView appView = ApplicationView.GetForCurrentView();
                    this.mainview = appView;
                    SetupTitleBar(appView);
                    SetupStatusBar(appColor);

                    appView.SetPreferredMinSize(new Size(Constants.AppMinWidth, Constants.AppMinHeight));

                    this.bootstraper = new Bootstraper(ApplicationVersion.GetAppVersion());

                    InitializeViewLocator();

                    await this.bootstraper.ConfigureAsync(rootFrame);

                    this.navigationService = Ioc.Resolve <INavigationService>();
                    this.platformService   = Ioc.Resolve <IPlatformService>();

                    this.suspensionManager = new SuspensionManager(Ioc.Resolve <IPersistenceLayer>(), Ioc.Resolve <ISynchronizationManager>(), Ioc.Resolve <ITileManager>());

                    rootFrame.Navigated        += this.OnNavigated;
                    rootFrame.NavigationFailed += this.OnNavigationFailed;

                    // Place the frame in the current Window
                    Window.Current.Content = rootFrame;

                    if (rootFrame.Content == null)
                    {
                        Type   startupPage         = typeof(MainPage);
                        object navigationParameter = launchActivatedEventArgs?.Arguments;

                        var startupManager = Ioc.Resolve <IStartupManager>();
                        if (startupManager.IsFirstLaunch)
                        {
                            startupPage = typeof(WelcomePage);
                        }
                        else if (!String.IsNullOrWhiteSpace(addTaskTitle))
                        {
                            startupPage         = typeof(WelcomePage);
                            navigationParameter = new TaskCreationParameters {
                                Title = addTaskTitle
                            };
                        }

                        SystemNavigationManager.GetForCurrentView().BackRequested += this.OnBackRequested;
                        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = rootFrame.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
                        Window.Current.VisibilityChanged += this.OnVisibilityChanged;

                        // When the navigation stack isn't restored navigate to the first page,
                        // configuring the new page by passing required information as a navigation parameter
                        rootFrame.Navigate(startupPage, navigationParameter);
                    }

                    if (launchActivatedEventArgs != null)
                    {
                        LauncherHelper.TryHandleArgs(launchActivatedEventArgs.Arguments);
                    }
                    else if (activatedEventArgs != null)
                    {
                        LauncherHelper.TryHandleArgs(activatedEventArgs);
                    }

                    // Ensure the current window is active
                    Window.Current.Activate();
                }
                catch (Exception ex)
                {
                    var messageBoxService = new MessageBoxService(new NavigationService(rootFrame));
                    await messageBoxService.ShowAsync("Error", "2Day was unable to start please send a screenshot of this page to the development team. Details: " + ex);

                    DeviceFamily deviceFamily = DeviceFamily.Unkown;
                    if (this.platformService != null)
                    {
                        deviceFamily = this.platformService.DeviceFamily;
                    }

                    var trackingManager = new TrackingManager(true, deviceFamily);
                    trackingManager.Exception(ex, "Bootstrap", true);
                }
            }
            else
            {
                if (launchActivatedEventArgs != null)
                {
                    LauncherHelper.TryHandleArgs(launchActivatedEventArgs.Arguments);
                }
                else if (activatedEventArgs != null)
                {
                    LauncherHelper.TryHandleArgs(activatedEventArgs);
                }
            }
        }
Exemplo n.º 5
0
        public static string GetDiagnosticsInformation(string page = null)
        {
            IPlatformService platformService = Ioc.Resolve <IPlatformService>();

            DateTime now = DateTime.Now;

            if (page == null)
            {
                try
                {
                    var frame = Window.Current.Content as Frame;
                    if (frame != null && frame.Content != null)
                    {
                        page = frame.Content.GetType().Name;
                    }
                }
                catch (Exception)
                {
                }
            }

            string installDate          = string.Empty;
            string backgroundLastStatus = string.Empty;
            string backgroundLastStart  = string.Empty;
            string backgroundLastEnd    = string.Empty;
            string backgroundAccess     = string.Empty;
            string backgroundSync       = string.Empty;

            try
            {
                installDate          = WinSettings.Instance.GetValue <DateTime>(CoreSettings.InstallDateTime).ToString("G");
                backgroundLastStatus = WinSettings.Instance.GetValue <BackgroundExecutionStatus>(CoreSettings.BackgroundLastStatus).ToString();
                backgroundLastStart  = WinSettings.Instance.GetValue <DateTime>(CoreSettings.BackgroundLastStartExecution).ToString("G");
                backgroundLastEnd    = WinSettings.Instance.GetValue <DateTime>(CoreSettings.BackgroundLastEndExecution).ToString("G");
                backgroundAccess     = WinSettings.Instance.GetValue <bool>(CoreSettings.BackgroundAccess).ToString();
                backgroundSync       = WinSettings.Instance.GetValue <bool>(CoreSettings.BackgroundSync).ToString();
            }
            catch (Exception)
            {
            }

            var builder = new StringBuilder();

            builder.AppendLine($"Version: {ApplicationVersion.GetAppVersion()}");
            builder.AppendLine($"Windows: {platformService.WindowsVersion}");
            builder.AppendLine($"Platform: {GetDeviceInfo()}");
            builder.AppendLine($"Resolution: {GetScreenResolution()}");
            builder.AppendLine($"Orientation: {GetScreenOrientation()}");
            builder.AppendLine($"Page: {page}");
            builder.AppendLine($"Crash date: {now.ToString("G")}");
            builder.AppendLine($"Install date: {installDate}");
            builder.AppendLine($"Background enabled: {backgroundAccess}");
            builder.AppendLine($"Background sync: {backgroundSync}");
            builder.AppendLine($"Background status: {backgroundLastStatus}");
            builder.AppendLine($"Background start: {backgroundLastStart}");
            builder.AppendLine($"Background end: {backgroundLastEnd}");

            if (Ioc.HasType <IStartupManager>())
            {
                var startupManager = Ioc.Resolve <IStartupManager>();
                builder.AppendLine($"Uptime: {startupManager.Uptime}");
            }

            builder.AppendLine($"Culture: {CultureInfo.CurrentUICulture}");
            builder.AppendLine($"Timezone: {TimeZoneInfo.Local}");

            builder.AppendLine($"DeviceId: {platformService.DeviceId}");
            builder.AppendLine($"DeviceFamily: {platformService.DeviceFamily}");

            try
            {
                if (Ioc.HasType <ISynchronizationManager>() && Ioc.HasType <IWorkbook>())
                {
                    var synchronizationManager = Ioc.Resolve <ISynchronizationManager>();
                    var workbook = Ioc.Resolve <IWorkbook>();

                    builder.AppendLine(string.Format("Ordering1: {0} {1}", workbook.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType1), workbook.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending1)));
                    builder.AppendLine(string.Format("Ordering2: {0} {1}", workbook.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType2), workbook.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending2)));
                    builder.AppendLine(string.Format("Ordering3: {0} {1}", workbook.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType3), workbook.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending3)));
                    builder.AppendLine();
                    builder.AppendLine(string.Format("Sync provider: {0}", synchronizationManager.ActiveService));
                    builder.AppendLine(string.Format("Last sync: {0}", synchronizationManager.Metadata != null ? synchronizationManager.Metadata.LastSync.ToString("G") : "N/A"));
                    builder.AppendLine(string.Format("Sync in progress {0}", synchronizationManager.IsSyncRunning));
                    builder.AppendLine(string.Format("Sync at startup: {0}", workbook.Settings.GetValue <bool>(CoreSettings.SyncOnStartup).ToString()));
                    builder.AppendLine(string.Format("Sync auto: {0}", workbook.Settings.GetValue <bool>(CoreSettings.SyncAutomatic).ToString()));
                    builder.AppendLine(string.Format("Sync background: {0}", workbook.Settings.GetValue <bool>(CoreSettings.BackgroundSync).ToString()));
                    builder.AppendLine(string.Format("Sync user id: {0}", workbook.Settings.GetValue <string>(CoreSettings.SyncUserId)));

                    if (workbook.Settings.GetValue <string>(ExchangeSettings.ActiveSyncServerUri) != null)
                    {
                        builder.AppendLine(string.Format("Active Sync Server uri: {0}", workbook.Settings.GetValue <string>(ExchangeSettings.ActiveSyncServerUri)));
                    }
                    if (workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeServerUri) != null)
                    {
                        builder.AppendLine(string.Format("Exchange Server uri: {0}", workbook.Settings.GetValue <string>(ExchangeSettings.ExchangeServerUri)));
                    }
                }
                else
                {
                    builder.Append("No synchronization manager available");
                }
            }
            catch (Exception e)
            {
                builder.AppendLine($"Error while getting additional info ({e})");
            }

            builder.AppendLine();

            return(builder.ToString());
        }