Esempio n. 1
0
 public ToastNotificationServiceTest()
 {
     _wpfTextView                 = CreateTextView();
     _editorFormatMap             = CompositionContainer.GetExportedValue <IEditorFormatMapService>().GetEditorFormatMap(_wpfTextView);
     _toastNotificationServiceRaw = new ToastNotificationService(_wpfTextView, _editorFormatMap);
     _toastNotificationService    = _toastNotificationServiceRaw;
     _toastControl                = _toastNotificationServiceRaw.ToastControl;
 }
Esempio n. 2
0
        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            // Register Services
            if (!SimpleIoc.Default.IsRegistered <INavigationService>())
            {
                var navigationService = CreateNavigationService();
                SimpleIoc.Default.Register(() => navigationService);
            }

            if (!SimpleIoc.Default.IsRegistered <IReactiveTVShowTimeApiService>())
            {
                var tvshowtimeApiService = new ReactiveTVShowTimeApiService();
                SimpleIoc.Default.Register <IReactiveTVShowTimeApiService>(() => tvshowtimeApiService);
            }

            if (!SimpleIoc.Default.IsRegistered <IHamburgerMenuService>())
            {
                var hamburgerMenuService = new HamburgerMenuService();
                SimpleIoc.Default.Register <IHamburgerMenuService>(() => hamburgerMenuService);
            }

            if (!SimpleIoc.Default.IsRegistered <IObjectStorageHelper>())
            {
                var localObjectStorageHelper = new LocalObjectStorageHelper();
                SimpleIoc.Default.Register <IObjectStorageHelper>(() => localObjectStorageHelper, ServiceLocatorConstants.LocalObjectStorageHelper);

                var roamingObjectStorageHelper = new RoamingObjectStorageHelper();
                SimpleIoc.Default.Register <IObjectStorageHelper>(() => roamingObjectStorageHelper, ServiceLocatorConstants.RoamingObjectStorageHelper);
            }

            if (!SimpleIoc.Default.IsRegistered <IEventService>())
            {
                var eventService = new EventService();
                SimpleIoc.Default.Register <IEventService>(() => eventService);
            }

            if (!SimpleIoc.Default.IsRegistered <IToastNotificationService>())
            {
                var toastNotificationService = new ToastNotificationService();
                SimpleIoc.Default.Register <IToastNotificationService>(() => toastNotificationService);
            }

            // Register ViewModels
            SimpleIoc.Default.Register <AgendaViewModel>();
            SimpleIoc.Default.Register <CollectionViewModel>();
            SimpleIoc.Default.Register <EpisodeViewModel>();
            SimpleIoc.Default.Register <ExploreViewModel>();
            SimpleIoc.Default.Register <FeedbackViewModel>();
            SimpleIoc.Default.Register <LoginViewModel>();
            SimpleIoc.Default.Register <MainViewModel>();
            SimpleIoc.Default.Register <SettingsViewModel>();
            SimpleIoc.Default.Register <ShowViewModel>();
            SimpleIoc.Default.Register <ToWatchViewModel>();
            SimpleIoc.Default.Register <UpcomingViewModel>();
        }
Esempio n. 3
0
        protected override Task OnSuspendingApplicationAsync()
        {
            var task = base.OnSuspendingApplicationAsync();
            // Stop Background Sync Tasks
            List <FolderSyncInfo> activeSyncs = SyncDbUtils.GetActiveSyncInfos();

            foreach (var fsi in activeSyncs)
            {
                ToastNotificationService.ShowSyncSuspendedNotification(fsi);
                SyncDbUtils.UnlockFolderSyncInfo(fsi);
            }
            return(task);
        }
Esempio n. 4
0
 public void OnPeerPresence(PeerUpdate peer)
 {
     ClientConfirmation(Confirmation.For(peer));
     GetPeerList(new Message());
     if (DateTimeOffset.UtcNow.Subtract(peer.SentDateTimeUtc).TotalSeconds < 10)
     {
         ToastNotificationService.ShowPresenceNotification(
             peer.PeerData.Name,
             AvatarLink.EmbeddedLinkFor(peer.PeerData.Avatar),
             peer.PeerData.IsOnline);
     }
     _foregroundChannel?.OnSignaledPeerDataUpdated();
 }
