Hi all,I am trying to duplicate features, as graphics, one at a time, as selected by a user, from a 'read only' FeatureLayer into a 'work space' FeatureLayer. Honestly this seems like it should be easy, but I'm missing something.The code I am posting below compiles and runs. The graphics objects are not null and appear properly defined. I'm doing only a shallow copy of the source feature graphic to create the duplicate, but I have no idea if that is a problem because ... despite having event handlers for SaveEditsFailed, EndSaveEdits, and BeginSaveEdits, when I finally call SaveEdits(), absolutely nothing happens as far as I can tell. I am trying to call SaveEdits(), and then just in case I'm way off, I'm calling the Save() command in my Editor object on the map. Despite the three event handlers that seem like I should at least see one of them called, and each event handler with a MessageBox and breakpoint, the event handlers never get called.Yes the FeatureLayer "SubAreas" that I am trying to save to is set as editable on the server, and is valid. I tried "AutoSave = true" for it, but had the same result, so that is set to false now.When I call SubAreaLayer.Graphics.Insert(...) I can see, after multiple calls, the number of graphics objects inside of the graphics collection for SubAreaLayer grows. But it never saves the graphics back to the FeatureLayer... when execution of the app ends, they all go away. I tried SubAreaLayer.Graphics.Add(...) as well - same result of graphics collection growing over multiple calls, but nothing be saved in the end.Here is my code chunk:
private void AddSubToScenario(Guid LUID, Guid SID)
{
MainPage MP = (MainPage)((MainContainer)App.Current.RootVisual).LayoutRoot.Children[0];
FeatureLayer SubAreaLayer = (FeatureLayer)MP.CPMap.Layers["SubAreas"];
FeatureLayer LandUnitLayer = (FeatureLayer)MP.CPMap.Layers["SplitLinesPLUs"];
SubAreaLayer.SaveEditsFailed += new EventHandler<TaskFailedEventArgs>(SubAreaLayer_SaveEditsFailed);
SubAreaLayer.EndSaveEdits += new EventHandler<EndEditEventArgs>(SubAreaLayer_EndSaveEdits);
SubAreaLayer.BeginSaveEdits += new EventHandler<BeginEditEventArgs>(SubAreaLayer_BeginSaveEdits);
MP.editorMainMap.LayerIDs = new[] { "SubAreas" }; // in case it matters?
Graphic copiedFeature = new Graphic();
Graphic sourceFeature = LandUnitLayer.SelectedGraphics.FirstOrDefault();
copiedFeature.Geometry = sourceFeature.Geometry;
copiedFeature.Symbol = sourceFeature.Symbol;
copiedFeature.Attributes["OBJECTID"] = sourceFeature.Attributes["OBJECTID"];
copiedFeature.Attributes["LandUseID"] = sourceFeature.Attributes["LandUseId"];
copiedFeature.Attributes["PlanningLandUnitID"] = sourceFeature.Attributes["PlanningLandUnitId"];
copiedFeature.Attributes["SubareaID"] = Guid.NewGuid();
SubAreaLayer.Graphics.Insert(0, copiedFeature); // I did try '.Add(...)' as well, same result either way.
SubAreaLayer.SaveEdits(); // Nothing Happens! No SaveEdit related events fire? No Errors?
if (MP.editorMainMap.Save.CanExecute(null)) MP.editorMainMap.Save.Execute(null); // Maybe??
SubAreaLayer.Update();
}
void SubAreaLayer_BeginSaveEdits(object sender, BeginEditEventArgs e)
{
MessageBox.Show("Copying Graphic Between Feature Layers Started");
}
void SubAreaLayer_EndSaveEdits(object sender, EndEditEventArgs e)
{
MessageBox.Show("Copying Graphic Between Feature Layers Ended");
}
void SubAreaLayer_SaveEditsFailed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show("Copying Graphic Between Feature Layers Failed");
}
And here is the XAML for the FeatureLayer...
<esri:FeatureLayer
ID="SplitLinesPLUs"
Url="http://SOMESERVER/ArcGIS/rest/services/Editing/SplitLinesPLUs/MapServer/0"
Renderer="{StaticResource TransFillSelRenderer}"
OutFields="*"
Mode="SelectionOnly"
SelectionColor="{x:Null}"
Opacity="0.75"
Visible="False">
</esri:FeatureLayer>
<esri:FeatureLayer
ID="SubAreas"
Url="http://SOMESERVER/ArcGIS/rest/services/Editing/SubAreas/MapServer/0"
OutFields="*"
Mode="OnDemand"
Visible="False"
AutoSave="False">
</esri:FeatureLayer>