コード例 #1
0
        public void DeleteErrorObjects(
            [NotNull] IQueryFilter filter,
            [NotNull] IDeletableErrorRowFilter deletableErrorRowFilter,
            [NotNull] IDictionary <int, QualityCondition> qualityConditionsById)
        {
            Assert.ArgumentNotNull(filter, nameof(filter));
            Assert.ArgumentNotNull(deletableErrorRowFilter, nameof(deletableErrorRowFilter));
            Assert.ArgumentNotNull(qualityConditionsById, nameof(qualityConditionsById));

            Stopwatch watch = _msg.DebugStartTiming();

            IQueryFilter tableSpecificFilter = AdaptFilterToErrorTable(filter);

            var        count   = 0;
            const bool recycle = true;
            ICursor    cursor  = Table.Update(tableSpecificFilter, recycle);

            try
            {
                for (IRow row = cursor.NextRow();
                     row != null;
                     row = cursor.NextRow())
                {
                    int?qualityConditionId = Get <int>(row, AttributeRole.ErrorConditionId);

                    if (qualityConditionId != null)
                    {
                        QualityCondition qualityCondition;
                        if (!qualityConditionsById.TryGetValue(qualityConditionId.Value,
                                                               out qualityCondition))
                        {
                            // the quality condition is not in the specified set, or the id was invalid
                            // -> don't delete
                            // NOTE: if the set of quality conditions is guaranteed to be complete then deletion would be possible
                            continue;
                        }

                        if (!deletableErrorRowFilter.IsDeletable(row, qualityCondition))
                        {
                            // the error is not deletable
                            continue;
                        }
                    }

                    // The error is deletable for it's quality condition, or it does not have a quality condition id
                    // -> delete it
                    cursor.DeleteRow();
                    count++;
                }
            }
            finally
            {
                ComUtils.ReleaseComObject(cursor);
            }

            _msg.DebugStopTiming(watch,
                                 "Deleted {0} error(s) in {1} based on deletable row filter",
                                 count, DatasetName);
        }
コード例 #2
0
        public int DeleteOrphanedErrorObjects([NotNull] IQueryFilter filter,
                                              [NotNull] ICollection <int> qualityConditionIds)
        {
            Assert.ArgumentNotNull(filter, nameof(filter));
            Assert.ArgumentNotNull(qualityConditionIds, nameof(qualityConditionIds));

            Stopwatch watch = _msg.DebugStartTiming("Deleting orphaned errors in {0}",
                                                    DatasetName);

            IQueryFilter tableSpecificFilter = AdaptFilterToErrorTable(filter);

            int fieldIndex = GetFieldIndex(AttributeRole.ErrorConditionId);

            var        count   = 0;
            const bool recycle = true;
            ICursor    cursor  = Table.Update(tableSpecificFilter, recycle);

            try
            {
                for (IRow row = cursor.NextRow();
                     row != null;
                     row = cursor.NextRow())
                {
                    object qualityConditionId = row.Value[fieldIndex];

                    bool isOrphaned = qualityConditionId == null ||
                                      qualityConditionId is DBNull ||
                                      !qualityConditionIds.Contains(
                        Convert.ToInt32(qualityConditionId));

                    if (isOrphaned)
                    {
                        count++;
                        cursor.DeleteRow();
                    }
                }
            }
            finally
            {
                ComUtils.ReleaseComObject(cursor);
            }

            _msg.DebugStopTiming(watch, "Deleted {0} error(s)", count);

            return(count);
        }
