コード例 #1
0
        private async void OnOpen()
        {
            _viewControl = await WindowManagerService.Current.TryShowAsViewModeAsync(SecondaryViewTitle, typeof(VideoPage), ApplicationViewMode.CompactOverlay);

            _viewControl.Released += _viewControl_Released;
            OpenCommand.OnCanExecuteChanged();
        }
コード例 #2
0
        public GalleryCompactView(IEventAggregator aggregator, ViewLifetimeControl lifetime, MediaPlayer player, RemoteFileStream fileStream)
        {
            _aggregator = aggregator;
            _lifetime   = lifetime;

            _mediaPlayer = player;
            _fileStream  = fileStream;

            _aggregator.Subscribe(this);

            RequestedTheme    = ElementTheme.Dark;
            TransportControls = new MediaTransportControls
            {
                IsCompact = true,
                IsCompactOverlayButtonVisible = false,
                IsFastForwardButtonVisible    = false,
                IsFastRewindButtonVisible     = false,
                IsFullWindowButtonVisible     = false,
                IsNextTrackButtonVisible      = false,
                IsPlaybackRateButtonVisible   = false,
                IsPreviousTrackButtonVisible  = false,
                IsRepeatButtonVisible         = false,
                IsSkipBackwardButtonVisible   = false,
                IsSkipForwardButtonVisible    = false,
                IsVolumeButtonVisible         = false,
                IsStopButtonVisible           = false,
                IsZoomButtonVisible           = false,
            };
            AreTransportControlsEnabled = true;

            SetMediaPlayer(player);

            lifetime.Closed   += OnReleased;
            lifetime.Released += OnReleased;
        }
コード例 #3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var param = e.Parameter as OpenNewViewParameterModel;

            _thisViewControl = param.NewView;
            _mainViewId      = ((App)App.Current).MainViewId;
            _mainDispatcher  = ((App)App.Current).MainDispatcher;

            _threadId      = param.ThreadId;
            RequestedTheme = param.ElementTheme;

            _replyViewModel = new ReplyListPageViewModel(
                1,
                _threadId,
                0,
                ReplyListView,
                () => {
                rightProgress.IsActive       = true;
                rightProgress.Visibility     = Visibility.Visible;
                ReplyRefreshButton.IsEnabled = false;
            },
                (tid, pageNo) => {
                rightProgress.IsActive       = false;
                rightProgress.Visibility     = Visibility.Collapsed;
                ReplyRefreshButton.IsEnabled = true;
            });

            DataContext = _replyViewModel;

            // When this view is finally release, clean up state
            _thisViewControl.Released += ViewLifetimeControl_Released;
        }
コード例 #4
0
        public static async Task <ViewLifetimeControl> CreateInNewViewAsync(string seriesTitle, NovelPositionIdentifier nav)
        {
            ViewLifetimeControl viewControl = null;
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // This object is used to keep track of the views and important
                // details about the contents of those views across threads
                // In your app, you would probably want to track information
                // like the open document or page inside that window
                viewControl       = ViewLifetimeControl.CreateForCurrentView();
                viewControl.Title = seriesTitle;
                AppGlobal.SecondaryViews.Add(viewControl);

                var frame = new Frame();
                frame.Navigate(typeof(ReadingPage), nav.ToString());
                Window.Current.Content = frame;
                var readingPage        = frame.Content as ReadingPage;
                readingPage.OpenInNewViewButton.Visibility = Visibility.Collapsed;
                if (readingPage != null)
                {
                    viewControl.Released += readingPage.ViewControl_Released;
                }

                ApplicationView.GetForCurrentView().Title = viewControl.Title;
                //ApplicationView.GetForCurrentView().Consolidated += readingPage.ReadingPage_Consolidated;
                //viewControl.StartViewInUse();
            });

            return(viewControl);
        }
コード例 #5
0
        private async void CreateView_Click(object sender, RoutedEventArgs e)
        {
            // Set up the secondary view, but don't show it yet
            ViewLifetimeControl viewControl = null;
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // This object is used to keep track of the views and important
                // details about the contents of those views across threads
                // In your app, you would probably want to track information
                // like the open document or page inside that window
                viewControl       = ViewLifetimeControl.CreateForCurrentView();
                viewControl.Title = DEFAULT_TITLE;
                // Increment the ref count because we just created the view and we have a reference to it
                viewControl.StartViewInUse();

                var frame = new Frame();
                frame.Navigate(typeof(SecondaryViewPage), viewControl);
                Window.Current.Content = frame;
                // This is a change from 8.1: In order for the view to be displayed later it needs to be activated.
                Window.Current.Activate();
                ApplicationView.GetForCurrentView().Title = viewControl.Title;
            });

            // Be careful! This collection is bound to the current thread,
            // so make sure to update it only from this thread
            ((App)App.Current).SecondaryViews.Add(viewControl);
        }
