/// <summary> /// Writes the stream states to the current schema. /// </summary> /// <param name="streamStates"></param> public static void WriteStreamStateList(DgnFile File, List <StreamState> streamStates) { DgnECManager Manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All)); IECSchema schema = RetrieveSchema(File, scope); 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); var data = JsonConvert.SerializeObject(streamStates) as string; StandaloneECDInstance _instance = instanceEnabler.SharedWipInstance; _instance.SetAsString(propertyName, data); instanceEnabler.CreateInstanceOnFile(File, _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); } }