private static bool Matches([NotNull] ExceptionObject exceptionObject,
                                    [NotNull] IBox exceptionBox,
                                    [NotNull] IBox issueBox)
        {
            if (exceptionObject.ShapeMatchCriterion == ShapeMatchCriterion.IgnoreShape)
            {
                return(true);
            }

            const double toleranceFactor = 2;

            double xyTolerance = Assert.NotNull(exceptionObject.XYTolerance).Value;

            double matchTolerance = xyTolerance * toleranceFactor;

            switch (exceptionObject.ShapeMatchCriterion)
            {
            case ShapeMatchCriterion.EqualEnvelope:
                return(AreEqual(exceptionBox, issueBox, matchTolerance));

            case ShapeMatchCriterion.WithinEnvelope:
                return(Contains(exceptionBox, issueBox, matchTolerance));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public bool ExistsExceptionFor(QaError qaError,
                                       QualitySpecificationElement element,
                                       out ExceptionObject exceptionObject)
        {
            var uuid = new Guid(element.QualityCondition.Uuid);

            // TODO if the error exceeds the verification extent, compare with envelope by "contained envelope" criterion instead of "equal envelope"
            // Reason: some tests cut off the error geometry at the verification extent

            QualityConditionExceptions qualityConditionExceptions;

            if (_qualityConditionExceptions.TryGetValue(uuid, out qualityConditionExceptions))
            {
                if (qualityConditionExceptions.ExistsExceptionFor(qaError, out exceptionObject))
                {
                    _exceptionEvaluationStatistics.AddUsedException(
                        exceptionObject, element, qaError);
                    return(true);
                }

                return(false);
            }

            // no exceptions exist for this quality condition
            exceptionObject = null;
            return(false);
        }
Ejemplo n.º 3
0
        private static IDictionary <Guid, QualityConditionExceptions> ReadTargetExceptions(
            [NotNull] IList <IObjectClass> targetExceptionClasses,
            [NotNull] IIssueTableFields fields)
        {
            Assert.ArgumentNotNull(targetExceptionClasses, nameof(targetExceptionClasses));
            Assert.ArgumentCondition(targetExceptionClasses.Count > 0, "no exception classes");

            var result = new Dictionary <Guid, QualityConditionExceptions>();

            foreach (ITable targetTable in targetExceptionClasses.Cast <ITable>())
            {
                var factory = new ExceptionObjectFactory(
                    targetTable, fields,
                    defaultStatus: ExceptionObjectStatus.Inactive,
                    includeManagedExceptionAttributes: true);

                foreach (IRow row in GdbQueryUtils.GetRows(targetTable, recycle: true))
                {
                    ExceptionObject exceptionObject = factory.CreateExceptionObject(row);

                    Guid qconVersionUuid = exceptionObject.QualityConditionVersionUuid;

                    QualityConditionExceptions exceptions;
                    if (!result.TryGetValue(qconVersionUuid, out exceptions))
                    {
                        exceptions = new QualityConditionExceptions(qconVersionUuid, null);
                        result.Add(qconVersionUuid, exceptions);
                    }

                    exceptions.Add(exceptionObject);
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        protected override bool MatchesCore(ExceptionObject exceptionObject,
                                            QaError qaError)
        {
            string searchIssueCodeId = qaError.IssueCode?.ID.Trim();

            return(Matches(exceptionObject.IssueCode, searchIssueCodeId));
        }
        private void Add([NotNull] ExceptionObject exceptionObject)
        {
            Guid uuid = exceptionObject.QualityConditionUuid;

            QualityCondition qualityCondition;

            if (!_conditionsByUuid.TryGetValue(uuid, out qualityCondition))
            {
                // unknown exception object
                return;
            }

            QualityConditionExceptions qualityConditionExceptions;

            if (!_qualityConditionExceptions.TryGetValue(uuid,
                                                         out qualityConditionExceptions))
            {
                qualityConditionExceptions = new QualityConditionExceptions(
                    qualityCondition, _datasetResolver, _involvedObjectsMatchCriteria,
                    _aoiBox);

                _qualityConditionExceptions.Add(uuid, qualityConditionExceptions);
            }

            _exceptionEvaluationStatistics.AddExceptionObject(
                exceptionObject, qualityCondition);

            qualityConditionExceptions.Add(exceptionObject);
        }
        public IEnumerable <ExceptionObject> Search(
            [NotNull] ExceptionObject exceptionObject)
        {
            if (_boxTree == null)
            {
                _boxTree = CreateBoxTree(_exceptionObjects, _xyTolerance);

                _exceptionObjects.Clear();
            }

            if (_boxTree.Count == 0 || exceptionObject.ShapeEnvelope == null)
            {
                yield break;
            }

            IBox searchBox = GeomUtils.CreateBox(exceptionObject.ShapeEnvelope, _xyTolerance);

            foreach (BoxTree <ExceptionObject> .TileEntry tileEntry in _boxTree.Search(searchBox)
                     )
            {
                ExceptionObject candidateExceptionObject = tileEntry.Value;

                if (Matches(candidateExceptionObject, tileEntry.Box,
                            exceptionObject.ShapeEnvelope))
                {
                    yield return(candidateExceptionObject);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Logs an exception with a specified error level.
        /// </summary>
        public override void Log(LogLevel level, Exception exception, ArraySegment <byte> buffer)
        {
            if (exception is TargetInvocationException)
            {
                exception = exception.InnerException;
            }
            if (exception == null)
            {
                return;
            }

            // Prepare an exception object.
            var ex = new ExceptionObject(level, exception, buffer);

            // Write to loggly and forget

            /*HttpUtility.PostAsync(
             *  "http://logs-01.loggly.com/inputs/186be958-25d8-4290-bc51-36e5f9502482/tag/http/",
             *  ex.ToBytes(),
             *  5000
             *  ).Forget();*/

            // Write to console
            Out.WriteLine(ex);
        }
Ejemplo n.º 8
0
        void IExceptionEvaluationStatistics.AddUsedException(
            ExceptionObject exceptionObject, QualitySpecificationElement element,
            QaError qaError)
        {
            ExceptionCount++;

            var issueGroupKey = new IssueGroupKey(new Issue(element, qaError));

            List <ExceptionObject> usedExceptionObjects;

            if (!_usedExceptions.TryGetValue(issueGroupKey, out usedExceptionObjects))
            {
                usedExceptionObjects           = new List <ExceptionObject>();
                _usedExceptions[issueGroupKey] = usedExceptionObjects;
            }

            usedExceptionObjects.Add(exceptionObject);

            string key = exceptionObject.ExceptionCategory?.Trim() ?? string.Empty;

            int count;

            count = _usedExceptionsByExceptionCategory.TryGetValue(key, out count)
                                        ? count + 1
                                        : 1;
            _usedExceptionsByExceptionCategory[key] = count;

            GetStatistics(element.QualityCondition).AddUsedException(exceptionObject);
        }
        public void CaDetectDistinct()
        {
            var involvedRows = new List <InvolvedRow>
            {
                new InvolvedRow("Table2", 100),
                new InvolvedRow("Table1", 1000),
                new InvolvedRow("Table2", 200)
            };

            var involvedTables =
                new List <InvolvedTable>
            {
                new InvolvedTable("Table2", new RowReference[] { new OIDRowReference(100) }),
                new InvolvedTable("Table1", new RowReference[] { new OIDRowReference(1000) })
            };

            ITable tableMock = ExceptionObjectTestUtils.GetMockTable();

            ExceptionObject exceptionObject = ExceptionObjectTestUtils.CreateExceptionObject(
                1, involvedTables);
            QaError qaError = ExceptionObjectTestUtils.CreateQaError(tableMock, involvedRows);

            var predicate = new ExceptionObjectInvolvedRowsPredicate(null);

            Assert.False(predicate.Matches(exceptionObject, qaError));
        }
Ejemplo n.º 10
0
        void IExceptionEvaluationStatistics.AddExceptionObject(
            ExceptionObject exceptionObject, QualityCondition qualityCondition)
        {
            ExceptionObjectCount++;

            GetStatistics(qualityCondition).AddExceptionObject(exceptionObject);
        }
Ejemplo n.º 11
0
 public void ReportExceptionInvolvingUnknownTable(
     [NotNull] ExceptionObject exceptionObject,
     [NotNull] string tableName,
     [NotNull] QualityCondition qualityCondition)
 {
     GetStatistics(qualityCondition).ReportExceptionInvolvingUnknownTable(
         exceptionObject, tableName);
 }
Ejemplo n.º 12
0
        public int GetUsageCount([NotNull] ExceptionObject exceptionObject)
        {
            ExceptionUsage usage;

            return(_usedExceptionObjects.TryGetValue(exceptionObject, out usage)
                                       ? usage.UsageCount
                                       : 0);
        }
Ejemplo n.º 13
0
        public bool Matches([NotNull] ExceptionObject exceptionObject,
                            [NotNull] ExceptionObject searchExceptionObject)
        {
            Assert.ArgumentNotNull(exceptionObject, nameof(exceptionObject));
            Assert.ArgumentNotNull(searchExceptionObject, nameof(searchExceptionObject));

            // TODO record match statistics etc.
            return(MatchesCore(exceptionObject, searchExceptionObject));
        }
Ejemplo n.º 14
0
        public bool Matches([NotNull] ExceptionObject exceptionObject,
                            [NotNull] QaError qaError)
        {
            Assert.ArgumentNotNull(exceptionObject, nameof(exceptionObject));
            Assert.ArgumentNotNull(qaError, nameof(qaError));

            // TODO record match statistics etc.
            return(MatchesCore(exceptionObject, qaError));
        }
        public IEnumerable <ExceptionObject> Search([NotNull] IGeometry geometry)
        {
            if (_boxTree == null)
            {
                _boxTree = CreateBoxTree(_exceptionObjects, _xyTolerance);

                _exceptionObjects.Clear();
            }

            if (_boxTree.Count == 0 || geometry.IsEmpty)
            {
                yield break;
            }

            IBox searchBox = QaGeometryUtils.CreateBox(geometry, _xyTolerance);

            IBox issueBox        = null;
            IBox clippedIssueBox = null;

            foreach (BoxTree <ExceptionObject> .TileEntry tileEntry in _boxTree.Search(searchBox)
                     )
            {
                ExceptionObject exceptionObject = tileEntry.Value;

                if (issueBox == null)
                {
                    issueBox = GetBox(geometry);
                }

                if (Matches(exceptionObject, tileEntry.Box, issueBox))
                {
                    yield return(exceptionObject);
                }
                else
                {
                    // Check if clipped envelope matches
                    if (_areaOfInterestBox == null ||
                        _areaOfInterestBox.Contains(issueBox) ||
                        exceptionObject.AreaOfInterestShapeEnvelope == null)
                    {
                        continue;
                    }

                    if (clippedIssueBox == null)
                    {
                        clippedIssueBox = GetBox(GetClippedGeometry(geometry, _areaOfInterestBox));
                    }

                    if (Matches(exceptionObject, exceptionObject.AreaOfInterestShapeEnvelope,
                                clippedIssueBox))
                    {
                        yield return(exceptionObject);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public void AddExceptionObject([NotNull] ExceptionObject exceptionObject)
        {
            bool added = _pendingExceptionObjects.Add(exceptionObject);

            _unusedExceptionObjectCount = null;

            Assert.True(added, "Exception already added: {0}", exceptionObject);

            ExceptionObjectCount++;
        }
Ejemplo n.º 17
0
 private bool Matches([NotNull] QaError qaError,
                      [NotNull] ExceptionObject exceptionObject,
                      bool applyInvolvedRowsPredicate)
 {
     return((!applyInvolvedRowsPredicate ||
             _involvedRowsPredicate.Matches(exceptionObject, qaError)) &&
            _issueCodePredicate.Matches(exceptionObject, qaError) &&
            _affectedComponentPredicate.Matches(exceptionObject, qaError) &&
            _valuesPredicate.Matches(exceptionObject, qaError));
 }
        public IEnumerable <ExceptionObject> Search(
            [NotNull] ExceptionObject exceptionObject)
        {
            string key = ExceptionObjectUtils.GetKey(exceptionObject.InvolvedTables,
                                                     _excludeTableFromKey);

            List <ExceptionObject> exceptionObjects;

            return(_index.TryGetValue(key, out exceptionObjects)
                                       ? exceptionObjects
                                       : _emptyList);
        }
Ejemplo n.º 19
0
        private static bool Matches([CanBeNull] string exceptionObjectIssueCode,
                                    [CanBeNull] string qaErrorIssueCode)
        {
            ExceptionObject exceptionObject = CreateExceptionObject(1, exceptionObjectIssueCode);
            ITable          table           = ExceptionObjectTestUtils.GetMockTable();
            QaError         qaError         = ExceptionObjectTestUtils.CreateQaError(table, qaErrorIssueCode,
                                                                                     null);

            var predicate = new ExceptionObjectIssueCodePredicate();

            return(predicate.Matches(exceptionObject, qaError));
        }
        private static void AssertCanFindGeometry([NotNull] IGeometry geometry)
        {
            ExceptionObject exceptionObject = CreateExceptionObject(1, geometry);

            var spatialIndex = new ExceptionObjectSpatialIndex();

            spatialIndex.Add(exceptionObject);

            List <ExceptionObject> exceptionObjects = spatialIndex.Search(geometry).ToList();

            Assert.AreEqual(1, exceptionObjects.Count);
        }
Ejemplo n.º 21
0
 public IEnumerable <ExceptionObject> GetMatchingExceptions(
     [NotNull] ExceptionObject exceptionObject)
 {
     foreach (ExceptionObjectCandidate candidate in GetCandidates(exceptionObject))
     {
         if (Matches(exceptionObject,
                     candidate.ExceptionObject,
                     !candidate.InvolvedRowsPredicateApplied))
         {
             yield return(candidate.ExceptionObject);
         }
     }
 }
        private static bool Matches([CanBeNull] string exceptionAffectedComponent,
                                    [CanBeNull] string qaErrorAffectedComponent)
        {
            ExceptionObject exceptionObject = CreateExceptionObject(1,
                                                                    exceptionAffectedComponent);
            ITable  table   = ExceptionObjectTestUtils.GetMockTable();
            QaError qaError = ExceptionObjectTestUtils.CreateQaError(table, null,
                                                                     qaErrorAffectedComponent);

            var predicate = new ExceptionObjectAffectedComponentPredicate();

            return(predicate.Matches(exceptionObject, qaError));
        }
Ejemplo n.º 23
0
        public int GetUsageCount([NotNull] ExceptionObject exceptionObject)
        {
            Guid uuid = exceptionObject.QualityConditionUuid;

            QualityCondition qualityCondition;

            if (!_conditionsByUuid.TryGetValue(uuid, out qualityCondition))
            {
                return(0);
            }

            return(_exceptionEvaluationStatistics.GetUsageCount(exceptionObject,
                                                                qualityCondition));
        }
        protected override bool MatchesCore(ExceptionObject exceptionObject,
                                            ExceptionObject searchExceptionObject)
        {
            const double toleranceFactor = 10;
            double       tolerance       = exceptionObject.XYTolerance * toleranceFactor ?? 0;

            return(Matches(exceptionObject.DoubleValue1,
                           searchExceptionObject.DoubleValue1,
                           tolerance) &&
                   Matches(exceptionObject.DoubleValue2,
                           searchExceptionObject.DoubleValue2,
                           tolerance) &&
                   Matches(exceptionObject.TextValue, searchExceptionObject.TextValue));
        }
Ejemplo n.º 25
0
 private static XmlExceptionObject CreateException(
     [NotNull] ExceptionObject exceptionObject,
     int usageCount)
 {
     return(new
            XmlExceptionObject
     {
         Id = exceptionObject.Id,
         ShapeType = Escape(ExceptionObjectUtils.GetShapeTypeText(
                                exceptionObject.ShapeType)),
         IssueCode = Escape(exceptionObject.IssueCode),
         InvolvedObjects = Escape(exceptionObject.InvolvedTablesText),
         UsageCount = usageCount
     });
 }
        public void Add([NotNull] ExceptionObject exceptionObject)
        {
            string key = ExceptionObjectUtils.GetKey(exceptionObject.InvolvedTables,
                                                     _excludeTableFromKey);

            List <ExceptionObject> exceptionObjects;

            if (!_index.TryGetValue(key, out exceptionObjects))
            {
                exceptionObjects = new List <ExceptionObject>();
                _index.Add(key, exceptionObjects);
            }

            exceptionObjects.Add(exceptionObject);
        }
Ejemplo n.º 27
0
        public void AddUsedException([NotNull] ExceptionObject exceptionObject)
        {
            ExceptionCount++;

            _pendingExceptionObjects.Remove(exceptionObject);

            ExceptionUsage exceptionUsage;

            if (!_usedExceptionObjects.TryGetValue(exceptionObject, out exceptionUsage))
            {
                exceptionUsage = new ExceptionUsage(exceptionObject);
                _usedExceptionObjects.Add(exceptionObject, exceptionUsage);
            }

            exceptionUsage.AddUsage();             // add the usage
        }
Ejemplo n.º 28
0
        private static void AddToReplacedExceptionObjects(
            [NotNull] ExceptionObject matchingExceptionObject,
            [NotNull] IDictionary <esriGeometryType, HashSet <int> > replacedExceptionObjects)
        {
            esriGeometryType shapeType = matchingExceptionObject.ShapeType ??
                                         esriGeometryType.esriGeometryNull;

            HashSet <int> oids;

            if (!replacedExceptionObjects.TryGetValue(shapeType, out oids))
            {
                oids = new HashSet <int>();
                replacedExceptionObjects.Add(shapeType, oids);
            }

            oids.Add(matchingExceptionObject.Id);
        }
Ejemplo n.º 29
0
        public void ReportExceptionInvolvingUnknownTable(
            [NotNull] ExceptionObject exceptionObject,
            [NotNull] string tableName)
        {
            Assert.ArgumentNotNull(exceptionObject, nameof(exceptionObject));
            Assert.ArgumentNotNullOrEmpty(tableName, nameof(tableName));

            List <ExceptionObject> list;

            if (!_exceptionObjectsInvolvingUnknownTable.TryGetValue(tableName, out list))
            {
                list = new List <ExceptionObject>();
                _exceptionObjectsInvolvingUnknownTable.Add(tableName, list);
            }

            list.Add(exceptionObject);
        }
Ejemplo n.º 30
0
        public static DalExceptionObject ToDalExceptionObject(this ExceptionObject orm)
        {
            if (orm == null)
            {
                return(null);
            }
            var exceptionObject = new DalExceptionObject
            {
                Id         = orm.Id,
                Message    = orm.Message,
                Controller = orm.Controller,
                Action     = orm.Action,
                Date       = orm.Date,
                StackTrace = orm.StackTrace
            };

            return(exceptionObject);
        }