public async Task <List <IFormattedValue> > GetValuesForRecord(IJournalParameter parameter, ushort[] recordUshorts, DeviceContext deviceContext) { var formattedValues = new List <IFormattedValue>(); switch (parameter) { case ComplexJournalParameter complexJournalParameter: foreach (ISubJournalParameter childJournalParameter in complexJournalParameter .ChildJournalParameters) { formattedValues.Add(await _formattingService.FormatValueAsync( childJournalParameter.UshortsFormatter, new[] { GetParameterUshortInRecord(recordUshorts, complexJournalParameter, childJournalParameter) }, new FormattingContext(null, deviceContext, false))); } break; case DependentJournalParameter dependentJournalParameter: ushort[] dependentValuesToFormat = recordUshorts.Skip(dependentJournalParameter.StartAddress) .Take(dependentJournalParameter.NumberOfPoints).ToArray(); foreach (IJournalCondition journalParameterDependancyCondition in dependentJournalParameter .JournalParameterDependancyConditions) { if (GetConditionResult(recordUshorts, journalParameterDependancyCondition, dependentJournalParameter)) { //Task loadingTask = (journalParameterDependancyCondition.UshortsFormatter as ILoadable)?.Load(); //if (loadingTask != null) // await loadingTask; formattedValues.Add(await _formattingService.FormatValueAsync( journalParameterDependancyCondition.UshortsFormatter, dependentValuesToFormat, new FormattingContext(null, deviceContext, false))); } } break; case JournalParameter journalParameter: ushort[] valuesToFormat = recordUshorts.Skip(journalParameter.StartAddress) .Take(journalParameter.NumberOfPoints).ToArray(); formattedValues.Add(await _formattingService.FormatValueAsync(journalParameter.UshortsFormatter, valuesToFormat, new FormattingContext(null, deviceContext, false))); break; } return(formattedValues); }
private void OnCheckCommandExecute() { FireErrorsChanged(nameof(TestValueOfX)); FireErrorsChanged(nameof(FormulaString)); if (HasErrors) { return; } _formulaFormatter.FormulaString = FormulaString; _formulaFormatter.NumberOfSimbolsAfterComma = NumberOfSimbolsAfterComma; if (ArgumentViewModels.Count > 0) { TestResult = _localizerService.GetLocalizedString(ApplicationGlobalNames.StatusMessages .DYNAMIC_VALUES_CHECKING_IMPOSSIBLE); return; } try { TestResult = _formattingService.FormatValueAsync(_formulaFormatter, new[] { (ushort)TestValueOfX }, new FormattingContext(null, null, true)) .ToString(); } catch { TestResult = _localizerService.GetLocalizedString(ApplicationGlobalNames.StatusMessages.ERROR); } }
private static async Task <Result <ushort> > GetConditionPropertyUshort( ICompareResourceCondition dependancyCondition, DeviceContext deviceContext, IFormattingService formattingService, bool isLocal, ushort addressOffset) { var resourceProperty = deviceContext.DeviceSharedResources.SharedResourcesInContainers.FirstOrDefault( container => container.ResourceName == dependancyCondition.ReferencedPropertyResourceName).Resource as IProperty; var propertyUshortsRes = (await GetConditionPropertyUshort(dependancyCondition.ReferencedPropertyResourceName, deviceContext, formattingService, isLocal, addressOffset, resourceProperty)); if (!propertyUshortsRes.IsSuccess) { return(Result <ushort> .Create(false)); } if (resourceProperty.UshortsFormatter != null) { var value = await formattingService.FormatValueAsync(resourceProperty.UshortsFormatter, propertyUshortsRes.Item, new FormattingContext(null, deviceContext, isLocal)); if (double.TryParse(value.AsString(), out double conditionNumber)) { return(Result <ushort> .Create((ushort)conditionNumber, true)); } else { return(Result <ushort> .Create(propertyUshortsRes.Item.First(), true)); } } return(Result <ushort> .Create(propertyUshortsRes.Item.First(), true)); }
private static async Task <bool> CheckRegexCondition(IRegexMatchCondition regexMatchCondition, DeviceContext deviceContext, IFormattingService formattingService, bool isLocal, ushort addressOffset) { var resourceProperty = deviceContext.DeviceSharedResources.SharedResourcesInContainers.FirstOrDefault( container => container.ResourceName == regexMatchCondition.ReferencedPropertyResourceName).Resource as IProperty; var propertyUshorts = (await GetConditionPropertyUshort(regexMatchCondition.ReferencedPropertyResourceName, deviceContext, formattingService, isLocal, addressOffset, resourceProperty)).Item; if (resourceProperty.UshortsFormatter != null) { var value = await formattingService.FormatValueAsync(resourceProperty.UshortsFormatter, propertyUshorts, new FormattingContext(null, deviceContext, isLocal)); if (value is IStringValue stringValue) { return(Regex.IsMatch(stringValue.StrValue, regexMatchCondition.RegexPattern)); } } return(false); }
public async void Execute() { if (!MemoryAccessor.IsMemoryContainsAddresses(_deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, true)) { return; } var newUshorts = GetLocalUshortsForProp(); if (_property?.Dependencies?.Count > 0) { bool isHidden = false; bool isInteractionBlocked = false; var formatterForDependentProperty = _property.UshortsFormatter; foreach (var dependency in _property.Dependencies) { if (dependency is IConditionResultDependency conditionResultDependency) { var checkResult = await DependentSubscriptionHelpers.CheckCondition( conditionResultDependency.Condition, _deviceContext, _formattingService, true, (ushort)_offset); if (checkResult.IsSuccess) { if (checkResult.Item) { switch (conditionResultDependency.Result) { case IApplyFormatterResult applyFormatterResult: formatterForDependentProperty = applyFormatterResult.UshortsFormatter; break; case IBlockInteractionResult blockInteractionResult: isInteractionBlocked = checkResult.Item; break; case IHidePropertyResult hidePropertyResult: isHidden = checkResult.Item; break; } } else { switch (conditionResultDependency.Result) { case IBlockInteractionResult blockInteractionResult: isInteractionBlocked = checkResult.Item; break; case IHidePropertyResult hidePropertyResult: isHidden = checkResult.Item; break; } } } else { return; } } } if (_prevUshorts.IsEqual(newUshorts) && _prevIsHidden == isHidden && formatterForDependentProperty == _prevUshortFormatter && _prevIsInteractionBlocked == isInteractionBlocked) { return; } _prevIsHidden = isHidden; _prevIsInteractionBlocked = isInteractionBlocked; _prevUshorts = newUshorts; _prevUshortFormatter = formatterForDependentProperty; if (_runtimePropertyViewModel?.LocalValue != null) { _deviceContext.DeviceEventsDispatcher.RemoveSubscriptionById(_runtimePropertyViewModel .LocalValue.Id); _runtimePropertyViewModel.LocalValue.Dispose(); } _runtimePropertyViewModel.IsHidden = _property.IsHidden || isHidden; var localValue = await _formattingService.FormatValueAsync(formatterForDependentProperty, newUshorts, new FormattingContext(_runtimePropertyViewModel, _deviceContext, true)); var editableValue = StaticContainer.Container.Resolve <IValueViewModelFactory>() .CreateEditableValueViewModel(new FormattedValueInfo(localValue, _property, formatterForDependentProperty, _property, !isInteractionBlocked, !_prevUshorts.IsEqual(newUshorts))); var editSubscription = new LocalDataEditedSubscription(_runtimePropertyViewModel, editableValue, _deviceContext, _property, _offset); _runtimePropertyViewModel.LocalValue = editableValue; editableValue?.InitDispatcher(_deviceContext.DeviceEventsDispatcher); if (_runtimePropertyViewModel.LocalValue != null) { _deviceContext.DeviceEventsDispatcher.AddSubscriptionById(editSubscription , _runtimePropertyViewModel.LocalValue.Id); } editableValue.InitDispatcher(_deviceContext.DeviceEventsDispatcher); } else { if (!MemoryAccessor.IsMemoryContainsAddresses(_deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, true)) { return; } if (!newUshorts.IsEqual(_prevUshorts)) { _prevUshorts = newUshorts; var subPropertyValue = await StaticContainer.Container.Resolve <IFormattingService>() .FormatValueAsync( _property.UshortsFormatter, newUshorts, new FormattingContext(_runtimePropertyViewModel, _deviceContext, true)); _runtimePropertyViewModel.LocalValue.Accept( new EditableValueSetFromLocalVisitor(subPropertyValue)); } } }
public async void Execute() { if (_property.IsFromBits) { IFormattingService formattingService = StaticContainer.Container.Resolve <IFormattingService>(); var formatterForProperty = _property?.UshortsFormatter; if (!MemoryAccessor.IsMemoryContainsAddresses(_deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, false)) { return; } var ushortsFromDevice = MemoryAccessor.GetUshortsFromMemory( _deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, false); var boolArray = ushortsFromDevice.GetBoolArrayFromUshortArray().ToArray(); List <bool> subPropertyBools = new List <bool>(); foreach (var bitNumber in _property.BitNumbers) { subPropertyBools.Add(boolArray[bitNumber]); } subPropertyBools.Reverse(); var subPropertyUshort = subPropertyBools.BoolArrayToUshort(); if (_property?.Dependencies?.Count > 0) { formatterForProperty = await DependentSubscriptionHelpers.GetFormatterConsideringDependencies( _property.Dependencies, _deviceContext, formattingService, _property?.UshortsFormatter, _offset, false); } var value = await formattingService.FormatValueAsync(formatterForProperty, subPropertyUshort.AsCollection(), new FormattingContext(_localAndDeviceValueContainingViewModel, _deviceContext, false)); _localAndDeviceValueContainingViewModel.DeviceValue = _valueViewModelFactory.CreateFormattedValueViewModel(value); } else { IFormattingService formattingService = StaticContainer.Container.Resolve <IFormattingService>(); var formatterForProperty = _property?.UshortsFormatter; if (_property?.Dependencies?.Count > 0) { formatterForProperty = await DependentSubscriptionHelpers.GetFormatterConsideringDependencies( _property.Dependencies, _deviceContext, formattingService, _property?.UshortsFormatter, _offset, false); } if (MemoryAccessor.IsMemoryContainsAddresses( _deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, false)) { var value = await formattingService.FormatValueAsync(formatterForProperty, MemoryAccessor.GetUshortsFromMemory( _deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, false), new FormattingContext(_localAndDeviceValueContainingViewModel, _deviceContext, false)); _localAndDeviceValueContainingViewModel.DeviceValue = _valueViewModelFactory.CreateFormattedValueViewModel(value); } } }