Exemplo n.º 1
0
        private IReadOnlyCollection <Version.ValidationResult> QueryTarget(MessageTypeCode messageType, long version)
        {
            using (Probe.Create("Query Cache"))
            {
                if (_cache.TryGet(messageType, out var targetValidationResults))
                {
                    return(targetValidationResults);
                }
            }

            using (Probe.Create("Query Target"))
            {
                var targetValidationResults =
                    _query
                    .For <Version.ValidationResult>()
                    .Where(x => x.MessageType == (int)messageType)
                    .ForVersion(version)
                    .ApplyVersionId(0)
                    .ToList();

                _cache.Initialize(messageType, targetValidationResults);

                return(targetValidationResults);
            }
        }
        private static Tuple <MessageTypeCode, IReadOnlyDictionary <CheckMode, RuleSeverityLevel> > Rule(
            MessageTypeCode rule,
            RuleSeverityLevel?single                  = null,
            RuleSeverityLevel?singleForCancel         = null,
            RuleSeverityLevel?singleForApprove        = null,
            RuleSeverityLevel?manualReport            = null,
            RuleSeverityLevel?manualReportWithAccount = null,
            RuleSeverityLevel?prerelease              = null,
            RuleSeverityLevel?release                 = null)
        {
            if (manualReport.HasValue && !manualReportWithAccount.HasValue)
            {
                manualReportWithAccount = manualReport;
            }

            var values = new Dictionary <CheckMode, RuleSeverityLevel?>
            {
                { CheckMode.Single, single },
                { CheckMode.SingleForCancel, singleForCancel },
                { CheckMode.SingleForApprove, singleForApprove },
                { CheckMode.Manual, manualReport },
                { CheckMode.ManualWithAccount, manualReportWithAccount },
                { CheckMode.Prerelease, prerelease },
                { CheckMode.Release, release },
            };

            return(new Tuple <MessageTypeCode, IReadOnlyDictionary <CheckMode, RuleSeverityLevel> >(rule, values.Where(x => x.Value.HasValue).ToDictionary(x => x.Key, x => x.Value.Value)));
        }
Exemplo n.º 3
0
        public void Update(MessageTypeCode messageType, IReadOnlyCollection <Version.ValidationResult> value)
        {
            var result = new Cache.ValidationResult {
                MessageType = messageType, Data = Serialize(value)
            };

            _repository.Update(result);
            _repository.Save();
        }
Exemplo n.º 4
0
        public bool TryGet(MessageTypeCode messageType, out IReadOnlyCollection <Version.ValidationResult> value)
        {
            var cachedResult = _query.For <Cache.ValidationResult>().SingleOrDefault(x => x.MessageType == messageType);

            if (cachedResult == null)
            {
                value = null;
                return(false);
            }

            value = Deserialize(cachedResult.Data);
            return(true);
        }
Exemplo n.º 5
0
        private void UpdateCache(MessageTypeCode messageType, IReadOnlyCollection <Version.ValidationResult> existing, IReadOnlyCollection <Version.ValidationResult> newResults, IReadOnlyCollection <Version.ValidationResult> resolvedResults)
        {
            if (newResults.Count == 0 && resolvedResults.Count == 0)
            {
                return;
            }

            using (Probe.Create("Update Cache"))
            {
                var hs = new HashSet <Version.ValidationResult>(existing, _equalityComparer);

                hs.UnionWith(newResults);
                hs.ExceptWith(resolvedResults);

                _cache.Update(messageType, hs);
            }
        }
Exemplo n.º 6
0
        public void TestRule(MessageTypeCode rule)
        {
            var results = GetResultsFromBigDatabase(x => x.MessageType == (int)rule && x.OrderId.HasValue);

            if (!results.Any())
            {
                Assert.Inconclusive();
            }

            var expectedResultsByOrder = results.GroupBy(x => x.OrderId.Value, x => x).Take(OrderPerRule).ToArray();

            var validator = new PipelineFactory().Create();

            foreach (var expected in expectedResultsByOrder)
            {
                var actual = validator.Execute(expected.Key, TestCheckMode.SingleRule(rule)).ToArray();

                AssertCollectionsEqual(MergePeriods(expected), MergePeriods(actual));
            }
        }