Esempio n. 5
0
        public IAsyncAction ServerRelayAsync(RelayMessage message)
        {
            return(Task.Run(async() =>
            {
                await ClientConfirmationAsync(Confirmation.For(message));
                if (message.Tag == RelayMessageTags.InstantMessage)
                {
                    await SignaledInstantMessages.AddAsync(message);
                }
                var shownUserId = await _foregroundChannel.GetShownUserIdAsync();
                if (message.Tag == RelayMessageTags.InstantMessage &&
                    !ReceivedPushNotifications.IsReceived(message.Id) &&
                    !(shownUserId != null && shownUserId.Equals(message.FromUserId)) &&
                    (DateTimeOffset.UtcNow.Subtract(message.SentDateTimeUtc).TotalMinutes < 10))
                {
                    ToastNotificationService.ShowInstantMessageNotification(message.FromName,
                                                                            message.FromUserId, AvatarLink.EmbeddedLinkFor(message.FromAvatar), message.Payload);
                }
                _foregroundChannel?.OnSignaledRelayMessagesUpdatedAsync();

                // Handle call tags
                if (message.Tag == RelayMessageTags.Call)
                {
                    await _callChannel.OnIncomingCallAsync(message);
                }
                else if (message.Tag == RelayMessageTags.CallAnswer)
                {
                    await _callChannel.OnOutgoingCallAcceptedAsync(message);
                }
                else if (message.Tag == RelayMessageTags.CallReject)
                {
                    await _callChannel.OnOutgoingCallRejectedAsync(message);
                }
                else if (message.Tag == RelayMessageTags.SdpOffer)
                {
                    await _callChannel.OnSdpOfferAsync(message);
                }
                else if (message.Tag == RelayMessageTags.SdpAnswer)
                {
                    await _callChannel.OnSdpAnswerAsync(message);
                }
                else if (message.Tag == RelayMessageTags.IceCandidate)
                {
                    await _callChannel.OnIceCandidateAsync(message);
                }
                else if (message.Tag == RelayMessageTags.CallHangup)
                {
                    await _callChannel.OnRemoteHangupAsync(message);
                }
            }).AsAsyncAction());
        }
