private static void AddResolvedInvolvedObjects(
            [NotNull] AllowedError allowedError,
            [NotNull] IDictionary <IObjectDataset, IDictionary <int, List <AllowedError> > >
            allowedErrorsByDatasetAndObjectId)
        {
            foreach (InvolvedDatasetRow involvedDatasetRow in allowedError.InvolvedDatasetRows)
            {
                IObjectDataset objectDataset = involvedDatasetRow.Dataset;
                int            oid           = involvedDatasetRow.ObjectId;

                IDictionary <int, List <AllowedError> > errorsByInvolvedOID;
                if (!allowedErrorsByDatasetAndObjectId.TryGetValue(
                        objectDataset,
                        out errorsByInvolvedOID))
                {
                    errorsByInvolvedOID = new Dictionary <int, List <AllowedError> >();
                    allowedErrorsByDatasetAndObjectId.Add(objectDataset,
                                                          errorsByInvolvedOID);
                }

                List <AllowedError> errors;
                if (!errorsByInvolvedOID.TryGetValue(oid, out errors))
                {
                    errors = new List <AllowedError>();
                    errorsByInvolvedOID.Add(oid, errors);
                }

                errors.Add(allowedError);
            }
        }
        private static void AddUnesolvedInvolvedObjects(
            [NotNull] AllowedError allowedError,
            [NotNull] IDictionary <string, IDictionary <int, List <AllowedError> > >
            allowedErrorsByUnresolvedTableNameAndObjectId)
        {
            foreach (
                KeyValuePair <string, ICollection <int> > pair in
                allowedError.InvolvedRowsByUnresolvedTableName)
            {
                string            tableName = pair.Key;
                ICollection <int> oids      = pair.Value;

                IDictionary <int, List <AllowedError> > errorsByInvolvedOID;
                if (!allowedErrorsByUnresolvedTableNameAndObjectId.TryGetValue(
                        tableName, out errorsByInvolvedOID))
                {
                    errorsByInvolvedOID = new Dictionary <int, List <AllowedError> >();
                    allowedErrorsByUnresolvedTableNameAndObjectId.Add(tableName,
                                                                      errorsByInvolvedOID);
                }

                foreach (int oid in oids)
                {
                    List <AllowedError> errors;
                    if (!errorsByInvolvedOID.TryGetValue(oid, out errors))
                    {
                        errors = new List <AllowedError>();
                        errorsByInvolvedOID.Add(oid, errors);
                    }

                    errors.Add(allowedError);
                }
            }
        }
        private static bool WasQualityConditionUpdatedSinceAllowedErrorCreation(
            [NotNull] AllowedError allowedError,
            [NotNull] QualityCondition qualityCondition)
        {
            // TODO compare hash of RELEVANT quality condition properties

            // TODO revise
            if (allowedError.QualityConditionVersion == null ||
                allowedError.QualityConditionVersion < qualityCondition.Version)
            {
                return(true);
            }

            return(false);
        }
        private static int FindAllowedErrorIndex(
            [NotNull] QaError comparableError,
            [NotNull] QualityCondition qualityCondition,
            [NotNull] List <AllowedError> allowedErrors,
            [NotNull] IQualityConditionObjectDatasetResolver datasetResolver)
        {
            const bool usesGdbDatasetNames = true;

            // TODO resolve involved rows to datasets - compare by datasets instead of table names
            var searchInstance = new AllowedError(qualityCondition,
                                                  comparableError,
                                                  datasetResolver,
                                                  usesGdbDatasetNames);

            return(allowedErrors.BinarySearch(searchInstance));
        }
        public static IEnumerable <AllowedError> GetAllowedErrors(
            [NotNull] IssueDatasetWriter issueWriter,
            [CanBeNull] IGeometry areaOfInterest,
            [NotNull] ISpatialFilter spatialFilter,
            [NotNull] AllowedErrorFactory allowedErrorFactory)
        {
            Assert.ArgumentNotNull(issueWriter, nameof(issueWriter));
            Assert.ArgumentNotNull(spatialFilter, nameof(spatialFilter));
            Assert.ArgumentNotNull(allowedErrorFactory, nameof(allowedErrorFactory));

            Stopwatch watch = _msg.DebugStartTiming();

            ITable       errorTable = issueWriter.Table;
            IQueryFilter filter;

            var errorFeatureClass = errorTable as IFeatureClass;

            if (errorFeatureClass != null)
            {
                if (areaOfInterest != null)
                {
                    spatialFilter.Geometry      = areaOfInterest;
                    spatialFilter.GeometryField = errorFeatureClass.ShapeFieldName;
                    spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                }

                filter = spatialFilter;
            }
            else
            {
                filter = new QueryFilterClass
                {
                    WhereClause = spatialFilter.WhereClause,
                    SubFields   = spatialFilter.SubFields
                };
            }

            var addedAllowedErrorsCount = 0;
            var readRowCount            = 0;

            const bool recycling = true;

            foreach (IRow row in GdbQueryUtils.GetRows(errorTable, filter, recycling))
            {
                readRowCount++;
                AllowedError allowedError =
                    allowedErrorFactory.CreateAllowedError(issueWriter, row);

                if (allowedError == null)
                {
                    continue;
                }

                addedAllowedErrorsCount++;

                yield return(allowedError);
            }

            _msg.DebugStopTiming(watch,
                                 "Collected {0} allowed error(s) based on {1} row(s) read from {2}",
                                 addedAllowedErrorsCount, readRowCount,
                                 issueWriter.DatasetName);
        }