public void NormalCase()
        {
            var rp = new ReactivePropertySlim <string>();

            rp.Value.IsNull();
            rp.Subscribe(x => x.IsNull());
        }
Esempio n. 2
0
        /// <summary>
        /// <para>Converts NotificationObject's property to ReactivePropertySlim. Value is two-way synchronized.</para>
        /// <para>PropertyChanged raise on selected scheduler.</para>
        /// </summary>
        /// <typeparam name="TSubject">The type of the subject.</typeparam>
        /// <typeparam name="TProperty">The type of the property.</typeparam>
        /// <param name="subject">The subject.</param>
        /// <param name="propertySelector">Argument is self, Return is target property.</param>
        /// <param name="mode">ReactiveProperty mode.</param>
        /// <returns></returns>
        public static ReactivePropertySlim <TProperty> ToReactivePropertySlimAsSynchronized <TSubject, TProperty>(
            this TSubject subject,
            Expression <Func <TSubject, TProperty> > propertySelector,
            ReactivePropertyMode mode = ReactivePropertyMode.DistinctUntilChanged | ReactivePropertyMode.RaiseLatestValueOnSubscribe)
            where TSubject : INotifyPropertyChanged
        {
            if (ExpressionTreeUtils.IsNestedPropertyPath(propertySelector))
            {
                var result     = new ReactivePropertySlim <TProperty>(mode: mode);
                var observer   = PropertyObservable.CreateFromPropertySelector(subject, propertySelector);
                var disposable = Observable.Using(() => observer, x => x)
                                 .StartWith(observer.GetPropertyPathValue())
                                 .Subscribe(x => result.Value = x);
                result.Subscribe(x => observer.SetPropertyPathValue(x), _ => disposable.Dispose(), () => disposable.Dispose());
                return(result);
            }
            else
            {
                var setter = AccessorCache <TSubject> .LookupSet(propertySelector, out _);

                var result     = new ReactivePropertySlim <TProperty>(mode: mode);
                var disposable = subject.ObserveProperty(propertySelector, isPushCurrentValueAtFirst: true)
                                 .Subscribe(x => result.Value = x);
                result.Subscribe(x => setter(subject, x), _ => disposable.Dispose(), () => disposable.Dispose());
                return(result);
            }
        }
Esempio n. 3
0
        public ConfigurationViewModel()
        {
            // ComboBoxの初期値を設定するにはItemsSourceで利用しているインスタンスの中から指定する必要がある
            SelectedSwatch = new ReactivePropertySlim <Swatch>(Swatches.FirstOrDefault(s => s.Name == ThemeService.CurrentTheme.Name));
            SelectedSwatch.Subscribe(s => ChangeTheme(s)).AddTo(CompositeDisposable);

            var backupPath = UserConfigurationManager.Instance.GetConfiguration <BackupPathConfig>(ConfigKey.BackupPath);

            BackupPath = new ReactivePropertySlim <string>(backupPath?.DirectoryPath);

            var favorites = UserConfigurationManager.Instance.GetConfiguration <FavoriteWorkTasksConfig>(ConfigKey.FavoriteWorkTask);

            FavoriteWorkTasks = new ObservableCollection <FavoriteWorkTask>(favorites?.FavoriteWorkTasks ?? new FavoriteWorkTask[0]);

            var maps = UserConfigurationManager.Instance.GetConfiguration <ScheduleTitleMapConfig>(ConfigKey.ScheduleTitleMap)?.ScheduleTitleMaps;

            if (maps == null || maps.Count() == 0)
            {
                // 新設定が未登録なら旧設定をとる
                var config = JsonFileIO.Deserialize <TimeRecorderConfiguration>("TimeRecorderConfiguration.json") ?? new TimeRecorderConfiguration();
                maps = config.WorkTaskBuilderConfig.TitleMappers?.Select(t => t.ConvertToScheduleTitleMap()).ToArray();
            }
            ScheduleTitleMaps = new ObservableCollection <ScheduleTitleMap>(maps ?? new ScheduleTitleMap[0]);

            ShowFavoriteDescription = new ReactivePropertySlim <bool>(FavoriteWorkTasks.Count == 0);
            ShowScheduleDescription = new ReactivePropertySlim <bool>(ScheduleTitleMaps.Count == 0);

            var url = UserConfigurationManager.Instance.GetConfiguration <WorkingHourImportApiUrlConfig>(ConfigKey.WorkingHourImportApiUrl);

            WorkingHourImportUrl = new ReactivePropertySlim <string>(url?.URL);
        }