Esempio n. 6
0
        public SettingsPageViewModel(
            HohoemaApp hohoemaApp
            , PageManager pageManager
            , RankingChoiceDialogService rakingChoiceDialog
            , EditAutoCacheConditionDialogService editAutoCacheDialog
            , AcceptCacheUsaseDialogService cacheAcceptDialogService
            , ToastNotificationService toastService
            )
            : base(hohoemaApp, pageManager)
        {
            RankingChoiceDialogService          = rakingChoiceDialog;
            EditAutoCacheConditionDialogService = editAutoCacheDialog;
            AcceptCacheUsaseDialogService       = cacheAcceptDialogService;
            ToastNotificationService            = toastService;

            SettingItems = ((IEnumerable <HohoemaSettingsKind>)Enum.GetValues(typeof(HohoemaSettingsKind)))
                           .Where(x => Util.DeviceTypeHelper.IsXbox ? x != HohoemaSettingsKind.Share : true)
                           .Select(x => KindToVM(x))
                           .ToList();

            CurrentSettingsContent = new ReactiveProperty <SettingsPageContentViewModel>();


            CurrentSettingsContent.Subscribe(x =>
            {
                _PrevSettingsContent?.Leaved();

                /*
                 * if (x != null)
                 * {
                 *  AddSubsitutionBackNavigateAction("settings_content_selection"
                 *      , () =>
                 *      {
                 *          CurrentSettingsContent.Value = null;
                 *
                 *          return true;
                 *      });
                 * }
                 * else
                 * {
                 *  RemoveSubsitutionBackNavigateAction("settings_content_selection");
                 * }
                 */

                _PrevSettingsContent = x;
                x?.Entered();
            });
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            using (new BackgroundTaskDeferralWrapper(taskInstance.GetDeferral()))
            {
                try
                {
                    var rawNotification = (RawNotification)taskInstance.TriggerDetails;
                    var rawContent      = rawNotification.Content;

                    var serializedParameter =
                        rawContent.Substring(rawContent.IndexOf(" ", StringComparison.CurrentCultureIgnoreCase) + 1);
                    var type    = typeof(RelayMessage);
                    var message = (RelayMessage)JsonConvert.DeserializeObject(serializedParameter, type);

                    if (message == null)
                    {
                        return;
                    }

                    var isTimeout = (DateTimeOffset.UtcNow - message.SentDateTimeUtc).TotalSeconds > 60;

                    if (message.Tag == RelayMessageTags.Call)
                    {
                        if (isTimeout)
                        {
                            return;
                        }
                        ToastNotificationService.ShowInstantMessageNotification(message.FromName, message.FromUserId,
                                                                                AvatarLink.EmbeddedLinkFor(message.FromAvatar),
                                                                                $"Missed call at {message.SentDateTimeUtc.ToLocalTime()}.");
                    }
                    else if (message.Tag == RelayMessageTags.InstantMessage)
                    {
                        if (isTimeout || await SignaledInstantMessages.IsReceivedAsync(message.Id))
                        {
                            return;
                        }
                        ToastNotificationService.ShowInstantMessageNotification(message.FromName, message.FromUserId,
                                                                                AvatarLink.EmbeddedLinkFor(message.FromAvatar), message.Payload);
                        ReceivedPushNotifications.Add(message.Id);
                        await SignaledInstantMessages.AddAsync(message);
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Esempio n. 8
0
 public IAsyncAction OnPeerPresenceAsync(PeerUpdate peer)
 {
     return(Task.Run(async() =>
     {
         await ClientConfirmationAsync(Confirmation.For(peer));
         await GetPeerListAsync(new Message());
         if (DateTimeOffset.UtcNow.Subtract(peer.SentDateTimeUtc).TotalSeconds < 10)
         {
             ToastNotificationService.ShowPresenceNotification(
                 peer.PeerData.Name,
                 AvatarLink.EmbeddedLinkFor(peer.PeerData.Avatar),
                 peer.PeerData.IsOnline);
         }
         _foregroundChannel?.OnSignaledPeerDataUpdatedAsync();
     }).AsAsyncAction());
 }
Esempio n. 9
0
        public void ServerRelay(RelayMessage message)
        {
            ClientConfirmation(Confirmation.For(message));
            SignaledRelayMessages.Add(message);
            var shownUserId = _foregroundChannel.GetShownUserId();

            if (message.Tag == RelayMessageTags.InstantMessage &&
                !SignaledRelayMessages.IsPushNotificationReceived(message.Id) &&
                !(shownUserId != null && shownUserId.Equals(message.FromUserId)) &&
                (DateTimeOffset.UtcNow.Subtract(message.SentDateTimeUtc).TotalMinutes < 10))
            {
                ToastNotificationService.ShowInstantMessageNotification(message.FromName,
                                                                        message.FromUserId, AvatarLink.EmbeddedLinkFor(message.FromAvatar), message.Payload);
            }
            _foregroundChannel?.OnSignaledRelayMessagesUpdated();

            // Handle Voip tags
            if (message.Tag == RelayMessageTags.VoipCall)
            {
                _voipChannel.OnIncomingCall(message);
            }
            else if (message.Tag == RelayMessageTags.VoipAnswer)
            {
                _voipChannel.OnOutgoingCallAccepted(message);
            }
            else if (message.Tag == RelayMessageTags.VoipReject)
            {
                _voipChannel.OnOutgoingCallRejected(message);
            }
            else if (message.Tag == RelayMessageTags.SdpOffer)
            {
                _voipChannel.OnSdpOffer(message);
            }
            else if (message.Tag == RelayMessageTags.SdpAnswer)
            {
                _voipChannel.OnSdpAnswer(message);
            }
            else if (message.Tag == RelayMessageTags.IceCandidate)
            {
                _voipChannel.OnIceCandidate(message);
            }
            else if (message.Tag == RelayMessageTags.VoipHangup)
            {
                _voipChannel.OnRemoteHangup(message);
            }
        }
Esempio n. 10
0
        public void SaveWebRTCTrace()
        {
            if (!WebRTC.IsTracing())
            {
                return;
            }

            Task.Run(async() =>
            {
                WebRTC.StopTracing(); //stop tracing so that trace file can be properly saved.
                ToastNotificationService.ShowToastNotification("Saving Webrtc trace");
                var webrtcTraceInternalFile = ApplicationData.Current.LocalFolder.Path + "\\" + "_webrtc_trace.txt";

                WebRTC.SaveTrace(webrtcTraceInternalFile);

                await SaveToUserPickedFolder(webrtcTraceInternalFile);

                WebRTC.StartTracing();

                ToastNotificationService.ShowToastNotification("Saving Webrtc trace finished!");
            });
        }
Esempio n. 11
0
        protected override Task OnSuspendingApplicationAsync()
        {
            var task = base.OnSuspendingApplicationAsync();
            // Stop Background Sync Tasks
            var activeSyncs = SyncDbUtils.GetActiveSyncInfos();

            if (SettingsLocal.PauseSyncInBackground)
            {
                foreach (var fsi in activeSyncs)
                {
                    ToastNotificationService.ShowSyncSuspendedNotification(fsi);
                    SyncDbUtils.UnlockFolderSyncInfo(fsi);
                }
            }
            else
            {
                foreach (var fsi in activeSyncs)
                {
                    ToastNotificationService.ShowSyncInBackgroundNotification(fsi);
                }
            }

            return(task);
        }
Esempio n. 12
0
        public SettingsPageViewModel(
            HohoemaApp hohoemaApp
            , PageManager pageManager
            , ToastNotificationService toastService
            , Services.HohoemaDialogService dialogService
            )
            : base(hohoemaApp, pageManager)
        {
            ToastNotificationService = toastService;
            _NGSettings           = HohoemaApp.UserSettings.NGSettings;
            _RankingSettings      = HohoemaApp.UserSettings.RankingSettings;
            _HohoemaDialogService = dialogService;

            IsLiveAlertEnabled = HohoemaApp.UserSettings.ActivityFeedSettings.ToReactivePropertyAsSynchronized(x => x.IsLiveAlertEnabled)
                                 .AddTo(_CompositeDisposable);

            // NG Video Owner User Id
            NGVideoOwnerUserIdEnable = _NGSettings.ToReactivePropertyAsSynchronized(x => x.NGVideoOwnerUserIdEnable);
            NGVideoOwnerUserIds      = _NGSettings.NGVideoOwnerUserIds
                                       .ToReadOnlyReactiveCollection();

            OpenUserPageCommand = new DelegateCommand <UserIdInfo>(userIdInfo =>
            {
                pageManager.OpenPage(HohoemaPageType.UserInfo, userIdInfo.UserId);
            });

            // NG Keyword on Video Title
            NGVideoTitleKeywordEnable = _NGSettings.ToReactivePropertyAsSynchronized(x => x.NGVideoTitleKeywordEnable);
            NGVideoTitleKeywords      = new ReactiveProperty <string>();
            NGVideoTitleKeywordError  = NGVideoTitleKeywords
                                        .Select(x =>
            {
                if (x == null)
                {
                    return(null);
                }

                var keywords     = x.Split('\r');
                var invalidRegex = keywords.FirstOrDefault(keyword =>
                {
                    Regex regex = null;
                    try
                    {
                        regex = new Regex(keyword);
                    }
                    catch { }
                    return(regex == null);
                });

                if (invalidRegex == null)
                {
                    return(null);
                }
                else
                {
                    return($"Error in \"{invalidRegex}\"");
                }
            })
                                        .ToReadOnlyReactiveProperty();

            // アピアランス

            var currentTheme = App.GetTheme();

            SelectedApplicationTheme = new ReactiveProperty <string>(currentTheme.ToString(), mode: ReactivePropertyMode.DistinctUntilChanged);

            SelectedApplicationTheme.Subscribe(x =>
            {
                var type = (ApplicationTheme)Enum.Parse(typeof(ApplicationTheme), x);
                App.SetTheme(type);

                // 一度だけトースト通知
                if (!ThemeChanged)
                {
                    toastService.ShowText("Hohoemaを再起動するとテーマが適用されます。", "");
                }

                ThemeChanged = true;
                RaisePropertyChanged(nameof(ThemeChanged));
            });

            IsTVModeEnable = HohoemaApp.UserSettings.AppearanceSettings
                             .ToReactivePropertyAsSynchronized(x => x.IsForceTVModeEnable);
            IsXbox = Helpers.DeviceTypeHelper.IsXbox;



            IsDefaultFullScreen = new ReactiveProperty <bool>(ApplicationView.PreferredLaunchWindowingMode == ApplicationViewWindowingMode.FullScreen);
            IsDefaultFullScreen.Subscribe(x =>
            {
                if (x)
                {
                    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
                }
                else
                {
                    ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
                }
            });

            StartupPageType = HohoemaApp.UserSettings.AppearanceSettings
                              .ToReactivePropertyAsSynchronized(x => x.StartupPageType);


            // キャッシュ
            DefaultCacheQuality                 = HohoemaApp.UserSettings.CacheSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCacheQuality);
            IsAllowDownloadOnMeteredNetwork     = HohoemaApp.UserSettings.CacheSettings.ToReactivePropertyAsSynchronized(x => x.IsAllowDownloadOnMeteredNetwork);
            DefaultCacheQualityOnMeteredNetwork = HohoemaApp.UserSettings.CacheSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCacheQualityOnMeteredNetwork);

            // シェア
            IsLoginTwitter           = new ReactiveProperty <bool>(/*TwitterHelper.IsLoggedIn*/ false);
            TwitterAccountScreenName = new ReactiveProperty <string>(/*TwitterHelper.TwitterUser?.ScreenName ?? ""*/);


            // アバウト
            var version = Windows.ApplicationModel.Package.Current.Id.Version;

#if DEBUG
            VersionText = $"{version.Major}.{version.Minor}.{version.Build} DEBUG";
#else
            VersionText = $"{version.Major}.{version.Minor}.{version.Build}";
#endif


            var dispatcher = Window.Current.CoreWindow.Dispatcher;
            LisenceSummary.Load()
            .ContinueWith(async prevResult =>
            {
                await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    var lisenceSummary = prevResult.Result;

                    LisenceItems = lisenceSummary.Items
                                   .OrderBy(x => x.Name)
                                   .Select(x => new LisenceItemViewModel(x))
                                   .ToList();
                    RaisePropertyChanged(nameof(LisenceItems));
                });
            });


            IsDebugModeEnabled = new ReactiveProperty <bool>((App.Current as App).IsDebugModeEnabled, mode: ReactivePropertyMode.DistinctUntilChanged);
            IsDebugModeEnabled.Subscribe(isEnabled =>
            {
                (App.Current as App).IsDebugModeEnabled = isEnabled;
            })
            .AddTo(_CompositeDisposable);
        }