コード例 #6
0
        private async void Show(Call call, VoIPControllerWrapper controller, DateTime started)
        {
            if (_callPage == null)
            {
                if (ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay))
                {
                    _callLifetime = await _viewService.OpenAsync(() => _callPage = _callPage ?? new VoIPPage(ProtoService, CacheService, Aggregator, _call, _controller, _callStarted), call.Id);

                    _callLifetime.WindowWrapper.ApplicationView().Consolidated -= ApplicationView_Consolidated;
                    _callLifetime.WindowWrapper.ApplicationView().Consolidated += ApplicationView_Consolidated;
                }
                else
                {
                    _callPage = new VoIPPage(ProtoService, CacheService, Aggregator, _call, _controller, _callStarted);

                    _callDialog = new OverlayPage();
                    _callDialog.HorizontalAlignment = HorizontalAlignment.Stretch;
                    _callDialog.VerticalAlignment   = VerticalAlignment.Stretch;
                    _callDialog.Content             = _callPage;
                    _callDialog.IsOpen = true;
                }

                Aggregator.Publish(new UpdateCallDialog(call, true));
            }

            await _callPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                if (controller != null)
                {
                    _callPage.Connect(controller);
                }

                _callPage.Update(call, started);
            });
        }
コード例 #7
0
        private async void Hide()
        {
            if (_callPage != null)
            {
                await _callPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    if (_callDialog != null)
                    {
                        _callDialog.IsOpen = false;
                        _callDialog        = null;
                    }
                    else if (_callLifetime != null)
                    {
                        _callLifetime.StopViewInUse();
                        _callLifetime.WindowWrapper.Window.Close();
                        _callLifetime = null;
                    }

                    _callPage.Dispose();
                    _callPage = null;
                });

                Aggregator.Publish(new UpdateCallDialog(_call, true));
            }
        }
コード例 #8
0
        private async Task <bool> ShowTask()
        {
            try
            {
                if (View == null)
                {
                    View = await ViewLifetimeControl.CreateForCurrentView();

                    bool status = true;

                    //on that view's thread, we need to assign the frame, activate it, and obtain its view ID
                    await View.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Frame frame = GenerateRootFrame();
                        if (frame == null)
                        {
                            status = false;
                            return;
                        }

                        Window.Current.Content = frame;

                        Window.Current.Activate();

                        // Prevent view from closing while switching to it
                        View.StartViewInUse();
                    });

                    if (!status)
                    {
                        return(false);
                    }

                    //then on the current (calling) thread, we can show the view
                    await ApplicationViewSwitcher.TryShowAsStandaloneAsync(View.Id);

                    // Signal that switching has completed, letting the view close
                    View.StopViewInUse();

                    //View.CoreWindow.CustomProperties[WINDOW_HOST_PROPERTY] = this;
                    return(true);
                }

                else
                {
                    await ApplicationViewSwitcher.SwitchAsync(View.Id);

                    return(true);
                }
            }

            finally
            {
                lock (this)
                {
                    _currShowTask = null;
                }
            }
        }
コード例 #9
0
        private async void DevicePicker_DeviceSelected(DevicePicker sender, DeviceSelectedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                // 更新 picker 上設備的 status
                sender.SetDisplayStatus(args.SelectedDevice, "connecting", DevicePickerDisplayStatusOptions.ShowProgress);

                // 取得目前選到設備的資訊
                activeDevice = args.SelectedDevice;

                // 現在 view 的 Id 與 CoreDispatcher
                int currentViewId = ApplicationView.GetForCurrentView().Id;
                CoreDispatcher currentDispatcher = Window.Current.Dispatcher;

                // 建立新的 view,
                if (projectionInstance.ProjectionViewPageControl == null)
                {
                    await CoreApplication.CreateNewView().Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        // 建立新 viewe 的生命管理器
                        projectionInstance.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();
                        projectionInstance.MainViewId = currentViewId;

                        var rootFrame = new Frame();
                        rootFrame.Navigate(typeof(ProjectionPage), projectionInstance);

                        // 這裏的 Window 代表是新建立這個 view 的 Window
                        // 但是要等到呼叫 ProjectionManager.StartProjectingAsync 才會顯示
                        Window.Current.Content = rootFrame;
                        Window.Current.Activate();
                    });
                }

                // 直接切換到指定的 view id
                //bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(projectionInstance.ProjectionViewPageControl.Id);

                // 通知要使用新的 view
                projectionInstance.ProjectionViewPageControl.StartViewInUse();

                try
                {
                    txtViewId.Text = $"{projectionInstance.ProjectionViewPageControl.Id}, {currentViewId}";
                    await ProjectionManager.StartProjectingAsync(projectionInstance.ProjectionViewPageControl.Id, currentViewId, activeDevice);

                    player.Pause();

                    sender.SetDisplayStatus(args.SelectedDevice, "connected", DevicePickerDisplayStatusOptions.ShowDisconnectButton);
                }
                catch (Exception ex)
                {
                    sender.SetDisplayStatus(args.SelectedDevice, ex.Message, DevicePickerDisplayStatusOptions.ShowRetryButton);
                    if (ProjectionManager.ProjectionDisplayAvailable == false)
                    {
                        throw;
                    }
                }
            });
        }
コード例 #10
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            thisViewControl = (ViewLifetimeControl)e.Parameter;
            mainViewId      = ((App)App.Current).MainViewId;
            mainDispatcher  = ((App)App.Current).MainDispatcher;

            // When this view is finally release, clean up state
            thisViewControl.Released += ViewLifetimeControl_Released;
        }
コード例 #11
0
        private void OnReleased(object sender, EventArgs e)
        {
            _lifetime.Closed   -= OnReleased;
            _lifetime.Released -= OnReleased;

            Current = null;

            Dispose();
        }
コード例 #12
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var parameter = e.Parameter as Tuple <Note, ViewLifetimeControl>;

            ViewModel.FillMyNote(parameter.Item1);
            _viewLifetimeControl           = parameter.Item2;
            _viewLifetimeControl.Released += OnViewLifetimeControlReleased;
        }