Esempio n. 4
0
 public TodoItem(string text, bool completed)
 {
     Text      = new ReactivePropertySlim <string>(text);
     Completed = new ReactivePropertySlim <bool>(completed);
     Text.Subscribe(_ => RaisePropertyChanged(nameof(Text)));
     Completed.Subscribe(_ => RaisePropertyChanged(nameof(Completed)));
 }
Esempio n. 5
0
        // view data source

        public MainWindowViewModel()
        {
            //コンボボックスの初期化
            Source       = new ObservableCollection <Item>(ProcessCollecter.collect().Select(x => new Item(x.ProcessName, x.ProcessId)));
            Items        = Source.ToReadOnlyReactiveCollection(x => new ItemViewModel(x));
            SelectedItem = new ReactivePropertySlim <ItemViewModel>(Items.First());

            SelectedItem.Subscribe(x =>
            {
                var res = Source.Where(y => y.Name.Value == x.Name.Value).ToList();
                if (res.Count > 0)
                {
                    System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
                    SelectedItemId   = res[0].Id.Value;
                    SelectedItemName = res[0].Name.Value;
                }
            });

            //スクリーンキャプチャ保存先
            PathOfScreencapture = new ReactiveProperty <string>();

            //キャプチャボタン
            CaptureCommand = new ReactiveCommand();
            CaptureCommand.Subscribe(_ => hookCapture(null, null));

            //セーブコマンド
            SaveCommand = new ReactiveCommand();
            SaveCommand.Subscribe(_ => saveSetting());

            //
            LoadedCommand = new ReactiveCommand();
            LoadedCommand.Subscribe(_ => setupdata());
        }
        public ArchiveManagerModel()
        {
            _GetDailyWorkRecordHeadersUseCase = new GetDailyWorkRecordHeadersUseCase(ContainerHelper.Resolver.Resolve <IDailyWorkRecordQueryService>());

            TargetDate = new ReactivePropertySlim <DateTime>(DateTime.Today);
            TargetDate.Subscribe(_ => Load()).AddTo(_Disposables);
        }
Esempio n. 7
0
        public MemberViewModel(string name, bool isSelected = false)
        {
            this.Name = name;

            IsSelected = new ReactivePropertySlim <bool>(isSelected);
            IsSelected.Subscribe(x => Debug.WriteLine($"IsSelected: {x}"));
        }
        public void InitialValue()
        {
            var rp = new ReactivePropertySlim <string>("Hello world");

            rp.Value.Is("Hello world");
            rp.Subscribe(x => x.Is("Hello world"));
        }
        public void NoRaiseLatestValueOnSubscribe()
        {
            var rp     = new ReactivePropertySlim <string>(mode: ReactivePropertyMode.DistinctUntilChanged);
            var called = false;

            rp.Subscribe(_ => called = true);
            called.Is(false);
        }
Esempio n. 10
0
 public ViewContentViewModel(ITwitterAgent twitterAgent)
 {
     this.twitterAgent = twitterAgent;
     TweetDatas        = this.twitterAgent.Tweets
                         .ToReactivePropertySlimAsSynchronized(x => x.Value)
                         .AddTo(this.disposables);
     TweetDatas.Subscribe(x => this.OnChangeTweetData(x));
 }
