Ejemplo n.º 1
0
        public SelectFixRectViewModel()
        {
            MouseLeftDownPoint = new ReactivePropertySlim <RoixBorderPoint>(mode: ReactivePropertyMode.None);
            MouseMovePoint     = new ReactivePropertySlim <RoixBorderPoint>();
            ViewBorderSize     = new ReactivePropertySlim <RoixSize>(mode: ReactivePropertyMode.DistinctUntilChanged);

            var imageSourceSize = MyImage.ToRoixIntSize();

            // 画像座標系の固定サイズ枠(これを基準に管理する) 右クリックで固定サイズの枠を描画する
            var clickedFixedRectangleOnImage = MouseLeftDownPoint
                                               .Where(border => border.Border.IsNotZero)
                                               .Select(borderPointOnView =>
            {
                var length         = 100;
                var rectBorderSize = new RoixIntSize(length).ToRoixBorder(imageSourceSize);
                var rectHalfSize   = rectBorderSize.Size / 2d;

                var newCenterPoint = borderPointOnView.ConvertToNewBorderInt(imageSourceSize);
                var newRect        = new RoixBorderIntRect(newCenterPoint - (RoixIntVector)rectHalfSize, rectBorderSize);
                return(newRect.GetClippedBorderIntRect(isPointPriority: false));
            })
                                               .ToReadOnlyReactivePropertySlim();

            // Model通知
            ClickedFixedRectangleToModel = clickedFixedRectangleOnImage
                                           .Where(border => border.Border.IsNotZero)
                                           .Select(borderRectOnView => borderRectOnView.Roi)
                                           .ToReadOnlyReactivePropertySlim();

            // View座標系の選択枠
            ClickedFixedRectangle = clickedFixedRectangleOnImage
                                    .CombineLatest(ViewBorderSize, (rect, border) => rect.ConvertToNewBorder(border).Roi)
                                    .ToReadOnlyReactivePropertySlim();
        }
