private static ECSchema RetrieveSchema(DgnFile File, FindInstancesScope scope) { DgnECManager Manager = DgnECManager.Manager; DgnModel model = Session.Instance.GetActiveDgnModel(); var schemas = (List <string>)Manager.DiscoverSchemasForModel(model, ReferencedModelScopeOption.All, false); var schemaString = schemas.Where(x => x.Contains(schemaName)).FirstOrDefault(); if (schemaString != null) { try { IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); return((ECSchema)schema); } catch (Exception e) { return(null); } } else { return(CreateSchema(File)); } }
public static ECSchema RetrieveSchema() { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); return((ECSchema)schema); }
public static DgnECInstanceCollection RetrieveInstances() { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); IECClass ecClass = schema.GetClass(className); ECQuery readWidget = new ECQuery(ecClass); readWidget.SelectClause.SelectAllProperties = true; DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget); return(instances); }
public static IDgnECInstance RetrieveInstance(StreamState streamState) { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); IECClass ecClass = schema.GetClass(className); ECQuery readWidget = new ECQuery(ecClass); readWidget.SelectClause.SelectAllProperties = true; DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget); var instance = instances.Where(x => x["Id"].StringValue == streamState.Stream.id).FirstOrDefault(); return(instance); }
/// <summary> /// Writes the stream states to the current schema. /// </summary> /// <param name="streamStates"></param> public static void WriteStreamStateList(List <StreamState> streamStates) { DgnFile File = Session.Instance.GetActiveDgnFile(); DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest); if (schema == null) { schema = StreamStateListSchema.GetSchema(); } IECClass ecClass = schema.GetClass(className); ECQuery readWidget = new ECQuery(ecClass); readWidget.SelectClause.SelectAllProperties = true; using (DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget)) { foreach (IDgnECInstance instance in instances) { instance.Delete(); } } DgnECInstanceEnabler instanceEnabler = Manager.ObtainInstanceEnabler(File, ecClass); foreach (var streamState in streamStates) { var data = JsonConvert.SerializeObject(streamState) as string; StandaloneECDInstance instance = instanceEnabler.SharedWipInstance; instance.SetAsString("Id", streamState.Stream.id); instance.SetAsString("StreamData", data); instanceEnabler.CreateInstanceOnFile(File, instance); } }