Esempio n. 13
0
 public ShereVideoInfoContentViewModel(NicoVideo nicoVideo, TextInputDialogService textInputService, ToastNotificationService toastService)
 {
     _NicoVideo = nicoVideo;
     _TextInputDialogService   = textInputService;
     _ToastNotificationService = toastService;
 }
Esempio n. 14
0
        public LiveVideoPlayerControlViewModel(
            HohoemaApp hohoemaApp,
            PageManager pageManager,
            TextInputDialogService textInputDialogService,
            ToastNotificationService toast
            )
            : base(hohoemaApp, pageManager, canActivateBackgroundUpdate: true)
        {
            _TextInputDialogService   = textInputDialogService;
            _ToastNotificationService = toast;

            MediaPlayer = HohoemaApp.MediaPlayer;

            // play
            CurrentState = new ReactiveProperty <MediaElementState>();
            NowPlaying   = CurrentState.Select(x => x == MediaElementState.Playing)
                           .ToReactiveProperty();


            NowUpdating    = new ReactiveProperty <bool>(false);
            LivePlayerType = new ReactiveProperty <Models.Live.LivePlayerType?>();

            CanChangeQuality = new ReactiveProperty <bool>(false);
            RequestQuality   = new ReactiveProperty <string>();
            CurrentQuality   = new ReactiveProperty <string>();

            IsAvailableSuperLowQuality = new ReactiveProperty <bool>(false);
            IsAvailableLowQuality      = new ReactiveProperty <bool>(false);
            IsAvailableNormalQuality   = new ReactiveProperty <bool>(false);
            IsAvailableHighQuality     = new ReactiveProperty <bool>(false);

            ChangeQualityCommand = new DelegateCommand <string>(
                (quality) =>
            {
                NicoLiveVideo.ChangeQualityRequest(quality).ConfigureAwait(false);
                HohoemaApp.UserSettings.PlayerSettings.DefaultLiveQuality = quality;
                HohoemaApp.UserSettings.PlayerSettings.Save().ConfigureAwait(false);
            },
                (quality) => NicoLiveVideo.Qualities.Any(x => x == quality)
                );

            IsVisibleComment = new ReactiveProperty <bool>(PlayerWindowUIDispatcherScheduler, true).AddTo(_CompositeDisposable);

            CommentCanvasHeight = new ReactiveProperty <double>(PlayerWindowUIDispatcherScheduler, 0.0).AddTo(_CompositeDisposable);
            CommentDefaultColor = new ReactiveProperty <Color>(PlayerWindowUIDispatcherScheduler, Colors.White).AddTo(_CompositeDisposable);

            CommentOpacity = HohoemaApp.UserSettings.PlayerSettings.ObserveProperty(x => x.CommentOpacity)
                             .Select(x => x.ToOpacity())
                             .ToReadOnlyReactiveProperty(eventScheduler: PlayerWindowUIDispatcherScheduler);


            // post comment
            WritingComment       = new ReactiveProperty <string>(PlayerWindowUIDispatcherScheduler, "").AddTo(_CompositeDisposable);
            NowCommentWriting    = new ReactiveProperty <bool>(PlayerWindowUIDispatcherScheduler).AddTo(_CompositeDisposable);
            NowSubmittingComment = new ReactiveProperty <bool>(PlayerWindowUIDispatcherScheduler).AddTo(_CompositeDisposable);

            // TODO: ニコ生での匿名コメント設定
            CommandString   = new ReactiveProperty <string>(PlayerWindowUIDispatcherScheduler, "").AddTo(_CompositeDisposable);
            CommandEditerVM = new CommentCommandEditerViewModel(true /* isDefaultAnnonymous */);
            CommandEditerVM.OnCommandChanged += CommandEditerVM_OnCommandChanged;
            CommandEditerVM.ChangeEnableAnonymity(true);
            CommandEditerVM.IsAnonymousComment.Value = true;

            CommandEditerVM_OnCommandChanged();


            CommentSubmitCommand = Observable.CombineLatest(
                WritingComment.Select(x => !string.IsNullOrEmpty(x)),
                NowSubmittingComment.Select(x => !x)
                )
                                   .Select(x => x.All(y => y))
                                   .ToReactiveCommand(PlayerWindowUIDispatcherScheduler)
                                   .AddTo(_CompositeDisposable);

            CommentSubmitCommand.Subscribe(async x =>
            {
                if (NicoLiveVideo != null)
                {
                    NowSubmittingComment.Value = true;
                    await NicoLiveVideo.PostComment(WritingComment.Value, CommandString.Value, LiveElapsedTime);
                }
            });


            // operation command
            PermanentDisplayText = new ReactiveProperty <string>(PlayerWindowUIDispatcherScheduler, "").AddTo(_CompositeDisposable);


            // sound
            IsFullScreen = new ReactiveProperty <bool>(PlayerWindowUIDispatcherScheduler, false).AddTo(_CompositeDisposable);
            IsFullScreen
            .Subscribe(isFullScreen =>
            {
                var appView = ApplicationView.GetForCurrentView();
                if (isFullScreen)
                {
                    if (!appView.TryEnterFullScreenMode())
                    {
                        IsFullScreen.Value = false;
                    }
                }
                else
                {
                    appView.ExitFullScreenMode();
                }
            })
            .AddTo(_CompositeDisposable);

            IsSmallWindowModeEnable = HohoemaApp.Playlist
                                      .ToReactivePropertyAsSynchronized(x => x.IsPlayerFloatingModeEnable);


            IsAutoHideEnable =
                Observable.CombineLatest(
                    NowPlaying
                    , NowCommentWriting.Select(x => !x)
                    )
                .Select(x => x.All(y => y))
                .ToReactiveProperty(PlayerWindowUIDispatcherScheduler)
                .AddTo(_CompositeDisposable);

            Suggestion    = new ReactiveProperty <LiveSuggestion>();
            HasSuggestion = Suggestion.Select(x => x != null)
                            .ToReactiveProperty();

            AutoHideDelayTime = HohoemaApp.UserSettings.PlayerSettings
                                .ToReactivePropertyAsSynchronized(x => x.AutoHidePlayerControlUIPreventTime, PlayerWindowUIDispatcherScheduler)
                                .AddTo(_CompositeDisposable);

            IsDisplayControlUI = HohoemaApp.Playlist.ToReactivePropertyAsSynchronized(x => x.IsDisplayPlayerControlUI);


            IsMuted = HohoemaApp.UserSettings.PlayerSettings
                      .ToReactivePropertyAsSynchronized(x => x.IsMute, PlayerWindowUIDispatcherScheduler)
                      .AddTo(_CompositeDisposable);
            IsMuted.Subscribe(isMuted =>
            {
                MediaPlayer.IsMuted = isMuted;
            })
            .AddTo(_CompositeDisposable);

            SoundVolume = HohoemaApp.UserSettings.PlayerSettings
                          .ToReactivePropertyAsSynchronized(x => x.SoundVolume, PlayerWindowUIDispatcherScheduler)
                          .AddTo(_CompositeDisposable);
            SoundVolume.Subscribe(volume =>
            {
                MediaPlayer.Volume = volume;
            })
            .AddTo(_CompositeDisposable);

            CommentUpdateInterval = HohoemaApp.UserSettings.PlayerSettings.ObserveProperty(x => x.CommentRenderingFPS)
                                    .Select(x => TimeSpan.FromSeconds(1.0 / x))
                                    .ToReactiveProperty()
                                    .AddTo(_CompositeDisposable);

            RequestCommentDisplayDuration = HohoemaApp.UserSettings.PlayerSettings
                                            .ObserveProperty(x => x.CommentDisplayDuration)
                                            .ToReactiveProperty(PlayerWindowUIDispatcherScheduler)
                                            .AddTo(_CompositeDisposable);

            CommentFontScale = HohoemaApp.UserSettings.PlayerSettings
                               .ObserveProperty(x => x.DefaultCommentFontScale)
                               .ToReactiveProperty(PlayerWindowUIDispatcherScheduler)
                               .AddTo(_CompositeDisposable);


            IsForceLandscape = new ReactiveProperty <bool>(PlayerWindowUIDispatcherScheduler, HohoemaApp.UserSettings.PlayerSettings.IsForceLandscape);



            IsStillLoggedInTwitter = new ReactiveProperty <bool>(!TwitterHelper.IsLoggedIn)
                                     .AddTo(_CompositeDisposable);
        }