コード例 #13
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _viewLifetimeControl = e.Parameter as ViewLifetimeControl;
            RxTxStatusViewmodel.Initialize(_viewLifetimeControl);

            _viewLifetimeControl.Height = RxTxStatusViewmodel.ViewControlHeight;
            _viewLifetimeControl.Width  = RxTxStatusViewmodel.ViewControlWidth;
        }
コード例 #14
0
ファイル: MainPage.xaml.cs プロジェクト: ashjain/UWP
        private async void StartProjecting(DeviceInformation selectedDisplay)
        {
            // If projection is already in progress, then it could be shown on the monitor again
            // Otherwise, we need to create a new view to show the presentation
            if (this.ProjectionViewPageControl == null)
            {
                // First, create a new, blank view
                await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // ViewLifetimeControl is a wrapper to make sure the view is closed only
                    // when the app is done with it
                    this.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();

                    // Assemble some data necessary for the new page
                    var initData                       = new ProjectionViewPageInitializationData();
                    initData.MainDispatcher            = thisDispatcher;
                    initData.ProjectionViewPageControl = this.ProjectionViewPageControl;
                    initData.MainViewId                = thisViewId;

                    // Display the page in the view. Note that the view will not become visible
                    // until "StartProjectingAsync" is called
                    var rootFrame = new Frame();
                    rootFrame.Navigate(typeof(ProjectionViewPage), initData);
                    Window.Current.Content = rootFrame;

                    // The call to Window.Current.Activate is required starting in Windos 10.
                    // Without it, the view will never appear.
                    Window.Current.Activate();
                });
            }

            try
            {
                // Start/StopViewInUse are used to signal that the app is interacting with the
                // view, so it shouldn't be closed yet, even if the user loses access to it
                rootPage.ProjectionViewPageControl.StartViewInUse();

                // Show the view on a second display that was selected by the user
                if (selectedDisplay != null)
                {
                    await ProjectionManager.StartProjectingAsync(rootPage.ProjectionViewPageControl.Id, thisViewId, selectedDisplay);
                }
                else
                {
                    await ProjectionManager.StartProjectingAsync(rootPage.ProjectionViewPageControl.Id, thisViewId);
                }

                rootPage.ProjectionViewPageControl.StopViewInUse();
            }
            catch (InvalidOperationException)
            {
                System.Diagnostics.Debug.WriteLine("Start projection failed");
            }
        }
コード例 #15
0
        // Displays a view as a standalone
        // You can use the resulting ViewLifeTileControl to interact with the new window.
        public async Task <ViewLifetimeControl> TryShowAsStandaloneAsync(string windowTitle, Type pageType)
        {
            ViewLifetimeControl viewControl = await CreateViewLifetimeControlAsync(windowTitle, pageType);

            SecondaryViews.Add(viewControl);
            viewControl.StartViewInUse();
            await ApplicationViewSwitcher.TryShowAsStandaloneAsync(viewControl.Id, ViewSizePreference.Default, ApplicationView.GetForCurrentView().Id, ViewSizePreference.Default);

            viewControl.StopViewInUse();
            return(viewControl);
        }
コード例 #16
0
        // Displays a view in the specified view mode
        public async Task <ViewLifetimeControl> TryShowAsViewModeAsync(string windowTitle, Type pageType, ApplicationViewMode viewMode = ApplicationViewMode.Default)
        {
            ViewLifetimeControl viewControl = await CreateViewLifetimeControlAsync(windowTitle, pageType);

            SecondaryViews.Add(viewControl);
            viewControl.StartViewInUse();
            await ApplicationViewSwitcher.TryShowAsViewModeAsync(viewControl.Id, viewMode);

            viewControl.StopViewInUse();
            return(viewControl);
        }
コード例 #17
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var parameter = e.Parameter as Tuple <Note, ViewLifetimeControl, TextBox>;

            ViewModel.FillMyNote(parameter.Item1);
            _viewLifetimeControl           = parameter.Item2;
            parentBox                      = parameter.Item3;
            parentBox.TextChanged         += ParentBox_TextChanged;
            PipBox.TextChanged            += PipBox_TextChanged;
            _viewLifetimeControl.Released += OnViewLifetimeControlReleased;
        }
コード例 #18
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var initData = (ProjectionViewPageInitializationData)e.Parameter;

            // The ViewLifetimeControl is a convenient wrapper that ensures the
            // view is closed only when the user is done with it
            thisViewControl = initData.ProjectionViewPageControl;
            mainDispatcher  = initData.MainDispatcher;
            mainViewId      = initData.MainViewId;

            // Listen for when it's time to close this view
            thisViewControl.Released += thisViewControl_Released;
        }
コード例 #19
0
ファイル: VoIPService.cs プロジェクト: vipadm/Unigram
        public async void Show()
        {
            Show(_call, _controller);

            if (_callDialog != null)
            {
                _callDialog.IsOpen = true;
            }
            else if (_callLifetime != null)
            {
                _callLifetime = await _viewService.OpenAsync(() => _callPage = _callPage ?? new PhoneCallPage(ProtoService, CacheService, Aggregator, _call, _controller), 0);
            }
        }
コード例 #20
0
 // Loop through the collection to find the view ID
 // This should only be run on the main thread.
 bool TryFindViewLifetimeControlForViewId(int viewId, out ViewLifetimeControl foundData)
 {
     foreach (var ViewLifetimeControl in SecondaryViews)
     {
         if (ViewLifetimeControl.Id == viewId)
         {
             foundData = ViewLifetimeControl;
             return(true);
         }
     }
     foundData = null;
     return(false);
 }