Esempio n. 11
0
        public ConvertFlowViewModel()
        {
            SelectedInputImageFormat  = new ReactivePropertySlim <ImageFileFormat>();
            SelectedConvertImageClass = new ReactivePropertySlim <ImageClass>();
            SelectedOutputImageFormat = new ReactivePropertySlim <ImageFileFormat>();


            SelectedInputImageFormat
            .Subscribe(x => Debug.WriteLine($"SelectedSourceImageFormat: {x}"));
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        internal PlaylistContentViewViewModel(
            IYouTubeService youTubeService,
            IWebClientService webClientService,
            IPlaylistListViewViewModel playlistListViewViewModel)
        {
            m_YouTubeService            = youTubeService;
            m_WebClientService          = webClientService;
            m_PlaylistListViewViewModel = playlistListViewViewModel;
            playlistListViewViewModel.SelectionChanged += PlaylistListViewViewModel_SelectionChanged;

            Title            = new ReactivePropertySlim <string>().AddTo(m_Disposables);
            Description      = new ReactivePropertySlim <string>().AddTo(m_Disposables);
            PlaylistItemList = new ReactiveCollection <PlaylistItemViewModel>().AddTo(m_Disposables);

            // コマンドの生成
            Playlist = new ReactivePropertySlim <Playlist?>().AddTo(m_Disposables);
            CanAddVideosToPlaylistItemAsync   = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            CanRemovePlaylistItemAsync        = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            CanMovePlaylistItemAsync          = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            CanClonePlaylistItemsFromPlaylist = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            CanAddOrClonePlaylistItems        = new ReactivePropertySlim <bool>().AddTo(m_Disposables);
            Playlist.Subscribe(v => {
                CanAddVideosToPlaylistItemAsync.Value   = (v != null);
                CanRemovePlaylistItemAsync.Value        = (v != null);
                CanMovePlaylistItemAsync.Value          = (v != null);
                CanClonePlaylistItemsFromPlaylist.Value = (v != null);
                CanAddOrClonePlaylistItems.Value        = (v != null);
            });
            AddVideosToPlaylistItemAsyncCommand = CanAddVideosToPlaylistItemAsync
                                                  .ToReactiveCommand()
                                                  .WithSubscribe(async() => await AddVideosToPlaylistItemAsync())
                                                  .AddTo(m_Disposables);
            RemovePlaylistItemAsyncCommand = CanRemovePlaylistItemAsync
                                             .ToReactiveCommand()
                                             .WithSubscribe(async() => await RemovePlaylistItemAsync())
                                             .AddTo(m_Disposables);
            MovePlaylistItemAsyncCommand = CanMovePlaylistItemAsync
                                           .ToReactiveCommand <IPlaylistListViewItemViewModel>()
                                           .WithSubscribe(async param => await MovePlaylistItemAsync(param))
                                           .AddTo(m_Disposables);
            ClonePlaylistItemsFromPlaylistCommand = CanClonePlaylistItemsFromPlaylist
                                                    .ToReactiveCommand()
                                                    .WithSubscribe(async() => await ClonePlaylistItemsFromPlaylist())
                                                    .AddTo(m_Disposables);
            AddOrClonePlaylistItemsCommand = CanAddOrClonePlaylistItems
                                             .ToReactiveCommand()
                                             .WithSubscribe(async() => await AddOrClonePlaylistItems())
                                             .AddTo(m_Disposables);

            // ダイアログを表示するインタラクションを保持
            ShowAddPlaylistItemDialog         = new Interaction <Unit, AddPlaylistItemDialogViewModel>();
            ShowClonePlaylistItemsDialog      = new Interaction <Unit, ClonePlaylistItemsDialogViewModel>();
            ShowAddOrClonePlaylistItemsDialog = new Interaction <Unit, AddOrClonePlaylistItemsDialogViewModel>();
        }
        public void CustomEqualityComparer()
        {
            var rp   = new ReactivePropertySlim <string>(equalityComparer: new IgnoreCaseComparer());
            var list = new List <string>();

            rp.Subscribe(list.Add);
            rp.Value = "Hello world";
            rp.Value = "HELLO WORLD";
            rp.Value = "Hello japan";
            list.Is(null, "Hello world", "Hello japan");
        }
        public void ForceNotify()
        {
            var rp        = new ReactivePropertySlim <int>(0);
            var collector = new List <int>();

            rp.Subscribe(collector.Add);

            collector.Is(0);
            rp.ForceNotify();
            collector.Is(0, 0);
        }
        public void NoDistinctUntilChanged()
        {
            var rp   = new ReactivePropertySlim <string>(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe);
            var list = new List <string>();

            rp.Subscribe(list.Add);
            rp.Value = "Hello world";
            rp.Value = "Hello world";
            rp.Value = "Hello japan";
            list.Is(null, "Hello world", "Hello world", "Hello japan");
        }
Esempio n. 16
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="youTubeService">YouTubeサービス</param>
        /// <param name="webClientService">Webクライエントサービス</param>
        public PlaylistListViewViewModel(IYouTubeService youTubeService, IWebClientService webClientService)
        {
            PlaylistList = new ReactiveCollection <IPlaylistListViewItemViewModel>().AddTo(m_Disposables);
            SelectedItem = new ReactivePropertySlim <PlaylistViewModel>().AddTo(m_Disposables);
            // 選択アイテムが変更されたら選択変更イベントも通知する
            SelectedItem.Subscribe(_ => RaiseSelectionChanged());

            m_YouTubeService   = youTubeService;
            m_WebClientService = webClientService;

            // ダイアログを表示するインタラクションを保持
            ShowAddPlaylistDialog = new Interaction <Unit, AddPlaylistDialogViewModel>();
        }
        protected ReactivePropertySlim <T> GetDefaultReactivePropertySlim <T>(T defaultVal, string name)
        {
            var rp = new ReactivePropertySlim <T>(defaultVal);

            rp.Subscribe(_ =>
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(name));
                }
            });
            return(rp);
        }
        public void EnumCase()
        {
            var rp      = new ReactivePropertySlim <TestEnum>();
            var results = new List <TestEnum>();

            rp.Subscribe(results.Add);
            results.Is(TestEnum.None);

            rp.Value = TestEnum.Enum1;
            results.Is(TestEnum.None, TestEnum.Enum1);

            rp.Value = TestEnum.Enum2;
            results.Is(TestEnum.None, TestEnum.Enum1, TestEnum.Enum2);
        }
