예제 #1
0
        /// <summary>
        ///     Invoked when the application is launched normally by the end user.  Other entry points
        ///     will be used when the application is launched to open a specific file, to display
        ///     search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            ToastNotificationLaunchArguments launchArg = null;

            if (args.Arguments != null && args.Arguments != String.Empty)
            {
                launchArg = ToastNotificationLaunchArguments.FromXmlString(args.Arguments);
            }

            if (args.PreviousExecutionState == ApplicationExecutionState.Running ||
                args.PreviousExecutionState == ApplicationExecutionState.Suspended)
            {
                Resume();
                ProcessLaunchArgument(launchArg);

                return;
            }

            await AvatarLink.ExpandAvatarsToLocal();

            Container.RegisterInstance(CoreApplication.MainView.CoreWindow.Dispatcher);

            Container
            .RegisterType <ISignalingSocketChannel, SignalingSocketChannel>(new ContainerControlledLifetimeManager())
            .RegisterType <ISignalingSocketOperation, SignalingSocketOperation>(new ContainerControlledLifetimeManager())
            .RegisterType <ISignalingSocketService, SignalingSocketService>(new ContainerControlledLifetimeManager())
            .RegisterType <SignalingClient>(new ContainerControlledLifetimeManager())
            .RegisterType <IVideoRenderHelper, VideoRenderHelper>()
            .RegisterType <IForegroundChannel, ForegroundSignalingUpdateService>(new ContainerControlledLifetimeManager())
            .RegisterType <IForegroundUpdateService, ForegroundSignalingUpdateService>(new ContainerControlledLifetimeManager())
            .RegisterType <IClientChannel, ClientChannel>(new ContainerControlledLifetimeManager())
            .RegisterType <IVoipCoordinator, VoipCoordinator>()
            .RegisterType <IHub, Voip.Hub>(new ContainerControlledLifetimeManager())
            .RegisterType <VoipContext>(new ContainerControlledLifetimeManager())
            .RegisterType <IVoipChannel, VoipChannel>(new ContainerControlledLifetimeManager())
            .RegisterType <ISocketConnection, SocketConnection>(new ContainerControlledLifetimeManager())
            .RegisterType <NtpService>(new ContainerControlledLifetimeManager())
            .RegisterType <IMediaSettingsChannel, MediaSettingsChannel>()
            .RegisterType <SettingsViewModel>(new ContainerControlledLifetimeManager())
            .RegisterInstance <MainViewModel>(Container.Resolve <MainViewModel>(), new ContainerControlledLifetimeManager());

            Container.Resolve <SettingsViewModel>().OnQuitApp -= QuitApp;
            Container.Resolve <SettingsViewModel>().OnQuitApp += QuitApp;

            var 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();

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored or there are launch arguments
                // indicating an alternate launch (e.g.: via toast or secondary tile),
                // navigate to the appropriate page, configuring the new page by passing required
                // information as a navigation parameter
                if (!rootFrame.Navigate(typeof(MainView), Container.Resolve <MainViewModel>()))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            // Avoid showing two dialogs in a short time or overlapping
            // otherwise an Access Denied exception is thrown.
            bool _isMessageForLockScreenShowed = false;
            var  currentStatus = BackgroundExecutionManager.GetAccessStatus();

            if (currentStatus == BackgroundAccessStatus.Unspecified ||
                currentStatus == BackgroundAccessStatus.Denied)
            {
                _isMessageForLockScreenShowed = true;
                ShowMessageForMissingLockScreen();
            }
            else
            {
                await RegisterForPush();
            }

            Container.Resolve <IMediaSettingsChannel>().RequestAccessForMediaCaptureAsync().AsTask().ContinueWith((d) =>
            {
                if (!d.Result && !_isMessageForLockScreenShowed)
                {
                    ShowMessageForMissingAccess();
                }
            });

            ProcessLaunchArgument(launchArg);
            // Ensure the current window is active
            Window.Current.Activate();
        }
예제 #2
0
        /// <summary>
        ///     Invoked when the application is launched normally by the end user.  Other entry points
        ///     will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            ToastNotificationLaunchArguments launchArg = null;

            //TODO: Find out why e.Kind is ActivationKind.Launch even when app is lauched by clicking a toast notification
            //if ((e.Kind == ActivationKind.ToastNotification) && (!string.IsNullOrEmpty(e.Arguments)))
            if ((!string.IsNullOrEmpty(e.Arguments)))
            {
                launchArg = ToastNotificationLaunchArguments.FromXmlString(e.Arguments);
            }
            if (e.PreviousExecutionState == ApplicationExecutionState.Running)
            {
                ProcessLaunchArgument(launchArg);
                return;
            }
            if (e.PreviousExecutionState == ApplicationExecutionState.Suspended)
            {
                Resume();
                ProcessLaunchArgument(launchArg);
                return;
            }

            await AvatarLink.ExpandAvatarsToLocal();

            //Register IoC types
            if (!Container.IsRegistered <HubClient>())
            {
                Container.RegisterInstance(CoreApplication.MainView.CoreWindow.Dispatcher);
                Container.RegisterType <TaskHelper>(new ContainerControlledLifetimeManager());
                Container.RegisterType <HubClient>(new ContainerControlledLifetimeManager());
                Container.RegisterInstance <IForegroundUpdateService>(Container.Resolve <HubClient>(), new ContainerControlledLifetimeManager());
                Container.RegisterInstance <IForegroundChannel>(Container.Resolve <HubClient>(), new ContainerControlledLifetimeManager());
                Container.RegisterInstance <ISignalingSocketChannel>(Container.Resolve <HubClient>(), new ContainerControlledLifetimeManager());
                Container.RegisterInstance <IClientChannel>(Container.Resolve <HubClient>(), new ContainerControlledLifetimeManager());
                Container.RegisterInstance <IVoipChannel>(Container.Resolve <HubClient>(), new ContainerControlledLifetimeManager());
                Container.RegisterInstance <IMediaSettingsChannel>(Container.Resolve <HubClient>(), new ContainerControlledLifetimeManager());
                Container.RegisterType <ISocketConnection, SocketConnection>(new ContainerControlledLifetimeManager());
                Container.RegisterType <NtpService>(new ContainerControlledLifetimeManager());
                Container.RegisterType <MainViewModel>(new ContainerControlledLifetimeManager());
                Container.RegisterType <SettingsViewModel>(new ContainerControlledLifetimeManager());
            }

            Container.Resolve <HubClient>().OnDisconnectedFromHub -= App_OnDisconnectedFromHub;
            Container.Resolve <HubClient>().OnDisconnectedFromHub += App_OnDisconnectedFromHub;
            Container.Resolve <SettingsViewModel>().OnQuitApp     -= QuitApp;
            Container.Resolve <SettingsViewModel>().OnQuitApp     += QuitApp;

            ConnectHubClient();

            await RegisterForPush(Container.Resolve <TaskHelper>());

            var signalingTask = await RegisterSignalingTask(Container.Resolve <TaskHelper>(), false);

            if (signalingTask == null)
            {
                var message = new MessageDialog("The signaling task is required.");
                await message.ShowAsync();

                return;
            }

            await RegisterSessionConnectedTask(Container.Resolve <TaskHelper>());

            var rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

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

            if (rootFrame.Content == null)
            {
                // 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(typeof(MainView), Container.Resolve <MainViewModel>());
            }

            ProcessLaunchArgument(launchArg);

            // Ensure the current window is active
            Window.Current.Activate();
        }