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));
        }
 public UpdateUser(ApplicationDbContext dbContext, IUpdatePersonTask updatePersonTask, IAddPersonTask addPersonTask, IFormattingService formattingService)
 {
     _dbContext         = dbContext;
     _updatePersonTask  = updatePersonTask;
     _addPersonTask     = addPersonTask;
     _formattingService = formattingService;
 }
        public EnterForm(EntranceContext context)
        {
            _context           = context ?? throw new ArgumentNullException(nameof(context));
            _entranceService   = _context.UnityContainer.Resolve <IEntranceService>();
            _formattingService = _context.UnityContainer.Resolve <IFormattingService>();

            if (ApplicationUtility.IsRunningOnMono)
            {
                Font = new Font("Arial", 8);
            }

            InitializeComponent();

            mTunableList.ServiceCommand += (sender, args) =>
            {
                switch (args.Command)
                {
                case "Remove":
                    removeButton_Click(this, null);
                    break;

                case "CellMouseDoubleClick":
                    enterButton_Click(this, null);
                    break;
                }
            };
        }
Example #4
0
        public FormulaFormatterViewModel(ILocalizerService localizerService, ITypesContainer container,
                                         Func <IArgumentViewModel> argumentViewModelGettingFunc,
                                         ISharedResourcesGlobalViewModel sharedResourcesGlobalViewModel, IFormattingService formattingService)
        {
            _localizerService               = localizerService;
            _container                      = container;
            _argumentViewModelGettingFunc   = argumentViewModelGettingFunc;
            _sharedResourcesGlobalViewModel = sharedResourcesGlobalViewModel;
            _formattingService              = formattingService;
            ArgumentViewModels              = new ObservableCollection <IArgumentViewModel>();
            _formulaFormatter               =
                _container.Resolve <IUshortsFormatter>(StringKeys.FORMULA_FORMATTER) as IFormulaFormatter;

            if (_formulaFormatter == null)
            {
                throw new ArgumentException();
            }

            CheckCommand          = new RelayCommand(OnCheckCommandExecute);
            DeleteArgumentCommand = new RelayCommand <IArgumentViewModel>(OnDeleteArgumentExecute);
            AddArgumentCommand    = new RelayCommand(OnAddArgumentExecute);
            _formulaFormatter.NumberOfSimbolsAfterComma = 3;

            InitializeFormulaTooltip();
        }
 public DefaultFormattingServiceTests()
 {
     formatService = new DefaultFormattingService();
     groups        = new List <Group>()
     {
         new Group("Simon", new [] { "Sergey", "Thomas" })
     };
 }
 public AdminModule(IBotConfig botConfig, IEmbedService embedService, IEmbedPayloadFactory embedPayloadFactory,
                    IResources resources, IFormattingService formattingService, IDiscordPayloadFactory discordPayloadFactory,
                    IDiscordModuleService discordModuleService)
     : base(botConfig, discordModuleService, embedService, embedPayloadFactory, resources)
 {
     _formattingService     = formattingService;
     _discordPayloadFactory = discordPayloadFactory;
 }
 public BarController(IBarServices barServices, ICocktailServices cocktailServices, IBarCocktailServices barCocktailServices, IApiServices apiServices, IFormattingService formattingService, IMailServices mailServices)
 {
     _barServices         = barServices;
     _cocktailServices    = cocktailServices;
     _barCocktailServices = barCocktailServices;
     _apiServices         = apiServices;
     _formattingService   = formattingService;
     _mailServices        = mailServices;
 }
Example #8
0
 public AnalogSubscription(IAnalogMeasuringElement analogMeasuringElement,
                           IAnalogMeasuringElementViewModel analogMeasuringElementViewModel, DeviceContext deviceContext,
                           string groupName, IFormattingService formattingService)
 {
     this._analogMeasuringElement          = analogMeasuringElement;
     this._analogMeasuringElementViewModel = analogMeasuringElementViewModel;
     _deviceContext          = deviceContext;
     this._formattingService = formattingService;
     GroupName = groupName;
 }