Exemplo n.º 7
0
 public RecalculateValidationRulePartiallyCommand(MessageTypeCode rule, IReadOnlyCollection <long> filter) =>
 (Rule, Filter) = (rule, filter);
Exemplo n.º 8
0
 private IDistinctor DistinctorForMessageType(MessageTypeCode messageType)
 {
     return(_distinctors.TryGetValue(messageType, out var distinctor) ? distinctor : Default);
 }
 public RecalculateValidationRuleCompleteCommand(MessageTypeCode rule)
 {
     Rule = rule;
 }
Exemplo n.º 10
0
 public void Add(MessageTypeCode ruleCode, Func <IReadOnlyCollection <T>, IReadOnlyCollection <long> > onChange)
 => _dictionary.Add(ruleCode, x => x.Any() ? new ResultPartiallyOutdatedEvent(ruleCode, onChange.Invoke(x)) : null);
Exemplo n.º 11
0
        private MergeResult <Version.ValidationResult> CalculateValidationRuleChanges(IReadOnlyCollection <Version.ValidationResult> currentVersionResults, MessageTypeCode ruleCode, Expression <Func <Version.ValidationResult, bool> > filter)
        {
            try
            {
                List <Version.ValidationResult> sourceObjects;

                using (Probe.Create("Query Source"))
                    using (new TransactionScope(TransactionScopeOption.RequiresNew, _transactionOptions))
                    {
                        // Запрос к данным посылаем вне транзакции, иначе будет DTC
                        var accessor = _accessors[ruleCode];
                        var query    = accessor.GetSource().Where(filter);
                        sourceObjects = query.ToList();
                    }

                using (Probe.Create("Merge"))
                {
                    var destObjects = currentVersionResults.Where(x => x.MessageType == (int)ruleCode).Where(filter.Compile());
                    var mergeResult = MergeTool.Merge(sourceObjects, destObjects, _equalityComparer);
                    return(mergeResult);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Ошибка при вычислении правила {ruleCode}", ex);
            }
        }
 public ResultPartiallyOutdatedEvent(MessageTypeCode rule, IReadOnlyCollection <long> orderIds) =>
 (Rule, OrderIds) = (rule, orderIds);
 protected ValidationResultAccessorBase(IQuery query, MessageTypeCode messageTypeId)
 {
     _query         = query;
     _messageTypeId = (int)messageTypeId;
 }
Exemplo n.º 14
0
 public void Add(MessageTypeCode ruleCode)
 => _dictionary.Add(ruleCode, x => x.Any() ? new ResultOutdatedEvent(ruleCode) : null);
Exemplo n.º 15
0
 public void Add(MessageTypeCode ruleCode)
 => _outdated.Add(ruleCode);
Exemplo n.º 16
0
 public static TestCheckMode SingleRule(MessageTypeCode rule)
 => new TestCheckMode
 {
     Rules = new[] { rule }.ToDictionary(x => x, x => RuleSeverityLevel.None)
 };
Exemplo n.º 17
0
 public RecalculateValidationRulePartiallyCommand(MessageTypeCode rule, IReadOnlyCollection <long> filter)
 {
     Rule   = rule;
     Filter = filter;
 }
Exemplo n.º 18
0
 public void Add(MessageTypeCode ruleCode, Func <IReadOnlyCollection <T>, IEnumerable <long> > func)
 => _partiallyOutdated.Add(ruleCode, func);
Exemplo n.º 19
0
 public ResultOutdatedEvent(MessageTypeCode rule) => Rule = rule;
 public ResultPartiallyOutdatedEvent(MessageTypeCode rule, IReadOnlyCollection <long> orderIds)
 {
     Rule     = rule;
     OrderIds = orderIds;
 }