Exemplo n.º 1
0
        private async Task TryExecutenextCommandAsync(IRuntimeDeviceViewModel runtimeDeviceViewModel)
        {
            if (_presiousDeviceCommands.ContainsKey(runtimeDeviceViewModel))
            {
                return;
            }
            if (_queueCommandDictionary[runtimeDeviceViewModel.Model as IRuntimeDevice].Count > 0)
            {
                Func <IDeviceCommand> commandCreator = _queueCommandDictionary[runtimeDeviceViewModel.Model as IRuntimeDevice].Dequeue();

                if (runtimeDeviceViewModel.StateWidget == WidgetState.NoConnection)
                {
                    await DelayExecution(commandCreator, runtimeDeviceViewModel);

                    return;
                }
                var command = commandCreator.Invoke();
                foreach (var starter in command.Starters)
                {
                    var starterVM = runtimeDeviceViewModel.StarterViewModels.FirstOrDefault((starterViewModel =>

                                                                                             starterViewModel?.Model == starter));
                    if (starterVM != null)
                    {
                        starterVM.DeviceCommandStateViewModel =
                            _deviceCommandStateViewModelFactory.CreateDeviceCommandStateViewModel(command);
                    }
                }
                _presiousDeviceCommands.TryAdd(runtimeDeviceViewModel, command);
                await _commandSendingService.TryExecuteCommand(command, runtimeDeviceViewModel.Model as IRuntimeDevice);
            }
        }