Example #9
0
 public LocalMemorySubscription(IUshortsFormatter ushortsFormatter, DeviceContext deviceContext,
                                IRuntimePropertyViewModel runtimePropertyViewModel,
                                IProperty property, IFormattingService formattingService, int offset, ushort[] prevUshorts)
 {
     _ushortsFormatter         = ushortsFormatter;
     _deviceContext            = deviceContext;
     _runtimePropertyViewModel = runtimePropertyViewModel;
     _property            = property;
     _formattingService   = formattingService;
     _offset              = offset;
     _prevUshorts         = prevUshorts;
     _prevUshortFormatter = property.UshortsFormatter;
 }
 public EventController(
     IBarServices barServices,
     IApiServices apiServices,
     ICocktailServices cocktailServices,
     IBarCocktailServices barCocktailServices,
     IMailServices mailServices,
     IFormattingService formattingService)
 {
     this.barServices         = barServices;
     this.apiServices         = apiServices;
     this.cocktailServices    = cocktailServices;
     this.barCocktailServices = barCocktailServices;
     this.mailServices        = mailServices;
     this.formattingService   = formattingService;
 }
Example #11
0
        public MainForm(SessionContext sessionContext)
        {
            _sessionContext = sessionContext ?? throw new ArgumentNullException(nameof(sessionContext));
            InitializeComponent();

            _identifierService = _sessionContext.UnityContainer.Resolve <IIdentifierService>();
            _formattingService = _sessionContext.UnityContainer.Resolve <IFormattingService>();

            BuildTitle();
            UpdateComboBox();
            BuildMainMenu();
            BuildScreens();

            removeIdentifierButton.Enabled = false;
        }
        public static string FormatIdentifierWithAlias(IFormattingService formattingService, long identifier, string identifierAlias)
        {
            if (null == formattingService)
            {
                throw new ArgumentNullException(nameof(formattingService));
            }

            if (null == identifierAlias)
            {
                identifierAlias = "[Master]";
            }

            var identifierValue = formattingService.FormatIdentifier(identifier);

            return($"{identifierAlias} WMID#{identifierValue}");
        }
Example #13
0
        public CertificateForm(SessionContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _formattingService = context.UnityContainer.Resolve <IFormattingService>();

            InitializeComponent();

            certificateTunableList.ServiceCommand += (sender, args) =>
            {
                ServiceCommand?.Invoke(sender, args);
            };

            attachedIdentifierTunableList.ServiceCommand += (sender, args) =>
            {
                ServiceCommand?.Invoke(sender, args);
            };
        }
Example #14
0
        public TransferRegisterForm(SessionContext context, string accountNumber = null)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));

            _currencyService   = context.UnityContainer.Resolve <ICurrencyService>();
            _formattingService = context.UnityContainer.Resolve <IFormattingService>();

            InitializeComponent();

            var origin = new AccountDropDownListOrigin(context.UnityContainer);

            origin.FilterCriteria.CurrencyCapabilities = CurrencyCapabilities.Actual | CurrencyCapabilities.Transfer;

            if (null != accountNumber)
            {
                origin.SelectedAccountNumber = accountNumber;
            }

            var itemTemplates = AccountDisplayHelper.BuildAccountDropDownListItemTemplates(origin);

            var accountDropDownListTemplate = new AccountDropDownListTemplate("[empty]");

            accountDropDownListTemplate.Items.AddRange(itemTemplates);

            sourcePurseDropDownList.BeginUpdate();
            sourcePurseDropDownList.Items.Clear();
            sourcePurseDropDownList.ApplyTemplate(accountDropDownListTemplate);
            sourcePurseDropDownList.EndUpdate();

            mTunableGrid.ParseCellValue += ParseCellValue;

            bundleNameTextBox.Click += (sender, args) =>
            {
                mErrorProvider.SetError(bundleNameTextBox, null);
            };
        }
        private static async Task <Result <ushort[]> > GetConditionPropertyUshort(string resourceName,
                                                                                  DeviceContext deviceContext, IFormattingService formattingService, bool isLocal, ushort addressOffset,
                                                                                  IProperty resourceProperty)
        {
            if (!MemoryAccessor.IsMemoryContainsAddresses(deviceContext.DeviceMemory,
                                                          (ushort)(resourceProperty.Address + addressOffset), resourceProperty.NumberOfPoints, isLocal))
            {
                return(Result <ushort[]> .Create(false));
            }


            var propertyUshorts = MemoryAccessor.GetUshortsFromMemory(
                deviceContext.DeviceMemory,
                (ushort)(resourceProperty.Address + addressOffset), resourceProperty.NumberOfPoints, isLocal);

            if (resourceProperty is ISubProperty subProperty)
            {
                var x = deviceContext.DeviceSharedResources.SharedResourcesInContainers.FirstOrDefault(
                    container =>
                    container.ResourceName == resourceName)
                        .Resource;

                var resultBitArray = new bool[16];
                var boolArray      = propertyUshorts.GetBoolArrayFromUshortArray();
                int counter        = 0;
                for (int i = 0; i < 16; i++)
                {
                    if (subProperty.BitNumbersInWord.Contains(i))
                    {
                        resultBitArray[counter] = boolArray[i];
                        counter++;
                    }
                }

                propertyUshorts = resultBitArray.BoolArrayToUshort().AsCollection();
            }

            if (resourceProperty.IsFromBits)
            {
                var x = deviceContext.DeviceSharedResources.SharedResourcesInContainers.FirstOrDefault(
                    container =>
                    container.ResourceName == resourceName)
                        .Resource;

                var resultBitArray = new bool[16];
                var boolArray      = propertyUshorts.GetBoolArrayFromUshortArray();
                int counter        = 0;
                for (int i = 0; i < 16; i++)
                {
                    if (resourceProperty.BitNumbers.Contains((ushort)i))
                    {
                        resultBitArray[counter] = boolArray[i];
                        counter++;
                    }
                }

                propertyUshorts = resultBitArray.BoolArrayToUshort().AsCollection();
            }

            return(Result <ushort[]> .Create(propertyUshorts, true));
        }
