1

I have a Hand-Held (HH) device in which I have downloaded to the MobileCache a limited amount of Features from a FeatureLayer. Now I need to remove from the cache all features of a certain type. We were able to delete them from the cache but this places them into a table called fs_table0_deleted_features in the MobileCache.db file. We are only doing a one-way synchronize (download), but if we ever did a two-way synchronize then these features would be deleted from the server too, which is not what we want. Also, if we try to re-synchronize the now deleted features from the server they are not removed from the deleted features table and the deleted features are not placed back into the fs_table0_current_features table; this behavior is causing issues with our application.

We also tried to use the MobileCache.RemoveData method, but this only accepts an Envelope (extent) and a list of FeatureSource. What I want to do is only remove a subset of Features that have been cached leaving the rest cached. Other solutions we have considered have been:

  1. Copy in memory from the MobileCache the features we want to save, Call RemoveData, then insert into the MobileCache the features that we saved.
  2. RemoveData from the MobileCache and then synchronize with the server for all the features we want
  3. Delete the MobileCache and then copy a backup that was previously made to replace the now deleted MobileCache.
  4. Find the Extent of all the features we want to remove and then call RemoveData with those extents.

Of these, I think #1 or #3 may the better solutions, but they seem overly complex and it could be resource intensive(#1), or may have problems with stale data(#3).

We don't like #2 because the load for synchronizing our devices may be heavy (thousands of devices all must synchronize in a very limited time frame)

The last one, #4 could be a potential problem if there are overlapping features in which we only want to remove one and not all.

Here is how we tried the delete, which is not working and isn't a valid solution.

public void PurgeCacheData(string whereClause)
{
    if (!Cache.IsOpen) return;

    var qFilter = new QueryFilter { WhereClause = whereClause };
    var featureSources = Cache.FeatureSources;

    foreach (var fSource in featureSources
             .Where(fSource => fSource.GetFeatureCount(qFilter) > 0))
    {

        using (var featReader = fSource.GetDataReader(qFilter))
        {
            while (featReader.Read())
            {
                featReader.Delete();
                featReader.Update();
            }
        }

        // Here we tried to delete the entries in the Delete table
        // but this doesn't work. Nothing happens. 
        using (FeatureDataTable featureDataTable = 
               fSource.GetDataTable(null, EditState.Deleted, null))
        {
            foreach (FeatureDataRow row in featureDataTable.Rows)
            {
                row.Delete();
            }
        }

    }
 }
1

You are missing SaveEdits on the featureSource:

fSource.SaveEdits(featureDataTable);

this after the last foreach (row.Delete()) . Saving edits lets's you commit the changes to the layer. It Returns the rows affected with the deletion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.