Exemplo n.º 2
0
 public void SetDevice(IRuntimeDeviceViewModel runtimeDeviceViewModel)
 {
     _runtimeDeviceViewModel = runtimeDeviceViewModel;
     _analogTimerInterrogationService.SetDeviceForInterrogation(_runtimeDeviceViewModel.Model as IRuntimeDevice);
     if (_runtimeDeviceViewModel.DeviceSignature != null)
     {
         if (_runtimeDeviceViewModel.DeviceSignature.Contains("RUNO") &&
             ((_runtimeDeviceViewModel.DeviceSignature.Contains("UC")) ||
              (_runtimeDeviceViewModel.DeviceSignature.Contains("M"))))
         {
             IsThreeEnergiesShowing = true;
         }
         //TODO: check signature for piconGS ver.27+ to enable/disable three energies showing
         else
         if ((_runtimeDeviceViewModel.DeviceSignature.Contains("gs") || _runtimeDeviceViewModel.DeviceSignature.Contains("GS")) &&
             (Convert.ToInt32(_runtimeDeviceViewModel.DeviceSignature.Split('.').Last()) >= 27))
         {
             IsThreeEnergiesShowing = true;
         }
         else
         {
             IsThreeEnergiesShowing = false;
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        ///     Called after the behavior is attached to an AssociatedObject.
        ///     Вызывается после того как поведение привяжется к AssociatedObject
        /// </summary>
        /// <remarks>
        ///     Override this to hook up functionality to the AssociatedObject.
        /// </remarks>
        protected override void OnAttached()
        {
            base.OnAttached();
            _deviceViewModel            = AssociatedObject.DataContext as IRuntimeDeviceViewModel;
            _defectAcknowledgingService =
                _globalDefectAcknowledgingService.GetDefectAcknowledgingService(
                    _deviceViewModel.Model as IRuntimeDevice);
            _assotiatedBorder          = AssociatedObject;
            AssociatedObject.Unloaded += AssociatedObject_Unloaded;

            if (_deviceViewModel != null)
            {
                (_deviceViewModel.Model as IRuntimeDevice).DeviceValuesUpdated += async() =>
                {
                    await Task.Run((() =>
                    {
                        CheckStateWidget();
                    }));
                };
                (_deviceViewModel.Model as IRuntimeDevice).TcpDeviceConnection.ConnectionLostAction += async() =>
                {
                    await Task.Run((() =>
                    {
                        CheckStateWidget();
                    }));
                };


                _defectAcknowledgingService.AcknowledgeValueChanged += CheckStateWidget;
                CheckAckFail();
                CheckStateWidget();
            }
        }
Exemplo n.º 4
0
        public IAnalogMeterViewModel CreateAnalogMeterViewModel(IRuntimeDeviceViewModel runtimeDeviceViewModel, object analogMeter)
        {
            IAnalogMeter analogMeterModel = analogMeter as IAnalogMeter;

            IAnalogMeterViewModel analogMeterViewModel =
                _container.Resolve <IAnalogMeterViewModel>(analogMeterModel.AnalogMeterType);

            analogMeterViewModel.Model = analogMeterModel;
            analogMeterViewModel.SetDevice(runtimeDeviceViewModel);
            return(analogMeterViewModel);
        }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="navigationContext"></param>
 public void OnNavigatedFrom(NavigationContext navigationContext)
 {
     _navigationContext.Add("CurrentdDeviceViewModel", _currentDeviceViewModel);
     _navigationContext.ForEach((pair =>
     {
         navigationContext.Parameters.Add(pair.Key, pair.Value);
     }));
     this._deviceName             = null;
     this._currentDeviceViewModel = null;
     this._sendLightingShedule    = null;
 }
Exemplo n.º 6
0
        /// <summary>
        /// вью-модель для показания счетчиков
        /// </summary>
        /// <param name="analogMeterType"></param>
        /// <param name="deviceViewModel"></param>
        public AnalogDataTableViewModel(string analogMeterType, IRuntimeDeviceViewModel deviceViewModel)
        {
            if (deviceViewModel.GetType().ToString().Contains(".Runo3."))
            {
                //if (deviceViewModel.DeviceSignature != null)
                //{
                //    if (deviceViewModel.DeviceSignature.Contains("UC") || deviceViewModel.DeviceSignature.Contains("M"))
                //    {
                //        IsThreeEnegriesShowing = true;
                //    }
                //    else
                //    {
                //        IsThreeEnegriesShowing = false;
                //    }
                //}
            }



            if (analogMeterType == null)
            {
                return;
            }
            //if (!analogMeterType.Contains(AnalogMetersEnum.МСА961.ToString())) return;
            //IsMsa961Checked = true;
            //if (!analogMeterType.Contains('%'))
            //{
            //    TransKoefA = 100;
            //    TransKoefB = 100;
            //    TransKoefC = 100;
            //}
            //var trks = analogMeterType.Replace(AnalogMetersEnum.МСА961.ToString(), "").Split('%');
            //if (trks.Length <= 2) return;
            //int trkA;
            //int trkB;
            //int trkC;
            //if (Int32.TryParse(trks[0], out trkA))
            //    TransKoefA = trkA;

            //if (Int32.TryParse(trks[1], out trkB))
            //    TransKoefB = trkB;

            //if (Int32.TryParse(trks[2], out trkC))
            //    TransKoefC = trkC;
        }
Exemplo n.º 7
0
 /// <summary>
 ///     Called when the implementer is being navigated away from.
 ///     Вызывается при переходе с вьюхи
 /// </summary>
 /// <param name="navigationContext">The navigation context</param>
 public void OnNavigatedFrom(NavigationContext navigationContext)
 {
     this.DeviceDate = null;
     navigationContext.Parameters.Add(ApplicationGlobalNames.CURRENT_DEVICE_VIEW_MODEL, _currentDeviceViewModel);
     _navigationContext.ForEach((pair =>
     {
         navigationContext.Parameters.Add(pair.Key, pair.Value);
     }));
     (_currentDeviceViewModel.Model as IRuntimeDevice).DeviceInitialized -= OnDeviceInitialized;
     (_currentDeviceViewModel.Model as IRuntimeDevice).SetUpdatingMode(false);
     OutgoingLinesViewModel?.Dispose();
     OutgoingLinesViewModel       = null;
     StarterDescriptions          = new List <string>();
     FiderDescriptions            = new List <string>();
     this._currentDeviceViewModel = null;
     _analogMeterViewModel?.Dispose();
     _analogMeterViewModel = null;
 }
Exemplo n.º 8
0
        public virtual void CheckIfCommandSucceed(IRuntimeDeviceViewModel runtimeDeviceViewModel)
        {
            bool isCommandSucceed = _rule.IsCommandSucceed(runtimeDeviceViewModel);

            if (isCommandSucceed)
            {
                _isCommandSucceed = true;
                CurrectCommandStateChanged?.Invoke();
            }
            else if (!_isCommandSucceed.HasValue)
            {
                _currentCommandcheckCounter++;
                if (_currentCommandcheckCounter == _commandCheckTimes)
                {
                    _isCommandSucceed = false;
                    CurrectCommandStateChanged?.Invoke();
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="runtimeDeviceViewModel"></param>
        public void OpenDeviceLog(IRuntimeDeviceViewModel runtimeDeviceViewModel)
        {
            _runtimeDeviceViewModel = runtimeDeviceViewModel;


            var logWnd = new Window();

            logWnd.Owner = Application.Current.MainWindow;
            var logView = new LogInteractionView();
            var vm      = this;

            logView.DataContext = vm;
            logView.Margin      = new Thickness(5, 5, 5, 5);
            logWnd.Content      = logView;
            logWnd.Title        = "Журнал устройства";
            logWnd.ResizeMode   = ResizeMode.CanMinimize;
            logWnd.Height       = 625;
            logWnd.Width        = 670;
            logWnd.Closing     += (o, e) =>
            {
                //this.IsLoadingInProcess = false;
                OnCanceling();
            };
            logWnd.Show();


            if (LogCollection.IsEmpty)
            {
                OnRefreshExecute();
            }
            //if (logList.Count == 0)
            //{
            //    logWnd.Close();
            //    this._interactionService.Interact(
            //        ApplicationInteractionProviders.InformationMessageBoxInteractionProvider,
            //        viewModel =>
            //        {
            //            viewModel.Title = "Журнал устройства";
            //            viewModel.Message = "Журнал пуст";
            //        });
            //}
        }
Exemplo n.º 10
0
        public async Task TryExecuteCommandOnDevice(IRuntimeDeviceViewModel runtimeDeviceViewModel)
        {
            if (_presiousDeviceCommands.ContainsKey(runtimeDeviceViewModel))
            {
                _presiousDeviceCommands[runtimeDeviceViewModel].CheckIfCommandSucceed(runtimeDeviceViewModel);
                if (_presiousDeviceCommands[runtimeDeviceViewModel].IsCommandSucceed.HasValue)
                {
                    IDeviceCommand command;
                    _presiousDeviceCommands.TryRemove(runtimeDeviceViewModel, out command);
                }
            }

            if (_queueCommandDictionary.ContainsKey(runtimeDeviceViewModel.Model as IRuntimeDevice))
            {
                if (_queueCommandDictionary[runtimeDeviceViewModel.Model as IRuntimeDevice].Count > 0)
                {
                    await TryExecutenextCommandAsync(runtimeDeviceViewModel);
                }
            }
        }
Exemplo n.º 11
0
 private void SetDateTimeToPersistance(IRuntimeDeviceViewModel deviceViewModel, DateTime newDate)
 {
     //deviceViewModel.SynchronizateTime(newDate);
 }
Exemplo n.º 12
0
        public async Task AddDeviceCommandCreator(Func <IDeviceCommand> deviceCommandCreator, IRuntimeDeviceViewModel runtimeDeviceViewModel)
        {
            if (!_queueCommandDictionary.ContainsKey(runtimeDeviceViewModel.Model as IRuntimeDevice))
            {
                _queueCommandDictionary.Add(runtimeDeviceViewModel.Model as IRuntimeDevice, new Queue <Func <IDeviceCommand> >());
            }

            _queueCommandDictionary[runtimeDeviceViewModel.Model as IRuntimeDevice].Enqueue(deviceCommandCreator);
            await  TryExecutenextCommandAsync(runtimeDeviceViewModel);
        }
Exemplo n.º 13
0
        private async Task DelayExecution(Func <IDeviceCommand> deviceCommandCreator, IRuntimeDeviceViewModel runtimeDeviceViewModel)
        {
            for (int i = 0; i < _settingsService.NumberOfLightingCommandRepeat; i++)
            {
                await Task.Delay(_settingsService.MillisecondRepeatInterval);

                if (runtimeDeviceViewModel.StateWidget == WidgetState.NoConnection)
                {
                    continue;
                }
                _queueCommandDictionary[runtimeDeviceViewModel.Model as IRuntimeDevice].Enqueue(deviceCommandCreator);
                await TryExecutenextCommandAsync(runtimeDeviceViewModel);
            }
        }
Exemplo n.º 14
0
 public override void CheckIfCommandSucceed(IRuntimeDeviceViewModel runtimeDevice)
 {
     _isCommandSucceed = IsCommandSent;
     CurrectCommandStateChanged?.Invoke();
 }
Exemplo n.º 15
0
 public void SetDevice(IRuntimeDeviceViewModel runtimeDeviceViewModel)
 {
     _runtimeDeviceViewModel = runtimeDeviceViewModel;
     _analogTimerInterrogation.SetDeviceForInterrogation(_runtimeDeviceViewModel.Model as IRuntimeDevice);
 }
Exemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="navigationContext"></param>
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            if (navigationContext.Parameters != null)
            {
                this._currentDeviceViewModel = navigationContext.Parameters["CurrentdDeviceViewModel"] as
                                               IRuntimeDeviceViewModel;
                // this._startAddress = ushort.Parse(navigationContext.Parameters["address"].ToString());
                this.Title = navigationContext.Parameters["title"].ToString();

                if (Title.Contains("1"))
                {
                    _startAddress = 0x3280;
                }
                if (Title.Contains("2"))
                {
                    _startAddress = 0x3580;
                }
                if (Title.Contains("3"))
                {
                    _startAddress = 0x3880;
                }

                this.DeviceName = this._currentDeviceViewModel.DeviceName;
                this._logger    = LogManager.GetLogger(this.DeviceName + " " + this.Title);
                this.RangeDaysEconomyStartMonth = new ObservableCollection <int>();
                this.RangeDaysEconomyStopMonth  = new ObservableCollection <int>();

                this._monthsCollection.Clear();
                foreach (var mothName in this._mothNames)
                {
                    this._monthsCollection.Add(mothName, new ObservableCollection <IDaySheduleViewModel>());
                }
                var monthLengthList = this._monthsLenghtDictionary.Values.ToArray();
                for (int i = 0; i < MONTH_COUNT; i++)
                {
                    for (int j = 0; j < monthLengthList[i]; j++)
                    {
                        this._monthsCollection[this._mothNames[i]].Add(new DaySheduleViewModel
                        {
                            Month     = this._mothNames[i],
                            DayNumber = j + 1
                        });
                    }
                    this._monthsCollection[this._mothNames[i]].Add(new DaySheduleViewModel
                    {
                        Month     = this._mothNames[i],
                        DayNumber = monthLengthList[i] + 1,
                        IsEconomy = true
                    });
                }


                this.CurrentMonthName = this._mothNames[DateTime.Now.Month - 1];

                this._logger = LogManager.GetLogger(this.DeviceName + " " + this.Title);
                this._logger.Trace(DateTime.Now.ToString(new CultureInfo("de-DE")) + " Переход в режим настройки " +
                                   this._title);

                for (int i = 0; i < this.MonthCollection.Count; i++)
                {
                    string monthName = this._mothNames[i];
                    for (int j = 0; j < this._monthsLenghtDictionary[monthName]; j++)
                    {
                        this._monthsCollection[monthName][j].StartHour   = 0;
                        this._monthsCollection[monthName][j].StartMinute = 0;
                        this._monthsCollection[monthName][j].StopHour    = 0;
                        this._monthsCollection[monthName][j].StopMinute  = 0;
                    }
                }

                for (int i = 0; i < CurrentMonthDayCollection.Count; i++)
                {
                    this.CurrentMonthDayCollection[i].StartHour   = 0;
                    this.CurrentMonthDayCollection[i].StartMinute = 0;
                    this.CurrentMonthDayCollection[i].StopHour    = 0;
                    this.CurrentMonthDayCollection[i].StopMinute  = 0;
                }

                if (this._sheduleCache.ContainsKey(this.Title))
                {
                    this.InitializeOnNavigateTo(this._sheduleCache[this.Title]);
                }
                else
                {
                    this.InitializeOnNavigateTo();
                }
            }
            _navigationContext.Clear();
        }
Exemplo n.º 17
0
        public bool IsCommandSucceed(IRuntimeDeviceViewModel runtimeDeviceViewModel)
        {
            foreach (var starterId in _starterIds)
            {
                var starter = runtimeDeviceViewModel.StarterViewModels.First((s => s.StarterNumber == starterId));
                switch (_commandType)
                {
                case CommandTypesEnum.ON:
                    if (!starter.IsStarterOn.HasValue)
                    {
                        return(false);
                    }
                    if (!starter.IsStarterOn.Value)
                    {
                        return(false);
                    }
                    break;

                case CommandTypesEnum.OFF:
                    if (!starter.IsStarterOn.HasValue)
                    {
                        return(false);
                    }
                    if (starter.IsStarterOn.Value)
                    {
                        return(false);
                    }
                    break;

                case CommandTypesEnum.AUTO:
                    if (!starter.IsInManualMode.HasValue)
                    {
                        return(false);
                    }
                    if (starter.IsInManualMode.Value)
                    {
                        return(false);
                    }
                    break;

                case CommandTypesEnum.MANUAL:
                    if (!starter.IsInManualMode.HasValue)
                    {
                        return(false);
                    }
                    if (!starter.IsInManualMode.Value)
                    {
                        return(false);
                    }
                    break;

                case CommandTypesEnum.Repair:
                    if (!starter.IsInRepairState.HasValue)
                    {
                        return(false);
                    }
                    if (!starter.IsInRepairState.Value)
                    {
                        return(false);
                    }
                    break;

                case CommandTypesEnum.NoRepair:
                    if (!starter.IsInRepairState.HasValue)
                    {
                        return(false);
                    }
                    if (starter.IsInRepairState.Value)
                    {
                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }