Example #1
0
        public ReestrSettingViewModel(
            ModalNavigationStore modalNavigationStore,
            IBarrelStorageDataService barrelStorageDataService,
            IReestrSettingDataService reestrSettingDataService,
            IRecipeDataService recipeDataService,
            ICustomerDataService customerDataService)
        {
            _modalNavigationStore     = modalNavigationStore;
            _barrelStorageDataService = barrelStorageDataService;
            _reestrSettingDataService = reestrSettingDataService;
            _recipeDataService        = recipeDataService;
            _customerDataService      = customerDataService;

            this.WhenAnyValue(x => x.Password)
            .Throttle(TimeSpan.FromSeconds(1))
            .Where(x => !string.IsNullOrWhiteSpace(x))
            .ObserveOnDispatcher()
            .Subscribe(PasswordChecker);

            this.WhenAnyValue(x => x.SelectedRecipe)
            .Skip(1)
            .SelectMany(async(x) => await _barrelStorageDataService.GetLastBarrelNumber(x))
            .ObserveOnDispatcher()
            .Subscribe(number => ReestrSetting.InitialBarrelNumber = number + 1);

            Task.Run(Initialize);
            SubmitCommand = new DelegateCommand(ExecuteSubmitCommand);
            CancelCommand = new DelegateCommand(() => modalNavigationStore.Close());
        }
Example #2
0
        public ShellViewModel(IComPortProvider comPortProvider,
                              IReestrSettingDataService reestrSettingDataService,
                              IDialogNavigationService dialogNavigationService,
                              IReestrDataService reestrDataService)
        {
            _comPortProvider          = comPortProvider;
            _reestrSettingDataService = reestrSettingDataService;
            _dialogNavigationService  = dialogNavigationService;
            _reestrDataService        = reestrDataService;
            MaxProgressValue          = 3;
            IsAutoMode = true;
            Task.Run(Initialize);

            var parsedValue = this.WhenAnyValue(x => x._comPortProvider.ComPortConnector.ParsedValue);

            parsedValue.Subscribe(ValueDropped);
            parsedValue.ObserveOnDispatcher()
            .Subscribe(x => Proggress(x));

            Observable.Interval(TimeSpan.FromSeconds(1))
            .ObserveOnDispatcher()
            .Subscribe(Progress2);

            parsedValue.Throttle(TimeSpan.FromSeconds(3))
            .Where(x => IsAutoMode && _isValueDroppedToMinimum)
            .Where(ValidateParsedValue)
            .SelectMany(InsertToDataBase)
            .Catch((Func <Exception, IObservable <ReestrObject> >)HandleException)
            .Where(x => x != null)
            .Select(x => x)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(InsertToCollection);

            var reestrCount = this.WhenAnyValue(x => x.ReestrsCollection.Count);

            _reestrCount = reestrCount
                           .Select(x => x)
                           .ToProperty(this, x => x.ReestrCount);

            _netTotal = reestrCount
                        .Select(x => ReestrsCollection.Sum(z => z.Net))
                        .ToProperty(this, x => x.NetTotal);


            _itemWeight = parsedValue.Select(x => x)
                          .ObserveOn(RxApp.MainThreadScheduler)
                          .ToProperty(this, x => x.ItemWeigth);

            var canExecute = this
                             .WhenAnyValue(x => x.IsAutoMode,
                                           isAutoMode => isAutoMode == false);

            Imitation   = ReactiveCommand.CreateFromTask(ExecuteImitation);
            SaveCommand = ReactiveCommand.CreateFromTask(ExecuteSaveCommand, canExecute);
            SaveCommand
            .Catch((Func <Exception, IObservable <ReestrObject> >)HandleException)
            .Where(x => x != null)
            .Select(x => x)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(InsertToCollection);


            var canEditAndCanPrint = this
                                     .WhenAnyValue(x => x.SelectedReestr)
                                     .Select(x => x != null);


            EditCommand  = ReactiveCommand.Create <ReestrObject>(ExecuteEditViewCommand, canEditAndCanPrint);
            PrintCommand = ReactiveCommand.Create <ReestrObject>(ExecutePrintViewCommand, canEditAndCanPrint);
            ExecuteOpenReestrSettingCommand();
        }