コード例 #21
0
        private async void StartProjecting_Click(object sender, RoutedEventArgs e)
        {
            // If projection is already in progress, then it could be shown on the monitor again
            // Otherwise, we need to create a new view to show the presentation
            if (rootPage.ProjectionViewPageControl == null)
            {
                // First, create a new, blank view
                var thisDispatcher = Window.Current.Dispatcher;
                await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // ViewLifetimeControl is a wrapper to make sure the view is closed only
                    // when the app is done with it
                    rootPage.ProjectionViewPageControl = ViewLifetimeControl.CreateForCurrentView();

                    // Assemble some data necessary for the new page
                    var initData                       = new ProjectionViewPageInitializationData();
                    initData.MainDispatcher            = thisDispatcher;
                    initData.ProjectionViewPageControl = rootPage.ProjectionViewPageControl;
                    initData.MainViewId                = thisViewId;

                    // Display the page in the view. Note that the view will not become visible
                    // until "StartProjectingAsync" is called
                    var rootFrame = new Frame();
                    rootFrame.Navigate(typeof(ProjectionViewPage), initData);
                    Window.Current.Content = rootFrame;

                    // The call to Window.Current.Activate is required starting in Windos 10.
                    // Without it, the view will never appear.
                    Window.Current.Activate();
                });
            }

            try
            {
                // Start/StopViewInUse are used to signal that the app is interacting with the
                // view, so it shouldn't be closed yet, even if the user loses access to it
                rootPage.ProjectionViewPageControl.StartViewInUse();

                // Show the view on a second display (if available) or on the primary display
                await ProjectionManager.StartProjectingAsync(rootPage.ProjectionViewPageControl.Id, thisViewId);

                rootPage.ProjectionViewPageControl.StopViewInUse();

                rootPage.NotifyUser("Projection started with success", NotifyType.StatusMessage);
            }
            catch (InvalidOperationException)
            {
                rootPage.NotifyUser("The projection view is being disposed", NotifyType.ErrorMessage);
            }
        }
コード例 #22
0
        public async void NavigateToInstant(string url)
        {
            if (_instantLifetime == null)
            {
                _instantLifetime = await OpenAsync(typeof(InstantPage), url);
            }
            else
            {
                await _instantLifetime.CoreDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    _instantLifetime.NavigationService.Navigate(typeof(InstantPage), url);
                });

                await ApplicationViewSwitcher.TryShowAsStandaloneAsync(_instantLifetime.Id, ViewSizePreference.Default, ApplicationView.GetApplicationViewIdForWindow(Window.Current.CoreWindow), ViewSizePreference.UseHalf);
            }
        }
コード例 #23
0
        private void ApplicationView_Consolidated(ApplicationView sender, ApplicationViewConsolidatedEventArgs args)
        {
            if (_callLifetime != null)
            {
                _callLifetime.StopViewInUse();
                _callLifetime.WindowWrapper.Window.Close();
                _callLifetime = null;
            }

            if (_callPage != null)
            {
                _callPage.Dispose();
                _callPage = null;
            }

            Aggregator.Publish(new UpdateCallDialog(_call, false));
        }
コード例 #24
0
        private async Task <ViewLifetimeControl> CreateViewLifetimeControlAsync(string windowTitle, Type pageType)
        {
            ViewLifetimeControl viewControl = null;

            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                viewControl       = ViewLifetimeControl.CreateForCurrentView();
                viewControl.Title = windowTitle;
                viewControl.StartViewInUse();
                var frame            = new Frame();
                frame.RequestedTheme = ThemeSelectorService.Theme;
                frame.Navigate(pageType, viewControl);
                Window.Current.Content = frame;
                Window.Current.Activate();
                ApplicationView.GetForCurrentView().Title = viewControl.Title;
            });

            return(viewControl);
        }
コード例 #25
0
ファイル: VoIPService.cs プロジェクト: vipadm/Unigram
        private void Hide()
        {
            if (_callPage != null)
            {
                _callPage.BeginOnUIThread(() =>
                {
                    if (_callDialog != null)
                    {
                        _callDialog.IsOpen = false;
                        _callDialog        = null;
                    }
                    else if (_callLifetime != null)
                    {
                        _callLifetime.StopViewInUse();
                        _callLifetime.WindowWrapper.Window.Close();
                        _callLifetime = null;
                    }

                    _callPage.Dispose();
                    _callPage = null;
                });
            }
        }
コード例 #26
0
        public async void Show()
        {
            if (_call == null)
            {
                return;
            }

            Show(_call, _controller, _callStarted);

            if (_callDialog != null)
            {
                _callDialog.IsOpen = true;
            }
            else if (_callLifetime != null)
            {
                _callLifetime = await _viewService.OpenAsync(() => _callPage = _callPage ?? new VoIPPage(ProtoService, CacheService, Aggregator, _call, _controller, _callStarted), _call.Id);

                _callLifetime.WindowWrapper.ApplicationView().Consolidated -= ApplicationView_Consolidated;
                _callLifetime.WindowWrapper.ApplicationView().Consolidated += ApplicationView_Consolidated;
            }

            Aggregator.Publish(new UpdateCallDialog(_call, true));
        }
