Exemplo n.º 1
0
 private static RuleCommand ToCommand(this RuleDto rule)
 {
     return(new RuleCommand
     {
         Body = rule.Body
     });
 }
Exemplo n.º 2
0
 public NewRule()
 {
     Rule = new RuleDto
     {
         Name = "+ Új szabály hozzáadása"
     };
 }
Exemplo n.º 3
0
 public void AppendRule(RuleDto rule)
 {
     if (OptionalList == null)
     {
         OptionalList = new List <RuleDto>();
     }
     OptionalList.Add(rule);
 }
Exemplo n.º 4
0
        public void RuleDto_is_not_valid(RuleDto dto, string message)
        {
            var result = dto.IsValid();

            result.Should().BeFalse();
            dto.ValidationResult.Errors.Should().NotBeNullOrEmpty();
            dto.ValidationResult.Errors.First().ErrorMessage.Should().Be(message);
        }
Exemplo n.º 5
0
        private Task UpdateRule(IOwinContext context, int version, string name, RuleDto rule)
        {
            var clientCredentials = context.Get <IClientCredentials>("ClientCredentials");

            _ruleData.UpdateRule(clientCredentials, version, name, rule);
            return(Json(context, new PostResponseDto {
                Success = true
            }));
        }
Exemplo n.º 6
0
        private async Task <RuleDto> InvokeCommandAsync(string app, ICommand command)
        {
            var context = await CommandBus.PublishAsync(command);

            var result   = context.Result <IEnrichedRuleEntity>();
            var response = RuleDto.FromRule(result, this, app);

            return(response);
        }
Exemplo n.º 7
0
 public static Rule Convert(this RuleDto rule)
 {
     return(new Rule
     {
         Name = rule.Name,
         PurchaseValue = rule.PurchaseValue,
         SellValue = rule.SellValue
     });
 }