Esempio n. 15
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            using (new BackgroundTaskDeferralWrapper(taskInstance.GetDeferral()))
            {
                try
                {
                    var details = (SocketActivityTriggerDetails)taskInstance.TriggerDetails;
                    switch (details.Reason)
                    {
                    case SocketActivityTriggerReason.SocketActivity:
                        string request = null;
                        using (var socketOperation = Hub.Instance.SignalingSocketChannel.SocketOperation)
                        {
                            if (socketOperation.Socket != null)
                            {
                                var socket = socketOperation.Socket;

                                const uint length  = 65536;
                                var        readBuf = new Buffer(length);

                                var readOp = socket.InputStream.ReadAsync(readBuf, length,
                                                                          InputStreamOptions.Partial);
                                // This delay is to limit how long we wait for reading.
                                // StreamSocket has no ability to peek to see if there's any
                                // data waiting to be read.  So we have to limit it this way.
                                for (var i = 0; i < 100 && readOp.Status == AsyncStatus.Started; ++i)
                                {
                                    await Task.Delay(10);
                                }
                                await socket.CancelIOAsync();

                                try
                                {
                                    var localBuffer = await readOp;
                                    var dataReader  = DataReader.FromBuffer(localBuffer);
                                    request = dataReader.ReadString(dataReader.UnconsumedBufferLength);
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine($"ReadAsync exception: {ex}");
                                }
                            }
                        }
                        if (request != null)
                        {
                            await Hub.Instance.SignalingClient.HandleRequest(request);
                        }
                        break;

                    case SocketActivityTriggerReason.KeepAliveTimerExpired:
                        await Hub.Instance.SignalingClient.ClientHeartBeatAsync();

                        break;

                    case SocketActivityTriggerReason.SocketClosed:
                        await Hub.Instance.SignalingClient.ServerConnectionErrorAsync();

                        //ToastNotificationService.ShowToastNotification("Disconnected.");
                        break;
                    }
                }
                catch (Exception exception)
                {
                    await Hub.Instance.SignalingClient.ServerConnectionErrorAsync();

                    ToastNotificationService.ShowToastNotification(string.Format("Error in SignalingTask: {0}",
                                                                                 exception.Message));
                }
            }
        }