コード例 #27
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _viewLifetimeControl = e.Parameter as ViewLifetimeControl;
            if (_viewLifetimeControl != null)
            {
                _viewLifetimeControl.StartViewInUse();
                // Register for window close
                _viewLifetimeControl.Released        += OnViewLifetimeControlReleased;
                _viewLifetimeControl.MessageReceived += OnViewLifetimeControlMessageReceived;
                // Deserialize passed in item to display in this window
                TabItems.Add(JsonConvert.DeserializeObject <DataItem>(_viewLifetimeControl.Context.ToString()));
                _viewLifetimeControl.Context = null;
                _viewLifetimeControl.StopViewInUse();
            }
            else
            {
                // Main Window Start
                InitializeTestData();

                WindowManagerService.Current.MainWindowMessageReceived += OnViewLifetimeControlMessageReceived;
            }
        }
コード例 #28
0
ファイル: VoIPService.cs プロジェクト: vipadm/Unigram
        private async void Show(Call call, VoIPControllerWrapper controller)
        {
            if (_callPage == null)
            {
                if (ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "IsViewModeSupported") && ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay))
                {
                    _callLifetime = await _viewService.OpenAsync(() => _callPage = _callPage ?? new PhoneCallPage(ProtoService, CacheService, Aggregator, _call, _controller), 0);

                    _callLifetime.Released += (s, args) =>
                    {
                        _callPage.Dispose();
                        _callPage = null;
                    };
                }
                else
                {
                    _callPage = new PhoneCallPage(ProtoService, CacheService, Aggregator, _call, _controller);

                    _callDialog = new ContentDialogBase();
                    _callDialog.HorizontalAlignment = HorizontalAlignment.Stretch;
                    _callDialog.VerticalAlignment   = VerticalAlignment.Stretch;
                    _callDialog.Content             = _callPage;
                    _callDialog.IsOpen = true;
                }
            }

            _callPage.BeginOnUIThread(() =>
            {
                if (controller != null)
                {
                    _callPage.Connect(controller);
                }

                _callPage.Update(call);
            });
        }
コード例 #29
0
ファイル: GalleryView.xaml.cs プロジェクト: GuocRen/Unigram
        private async void Compact_Click(object sender, RoutedEventArgs e)
        {
            var item = ViewModel.SelectedItem;

            if (item == null)
            {
                return;
            }

            _viewService = TLContainer.Current.Resolve <IViewService>();

            if (_mediaPlayer == null || _mediaPlayer.Source == null)
            {
                Play(item, item.GetFile());
            }

            _mediaPlayerElement.SetMediaPlayer(null);

            var width  = 340d;
            var height = 200d;

            var constraint = item.Constraint;

            if (constraint is MessageAnimation messageAnimation)
            {
                constraint = messageAnimation.Animation;
            }
            else if (constraint is MessageVideo messageVideo)
            {
                constraint = messageVideo.Video;
            }

            if (constraint is Animation animation)
            {
                width  = animation.Width;
                height = animation.Height;
            }
            else if (constraint is Video video)
            {
                width  = video.Width;
                height = video.Height;
            }

            if (width > 500 || height > 500)
            {
                var ratioX = 500d / width;
                var ratioY = 500d / height;
                var ratio  = Math.Min(ratioX, ratioY);

                width  *= ratio;
                height *= ratio;
            }

            _compactLifetime = await _viewService.OpenAsync(() =>
            {
                var element            = new MediaPlayerElement();
                element.RequestedTheme = ElementTheme.Dark;
                element.SetMediaPlayer(_mediaPlayer);
                element.TransportControls = new MediaTransportControls
                {
                    IsCompact = true,
                    IsCompactOverlayButtonVisible = false,
                    IsFastForwardButtonVisible    = false,
                    IsFastRewindButtonVisible     = false,
                    IsFullWindowButtonVisible     = false,
                    IsNextTrackButtonVisible      = false,
                    IsPlaybackRateButtonVisible   = false,
                    IsPreviousTrackButtonVisible  = false,
                    IsRepeatButtonVisible         = false,
                    IsSkipBackwardButtonVisible   = false,
                    IsSkipForwardButtonVisible    = false,
                    IsVolumeButtonVisible         = false,
                    IsStopButtonVisible           = false,
                    IsZoomButtonVisible           = false,
                };
                element.AreTransportControlsEnabled = true;
                return(element);
            }, "PIP", width, height);

            _compactLifetime.WindowWrapper.ApplicationView().Consolidated += (s, args) =>
            {
                if (_compactLifetime != null)
                {
                    _compactLifetime.StopViewInUse();
                    _compactLifetime.WindowWrapper.Window.Close();
                    _compactLifetime = null;
                }

                this.BeginOnUIThread(() =>
                {
                    Dispose();
                });
            };

            OnBackRequestedOverride(this, new HandledEventArgs());
        }
