public static void UpdateName([NotNull] IModelElement modelElement, [NotNull] IDatasetName datasetName, bool useQualifiedName) { Assert.ArgumentNotNull(modelElement, nameof(modelElement)); Assert.ArgumentNotNull(datasetName, nameof(datasetName)); UpdateName(modelElement, datasetName.Name, useQualifiedName); var featureDatasetElement = modelElement as IFeatureDatasetElement; if (featureDatasetElement == null) { return; } IDatasetName featureDatasetName = DatasetUtils.GetFeatureDatasetName(datasetName); Assert.NotNull(featureDatasetName, "Unable to determine feature dataset name for {0}", datasetName.Name); featureDatasetElement.FeatureDatasetName = useQualifiedName ? featureDatasetName.Name : ModelElementNameUtils.GetUnqualifiedName(featureDatasetName.Name); }
public static T GetDataset <T>([NotNull] string datasetName, [NotNull] IEnumerable <Dataset> datasets) where T : Dataset { Assert.ArgumentNotNullOrEmpty(datasetName, nameof(datasetName)); Assert.ArgumentNotNull(datasets, nameof(datasets)); foreach (Dataset dataset in datasets) { var typedDataset = dataset as T; if (typedDataset == null) { continue; } string modelDatasetName = dataset.Model.ElementNamesAreQualified ? datasetName // matches only if also qualified : ModelElementNameUtils.GetUnqualifiedName( datasetName); if (string.Equals(dataset.Name, modelDatasetName, StringComparison.OrdinalIgnoreCase)) { return(typedDataset); } } return(null); }
public static void UpdateName([NotNull] IModelElement modelElement, [NotNull] string gdbDatasetName, bool useQualifiedName) { Assert.ArgumentNotNull(modelElement, nameof(modelElement)); Assert.ArgumentNotNullOrEmpty(gdbDatasetName, nameof(gdbDatasetName)); modelElement.Name = useQualifiedName ? gdbDatasetName : ModelElementNameUtils.GetUnqualifiedName(gdbDatasetName); }
public static Association CreateAssociation( [NotNull] IRelationshipClass relClass, [NotNull] IObjectDataset destinationDataset, [NotNull] IObjectDataset originDataset, [NotNull] Model model) { bool unqualifyDatasetName = !model.HarvestQualifiedElementNames; string relClassName = DatasetUtils.GetName(relClass); AssociationCardinality cardinality = GetCardinality(relClass); ObjectAttribute originPK = GetOriginPK(relClass, originDataset); string associationName = !unqualifyDatasetName ? relClassName : ModelElementNameUtils.GetUnqualifiedName(relClassName); if (!relClass.IsAttributed && relClass.Cardinality != esriRelCardinality.esriRelCardinalityManyToMany) { ObjectAttribute originFK = GetOriginFK(relClass, destinationDataset); return(new ForeignKeyAssociation(associationName, cardinality, originFK, originPK) { Model = model }); } ObjectAttribute destinationPK = GetDestinationPK( relClass, destinationDataset); var relTable = (ITable)relClass; esriFieldType destinationFKType = DatasetUtils.GetField( relTable, relClass.DestinationForeignKey).Type; esriFieldType originFKType = DatasetUtils.GetField( relTable, relClass.OriginForeignKey).Type; return(new AttributedAssociation( associationName, cardinality, relClass.DestinationForeignKey, (FieldType)destinationFKType, destinationPK, relClass.OriginForeignKey, (FieldType)originFKType, originPK) { Model = model }); }
private static string GetRelationshipClassName([NotNull] IWorkspace masterWorkspace, [NotNull] string associationName, [NotNull] Model model) { // TODO: Copy from QaRelationTestFactory: if (masterWorkspace.Type != esriWorkspaceType.esriRemoteDatabaseWorkspace) { // the workspace uses unqualified names return(ModelElementNameUtils.IsQualifiedName(associationName) ? ModelElementNameUtils.GetUnqualifiedName(associationName) : associationName); } // the workspace uses qualified names if (!ModelElementNameUtils.IsQualifiedName(associationName)) { Assert.NotNullOrEmpty( model.DefaultDatabaseSchemaOwner, "The master database schema owner is not defined, cannot qualify unqualified association name ({0})", associationName); return(ModelElementNameUtils.GetQualifiedName( model.DefaultDatabaseName, model.DefaultDatabaseSchemaOwner, ModelElementNameUtils.GetUnqualifiedName(associationName))); } // the association name is already qualified if (StringUtils.IsNotEmpty(model.DefaultDatabaseSchemaOwner)) { return(ModelElementNameUtils.GetQualifiedName( model.DefaultDatabaseName, model.DefaultDatabaseSchemaOwner, ModelElementNameUtils.GetUnqualifiedName(associationName))); } return(associationName); }
private T GetModelElement <T>( [NotNull] string fullName, [NotNull] IWorkspaceName workspaceName, [NotNull] IDictionary <WorkspaceElement, T> index, [NotNull] Func <string, IList <T> > getForName, [CanBeNull] Func <string, IWorkspaceName, T> getForCurrentContext) where T : class, IModelElement { Assert.ArgumentNotNullOrEmpty(fullName, nameof(fullName)); Assert.ArgumentNotNull(workspaceName, nameof(workspaceName)); Assert.ArgumentNotNull(index, nameof(index)); Assert.ArgumentNotNull(getForName, nameof(getForName)); var workspaceElement = new WorkspaceElement(workspaceName, fullName); T modelElement; if (index.TryGetValue(workspaceElement, out modelElement)) { return(modelElement); } // model element not yet cached - search for it IWorkspace workspace; try { workspace = WorkspaceUtils.OpenWorkspace(workspaceName); } catch (Exception e) { throw new InvalidOperationException( $"Error opening workspace name to select model element for name '{fullName}'", e); } var inaccessibleModels = new List <string>(); _domainTransactions.UseTransaction( delegate { if (getForCurrentContext != null) { modelElement = getForCurrentContext(fullName, workspaceName); if (modelElement != null) { return; } } IList <T> candidates = getForName(fullName); Assert.NotNull(candidates, "no dataset list returned"); if (!ModelElementNameUtils.IsQualifiedName(fullName)) { // the gdb element name is unqualified // search as is (in models that allow opening from default db) modelElement = GetCandidateInSameDatabase( candidates, workspace, ModelElementNameType.Any, inaccessibleModels); } else { // the dataset name is qualified // search datasets in models that use qualified names (and that allow opening from default db) modelElement = GetCandidateInSameDatabase( candidates, workspace, ModelElementNameType.Qualified, inaccessibleModels); // not found: unqualify, search in models with unqualified dataset names if (modelElement == null) { candidates = getForName(ModelElementNameUtils.GetUnqualifiedName(fullName)); modelElement = GetCandidateInSameDatabase( candidates, workspace, ModelElementNameType.Unqualified, inaccessibleModels); } } }); if (modelElement == null && inaccessibleModels.Count > 0) { // only if no candidate was found: warn if any of the candidates // could not be verified because of an invalid workspace reference if (inaccessibleModels.Count == 1) { string inaccessibleModelName = inaccessibleModels.First(); _msg.Warn( $"Workspace for model '{inaccessibleModelName}' containing '{fullName}' cannot be opened."); } else { _msg.Warn( "The master database workspaces for the following models cannot be opened:"); using (_msg.IncrementIndentation()) { foreach (string inaccessibleModelName in inaccessibleModels) { _msg.Warn($"{inaccessibleModelName}"); } } } } // add element even if null (to not search again for unregistered element) index.Add(workspaceElement, modelElement); return(modelElement); }