Example #16
0
 public MailServices(IFormattingService formattingService)
 {
     this.formattingService = formattingService;
 }
        public async void Execute()
        {
            if (_property.IsFromBits)
            {
                //var resultBitArray=new bool[16];
                var resultBitArray = _deviceContext.DeviceMemory.LocalMemoryValues[(ushort)(_property.Address + _offset)].GetBoolArrayFromUshort();


                IFormattingService formattingService = StaticContainer.Container.Resolve <IFormattingService>();
                IEditableValueFetchingFromViewModelVisitor fetchingFromViewModelVisitor =
                    StaticContainer.Container.Resolve <IEditableValueFetchingFromViewModelVisitor>();


                var formatterForDependentProperty = _property.UshortsFormatter;

                if (_property?.Dependencies?.Count > 0)
                {
                    formatterForDependentProperty = await
                                                    DependentSubscriptionHelpers.GetFormatterConsideringDependencies(_property.Dependencies,
                                                                                                                     _deviceContext, formattingService, _property.UshortsFormatter, (ushort)_offset, true);
                }


                var ushorts = await formattingService.FormatBackAsync(formatterForDependentProperty,
                                                                      EditableValueViewModel.Accept(fetchingFromViewModelVisitor), new FormattingContext(_runtimePropertyViewModel, _deviceContext, true));

                var ushortOfSubProperty = ushorts.Item.First();
                var boolArray           = ushorts.Item.GetBoolArrayFromUshortArray();
                int counter             = 0;
                for (int i = 0; i < 16; i++)
                {
                    if (_property.BitNumbers.Contains((ushort)i))
                    {
                        resultBitArray[i] = boolArray[counter];
                        counter++;
                    }
                }



                resultBitArray = resultBitArray.ToArray();
                var resUshorts = new ushort[] { resultBitArray.BoolArrayToUshort() };
                MemoryAccessor.SetUshortsInMemory(_deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), resUshorts, true);
                _deviceContext.DeviceEventsDispatcher.TriggerLocalAddressSubscription(
                    (ushort)(_property.Address + _offset), (ushort)resUshorts.Length);
            }
            else
            {
                IFormattingService formattingService = StaticContainer.Container.Resolve <IFormattingService>();
                IEditableValueFetchingFromViewModelVisitor fetchingFromViewModelVisitor =
                    StaticContainer.Container.Resolve <IEditableValueFetchingFromViewModelVisitor>();


                var formatterForDependentProperty = _property.UshortsFormatter;

                if (_property?.Dependencies?.Count > 0)
                {
                    formatterForDependentProperty = await
                                                    DependentSubscriptionHelpers.GetFormatterConsideringDependencies(_property.Dependencies,
                                                                                                                     _deviceContext, formattingService, _property.UshortsFormatter, (ushort)_offset, true);
                }


                var ushorts = await formattingService.FormatBackAsync(formatterForDependentProperty,
                                                                      EditableValueViewModel.Accept(fetchingFromViewModelVisitor), new FormattingContext(_runtimePropertyViewModel, _deviceContext, true));


                if (!ushorts.IsSuccess)
                {
                    if (EditableValueViewModel is ValidatableBindableBase validatableBindableBase)
                    {
                        validatableBindableBase.AddError("NumValue", ushorts.Exception.Message);
                    }
                }
                else
                {
                    MemoryAccessor.SetUshortsInMemory(_deviceContext.DeviceMemory, (ushort)(_property.Address + _offset),
                                                      ushorts.Item, true);
                    _deviceContext.DeviceEventsDispatcher.TriggerLocalAddressSubscription(
                        (ushort)(_property.Address + _offset), (ushort)ushorts.Item.Length);
                }
            }
        }
