Exemplo n.º 1
0
        public void Resolve(Conflict conflict)
        {
            Transaction transaction = this.transactionManager.Current();
            //TransactionConfig.LayerConfig lc = this.transactionManager.transactionConfig().get_LayerConfig(conflict.ConfigKey);

            IFeatureClass con_fc = null;
            try
            {
                con_fc = ((IFeatureWorkspace)transaction.PGDBConnection).
                    OpenFeatureClass("C_" + conflict.ConfigKey);
            }
            catch(Exception e)
            {
                MessageBox.Show("PGDB Feature Class " + "C_" + conflict.ConfigKey + " Not Found",
                    "EXCEPTION", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                throw new HandledException(e);
            }

            string[] keys = new string[] { "ACQUISITION_SID", "ADMIN_AREA_SID", "INTRID_SID", "TA_REVERSIONS", "REVERSION_SID", "PIN_SID", "MAJOR_TRANS_SID", "WELLSITE_SID", con_fc.Fields.get_Field(0).Name };

            IQueryFilter pk_filter = new QueryFilterClass();
            string where = null;

            for (int i = 0; i < keys.Length; i++)
            {
                int index = con_fc.FindField(keys[i]);

                if (index != -1)
                {
                    string cond = keys[i] + " = " + conflict.PrimaryKeyValues[i];

                    if (where == null)
                    {
                        // first time
                        where = cond;
                        break;
                    }
                }
                else
                {
                    Logger.Write("Field not found: " + keys[i] + " for " + con_fc.AliasName);
                }
            }

            pk_filter.WhereClause = where;

            IFeatureCursor cursor = null;
            try
            {
                // is this an insert or update?
                cursor = con_fc.Update(pk_filter,true);

                IFeature feature = cursor.NextFeature();
                int index = -1;
                if(feature != null)
                {
                    // update -- in all cases this represents newer information, so store it

                    index = feature.Fields.FindField(CONFLICT_STATE);
                    if(index>-1)
                    {
                        feature.set_Value(index,CONFLICT_STATE_RESOLVED);
                        conflict.State = ConflictState.Resolved;
                    }

                    cursor.UpdateFeature(feature);
                    if(cursor.NextFeature() != null)
                    {
                        throw new Exception("Error Storing Conflict for "+conflict.ConfigKey);
                    }
                }
            }
            finally
            {
                if (pk_filter != null)
                {
                    Utils.Release(pk_filter);
                }
                if(cursor != null)
                {
                    Utils.Release(cursor);
                }
            }
        }
Exemplo n.º 2
0
        private bool same(Conflict conflict, IFeature conflictFeature, string[] keys)
        {
            // check type, values
            // create conflict ...
            int index = -1;
            for(int i=0;i<keys.Length;i++)
            {
                index = conflictFeature.Fields.FindField(keys[i]);
                if(index>-1)
                {
                    object o = conflictFeature.get_Value(index);
                    if( (conflict.PrimaryKeyValues[i] == null && o != null) ||
                        (conflict.PrimaryKeyValues[i] != null && o == null))
                    {
                        return false;
                    }

                    if(conflict.PrimaryKeyValues[i] != null && o != null &&
                        !conflict.PrimaryKeyValues[i].Equals(o.ToString()))
                    {
                        return false;
                    }
                }
                else
                {
                    if(conflict.PrimaryKeyValues[i] != null)
                        return false;
                }
            }

            index = conflictFeature.Fields.FindField(CONFLICT_TYPE);
            if(index>-1)
            {
                string t = (string)conflictFeature.get_Value(index);
                switch(t)
                {
                    case CONFLICT_TYPE_DU:
                        if (conflict.Type != ConflictType.Delete_Update)
                            return false;
                        break;
                    case CONFLICT_TYPE_II:
                        if (conflict.Type != ConflictType.Insert_Insert)
                            return false;
                        break;
                    case CONFLICT_TYPE_IU:
                        if (conflict.Type != ConflictType.Insert_Update)
                            return false;
                        break;
                    case CONFLICT_TYPE_UD:
                        if (conflict.Type != ConflictType.Update_Delete)
                            return false;
                        break;
                    case CONFLICT_TYPE_UI:
                        if (conflict.Type != ConflictType.Update_Insert)
                            return false;
                        break;
                    case CONFLICT_TYPE_UU:
                        if (conflict.Type != ConflictType.Update_Update)
                            return false;
                        break;
                }
            }
            else
            {
                return false;
            }

            return true;
        }