Esempio n. 19
0
 public SelectHamburgerMenuViewModel(IRegionManager regionManager, IVisualPlugins plugins) : base(regionManager)
 {
     _Plugins             = plugins;
     PluginMainViewRegion = new ReactivePropertySlim <string>(RegionNames.MenuViewRegion).AddTo(Disposable);
     ActiveViewName       = new ReactiveProperty <string>("").AddTo(Disposable);
     PluginList           = new ObservableCollection <HamburgerMenuIconItem>(plugins.Select(ConvertTo));
     PluginList.RemoveAt(plugins.IndexOf(plugins.FirstOrDefault(x => x.MainViewName == nameof(SelectTile))));
     OptionList = new ObservableCollection <HamburgerMenuIconItem>();
     OptionList.Add(new HamburgerMenuIconItem()
     {
         Label = "Option", Icon = "Cog", Tag = nameof(OptionMenu)
     });
     PluginSelectedIndex = new ReactivePropertySlim <int>(-1).AddTo(Disposable);
     PluginSelectedIndex.Subscribe(OnSelectedMenu);
     OptionSelectedIndex = new ReactivePropertySlim <int>(-1).AddTo(Disposable);
     OptionSelectedIndex.Subscribe(OnSelectedOptionMenu);
 }
Esempio n. 20
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="youtubeService">YouTubeサービス</param>
        /// <param name="webClientService">Webクライエントサービス</param>
        public AddOrClonePlaylistItemsDialogViewModel(IYouTubeService youtubeService, IWebClientService webClientService)
        {
            m_YouTubeService   = youtubeService;
            m_WebClientService = webClientService;

            SearchWord         = new ReactivePropertySlim <string>().AddTo(m_Disposables);
            SearchResultList   = new ReactiveCollection <ChannelViewModel>().AddTo(m_Disposables);
            TargetPlaylistList = new ReactiveCollection <PlaylistViewModel>().AddTo(m_Disposables);
            TargetVideoList    = new ReactiveCollection <VideoViewModel>().AddTo(m_Disposables);
            SearchResultList   = new ReactiveCollection <ChannelViewModel>().AddTo(m_Disposables);
            SelectedItem       = new ReactivePropertySlim <ChannelViewModel>().AddTo(m_Disposables);
            ActiveTab          = new ReactivePropertySlim <ItemType>().AddTo(m_Disposables);

            // 選択アイテム・タブが変更されたらプレイリスト・動画一覧を更新
            SelectedItem.Subscribe(_ => UpdateActiveTab());
            ActiveTab.Subscribe(_ => UpdateActiveTab());
        }
