string errorMessage = await QueuedTask.Run(async () =>
{
var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<ParcelLayer>().FirstOrDefault();
if (myParcelFabricLayer == null)
return "Please add a parcel fabric to the map";
try
{
FeatureLayer destPolygonL = null;
//find the first layer that is a parcel type, is non-historic, and has a selection
bool bFound = false;
var ParcelTypesEnum = await myParcelFabricLayer.GetParcelTypeNamesAsync();
foreach (FeatureLayer mapFeatLyr in MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>())
{
foreach (string ParcelType in ParcelTypesEnum)
{
var layerEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeNameAsync(ParcelType);
foreach (FeatureLayer flyr in layerEnum)
{
if (flyr == mapFeatLyr)
{
bFound = mapFeatLyr.SelectionCount > 0;
destPolygonL = mapFeatLyr;
break;
}
}
if (bFound) break;
}
if (bFound) break;
}
if (!bFound)
return "Please select parcels to set as historic.";
var theActiveRecord = myParcelFabricLayer.GetActiveRecord();
if (theActiveRecord == null)
return "There is no Active Record. Please set the active record and try again.";
var ids = new List<long>(destPolygonL.GetSelection().GetObjectIDs());
//can do multi layer selection but using single per code above
var sourceFeatures = new Dictionary<MapMember, List<long>>();
sourceFeatures.Add(destPolygonL, ids);
var editOper = new EditOperation()
{
Name = "Set Parcels Historic",
ProgressMessage = "Set Parcels Historic...",
ShowModalMessageAfterFailure = true,
SelectNewFeatures = true,
SelectModifiedFeatures = false
};
editOper.SetParcelHistoryRetired(myParcelFabricLayer,
SelectionSet.FromDictionary(sourceFeatures), theActiveRecord);
if (!editOper.Execute())
return editOper.ErrorMessage;
}
catch (Exception ex)
{
return ex.Message;
}
return "";
});
if (!string.IsNullOrEmpty(errorMessage))
MessageBox.Show(errorMessage, "Set Parcels Historic.");