Ejemplo n.º 2
0
        public SelectLineModel()
        {
            var imageSourceSize = MyImage.ToRoixIntSize();

            Line = new ReactivePropertySlim <RoixBorderIntLine>(initialValue: RoixIntLine.Zero.ToRoixBorder(imageSourceSize));

            PointsOnLine = Line
                           .Where(borderLine => borderLine.Border == imageSourceSize)
                           .Select(borderLine => borderLine.ClipToBorder().Line.GetIntPointsOnLine().ToArray())
                           .ToReadOnlyReactiveProperty <IReadOnlyList <RoixIntPoint> >();
        }
        public DeployToOpenShiftViewModel()
        {
            Masters        = model.Masters.ToReadOnlyReactiveCollection(m => new OpenShiftMasterViewModel(m));
            SelectedMaster = new ReactivePropertySlim <OpenShiftMasterViewModel>();
            SelectedMaster
            .Where(x => x != null)
            .Subscribe(x => model.SelectedMaster.Value = x.Model)
            .AddTo(Disposable);

            Projects          = model.Projects.ToReadOnlyReactiveCollection();
            SelectedNameSpace = model.SelectedProject.ToReactivePropertyAsSynchronized(x => x.Value);

            Name = model.Name
                   .ToReactiveProperty()
                   .SetValidateAttribute(() => Name)
                   .AddTo(Disposable);

            Host = model.Host
                   .ToReactiveProperty()
                   .SetValidateAttribute(() => Host)
                   .AddTo(Disposable);

            MemoryLimit = model.MemoryLimit
                          .ToReactiveProperty()
                          .SetValidateAttribute(() => MemoryLimit)
                          .AddTo(Disposable);

            GitSource = model.GitSource
                        .ToReactiveProperty()
                        .SetValidateAttribute(() => GitSource)
                        .AddTo(Disposable);

            GitRef = model.GitRef
                     .ToReactiveProperty()
                     .SetValidateAttribute(() => GitRef)
                     .AddTo(Disposable);

            StartupProject = model.StartupProject
                             .ToReactiveProperty()
                             .SetValidateAttribute(() => StartupProject)
                             .AddTo(Disposable);

            IsDeploying = model.IsDeploying.ToReadOnlyReactivePropertySlim();

            Message = model.Message.ToReadOnlyReactivePropertySlim();

            DeployCommand = SelectedMaster.Select(s => s != null)
                            .ToReactiveCommand()
                            .WithSubscribe(() =>
            {
                model.StartDeploy();
            });
        }
        public UserPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService, IAuthService authService) : base(navigationService)
        {
            _pageDialogService = pageDialogService;
            _authService       = authService;

            Title = "User";

            _user.Value = CrossFirebaseAuth.Current.Instance.CurrentUser;

            Name        = new ReactivePropertySlim <string>(_user.Value?.DisplayName);
            Email       = new ReactivePropertySlim <string>(_user.Value?.Email);
            PhoneNumber = new ReactivePropertySlim <string>(_user.Value?.PhoneNumber);

            IsLinkedWithGoogle = _user.Where(user => user != null)
                                 .Select(user => user.ProviderData.FirstOrDefault(data => data.ProviderId == CrossFirebaseAuth.Current.GoogleAuthProvider.ProviderId) != null)
                                 .ToReadOnlyReactivePropertySlim();

            IsLinkedWithTwitter = _user.Where(user => user != null)
                                  .Select(user => user.ProviderData.FirstOrDefault(data => data.ProviderId == CrossFirebaseAuth.Current.TwitterAuthProvider.ProviderId) != null)
                                  .ToReadOnlyReactivePropertySlim();

            IsLinkedWithFacebook = _user.Where(user => user != null)
                                   .Select(user => user.ProviderData.FirstOrDefault(data => data.ProviderId == CrossFirebaseAuth.Current.FacebookAuthProvider.ProviderId) != null)
                                   .ToReadOnlyReactivePropertySlim();

            IsLinkedWithGitHub = _user.Where(user => user != null)
                                 .Select(user => user.ProviderData.FirstOrDefault(data => data.ProviderId == CrossFirebaseAuth.Current.GitHubAuthProvider.ProviderId) != null)
                                 .ToReadOnlyReactivePropertySlim();

            _user.Where(user => user != null)
            .Select(user => user.DisplayName)
            .DistinctUntilChanged()
            .Subscribe(name => Name.Value = name);

            _user.Where(user => user != null)
            .Select(user => user.Email)
            .DistinctUntilChanged()
            .Subscribe(email => Email.Value = email);

            _user.Where(user => user != null)
            .Select(user => user.PhoneNumber)
            .DistinctUntilChanged()
            .Subscribe(phoneNumber => PhoneNumber.Value = phoneNumber);

            UpdateNameCommand.Subscribe(UpdateName);
            UpdateEmailCommand.Subscribe(UpdateEmail);
            UpdatePhoneNumberCommand.Subscribe(UpdatePhoneNumber);
            SignOutCommand.Subscribe(SignOut);
            LinkOrUnlinkWithGoogleCommand.Subscribe(() => IsLinkedWithGoogle.Value ? UnlinkWithGoogle() : LinkWithGoogle());
            LinkOrUnlinkWithTwitterCommand.Subscribe(() => IsLinkedWithTwitter.Value ? UnlinkWithTwitter() : LinkWithTwitter());
            LinkOrUnlinkWithFacebookCommand.Subscribe(() => IsLinkedWithFacebook.Value ? UnlinkWithFacebook() : LinkWithFacebook());
            LinkOrUnlinkWithGitHubCommand.Subscribe(() => IsLinkedWithGitHub.Value ? UnlinkWithGitHub() : LinkWithGitHub());
            DeleteCommand.Subscribe(Delete);
        }
        public TodoItemDetailPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService) : base(navigationService)
        {
            _pageDialogService = pageDialogService;

            Title = "Todo Item";

            _id.Where(id => id != null)
            .SelectMany(id => CrossCloudFirestore.Current.Instance.GetDocument($"{TodoItem.CollectionPath}/{id}").GetDocumentAsync())
            .Where(document => document != null)
            .Select(document => document.ToObject <TodoItem>())
            .Subscribe(todoItem =>
            {
                if (_todoItem != null)
                {
                    _todoItem.Value = todoItem;
                    Name.Value      = todoItem.Name;
                    Notes.Value     = todoItem.Notes;
                }
            }, ex => System.Diagnostics.Debug.WriteLine(ex));

            UpdateCommand = new[] {
                _todoItem.Select(x => x == null),
                Name.Select(x => string.IsNullOrEmpty(x))
            }.CombineLatestValuesAreAllFalse()
            .ObserveOn(SynchronizationContext.Current)
            .ToAsyncReactiveCommand();

            UpdateCommand.Subscribe(async() =>
            {
                var todoItem   = _todoItem.Value;
                todoItem.Name  = Name.Value;
                todoItem.Notes = Notes.Value;

                CrossCloudFirestore.Current.Instance.GetDocument($"{TodoItem.CollectionPath}/{todoItem.Id}")
                .UpdateData(todoItem, (error) =>
                {
                    if (error != null)
                    {
                        System.Diagnostics.Debug.WriteLine(error);
                    }
                });

                await navigationService.GoBackAsync();
            });

            DeleteCommand = new[] {
                _todoItem.Select(x => x == null)
            }.CombineLatestValuesAreAllFalse()
            .ObserveOn(SynchronizationContext.Current)
            .ToAsyncReactiveCommand();

            DeleteCommand.Subscribe(async() =>
            {
                var ok = await _pageDialogService.DisplayAlertAsync("Are you sure you want to delete this?", _todoItem.Value.Name, "Ok", "Cancel");

                if (ok)
                {
                    CrossCloudFirestore.Current
                    .Instance
                    .GetDocument($"{TodoItem.CollectionPath}/{_todoItem.Value.Id}")
                    .DeleteDocument((error) =>
                    {
                        if (error != null)
                        {
                            System.Diagnostics.Debug.WriteLine(error);
                        }
                    });

                    await NavigationService.GoBackAsync();
                }
            });
        }