Example #18
0
 public AddRecordLabel(ApplicationDbContext dbContext, IFormattingService formattingService)
 {
     _dbContext         = dbContext;
     _formattingService = formattingService;
 }
        public static async Task <Result <bool> > CheckCondition(ICondition condition,
                                                                 DeviceContext deviceContext, IFormattingService formattingService, bool isLocal, ushort addressOffset)
        {
            if (condition is ICompareResourceCondition compareResourceCondition)
            {
                var conditionUshortResult = await GetConditionPropertyUshort(compareResourceCondition, deviceContext,
                                                                             formattingService, isLocal, addressOffset);

                //  var ushortToCompare = compareResourceCondition.UshortValueToCompare;
                if (!conditionUshortResult.IsSuccess)
                {
                    return(Result <bool> .Create(false));
                }

                return(ConditionHelper.CheckConditionEnum(compareResourceCondition, conditionUshortResult.Item));
            }

            if (condition is IRegexMatchCondition regexMatchCondition)
            {
                return(await CheckRegexCondition(regexMatchCondition, deviceContext, formattingService, isLocal,
                                                 addressOffset));
            }

            return(Result <bool> .Create(false));
        }
Example #20
0
 public AddPerson(ApplicationDbContext dbContext, IFormattingService formattingService)
 {
     _dbContext         = dbContext;
     _formattingService = formattingService;
 }
        public static async Task <IUshortsFormatter> GetFormatterConsideringDependencies(List <IDependency> dependencies,
                                                                                         DeviceContext deviceContext, IFormattingService formattingService,
                                                                                         IUshortsFormatter ushortsFormatterInitial, ushort offset, bool isLocal)
        {
            var formatterForDependentProperty = ushortsFormatterInitial;

            foreach (var dependency in dependencies)
            {
                switch (dependency)
                {
                case IConditionResultDependency conditionResultDependency:
                    if (
                        conditionResultDependency
                        ?.Condition is ICompareResourceCondition compareResourceCondition &&
                        conditionResultDependency.Result is IApplyFormatterResult applyFormatterResult)
                    {
                        var checkResult = await CheckCondition(compareResourceCondition,
                                                               deviceContext, formattingService, isLocal, offset);

                        if (checkResult.IsSuccess)
                        {
                            if (checkResult.Item)
                            {
                                formatterForDependentProperty = applyFormatterResult.UshortsFormatter;
                            }
                        }
                    }

                    break;
                }
            }

            return(formatterForDependentProperty);
        }
        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);
        }
Example #23
0
 public MeasuringMemorySubscriptionFactory(IFormattingService formattingService)
 {
     this._formattingService = formattingService;
 }
Example #24
0
 public UpdatePublisher(ApplicationDbContext dbContext, IFormattingService formattingService)
 {
     _dbContext         = dbContext;
     _formattingService = formattingService;
 }
Example #25
0
 public PropertyValueService(IFormattingService formattingService)
 {
     this._formattingService = formattingService;
 }
Example #26
0
 public JournalRecordFactory(ITypesContainer container, IFormattingService formattingService)
 {
     _container         = container;
     _formattingService = formattingService;
 }
Example #27
0
 public GroupTestStudentController(IGroupingService groupingService, IFormattingService formattingService)
 {
     _groupingService   = groupingService ?? throw new ArgumentNullException(nameof(groupingService));
     _formattingService = formattingService ?? throw new ArgumentNullException(nameof(formattingService));
 }
Example #28
0
 public HomeController(IFormattingService formattingService)
 {
     this.formattingService = formattingService;
 }
        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);
                }
            }
        }