Select to view content in your preferred language

InvalidOperationException when collecting feature

1900
4
02-07-2011 06:19 AM
NilsRydh
Deactivated User
I have created a task for the ArcGIS Mobile application. I try to select FeatureType programatically and then use SketchCollectionMethod for collecting data of that feature type.

Everything seems to work fine until I save the data, then I get an exception. This is what I do:
1. Register CollectionStarting and CollectionCompleted events
2. Find the feature type among the Mobile project data
3. Initilize a feature of that type and start the SketchCollectionMethod.
4. When the GeometryCollectionCompleted event is fired, I show an EditAttributesDialog
5. Try to save using feature.SaveEdits();
6. InvalidOperationException is thrown and the Mobile Cache is corrupted and won't open the next time i start the application. I have attached the stack trace, but it isn't very helpful.

Do I have to show the FeatureTypePage for this to work, or am I missing something?
0 Kudos
4 Replies
AkhilParujanwala
Regular Contributor
In your other post regarding debugging, yes the number of steps to create a feature is too long, I am also working on a simpler method.

It appears you are doing everything correct. I am using the Windows Tablet version of the out-of-the-box solution, I know your using the Mobile version.

For the Mobile version (I looked at the sample code) it does make sense. But you want to remove the FeatureTypePage? If so. Your process may look something similar to what I am doing.

1) Person clicks on tasks
2) Person clicks on collect "Trees" <- this is key since you don't need the FeatureTypePage
3) Program searches the cache for the "Tree" layers and then uses that for sketching
4) This eliminate that FeatureTypePage, because the Tasks you set contains the name of the featurelayer you want to create a feature in.

If you have 3 featurelayers you want your user to create feature in, then you will want 3 tasks (using the same code). Each of the tasks will have the name of the feature in the title or the routed command. "Collect Trees", "Collect Birds", "Collect Dogs". Once the user clicks on either of this, you can easily remove the word Collect from the string and just search the cache for the layer named "Trees" and then follow through with the sketchgeometry and attributes page.

Here is the sample code for the first part, once again the name of the Layer in my case comes from a Button that the use presses, so you don't see that in this code snippet.

private void CollectRadiationDataByMap(string featureTypeName)
    {        
      try
      {
        Cursor.Current = Cursors.WaitCursor;

        // Cache homepage for the application
        // Once data collection is done, we come back to this cached page
        _homePage = MobileApplication.Current.CurrentPage;  

        // Reset _feature and _featureType
        _feature = null;
        _featureType = FindFeatureTypeByName(featureTypeName);
        if (_featureType == null)
        {
          ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog("Can't find " + featureTypeName + ".", "Warning");
          return;
        }

        // Create a new Feature, this will automatically call StartEditing on this feature
        _feature = new Feature(_featureType, null);
        
        

        // If this is the first time, create a SketchGeometryCollectionMethod, 
        // and listen to its Completed event. Once user accepts geometry, this event
        // will be fired
        if (_sketchGeometryCollectionMethod == null)
        {
            _sketchGeometryCollectionMethod = new SketchGeometryCollectionMethod();
            _sketchGeometryCollectionMethod.Completed += new EventHandler<CompletedEventArgs>(_sketchGeometryCollectionMethod_Completed);
        }

        _sketchGeometryCollectionMethod.GeometryCollectionPage.Title = "Collect " + _featureType.Name;
        _sketchGeometryCollectionMethod.GeometryCollectionPage.Note = "Create " + _featureType.Name + " by digitizing on the map";

        _sketchGeometryCollectionMethod.StartGeometryCollection(_feature);
                  
        SaveTeamInfoClass.SaveTeamInfo(_feature);
      }
      finally
      {
        Cursor.Current = Cursors.Default;
      }
    }
0 Kudos
NilsRydh
Deactivated User
Hi Akhil,

What you are describing is exactly the kind of workflow I want to implement.
I have it all working, but I'm constantly running into problems when I want to save a new feature.
I either get the InvalidOperationException, or nothing happens and the new feature doesn't show up.

I have tried with several mobile caches, and cannot get it to work. I have attached the code, in case you care to take a look.
0 Kudos
AkhilParujanwala
Regular Contributor
No problem I am looking at it today. I will let you know how things go in a couple hours.
0 Kudos
AkhilParujanwala
Regular Contributor
When I have problem with things I generally put a try and catch around it, for example:
Try
{
SOMETHING (in this case _featureDRAWN.SaveEdits();
}
Catch (Exception ex)
{
System.Windows.Messagebox.Show(ex.toString());
}


I personally can't see anything wrong with the code it make sense to me, all I can suggest is the tools I used to make it work.

C:\Program Files (x86)\ArcGIS\Mobile10.0\DeveloperKit\Samples\ApplicationFramework\Windows\SimpleDataCollectionExtension

That's the sample I used. In this case you don't need to show the FeatureTypePage, hence in my Mobile application I am trying to avoid that page. Instead I have a button on the form for each feature we would collect.

If the use click on the first button, it passes the name of the featurelayer, in which I can determine the featuretype and then create a new feature using the featuretype.

I do suggest making proper EditAttributePage event handlers for OK and Cancel like in the sample provided above. I doubt this will make a difference but its worth a shot.

I have attached my code, which is a modified version of the SimpleDataCollection extension.
0 Kudos