public static void AddEntities <T>(T item, IWorkspaceContext workspace, int parentId) where T : class, IEntityClass { if (item.Id > 0 && parentId == 0) { workspace.MarkUnchanged(item); } var items = item.GetType().GetProperties() .Where(y => y.CanWrite && y.PropertyType.GetInterfaces().Contains(typeof(IEntityClass))) .Select(x => x.GetValue(item, null)).Cast <IEntityClass>().ToList(); items.ForEach(x => AddEntities(x, workspace, item.Id)); var collections = item.GetType().GetProperties().Where( x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericTypeDefinition().GetInterfaces().Contains(typeof(IEnumerable)) && x.PropertyType.GetGenericArguments()[0].GetInterfaces().Contains(typeof(IEntityClass))).ToList(); var cis = collections.SelectMany(pi => (pi.GetValue(item, null) as IEnumerable).Cast <IEntityClass>()).ToList(); foreach (var i in cis) { AddEntities(i, workspace, item.Id); } }
public static IRelationshipClass TryOpenFromMasterDatabase( [NotNull] Association association, bool allowAlways = false) { IWorkspaceContext context = GetMasterDatabaseWorkspaceContext(association, allowAlways); return(context?.OpenRelationshipClass(association)); }
/// <summary> /// Reads the object types from the geodatabase. /// </summary> public static void HarvestObjectTypes([NotNull] ObjectDataset objectDataset) { IWorkspaceContext workspaceContext = ModelElementUtils.GetMasterDatabaseWorkspaceContext(objectDataset); Assert.NotNull(workspaceContext, "The master database is not accessible"); IObjectClass objectClass = workspaceContext.OpenObjectClass(objectDataset); Assert.NotNull(objectClass, "Unable to open object class {0}", objectDataset.Name); HarvestObjectTypes(objectDataset, objectClass); }
private static void AddToEntityCache <T>(ICacheable entity, IWorkspaceContext workspace) { if (entity == null) { return; } if (!EntityCache.ContainsKey(typeof(T))) { EntityCache.Add(typeof(T), new Dictionary <int, CacheEntry>()); } if (EntityCache[typeof(T)].ContainsKey(entity.Id)) { RemoveFromEntityCache <T>(EntityCache[typeof(T)][entity.Id]); } EntityCache[typeof(T)].Add(entity.Id, new CacheEntry { Cacheable = entity, Workspace = workspace }); }
public static IEnumerable <IFeature> GetDerivedTableGeometryFeatures( [NotNull] IObject obj, [NotNull] ObjectDataset dataset, [NotNull] IModelContext modelContext) { Assert.ArgumentNotNull(obj, nameof(obj)); Assert.ArgumentNotNull(dataset, nameof(dataset)); Assert.ArgumentNotNull(modelContext, nameof(modelContext)); // TODO move elsewhere - domain? IObjectDataset? use objectrepository (moved from AE)? var relationList = new List <IRelationshipClass>(); IWorkspaceContext workspaceContext = null; foreach (AssociationEnd associationEnd in dataset.GetAssociationEnds()) { if (!(associationEnd.OppositeDataset is VectorDataset) || associationEnd.Association.NotUsedForDerivedTableGeometry) { continue; } // make sure to open the relationship class from the same workspace context as the dataset if (workspaceContext == null) { workspaceContext = modelContext.GetWorkspaceContext(dataset); Assert.NotNull(workspaceContext, "Unable to determine workspace context for dataset {0}", dataset); } IRelationshipClass relationshipClass = workspaceContext.OpenRelationshipClass(associationEnd.Association); if (relationshipClass != null) { relationList.Add(relationshipClass); } } return(GdbQueryUtils.GetRelatedObjectList(obj, relationList).Cast <IFeature>()); }
public static void HarvestAttributes( [NotNull] ObjectDataset objectDataset, [CanBeNull] IWorkspaceContext workspaceContext = null, [CanBeNull] IAttributeConfigurator configurator = null) { if (workspaceContext == null) { workspaceContext = ModelElementUtils.GetMasterDatabaseWorkspaceContext(objectDataset); } Assert.NotNull(workspaceContext, "The master database is not accessible"); IObjectClass objectClass = workspaceContext.OpenObjectClass(objectDataset); Assert.NotNull(objectClass, "Unable to open object class {0}", objectDataset.Name); HarvestAttributes(objectDataset, configurator, objectClass); }
public static IObjectClass OpenFromDefaultDatabase( [NotNull] IObjectDataset objectDataset) { Assert.ArgumentNotNull(objectDataset, nameof(objectDataset)); IWorkspaceContext masterDbContext = ModelElementUtils.GetMasterDatabaseWorkspaceContext(objectDataset); Assert.NotNull(masterDbContext, "The model master database for dataset {0} is not accessible", objectDataset.Name); IObjectClass result = masterDbContext.OpenObjectClass(objectDataset); Assert.NotNull(result, "Object class {0} not found in master database", objectDataset.Name); return(result); }
public static bool CanOpenFromMasterDatabase([NotNull] IDdxDataset dataset) { Model model = dataset.Model as Model; if (model == null) { return(false); } if (model.UseDefaultDatabaseOnlyForSchema) { return(false); } IWorkspaceContext masterDatabaseWorkspaceContext = model.MasterDatabaseWorkspaceContext; return(masterDatabaseWorkspaceContext != null && masterDatabaseWorkspaceContext.Contains(dataset)); }
private Dataset GetDatasetByModelNameCore( [NotNull] string modelName, [NotNull] QualityCondition qualityCondition) { List <Dataset> parameterDatasets = qualityCondition.GetDatasetParameterValues().ToList(); // search first for directly involved dataset foreach (Dataset dataset in parameterDatasets) { if (string.Equals(dataset.Name, modelName, StringComparison.OrdinalIgnoreCase)) { return(dataset); } } // if not found: search for other dataset in same workspace context as one of the directly involved datasets // (-> base datasets for topology, geometric network, terrain, etc.) foreach (Dataset involvedDataset in parameterDatasets) { IWorkspaceContext workspaceContext = _workspaceContextLookup.GetWorkspaceContext(involvedDataset); if (workspaceContext == null) { // TODO assertion exception? continue; } Dataset dataset = workspaceContext.GetDatasetByModelName(modelName); if (dataset != null) { return(dataset); } } return(null); // not found }
private Dataset GetDatasetByGdbTableNameCore( [NotNull] string gdbDatasetName, [NotNull] QualityCondition qualityCondition) { foreach (Dataset involvedDataset in qualityCondition.GetDatasetParameterValues()) { IWorkspaceContext workspaceContext = _workspaceContextLookup.GetWorkspaceContext(involvedDataset); if (workspaceContext == null) { // TODO assertion exception? continue; } Dataset dataset = workspaceContext.GetDatasetByGdbName(gdbDatasetName); if (dataset != null) { return(dataset); } } return(null); // not found }
GetRelationshipClassChainsToVerifiedFeatureClassesCore( [NotNull] IObjectDataset objectDataset, [NotNull] ICollection <IRelationshipClass> precedingRelationshipClasses, [NotNull] IWorkspaceContextLookup workspaceContextLookup, [CanBeNull] Predicate <VectorDataset> isRelevantVectorDataset, out bool hasAnyAssociationsToFeatureClasses) { var result = new List <IList <IRelationshipClass> >(); var relClassesToFeatureClasses = new List <IRelationshipClass>(); var associationEndsToTables = new List <AssociationEnd>(); IWorkspaceContext workspaceContext = null; hasAnyAssociationsToFeatureClasses = false; foreach (AssociationEnd associationEnd in objectDataset.GetAssociationEnds()) { ObjectDataset oppositeDataset = associationEnd.OppositeDataset; var oppositeVectorDataset = oppositeDataset as VectorDataset; if (oppositeVectorDataset != null) { if (associationEnd.Association.NotUsedForDerivedTableGeometry) { continue; } hasAnyAssociationsToFeatureClasses = true; if (isRelevantVectorDataset != null && !isRelevantVectorDataset(oppositeVectorDataset)) { continue; } if (workspaceContext == null) { workspaceContext = workspaceContextLookup.GetWorkspaceContext(objectDataset); Assert.NotNull(workspaceContext, "Unable to determine workspace context for dataset {0}", objectDataset); } IRelationshipClass relationshipClass = workspaceContext.OpenRelationshipClass(associationEnd.Association); if (relationshipClass != null) { relClassesToFeatureClasses.Add(relationshipClass); } } else if (oppositeDataset is TableDataset) { associationEndsToTables.Add(associationEnd); } } if (relClassesToFeatureClasses.Count > 0) { foreach (IRelationshipClass relClass in relClassesToFeatureClasses) { result.Add(new List <IRelationshipClass>(precedingRelationshipClasses) { relClass }); } } else { foreach (AssociationEnd associationEndToTable in associationEndsToTables) { if (workspaceContext == null) { workspaceContext = workspaceContextLookup.GetWorkspaceContext(objectDataset); Assert.NotNull(workspaceContext, "Unable to determine workspace context for dataset {0}", objectDataset); } IRelationshipClass relClassToTable = workspaceContext.OpenRelationshipClass(associationEndToTable.Association); if (relClassToTable == null) { continue; } if (precedingRelationshipClasses.Contains(relClassToTable)) { continue; } var relClassChainToTable = new List <IRelationshipClass>(precedingRelationshipClasses) { relClassToTable }; bool hasAnyIndirectAssociationsToFeatureClasses; ICollection <IList <IRelationshipClass> > indirectRelClassChains = GetRelationshipClassChainsToVerifiedFeatureClassesCore( associationEndToTable.OppositeDataset, relClassChainToTable, workspaceContextLookup, isRelevantVectorDataset, out hasAnyIndirectAssociationsToFeatureClasses); if (hasAnyIndirectAssociationsToFeatureClasses) { hasAnyAssociationsToFeatureClasses = true; } result.AddRange(indirectRelClassChains); // TODO REVISE: use only the first association end to a table which leads to a verified feature class if (indirectRelClassChains.Count > 0) { break; } } } return(result); }
private string GetFile(IWorkspaceContext workspaceContext, string sourcesDirectory, string buildDirectory, string fileToGet, string destinationDirectory) { if (fileToGet.StartsWith("$/")) { return workspaceContext.GetFile(fileToGet, Path.Combine(Path.Combine(buildDirectory, destinationDirectory), Path.GetFileName(fileToGet))); } return Path.IsPathRooted(fileToGet) ? fileToGet : Path.Combine(sourcesDirectory, fileToGet); }
public void ProcessPackage(Models.PackagesPackage package, string nuGetExeFilePath, INuGetProcess nuGetProcess, string sourcesDirectory, string buildDirectory, string dropFolder, IWorkspaceContext workspaceContext, IBuildMessageWriter buildMessageWriter, ICodeActivityContext context, string buildNumber, int buildNumberPrefex, string inputVersion) { var nuspecFile = GetFile(workspaceContext, sourcesDirectory, buildDirectory, package.NuSpecPath, package.name + "-nuspec"); if(!File.Exists(nuspecFile)) { throw new Exception(string.Format("The nuspec file \"{0}\" doesn't exist. It was defined in package \"{1}\"", nuspecFile, package.name)); } if(string.IsNullOrEmpty(package.OutputDirectory)) { package.OutputDirectory = "Packages"; } if(string.IsNullOrEmpty(package.AdditionalOptions)) { package.AdditionalOptions = string.Empty; } var outputDirectory = Path.Combine(dropFolder, package.OutputDirectory); if(!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } var basePath = dropFolder; if(!string.IsNullOrEmpty(package.BasePath)) { basePath = Path.Combine(basePath, package.BasePath); } string version = !string.IsNullOrEmpty(package.Version) ? new VersionPatternConverter().Convert(buildNumber, buildNumberPrefex, package.Version) : new VersionPatternConverter().Convert(buildNumber, buildNumberPrefex, inputVersion); string versionParameter = string.Empty; // if the nuspec has a version token, it is expecting us to set it from out global version number created if (GetNuSpecPackageVersion(nuspecFile).Equals("$version$", StringComparison.InvariantCultureIgnoreCase)) { // the package expects us to set a version // if the defintion defines a version, use it, otherwise, use the global version number versionParameter = string.Format("-version {0}", version); } // if the nuspec file has a $inputVersion$ token, we need to replace it. var nuspec = File.ReadAllText(nuspecFile); if(nuspec.Contains("$inputVersion$")) { FileAttributes attributes = File.GetAttributes(nuspecFile); if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) File.SetAttributes(nuspecFile, attributes ^ FileAttributes.ReadOnly); File.Delete(nuspecFile); File.WriteAllText(nuspecFile, nuspec.Replace("$inputVersion$", version)); } // TODO //package.PrePackagePowerShell var arguments = string.Format("pack \"{0}\" -OutputDirectory \"{1}\" -BasePath \"{2}\" {3} {4}", nuspecFile, outputDirectory, basePath, versionParameter, package.AdditionalOptions).Trim(); buildMessageWriter.WriteBuildMessage(string.Format("Calling nuget with arguments: {0}", arguments), BuildMessageImportance.High); nuGetProcess.RunNuGetProcess(nuGetExeFilePath, arguments, buildMessageWriter); // TODO //package.PreDeployPowerShell if(package.Deployments != null && package.Deployments.Length > 0) { var packageLocation = string.Empty; var pattern = GetNuSpecPackageName(nuspecFile) + "*.nupkg"; var files = new DirectoryInfo(outputDirectory).GetFiles(pattern).ToList(); if(files.Count > 1) { context.AddBuildError(string.Format("An attempt was made to deploy but there was more than 1 package found in the directory \"{0}\" matching the pattern \"{1}\".", outputDirectory, pattern)); }else if(files.Count == 0) { context.AddBuildError(string.Format("An attempt was made to deploy but there was no package found in the directory \"{0}\" matching the pattern \"{1}\".", outputDirectory, pattern)); }else { packageLocation = files[0].FullName; } if(!string.IsNullOrEmpty(packageLocation) && File.Exists(packageLocation)) { foreach (var deployment in package.Deployments) { ProcessDeployment(packageLocation, deployment, buildMessageWriter, nuGetProcess, nuGetExeFilePath); } } } }
public void DoProcessNuGetDefinitionsActivitiy( ICodeActivityContext context, IWorkspaceContext workspaceContext, IBuildMessageWriter buildMessageWriter, INuGetProcess nuGetProcess, string sourcesDirectory, string buildDirectory, string nuGetExeFilePath, string definitionsFilePath, string dropFolder, string buildNumber, int buildNumberPrefex, string version) { if (string.IsNullOrEmpty(definitionsFilePath)) { buildMessageWriter.WriteBuildMessage("No definition path was given.", BuildMessageImportance.High); return; } #region Gaurd if (string.IsNullOrEmpty(sourcesDirectory)) { throw new Exception("sourcesDirectory is null/empty"); } if (string.IsNullOrEmpty(dropFolder)) { throw new Exception("dropFolder is null/empty"); } if (workspaceContext == null) { throw new Exception("workspaceContext is null"); } if (string.IsNullOrEmpty(buildDirectory)) { throw new Exception("buildDirectory is null/empty"); } if (string.IsNullOrEmpty(nuGetExeFilePath)) { throw new Exception("nuGetExeFilePath is null/empty"); } #endregion nuGetExeFilePath = GetFile(workspaceContext, sourcesDirectory, buildDirectory, nuGetExeFilePath, "NuGetExe"); definitionsFilePath = GetFile(workspaceContext, sourcesDirectory, buildDirectory, definitionsFilePath, "DefinitionsFile"); if (!File.Exists(nuGetExeFilePath)) { context.AddBuildError(string.Format("The nuget exe was not found at the path {0}.", nuGetExeFilePath)); return; } if (!File.Exists(definitionsFilePath)) { context.AddBuildError(string.Format("The definitions xml was not found at the path {0}.", definitionsFilePath)); return; } Models.Packages definitions = null; try { definitions = GetDefinitions(definitionsFilePath); } catch (Exception ex) { context.AddBuildError(string.Format("There was a problem with the format of the definitions xml. {0}", ex.Message)); return; } if (definitions == null || definitions.Package == null || definitions.Package.Length == 0) { buildMessageWriter.WriteBuildMessage("There were not packages in the definition file.", BuildMessageImportance.High); return; } if(definitions.Package.Any(x => string.IsNullOrEmpty(x.name))) { context.AddBuildError("All package definitions must have a name (Package[name='name'])."); return; } if (definitions.Package.Select(x => x.name.ToLower()).Distinct().Count() != definitions.Package.Count()) { context.AddBuildError("The names for each package must be unique."); return; } foreach (var package in definitions.Package) { ProcessPackage(package, nuGetExeFilePath, nuGetProcess, sourcesDirectory, buildDirectory, dropFolder, workspaceContext, buildMessageWriter, context, buildNumber, buildNumberPrefex, version); } }