コード例 #3
0
        public bool DeleteRowsUnversioned(IWorkspace TheWorkSpace, ITable inTable,
                                          IFIDSet pFIDSet, IStepProgressor StepProgressor, ITrackCancel TrackCancel)
        {
            IMouseCursor pMouseCursor = new MouseCursorClass();

            pMouseCursor.SetCursor(2);

            if (StepProgressor != null)
            {
                StepProgressor.MinRange = StepProgressor.Position; //reset the progress bar position
                StepProgressor.MaxRange = StepProgressor.Position + pFIDSet.Count();
                if (StepProgressor.Position < StepProgressor.MaxRange)
                {
                    StepProgressor.Step();
                }
            }

            IQueryFilter pQF = new QueryFilterClass();

            ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace;
            string     sPref      = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
            string     sSuff      = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

            ICursor ipCursor = null;
            IRow    pRow     = null;
            //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database)
            int    iTokenLimit     = 995;
            int    iTokenSet       = 0; //the index of the set of 995 tokens
            string sWhereClauseLHS = sPref + inTable.OIDFieldName + sSuff + " in (";

            string[] ids = { sWhereClauseLHS };

            try
            {
                ITableWrite pTableWr = (ITableWrite)inTable;
                pFIDSet.Reset();
                bool  bCont = true;
                Int32 iID;

                Int32 count = pFIDSet.Count();
                int   j     = 0; //inner count for each set of IDs
                for (int k = 0; k < count; k++)
                {
                    if (j > iTokenLimit)
                    {                                     //over the limit for this Token set, time to create a new set
                        ids[iTokenSet] += ")";            //close the previous set
                        RedimPreserveString(ref ids, 1);  //make space in the string array for the next token set
                        iTokenSet++;                      //increment the index
                        ids[iTokenSet] = sWhereClauseLHS; //left-hand side of the where clause
                        j = 0;                            //reset the inner count back to zero
                    }

                    pFIDSet.Next(out iID);
                    if (j > 0) //write a comma if this is not the first ID
                    {
                        ids[iTokenSet] += ",";
                    }
                    ids[iTokenSet] += iID.ToString();
                    j++; //increment the inner count
                }
                ids[iTokenSet] += ")";

                if (count > 0)
                {
                    for (int k = 0; k <= iTokenSet; k++)
                    {
                        pQF.WhereClause = ids[k];
                        ipCursor        = pTableWr.UpdateRows(pQF, false);
                        pRow            = ipCursor.NextRow();
                        while (pRow != null)
                        {
                            ipCursor.DeleteRow();
                            Marshal.ReleaseComObject(pRow);
                            if (StepProgressor != null)
                            {
                                //Check if the cancel button was pressed. If so, stop process
                                if (TrackCancel != null)
                                {
                                    bCont = TrackCancel.Continue();
                                }
                                if (!bCont)
                                {
                                    break;
                                }
                                if (StepProgressor.Position < StepProgressor.MaxRange)
                                {
                                    StepProgressor.Step();
                                }
                            }
                            pRow = ipCursor.NextRow();
                        }

                        if (!bCont)
                        {
                            AbortEditing(TheWorkSpace);
                            if (ipCursor != null)
                            {
                                Marshal.ReleaseComObject(ipCursor);
                            }
                            if (pRow != null)
                            {
                                Marshal.ReleaseComObject(pRow);
                            }
                            if (pQF != null)
                            {
                                Marshal.ReleaseComObject(pQF);
                            }
                            if (pMouseCursor != null)
                            {
                                Marshal.ReleaseComObject(pMouseCursor);
                            }
                            return(false);
                        }
                        Marshal.ReleaseComObject(ipCursor);
                    }
                    Marshal.ReleaseComObject(pQF);
                }

                Marshal.ReleaseComObject(pMouseCursor);
                return(true);
            }

            catch (COMException ex)
            {
                if (ipCursor != null)
                {
                    Marshal.ReleaseComObject(ipCursor);
                }
                if (pRow != null)
                {
                    Marshal.ReleaseComObject(pRow);
                }
                if (pQF != null)
                {
                    Marshal.ReleaseComObject(pQF);
                }
                if (pMouseCursor != null)
                {
                    Marshal.ReleaseComObject(pMouseCursor);
                }
                MessageBox.Show(Convert.ToString(ex.ErrorCode));
                return(false);
            }
        }
コード例 #4
0
        public bool DeleteByInClause(IWorkspace TheWorkSpace, ITable inTable, IField QueryIntegerField,
                                     List <string> InClauseIDs, bool IsVersioned, IStepProgressor StepProgressor, ITrackCancel TrackCancel)
        {
            IMouseCursor pMouseCursor = new MouseCursorClass();

            pMouseCursor.SetCursor(2);

            IQueryFilter pQF = new QueryFilterClass();

            ISQLSyntax pSQLSyntax = (ISQLSyntax)TheWorkSpace;
            string     sPref      = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
            string     sSuff      = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

            ICursor ipCursor = null;
            IRow    pRow     = null;
            //make sure that there are no more then 999 tokens for the in clause(ORA- query will otherwise error on an Oracle database)
            //this code assumes that InClauseIDs holds an arraylist of comma separated OIDs with no more than 995 id's per list item
            string sWhereClauseLHS = sPref + QueryIntegerField.Name + sSuff + " in (";

            try
            {
                ITableWrite pTableWr = (ITableWrite)inTable;
                bool        bCont    = true;

                Int32 count = InClauseIDs.Count - 1;
                for (int k = 0; k <= count; k++)
                {
                    pQF.WhereClause = sWhereClauseLHS + InClauseIDs[k] + ")"; //left-hand side of the where clause
                    if (pQF.WhereClause.Contains("()"))
                    {
                        continue;
                    }
                    if (!IsVersioned)
                    {
                        ipCursor = pTableWr.UpdateRows(pQF, false);
                    }
                    else
                    {
                        ipCursor = inTable.Update(pQF, false);
                    }

                    pRow = ipCursor.NextRow();
                    while (pRow != null)
                    {
                        ipCursor.DeleteRow();
                        Marshal.ReleaseComObject(pRow);
                        if (StepProgressor != null)
                        {
                            //Check if the cancel button was pressed. If so, stop process
                            if (TrackCancel != null)
                            {
                                bCont = TrackCancel.Continue();
                            }
                            if (!bCont)
                            {
                                break;
                            }
                            if (StepProgressor.Position < StepProgressor.MaxRange)
                            {
                                StepProgressor.Step();
                            }
                        }
                        pRow = ipCursor.NextRow();
                    }

                    if (!bCont)
                    {
                        AbortEditing(TheWorkSpace);
                        if (ipCursor != null)
                        {
                            Marshal.ReleaseComObject(ipCursor);
                        }
                        if (pRow != null)
                        {
                            Marshal.ReleaseComObject(pRow);
                        }
                        return(false);
                    }
                    Marshal.ReleaseComObject(ipCursor);
                }
                return(true);
            }

            catch (Exception ex)
            {
                if (ipCursor != null)
                {
                    Marshal.ReleaseComObject(ipCursor);
                }
                if (pRow != null)
                {
                    Marshal.ReleaseComObject(pRow);
                }
                MessageBox.Show(Convert.ToString(ex.Message));
                return(false);
            }
        }