コード例 #30
0
        public async Task BBSConnectAsync2()
        {
            (string bbsName, string tncName, string MessageFrom) = Utilities.GetProfileDataBBSStatusChecked();
            //BBSData bbs = PacketSettingsViewModel.Instance.BBSFromSelectedProfile;
            BBSData bbs = BBSDefinitions.Instance.BBSDataArray.Where(bBS => bBS.Name == bbsName).FirstOrDefault();
            //TNCDevice tncDevice = TNCDeviceArray.Instance.TNCDeviceList.Where(tnc => tnc.Name == tncName).FirstOrDefault();
            TNCDevice tncDevice = PacketSettingsViewModel.Instance.TNCFromSelectedProfile;

            //if (tncName.Contains(SharedData.EMail) && tncDevice is null)
            //{
            //    tncDevice = TNCDeviceArray.Instance.TNCDeviceList.Where(tnc => tnc.Name.Contains(SharedData.EMail)).FirstOrDefault();
            //}

            _logHelper.Log(LogLevel.Info, "Start a new send/receive session");
            // Collect messages to be sent
            _packetMessagesToSend.Clear();
            List <string> fileTypeFilter = new List <string>()
            {
                ".xml"
            };
            QueryOptions queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, fileTypeFilter);

            // Get the files in the Outbox folder
            StorageFileQueryResult results = SharedData.UnsentMessagesFolder.CreateFileQueryWithOptions(queryOptions);
            // Iterate over the results
            IReadOnlyList <StorageFile> unsentFiles = await results.GetFilesAsync();

            foreach (StorageFile file in unsentFiles)
            {
                // Add Outpost message format by Filling the MessageBody field in packetMessage.
                PacketMessage packetMessage = PacketMessage.Open(file.Path);
                if (packetMessage is null)
                {
                    _logHelper.Log(LogLevel.Error, $"Error opening message file {file.Path}");
                    continue;
                }

                // messages that are opened for editing will not be sent until editing is finished
                if (packetMessage.MessageState == MessageState.Edit)
                {
                    continue;
                }

                // Moved to send button processing
                //DateTime now = DateTime.Now;

                //var operatorDateField = packetMessage.FormFieldArray.Where(formField => formField.ControlName == "operatorDate").FirstOrDefault();
                //if (operatorDateField != null)
                //{
                //    operatorDateField.ControlContent = $"{now.Month:d2}/{now.Day:d2}/{(now.Year):d4}";
                //}
                //var operatorTimeField = packetMessage.FormFieldArray.Where(formField => formField.ControlName == "operatorTime").FirstOrDefault();
                //if (operatorTimeField != null)
                //    operatorTimeField.ControlContent = $"{now.Hour:d2}:{now.Minute:d2}";

                FormControlBase formControl = FormsViewModel.CreateFormControlInstance(packetMessage.PacFormName);
                if (formControl is null)
                {
                    _logHelper.Log(LogLevel.Error, $"Could not create an instance of {packetMessage.PacFormName}");
                    await ContentDialogs.ShowSingleButtonContentDialogAsync($"Form {packetMessage.PacFormName} not found");

                    continue;
                }
                packetMessage.MessageBody = formControl.CreateOutpostData(ref packetMessage);
                packetMessage.UpdateMessageSize();
                // Save updated message
                packetMessage.Save(SharedData.UnsentMessagesFolder.Path);

                _packetMessagesToSend.Add(packetMessage);
            }
            _logHelper.Log(LogLevel.Info, $"Send messages count: {_packetMessagesToSend.Count}");

            if (tncDevice.Name.Contains(PublicData.EMail) && _packetMessagesToSend.Count == 0)
            {
                return;
            }
            List <PacketMessage> messagesSentAsEMail = new List <PacketMessage>();

            // Send email messages
            foreach (PacketMessage packetMessage in _packetMessagesToSend)
            {
                //tncDevice = TNCDeviceArray.Instance.TNCDeviceList.Where(tnc => tnc.Name == packetMessage.TNCName).FirstOrDefault();
                //bbs = BBSDefinitions.Instance.BBSDataList.Where(bBS => bBS.Name == packetMessage.BBSName).FirstOrDefault();

                //TNCInterface tncInterface = new TNCInterface(bbs?.ConnectName, ref tncDevice, packetSettingsViewModel.ForceReadBulletins, packetSettingsViewModel.AreaString, ref _packetMessagesToSend);
                // Send as email if a TNC is not reachable, or if message is defined as an e-mail message
                if (tncDevice.Name.Contains(PublicData.EMail))
                {
                    try
                    {
                        // Mark message as sent by email
                        packetMessage.TNCName = tncDevice.Name;
                        //if (!tncDevice.Name.Contains(SharedData.EMail))
                        //{
                        //    packetMessage.TNCName = "E-Mail-" + PacketSettingsViewModel>.Instance.CurrentTNC.MailUserName;
                        //}

                        bool sendMailSuccess = await SendMessageViaEMailAsync(packetMessage);

                        if (sendMailSuccess)
                        {
                            packetMessage.MessageState = MessageState.Locked;
                            packetMessage.SentTime     = DateTime.Now;
                            packetMessage.MailUserName = SmtpClient.Instance.UserName;
                            _logHelper.Log(LogLevel.Info, $"Message sent via E-Mail: {packetMessage.MessageNumber}");

                            var file = await SharedData.UnsentMessagesFolder.CreateFileAsync(packetMessage.FileName, CreationCollisionOption.OpenIfExists);

                            await file?.DeleteAsync();

                            // Do a save to ensure that updates are saved
                            packetMessage.Save(SharedData.SentMessagesFolder.Path);

                            //_packetMessagesToSend.Remove(packetMessage);
                            messagesSentAsEMail.Add(packetMessage);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logHelper.Log(LogLevel.Error, $"Error sending e-mail message {packetMessage.MessageNumber}");
                        string text = ex.Message;
                        continue;
                    }
                }
            }

            // Remove already processed E-Mail messages.
            foreach (PacketMessage packetMessage in messagesSentAsEMail)
            {
                _packetMessagesToSend.Remove(packetMessage);
            }

            // TODO check if TNC connected otherwise suggest send via email
            //if (_packetMessagesToSend.Count == 0)
            //{
            //    tncDevice = PacketSettingsViewModel>.Instance.CurrentTNC;

            //    (string bbsName, string tncName, string MessageFrom) = Utilities.GetProfileData();
            //    //string MessageFrom = from;
            //    BBSData MessageBBS = Singleton<PacketSettingsViewModel>.Instance.CurrentBBS;
            //    if (MessageBBS == null || !MessageBBS.Name.Contains("XSC") && !tncDevice.Name.Contains(SharedData.EMail))
            //    {
            //        //string bbsName = AddressBook.Instance.GetBBS(MessageFrom);
            //        bbs = BBSDefinitions.Instance.GetBBSFromName(bbsName);
            //    }
            //    else
            //    {
            //        bbs = Singleton<PacketSettingsViewModel>.Instance.CurrentBBS;
            //    }
            //    tncDevice = TNCDeviceArray.Instance.TNCDeviceList.Where(tnc => tnc.Name == tncName).FirstOrDefault();
            //}
            //else
            //{
            //    //tncDevice = Singleton<PacketSettingsViewModel>.Instance.CurrentTNC;
            //    tncDevice = TNCDeviceArray.Instance.TNCDeviceList.Where(tnc => tnc.Name == _packetMessagesToSend[0].TNCName).FirstOrDefault();
            //    bbs = BBSDefinitions.Instance.BBSDataList.Where(bBS => bBS.Name == _packetMessagesToSend[0].BBSName).FirstOrDefault();
            //    //Utilities.SetApplicationTitle(bbs.Name);
            //    //bbs = PacketSettingsViewModel>.Instance.CurrentBBS;
            //}

            //Utilities.SetApplicationTitle(bbs?.Name);

            if (!tncDevice.Name.Contains(PublicData.EMail))
            {
                ViewLifetimeControl viewLifetimeControl = await WindowManagerService.Current.TryShowAsStandaloneAsync("Connection Status", typeof(RxTxStatusPage));

                //RxTxStatusPage.rxtxStatusPage._viewLifetimeControl.Height = RxTxStatusPage.rxtxStatusPage.RxTxStatusViewmodel.ViewControlHeight;
                //RxTxStatusPage.rxtxStatusPage._viewLifetimeControl.Width = RxTxStatusPage.rxtxStatusPage.RxTxStatusViewmodel.ViewControlWidth;

                //bool success = RxTxStatusPage.rxtxStatusPage._viewLifetimeControl.ResizeView();


                //return;     //Test

                PacketSettingsViewModel packetSettingsViewModel = PacketSettingsViewModel.Instance;

                //_tncInterface = new TNCInterface(bbs?.ConnectName, ref tncDevice, packetSettingsViewModel.ForceReadBulletins, packetSettingsViewModel.AreaString, ref _packetMessagesToSend);
                _tncInterface = new TNCInterface(bbs?.ConnectName, ref tncDevice, packetSettingsViewModel.ForceReadBulletins, packetSettingsViewModel.AreaCommands, ref _packetMessagesToSend);

                // Collect remaining messages to be sent
                // Process files to be sent via BBS
                await _tncInterface.BBSConnectThreadProcAsync();

                // Close status window
                await RxTxStatusPage.Current._viewLifetimeControl.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    //RxTxStatusPage.rxtxStatusPage.CloseStatusWindowAsync();
                    //RxTxStatusPage.Current.RxTxStatusViewmodel.CloseStatusWindowAsync();
                    RxTxStatViewModel.Instance.CloseStatusWindowAsync();
                });

                PacketSettingsViewModel.Instance.ForceReadBulletins = false;
                if (!string.IsNullOrEmpty(bbs?.Name))
                {
                    _logHelper.Log(LogLevel.Info, $"Disconnected from: {bbs?.ConnectName}. Connect time = {_tncInterface.BBSDisconnectTime - _tncInterface.BBSConnectTime}");
                }

                // Move sent messages from unsent folder to the Sent folder
                foreach (PacketMessage packetMsg in _tncInterface.PacketMessagesSent)
                {
                    try
                    {
                        _logHelper.Log(LogLevel.Info, $"Message number {packetMsg.MessageNumber} Sent");

                        StorageFile file = await SharedData.UnsentMessagesFolder.CreateFileAsync(packetMsg.FileName, CreationCollisionOption.OpenIfExists);

                        await file.DeleteAsync();

                        // Do a save to ensure that updates from tncInterface.BBSConnect are saved
                        packetMsg.Save(SharedData.SentMessagesFolder.Path);
                    }
                    catch (FileNotFoundException)
                    {
                        _logHelper.Log(LogLevel.Error, $"File Not Found {packetMsg.FileName}");
                        continue;
                    }
                    catch (UnauthorizedAccessException)
                    {
                        _logHelper.Log(LogLevel.Error, $"Unauthorized Access {packetMsg.FileName}");
                        continue;
                    }
                    if (string.IsNullOrEmpty(packetMsg.Area) && SettingsViewModel.Instance.PrintSentMessages)
                    {
                        // Do printing if requested
                        _logHelper.Log(LogLevel.Info, $"Message number {packetMsg.MessageNumber} to be printed");

                        packetMsg.Save(SharedData.PrintMessagesFolder.Path);

                        SettingsViewModel settingsViewModel = SettingsViewModel.Instance;
                        PrintQueue.Instance.AddToPrintQueue(packetMsg.FileName, settingsViewModel.SentCopyNamesAsArray());
                    }
                }
                _packetMessagesReceived = _tncInterface.PacketMessagesReceived;
                await ProcessReceivedMessagesAsync();

                /*
                 * ApplicationTrigger trigger = new ApplicationTrigger();
                 * var task = RxTxBackgroundTask.RegisterBackgroundTask(RxTxBackgroundTask.RxTxBackgroundTaskEntryPoint,
                 *                                                     RxTxBackgroundTask.ApplicationTriggerTaskName,
                 *                                                     trigger,
                 *                                                     null);
                 * task.Progress += new BackgroundTaskProgressEventHandler(OnProgress);
                 * task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
                 *
                 *
                 * // Register a ApplicationTriggerTask.
                 * RxTxBackgroundTask rxTxBackgroundTask = new RxTxBackgroundTask(bbs?.ConnectName, ref tncDevice, packetSettingsViewModel.ForceReadBulletins, packetSettingsViewModel.AreaString, ref _packetMessagesToSend);
                 *          rxTxBackgroundTask.Register();
                 * // Start backgroung task
                 * // Reset the completion status
                 * var settings = ApplicationData.Current.LocalSettings;
                 * settings.Values.Remove(BackgroundTaskSample.ApplicationTriggerTaskName);
                 *
                 * //Signal the ApplicationTrigger
                 * var result = await trigger.RequestAsync();
                 *
                 * ApplicationTriggerResult result = await rxTxBackgroundTask._applicationTrigger.RequestAsync();
                 * //            await Singleton<BackgroundTaskService>.Instance.HandleAsync(RxTxBackgroundTask);
                 * // RxTxBackgroundTask is finished
                 *
                 * if (_connectState == ConnectState.ConnectStateBBSConnect)
                 * {
                 *  await Utilities.ShowSingleButtonContentDialogAsync(_result, "Close", "BBS Connect Error");
                 *  //_result = "It appears that the radio is tuned to the wrong frequency,\nor the BBS was out of reach";
                 * }
                 *          else if (_connectState == ConnectState.ConnectStatePrepareTNCType)
                 *          {
                 *              await Utilities.ShowSingleButtonContentDialogAsync("Unable to connect to the TNC.\nIs the TNC on?\nFor Kenwood; is the radio in \"packet12\" mode?", "Close", "BBS Connect Error");
                 *              //_result = "";
                 *          }
                 *          else if (_connectState == ConnectState.ConnectStateConverseMode)
                 *          {
                 *              await Utilities.ShowSingleButtonContentDialogAsync($"Error sending FCC Identification - {Singleton<IdentityViewModel>.Instance.UserCallsign}.", "Close", "TNC Converse Error");
                 *              //_result = $"Error sending FCC Identification - { Singleton<IdentityViewModel>.Instance.UserCallsign}.";
                 *          }
                 *          //else if (e.Message.Contains("not exist"))
                 *          else if (e.GetType() == typeof(IOException))
                 *          {
                 *              await Utilities.ShowSingleButtonContentDialogAsync("Looks like the USB or serial cable to the TNC is disconnected", "Close", "TNC Connect Error");
                 *              //_result = "Looks like the USB or serial cable to the TNC is disconnected";
                 *          }
                 *          else if (e.GetType() == typeof(UnauthorizedAccessException))
                 *          {
                 *              await Utilities.ShowSingleButtonContentDialogAsync($"The COM Port ({_TncDevice.CommPort.Comport}) is in use by another application. ", "Close", "TNC Connect Error");
                 *              //_result = $"The COM Port ({_TncDevice.CommPort.Comport}) is in use by another application.";
                 *          }
                 *
                 *          PacketSettingsViewModel>.Instance.ForceReadBulletins = false;
                 *          if (!string.IsNullOrEmpty(bbs?.Name))
                 *          {
                 *              _logHelper.Log(LogLevel.Info, $"Disconnected from: {bbs?.ConnectName}. Connect time = {rxTxBackgroundTask.BBSDisconnectTime - rxTxBackgroundTask.BBSConnectTime}");
                 *          }
                 *
                 *          // Move sent messages from unsent folder to the Sent folder
                 *          foreach (PacketMessage packetMsg in rxTxBackgroundTask.PacketMessagesSent)
                 *          {
                 *              try
                 *              {
                 *                  _logHelper.Log(LogLevel.Info, $"Message number {packetMsg.MessageNumber} Sent");
                 *
                 *                  StorageFile file = await SharedData.UnsentMessagesFolder.CreateFileAsync(packetMsg.FileName, CreationCollisionOption.OpenIfExists);
                 *                  await file.DeleteAsync();
                 *
                 *                  // Do a save to ensure that updates from tncInterface.BBSConnect are saved
                 *                  packetMsg.Save(SharedData.SentMessagesFolder.Path);
                 *              }
                 *              catch (Exception e)
                 *              {
                 *                  _logHelper.Log(LogLevel.Error, $"Exception {e.Message}");
                 *              }
                 *          }
                 *          _packetMessagesReceived = rxTxBackgroundTask.PacketMessagesReceived;
                 *          ProcessReceivedMessagesAsync();
                 *///_deviceFound = true;
                //try
                //{
                //    _serialPort = new SerialPort(Singleton<TNCSettingsViewModel>.Instance.CurrentTNCDevice.CommPort.Comport);
                //}
                //catch (IOException e)
                //{
                //    _deviceFound = false;
                //}
                //_serialPort.Close();
            }
        }