Beispiel #1
0
        /// <summary>
        ///     This is the main class for this app. This function is the first function
        ///     called and it setups the app analytic (If in release mode), components,
        ///     requested theme and event handlers.
        /// </summary>
        public App()
        {
            // Init XAML Resources
            InitializeComponent();

            // We want to use the controler if on xbox
            if (DeviceHelper.IsXbox)
            {
                RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
            }

            // Check that we are not using the default theme,
            // if not change the requested theme to the users
            // picked theme.
            if (!SettingsService.Instance.IsDefaultTheme)
            {
                RequestedTheme = SettingsService.Instance.ThemeType;
            }

            // Registor the dialogs
            NavigationService.Current.RegisterTypeAsDialog <CrashDialog>();
            NavigationService.Current.RegisterTypeAsDialog <FilterDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PendingUpdateDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PinTileDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PlaylistDialog>();
            NavigationService.Current.RegisterTypeAsDialog <ShareDialog>();

            // Init Keys
            ApiKeyService.Init();

            // Handle App Crashes
            CrashHelper.HandleAppCrashes(Current);

            // Enter and Leaving background handlers
            EnteredBackground += AppEnteredBackground;
            LeavingBackground += AppLeavingBackground;

            // During the transition from foreground to background the
            // memory limit allowed for the application changes. The application
            // has a short time to respond by bringing its memory usage
            // under the new limit.
            MemoryManager.AppMemoryUsageLimitChanging += MemoryManager_AppMemoryUsageLimitChanging;

            // After an application is backgrounded it is expected to stay
            // under a memory target to maintain priority to keep running.
            // Subscribe to the event that informs the app of this change.
            MemoryManager.AppMemoryUsageIncreased += MemoryManager_AppMemoryUsageIncreased;
        }
Beispiel #2
0
        /// <summary>
        ///     This is the main class for this app. This function is the first function
        ///     called and it setups the app analytic (If in release mode), components,
        ///     requested theme and event handlers.
        /// </summary>
        public App()
        {
            // Init XAML Resources
            InitializeComponent();

            // We want to use the controler if on xbox
            if (DeviceHelper.IsXbox)
            {
                RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
            }

            // Check that we are not using the default theme,
            // if not change the requested theme to the users
            // picked theme.
            if (!SettingsService.Instance.IsDefaultTheme)
            {
                RequestedTheme = SettingsService.Instance.ThemeType;
            }

            // Registor the dialogs
            NavigationService.Current.RegisterTypeAsDialog <CrashDialog>();
            NavigationService.Current.RegisterTypeAsDialog <SearchDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PendingUpdateDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PinTileDialog>();
            NavigationService.Current.RegisterTypeAsDialog <PlaylistDialog>();
            NavigationService.Current.RegisterTypeAsDialog <ShareDialog>();

            // Init Keys
            ApiKeyService.Init();

            // Live tile helpers
            TileHelper.Init();

            // Init service
            InitV3Service();

            // Handle App Crashes
            CrashHelper.HandleAppCrashes(Current);

            // Migrate and database changes
            using (var db = new HistoryContext())
            {
                db.Database.Migrate();
            }

            // Enter and Leaving background handlers
            EnteredBackground += AppEnteredBackground;
            LeavingBackground += AppLeavingBackground;

            // During the transition from foreground to background the
            // memory limit allowed for the application changes. The application
            // has a short time to respond by bringing its memory usage
            // under the new limit.
            MemoryManager.AppMemoryUsageLimitChanging += MemoryManager_AppMemoryUsageLimitChanging;

            // After an application is backgrounded it is expected to stay
            // under a memory target to maintain priority to keep running.
            // Subscribe to the event that informs the app of this change.
            MemoryManager.AppMemoryUsageIncreased += MemoryManager_AppMemoryUsageIncreased;

            // Run this code when a service is connected to SoundByte
            SoundByteV3Service.Current.OnServiceConnected += (type, token) =>
            {
                var vault = new PasswordVault();

                // Add the password to the vault so we can access it when restarting the app
                switch (type)
                {
                case ServiceType.SoundCloud:
                case ServiceType.SoundCloudV2:
                    vault.Add(new PasswordCredential("SoundByte.SoundCloud", "Token", token.AccessToken));
                    vault.Add(new PasswordCredential("SoundByte.SoundCloud", "Scope", token.Scope));
                    break;

                case ServiceType.Fanburst:
                    vault.Add(new PasswordCredential("SoundByte.FanBurst", "Token", token.AccessToken));
                    break;

                case ServiceType.YouTube:
                    vault.Add(new PasswordCredential("SoundByte.YouTube", "Token", token.AccessToken));
                    break;
                }

                // Track the connect event
                TelemetryService.Instance.TrackEvent("Service Connected",
                                                     new Dictionary <string, string>
                {
                    { "Service", type.ToString() }
                });

                // Navigate home if we connected SoundCloud, else navigate to explore
                NavigateTo(type == ServiceType.SoundCloud ? typeof(HomeView) : typeof(ExploreView));
            };

            // Run this code when a service is disconencted from SoundByte
            SoundByteV3Service.Current.OnServiceDisconnected += type =>
            {
                // Get the password vault
                var vault = new PasswordVault();

                // Delte the vault depending on the service type
                switch (type)
                {
                case ServiceType.SoundCloud:
                case ServiceType.SoundCloudV2:
                    vault.FindAllByResource("SoundByte.SoundCloud").ForEach(x => vault.Remove(x));
                    break;

                case ServiceType.Fanburst:
                    vault.FindAllByResource("SoundByte.FanBurst").ForEach(x => vault.Remove(x));
                    break;

                case ServiceType.YouTube:
                    vault.FindAllByResource("SoundByte.YouTube").ForEach(x => vault.Remove(x));
                    break;
                }

                // Track the disconnect event
                TelemetryService.Instance.TrackEvent("Service Disconnected",
                                                     new Dictionary <string, string>
                {
                    { "Service", type.ToString() }
                });

                // Navigate to the explore view
                NavigateTo(typeof(ExploreView));
            };
        }