Esempio n. 21
0
        public MainWindowViewModel()
        {
            DataSource = new ReactiveCollection <Fruit>();

            foreach (Fruit g in Enum.GetValues(typeof(Fruit)))
            {
                DataSource.Add(g);
            }

            SelectedItem = new ReactivePropertySlim <Fruit>(DataSource.First());
            SelectedItem.Subscribe(g =>
            {
                ItemName.Value      = $"Item : {g}";
                ItemPrice.Value     = $"Price : {g.GetPrice()}";
                ItemColor.Value     = $"Color : {g.GetColor()} ";
                SelectedColor.Value = g.GetColor().ToMediaColor();
                ItemImage.Value     = new Uri($"..\\Resource\\{g.GetResourceName()}", UriKind.Relative);
            });
        }
Esempio n. 22
0
        public WorkUnitRecorderModel()
        {
            _WorkTaskUseCase = new WorkTaskUseCase(
                ContainerHelper.Resolver.Resolve <IWorkTaskRepository>(),
                ContainerHelper.Resolver.Resolve <IWorkingTimeRangeRepository>());
            _WorkingTimeRangeUseCase = new WorkingTimeRangeUseCase(
                ContainerHelper.Resolver.Resolve <IWorkingTimeRangeRepository>(),
                ContainerHelper.Resolver.Resolve <IWorkTaskRepository>());
            _GetWorkingTimeForTimelineUseCase = new GetWorkingTimeForTimelineUseCase(ContainerHelper.Resolver.Resolve <IWorkingTimeQueryService>());
            _GetWorkTaskWithTimesUseCase      = new GetWorkTaskWithTimesUseCase(ContainerHelper.Resolver.Resolve <IWorkTaskWithTimesQueryService>());

            ObjectChangedNotificator.Instance.WorkTaskEdited += Load;
            MessageBroker.Default.Subscribe <WorkTaskRegistedEventArg>(_ => Load());

            TargetDate = new ReactivePropertySlim <DateTime>(DateTime.Today);
            TargetDate.Subscribe(_ => Load()).AddTo(_Disposables);

            ContainsCompleted.Subscribe(_ => Load()).AddTo(_Disposables);
        }
        public WorkTaskWithTimesCardViewModel(WorkTaskWithTimesDto dto)
        {
            Dto = dto;
            UpdateStatus();

            IsCompleted       = new ReactivePropertySlim <bool>(dto.IsCompleted, ReactivePropertyMode.DistinctUntilChanged);
            CheckboxIsEnabled = new ReactivePropertySlim <bool>(dto.IsCompleted == false);

            IsCompleted.Subscribe(b =>
            {
                if (b)
                {
                    CompleteWorkTask();
                }
            })
            .AddTo(CompositeDisposable);

            ShowWarning.Value = dto.TaskCategory != Domain.Domain.Tasks.Definitions.TaskCategory.Other &&
                                string.IsNullOrEmpty(dto.ProductName) &&
                                string.IsNullOrEmpty(dto.ClientName);
        }