Exemplo n.º 8
0
 private static void DeleteRule(RuleDto rule, List <RuleDto> removeRules)
 {
     if (MessageBox.Show(
             "Rule '" + rule.Name + "' could not be imported.\nDelete this rule?", "Error",
             MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
     {
         removeRules.Add(rule);
     }
 }
Exemplo n.º 9
0
        public async Task <IActionResult> GetBy([FromRoute] Guid tenantId, [FromRoute] Guid id)
        {
            RuleDto ruleDto = await this.ruleService.GetBy(tenantId, id);

            if (ruleDto != null)
            {
                return(this.Ok(ruleDto));
            }

            return(this.NotFound("A rule with the given tenant id and id was not found."));
        }
Exemplo n.º 10
0
        public async Task ProcessRulesAsync()
        {
            var service = new ExerciseService();

            Rules = await service.GetGrammarRules(Test.ID);

            if (Rules.Count != 0)
            {
                CurrentRule = Rules[0];
            }
        }
Exemplo n.º 11
0
        private Task CreateRule(IOwinContext context, int version, RuleDto rule)
        {
            var clientCredentials = context.Get <IClientCredentials>("ClientCredentials");

            _ruleData.AddRules(clientCredentials, version, new List <RuleDto> {
                rule
            });
            return(Json(context, new PostResponseDto {
                Success = true
            }));
        }
Exemplo n.º 12
0
        private async Task <RuleDto> InvokeCommandAsync(ICommand command)
        {
            var context = await CommandBus.PublishAsync(command);

            var runningRuleId = await ruleRunnerService.GetRunningRuleIdAsync(Context.App.Id);

            var result   = context.Result <IEnrichedRuleEntity>();
            var response = RuleDto.FromRule(result, runningRuleId == null, ruleRunnerService, Resources);

            return(response);
        }
Exemplo n.º 13
0
        public RuleBookBuilder <TTarget, TComparison> AddRule(RuleDto ruleDto)
        {
            if (ruleDto == null)
            {
                throw new ArgumentNullException(nameof(ruleDto));
            }

            _ruleStore.UpdateRule <TTarget, TComparison>(ruleDto);

            return(this);
        }
Exemplo n.º 14
0
        public void InsertOrUpdateRule(int version, RuleDto rule)
        {
            var ruleVersion = _rules.FirstOrDefault(r => r.Version == version);

            if (ruleVersion == null)
            {
                return;
            }

            ruleVersion.Rules.RemoveAll(r => string.Equals(r.RuleName, rule.RuleName, StringComparison.InvariantCultureIgnoreCase));
            ruleVersion.Rules.Add(rule);
        }
Exemplo n.º 15
0
        public async Task <IActionResult> RuleAddOrUpdate(string id)
        {
            var ruleDto = new RuleDto();

            if (!string.IsNullOrEmpty(id))
            {
                var rule = await _service.GetRule(userId, id);

                var bistDto = (await StockContext.GetBist()).Where(x => x.StockName == id).FirstOrDefault();
                ruleDto = rule.ConvertToDto(bistDto.ConvertToDto());
            }
            return(View(ruleDto));
        }
Exemplo n.º 16
0
 /// <summary>
 /// From Rule dto To Rule pivot.
 /// </summary>
 /// <param name="ruleDto">rule dto to assemble.</param>
 /// <returns>Rulepivot result.</returns>
 public static RulePivot ToPivot(this RuleDto ruleDto)
 {
     if (ruleDto == null)
     {
         return(null);
     }
     return(new RulePivot
     {
         RulePrefix = ruleDto.RulePrefix,
         RuleName = ruleDto.RuleName,
         RuleId = ruleDto.RuleId
     });
 }
Exemplo n.º 17
0
        public ServiceResult <RuleDto> Create(RuleDto ruleDto)
        {
            var v = validator.Validate(ruleDto);

            if (!v.IsValid)
            {
                return(ServiceResult <RuleDto> .BadInput(v.ExtractErrors()));
            }

            var rule = rulesRepository.Create(mapper.Map <Rule>(ruleDto));

            return(ServiceResult <RuleDto> .Success(mapper.Map <RuleDto>(rule)));
        }
Exemplo n.º 18
0
        public void Add(RuleDto dto)
        {
            if (!dto.IsValid())
            {
                NotifyValidationError(dto);
                return;
            }

            var entity = new Rule(days: dto.Days.Value, type: dto.Type.Value, interestPerDay: dto.InterestPerDay.Value, penalty: dto.Penalty.Value);

            _ruleRepository.Add(entity);

            Commit();
        }
        public async Task EditRule(RuleDto rule)
        {
            if (rule.Id == 0)
            {
                rule.Name   = "";
                rule.TestId = Exercise.TestId;
            }
            var contentDialog = new EditRuleView(rule);
            var result        = await contentDialog.ShowAsync();

            if (result == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
            {
                await SetRules();
            }
        }
Exemplo n.º 20
0
        public void RuleDto_is_valid()
        {
            var dto = new RuleDto
            {
                Days           = 1,
                InterestPerDay = 0.2m,
                Penalty        = 2,
                Type           = RuleType.UpUntil
            };

            var result = dto.IsValid();

            result.Should().BeTrue();

            dto.ValidationResult.Errors.Should().BeNullOrEmpty();
        }
Exemplo n.º 21
0
        public SelectRuleForm(RuleDto rule, IEnumerable <FirewallRuleDto> rules)
        {
            InitializeComponent();

            lblHeader.Text = string.Format(lblHeader.Text, rule.Profile, rule.Direction, rule.Name);

            foreach (var r in rules)
            {
                lboxChoices.Items.Add(new RuleItem
                {
                    Rule = r
                });
            }

            lboxChoices.SelectedIndex = 0;
        }
Exemplo n.º 22
0
        public void InsertOrUpdateRule(int version, RuleDto rule)
        {
            CheckForUpdate();

            var ruleVersion = GetVersion(version, true);

            if (ruleVersion == null)
            {
                return;
            }

            ruleVersion.Rules.RemoveAll(r => string.Equals(r.RuleName, rule.RuleName, StringComparison.InvariantCultureIgnoreCase));
            ruleVersion.Rules.Add(rule);

            SaveChanges();
        }
Exemplo n.º 23
0
        private void UpdateNooshEvent(SiteInfo site)
        {
            if (site != null)
            {
                var url      = SettingsKeyInfoProvider.GetValue($"{site.SiteName}.{_configuratorSettingKey}");
                var ruleName = SettingsKeyInfoProvider.GetValue($"{site.SiteName}.{_ruleNameSettingKey}");
                if (!string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(ruleName))
                {
                    var nooshRule = new RuleDto
                    {
                        RuleName = ruleName,
                        Rate     = SettingsKeyInfoProvider.GetIntValue($"{site.SiteName}.{_rateSettingKey}"),
                        TargetId = SettingsKeyInfoProvider.GetValue($"{site.SiteName}.{_targetIdSettingKey}")
                    };
                    var nooshSettings = new NooshDto
                    {
                        WorkgroupName = SettingsKeyInfoProvider.GetValue($"{site.SiteName}.{_workgroupNameSettingKey}"),
                        NooshUrl      = SettingsKeyInfoProvider.GetValue($"{site.SiteName}.{_nooshApiSettingKey}"),
                        NooshToken    = SettingsKeyInfoProvider.GetValue($"{site.SiteName}.{_nooshTokenSettingKey}")
                    };

                    nooshRule.Enabled = nooshRule.Rate > 0 &&
                                        !string.IsNullOrWhiteSpace(nooshRule.TargetId) &&
                                        !string.IsNullOrWhiteSpace(nooshSettings.WorkgroupName) &&
                                        !string.IsNullOrWhiteSpace(nooshSettings.NooshToken) &&
                                        !string.IsNullOrWhiteSpace(nooshSettings.NooshUrl);

                    try
                    {
                        var client = DIContainer.Resolve <ICloudEventConfiguratorClient>();
                        var result = client.UpdateNooshRule(nooshRule, nooshSettings).Result;
                        if (!result.Success)
                        {
                            throw new InvalidOperationException(result.ErrorMessages);
                        }
                        else
                        {
                            EventLogProvider.LogInformation("UPDATE - NOOSH EVENT SETTINGS", "MICROREQUEST", result.Payload);
                        }
                    }
                    catch (Exception e)
                    {
                        EventLogProvider.LogException("UPDATE - NOOSH EVENT SETTINGS", "EXCEPTION", e, site.SiteID);
                    }
                }
            }
        }
Exemplo n.º 24
0
        public static RuleDto ConvertToDto(this Rule rule, StockCodeRate bist)
        {
            var ruleDto = new RuleDto
            {
                Name          = rule.Name,
                PurchaseValue = rule.PurchaseValue,
                SellValue     = rule.SellValue,
                CurrentValue  = bist?.Rate
            };

            if (bist?.Rate != null)
            {
                if (rule.PurchaseValue != null)
                {
                    ruleDto.Percentage = (rule.PurchaseValue - bist?.Rate) / bist.Rate;
                }
            }
            return(ruleDto);
        }
Exemplo n.º 25
0
        public static RuleDto ToModel(this IRuleEntity entity)
        {
            var dto = new RuleDto();

            SimpleMapper.Map(entity, dto);
            SimpleMapper.Map(entity.RuleDef, dto);

            if (entity.RuleDef.Trigger != null)
            {
                dto.Trigger = RuleTriggerDtoFactory.Create(entity.RuleDef.Trigger);
            }

            if (entity.RuleDef.Action != null)
            {
                dto.Action = RuleActionDtoFactory.Create(entity.RuleDef.Action);
            }

            return(dto);
        }
Exemplo n.º 26
0
        public async Task <Profile> AddOrUpdateRule(Guid userId, RuleDto ruleDto)
        {
            var profile = await _repo.GetByUserId(userId);

            var existingRule = profile.Rules.FirstOrDefault(x => x.Name == ruleDto.Name);

            if (existingRule != null)
            {
                existingRule.PurchaseValue = ruleDto.PurchaseValue;
                existingRule.SellValue     = ruleDto.SellValue;
            }
            else
            {
                profile.Rules.Add(ruleDto.Convert());
            }
            await _repo.Update(profile.Id, profile);

            return(profile);
        }
Exemplo n.º 27
0
        private RuleControl ProcessRule(RuleDto rule, List <RuleDto> removeRules, RuleControl prev)
        {
            var matchingFwRules      = firewallService.GetMatchingRules(rule.Name, rule.Profile, rule.Direction);
            var matchingFwRulesCount = matchingFwRules.Count();

            if (matchingFwRulesCount == 0)
            {
                DeleteRule(rule, removeRules);
            }
            else
            {
                FirewallRuleDto fwRule = null;
                if (matchingFwRulesCount > 1)
                {
                    using (var selectRule = new SelectRuleForm(rule, matchingFwRules))
                    {
                        if (selectRule.ShowDialog() == DialogResult.OK)
                        {
                            fwRule = selectRule.SelectedRule;
                        }
                    }
                }
                else
                {
                    fwRule = matchingFwRules.Single();
                }

                if (fwRule == null)
                {
                    DeleteRule(rule, removeRules);
                }
                else
                {
                    var ruleControl = prev == null
                        ? new RuleControl(rule, fwRule, FIRST_RULE_LOCATION, firewallService)
                        : new RuleControl(rule, fwRule, prev, firewallService);
                    return(ruleControl);
                }
            }

            return(null);
        }
Exemplo n.º 28
0
        public ServiceResult <RuleDto> Update(RuleDto ruleDto)
        {
            var v = validator.Validate(ruleDto);

            if (!v.IsValid)
            {
                return(ServiceResult <RuleDto> .BadInput(v.ExtractErrors()));
            }

            var rule = rulesRepository.Read(ruleDto.Id);

            if (rule == null)
            {
                return(ServiceResult <RuleDto> .NotFound());
            }

            rule = rulesRepository.Update(mapper.Map <Rule>(ruleDto));

            return(ServiceResult <RuleDto> .Success(mapper.Map <RuleDto>(rule)));
        }
Exemplo n.º 29
0
        public async Task <RuleDto> PutRuleAsync(RuleDto rule)
        {
            using (var client = new HttpClient())
            {
                InitializeClient(client);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("api/exercise"));

                HttpResponseMessage response = await client.PutAsJsonAsync("api/exercise/rule", rule);

                if (response.IsSuccessStatusCode)
                {
                    var serializer = new DataContractJsonSerializer(typeof(RuleDto));
                    return(serializer.ReadObject(await response.Content.ReadAsStreamAsync()) as RuleDto);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 30
0
        private RuleControl(
            RuleDto rule, FirewallRuleDto firewallRuleDto,
            RuleControl previous, Point?location,
            IFirewallService firewallService)
        {
            if (previous == null && location == null)
            {
                throw new ArgumentNullException(
                          $"{nameof(previous)},{nameof(location)}");
            }

            InitializeComponent();

            Previous             = previous;
            Rule                 = rule;
            this.firewallRuleDto = firewallRuleDto;
            this.firewallService = firewallService;

            MyInitializeComponent(location);
        }