Esempio n. 1
0
 public GateProvider(Gate gate)
 {
     this.Gate = gate;
     
     this._comPortProvider = GetComPortProvider();
     this._cameraProviders = this.Gate.Cameras.Select(x => new HikVisionCameraProvider(x));
     this._licenceNumberProvider = new LicenceNumberProvider(this.Gate.VehicleNumberSaveFolder);
 }
        public SettingViewModel(IComPortProvider comPortProvider)
        {
            ComPorts  = new ObservableCollection <string>(SerialPort.GetPortNames());
            BaudRates = new ObservableCollection <string>(new string[] { "2400", "4800", "9600" });
            DataBits  = new ObservableCollection <string>(new string[] { "5", "6", "7", "8" });
            StopBits  = new ObservableCollection <string>(new string[] { "One", "Two" });
            Parity    = new ObservableCollection <string>(new string[] { "None", "Odd", "Even" });

            ComPortSetting   = ComPortConnectorSetting.GetComPortConnectorSetting() ?? new ComPortConnectorSetting();
            SaveSetting      = ReactiveCommand.Create(ExecuteSaveSetting);
            _comPortProvider = comPortProvider;
        }
Esempio n. 3
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();
        }