Esempio n. 24
0
        public CacheManagementPageViewModel(
            IScheduler scheduler,
            NiconicoSession niconicoSession,
            ApplicationLayoutManager applicationLayoutManager,
            VideoCacheSettings cacheSettings,
            VideoCacheManager videoCacheManager,
            VideoCacheFolderManager videoCacheFolderManager,
            VideoCacheDownloadOperationManager videoCacheDownloadOperationManager,
            NicoVideoProvider nicoVideoProvider,
            PageManager pageManager,
            DialogService dialogService,
            NotificationService notificationService,
            SelectionModeToggleCommand selectionModeToggleCommand,
            VideoPlayWithQueueCommand videoPlayWithQueueCommand
            )
        {
            _scheduler                          = scheduler;
            _niconicoSession                    = niconicoSession;
            ApplicationLayoutManager            = applicationLayoutManager;
            VideoCacheSettings                  = cacheSettings;
            VideoCacheManager                   = videoCacheManager;
            _videoCacheFolderManager            = videoCacheFolderManager;
            _videoCacheDownloadOperationManager = videoCacheDownloadOperationManager;
            NicoVideoProvider                   = nicoVideoProvider;
            HohoemaDialogService                = dialogService;
            NotificationService                 = notificationService;
            SelectionModeToggleCommand          = selectionModeToggleCommand;
            VideoPlayWithQueueCommand           = videoPlayWithQueueCommand;
            Groups = new (new[]
            {
                VideoCacheStatus.Failed,
                VideoCacheStatus.Downloading,
                VideoCacheStatus.DownloadPaused,
                VideoCacheStatus.Pending,
                VideoCacheStatus.Completed,
            }
                          .Select(x => new CacheItemsGroup(x, new ObservableCollection <CacheVideoViewModel>()))
                          );

            IsLoggedInWithPremiumMember = _niconicoSession.ObserveProperty(x => x.IsPremiumAccount).ToReadOnlyReactivePropertySlim(_niconicoSession.IsPremiumAccount)
                                          .AddTo(_CompositeDisposable);

            CurrentlyCachedStorageSize = VideoCacheSettings.ObserveProperty(x => x.CachedStorageSize).ToReadOnlyReactivePropertySlim(VideoCacheSettings.CachedStorageSize)
                                         .AddTo(_CompositeDisposable);

            MaxCacheStorageSize = VideoCacheSettings.ObserveProperty(x => x.MaxVideoCacheStorageSize).ToReadOnlyReactivePropertySlim(VideoCacheSettings.MaxVideoCacheStorageSize)
                                  .AddTo(_CompositeDisposable);

            IsAllowDownload = new ReactivePropertySlim <bool>(_videoCacheDownloadOperationManager.IsAllowDownload, mode: ReactivePropertyMode.DistinctUntilChanged);
            IsAllowDownload.Subscribe(isAllowDownload =>
            {
                if (isAllowDownload)
                {
                    _videoCacheDownloadOperationManager.ResumeDownload();
                }
                else
                {
                    _videoCacheDownloadOperationManager.SuspendDownload();
                }
            })
            .AddTo(_CompositeDisposable);

            AvairableStorageSizeNormalized = new[]
            {
                CurrentlyCachedStorageSize,
                MaxCacheStorageSize.Select(x => x ?? 0),
            }
            .CombineLatest()
            .Select(xy => xy[1] == 0 ? 0.0 : ((double)xy[0] / xy[1]))
            .ToReadOnlyReactivePropertySlim()
            .AddTo(_CompositeDisposable);
        }