pascal_coulon

Replica - issue with query definition and fetch related objects

Discussion created by pascal_coulon on Mar 8, 2011
Hi There,

I have encountered two issues when working replica (checkout) in ArcMap / ArcObject v10 SP1.

I am current implementing some ArcObject code to extend the ArcMap v 10 SP1 (ArcEditor Licence) to handle some database replica (checkout). Note that we are using ArcSDE 10 SP1 too with Oracle 11G.

Essentially, it seems that both through the ArcMap replica wizard and ArcObject the solution keep copying related features despite setting the properties to false (i.e. do not copy related features). Furthermore, it appears that setting a definition query on table involved in a replica is also not working as per expected.

Any help would greatly appreciated.

Cheers,

Pascal


I have implemented the following code.

public Boolean createReplica(LayerDefinition[] layerDefinitions, String TaskID)
{
try
{
//Define the output workspace
setOuPutWorkspaceName();

//Define the source workspace
setinPutWorkspaceName();

//Set the source replicate dataset
IReplicaDescription2 rDDescription = initialiseReplica(layerDefinitions, m_sourceWorkspaceName, m_outPutWorkspaceName);

if (rDDescription == null)
throw new GISException("replica not initialised");

//If replica already exists unregister it!
Workspace masterWorkspace = (Workspace)WorkspaceHelper.openFromSDEConnection(ApplicationConfigReader.Instance().GetValue("SDEFilePath"));

IWorkspaceReplicas replicaWorkspace = (IWorkspaceReplicas)masterWorkspace;
IReplica replica = replicaWorkspace.get_ReplicaByName("mycheckout_" + TaskID);

if (replica != null)
{
IWorkspaceReplicasAdmin2 replicaWorkspaceManager = (IWorkspaceReplicasAdmin2)masterWorkspace;
replicaWorkspaceManager.UnregisterReplica(replica, true);
}

ICheckOut _checkOut = new CheckOutClass();
//Set to NOT Replicate related features
_checkOut.CheckOutData(rDDescription, false, "mycheckout_" + TaskID);
  // Note that rDDescription.FetchRelatedObjects is equal to False.
// However data replicated in the FGDB includes related features!

}

catch (Exception e)

{
throw new GISException(GISExceptionCode.ERROR_FGDB_NOT_INIT, e);
}

return true;
}

private IReplicaDescription2 initialiseReplica(LayerDefinition[] layerDefinitions,

IWorkspaceName sourceWorkSpaceName, IWorkspaceName OutputWorspaceName)

{

// Create an enumerator for source datasets.

IEnumName sourceEnumName = new NamesEnumeratorClass();

IEnumNameEdit sourceEnumNameEdit = (IEnumNameEdit)sourceEnumName;


for (int i = 0; i < layerDefinitions.Length; i++)
{

// Create a name object for the source feature class.
IFeatureClassName featureClassName = new FeatureClassNameClass();



// Set the featureClassName properties.
IDatasetName sourceDatasetName = (IDatasetName)featureClassName;
sourceDatasetName.WorkspaceName = sourceWorkSpaceName;
sourceDatasetName.Name = layerDefinitions[i].layerName;


IName sourceName = (IName)sourceDatasetName;
sourceName.NameString = layerDefinitions[i].layerName;


// Add the name object for the source class to the enumerator.
sourceEnumNameEdit.Add(sourceName);
}


//Set the data extraction details
IReplicaDescription2 rDDescription = new ReplicaDescriptionClass();

rDDescription.Init(sourceEnumName, OutputWorspaceName, true, esriDataExtractionType.esriDataCheckOut);

//rDDescription.AddDatasetNames(sourceEnumName);
rDDescription.ReplicaModelType = esriReplicaModelType.esriModelTypeFullGeodatabase;

IReplicaFilterDescriptionEdit rDDescriptionFilter = (IReplicaFilterDescriptionEdit)rDDescription;
IReplicaFilterDescription dd = (IReplicaFilterDescription)rDDescription;

for (int i = 0; i < layerDefinitions.Length; i++)
{
for (int j = 0; j < rDDescription.TableNameCount; j++)
{

IName tableName = rDDescription.get_TableName(j);
if (tableName.NameString == layerDefinitions[i].layerName)
{
  // The Query definition does not seem to be
//set as in the replica I get all features available in the table.
rDDescriptionFilter.set_TableDefQuery(j, layerDefinitions[i].queryDefinition);

//rDDescriptionFilter.set_TableUsesQueryGeometry(j, true);
String query = dd.get_TableDefQuery(j);
}
}
}

return rDDescription;
}

Outcomes