DgnECManager.Manager.OnInstanceUpdated

I am trying to use OnInstanceUpdated but it doesn't even hit my breakpoint? (It does update the Schema, and returns Success, but it just seems to remove the element instances.)

private DGN.SchemaUpdateStatus UpdateSchema()
{
try
{
FindInstancesScope scope = FindInstancesScope.CreateScope(ActiveDgnFile, new FindInstancesScopeOption(DgnECHostType.File, false));
IECSchema dgnSchema = DgnECManager.Manager.LocateSchemaInScope(scope, SchemaName, VersionMajor, VersionMinor, SchemaMatchType.Latest);
if (null != dgnSchema)
{
DGN.SchemaUpdateStatus updStatus = DGN.SchemaUpdateStatus.Success;
if (dgnSchema.VersionMajor < VersionMajor || dgnSchema.VersionMinor < VersionMinor)
{
UpdateSchemaOptions opts = new UpdateSchemaOptions((ushort)ECProviderId, false, true);
DgnECManager.Manager.OnInstanceUpdated += UpdateInstanceHandler;
updStatus = DgnECManager.Manager.UpdateSchema(MySchema, ActiveDgnFile, opts);
DgnECManager.Manager.OnInstanceUpdated -= UpdateInstanceHandler;
}
return updStatus;
}
}
catch { }
return DGN.SchemaUpdateStatus.SchemaNotFound;
}

public override void UpdateInstanceHandler(IDgnECInstance ecInstance)
{
string msg = "WTF Tom?";   // <- Breakpoint
Debug.WriteLine(msg);
//SetPropertyStringValue(ecInstance, VersionName, Version()); <- I want to do more than this, just trying to test right now...
}

  • Hi,

    at first, please read and follow the best practices. Especially to specify used product and its version exactly (e.g. using its build number) can be crucial to identify the issue.

    Also, please alwyas use Insert > Insert code tool every time you share any code snippet (even one line). Otherwise it hard-to-read plain text.

    I am trying to use OnInstanceUpdated

    Can you provide more details what you want to achieve?

    It's just quick assumption only, but when EC schema is updated and all related EC data instances are removed, the even it not "instance was updated", so the event is not raised.

    With regards,

      Jan

  • Sorry about the code, I don't use the forums much so I'm not very familiar. I will use that in the future.

    I am trying to add 2 new members to the schema. I want it to update the instances, and if possible, I want to add their values to the instances during the event.

    I don't understand: Jan said: "..., the even it not "instance was updated", so the event is not raised." why was the event not raised?

  • I will use that in the future.

    It should be possible to edit existing post as well.

    I am trying to add 2 new members to the schema.

    It would be possible, even when it's potentially risky operation.

    I want it to update the instances

    Yes, it is what you always should do when you update the schema.

    I think the right way is - when you obtain the schema update result (when it was success) - to iterate all EC instances and to update their values.

    I want to add their values to the instances during the event.

    During what event? I did not find any documentation when OnInstanceUpdate is raised, but from the name I guess it is called when EC data instances are updated. I do not see any relation to EC schema update.

    Regards,

      Jan

  • 						UpdateSchemaOptions opts = new UpdateSchemaOptions((ushort)ECProviderId, false, true);
    						DgnECManager.Manager.OnInstanceUpdated += UpdateInstanceHandler;
    						updStatus = DgnECManager.Manager.UpdateSchema(MySchema, ActiveDgnFile, opts);
    

    the last parameter of new UpdateSchemaOptions(...., true) is supposed to be telling UpdateSchema() to also updateInstances?

    or am I wrong?

    In previous times I have updated the schema and successfully updated the instances, but in those cases I did not need to do anything extra, like adding the values, so I wasn't attempting to use the OnInstanceUpdated event.

    previously I added a bool flag and wanted it to just default to false anyway, so I didn't need the event. It did update the schema, and it updated the instances to add the bool and it updated the Version of the instances to the correct new version.

  • the last parameter of new UpdateSchemaOptions(...., true) is supposed to be telling UpdateSchema() to also updateInstances?

    Did you read API documentation? In this case (as in many other situations), I mean C++ documentation for native equivalent of the managed one:

    There is no transformation of data already stored in the file.
    The caller is at their own risk to ensure that the new ECSchema is compatible
    with existing data 

    so I wasn't attempting to use the OnInstanceUpdated event.

    I did not implement such code in the past, so I am not sure I am right, but it sounds to me like a missunderstanding how EC ecosystem works: Schema and EC data are stored separately (both as XAttributes). In fact, they are plain (probably compressed) XML data.

    EC schema is updated without any relation to existing EC data. And OnInstanceUpdate event is not involved in this process in any way (because EC schema, not EC instance data is changed).

    With regards,

      Jan

  • Yes, I think I misspoke... It's been a while... My GetProperties() function does check the instance version and if not latest, it reads the instance as from the older version then adds the new values and rewrites it.... 

    So I guess I am updating it when it get read / rewritten.

    But why does it actually remove the instance when I do the UpdateSchema? Or is it just that it doesn't display in properties until I fix the instance??

  • I am using ProStructures Connect, v. 10.5.2.50 and SDK v.10.00.00.26

    And the documentation seems to be very incomplete.

  • Hi,

    My GetProperties() function does check the instance version and if not latest, it reads the instance as from the older version then adds the new values and rewrites it....

    I am not sure I understand the whole process right. When you update the schema, you do not update EC data instances, attached to elements. They are disconnected records.

    But why does it actually remove the instance when I do the UpdateSchema?

    I do not now. The problem is that UpdateSchemaOption class is NET API specific, not existing in native API.

    I recommend to try what happens when you pass null, because in such scenario, default UpdateSchemaOption configuration is used (the option class is created with default values, with default provider id and the update option set to false).

    I still think that the best way is to follow native API approach: To update schema separately, and to iterate and update EC data instances explicitly using own code. Because only you know, how the update should be done right.

    Or is it just that it doesn't display in properties until I fix the instance??

    My understanding of the display process is that when EC data instance is displayed, EC schema is analyzed for the data format. When specific EC property does not exist in the instance, it does not cause any problem (it's just null data). But I am not sure what happens when EC instance property exist, but it's not defined in EC schema. Maybe it's processed as ad-hoc EC data.

    I am using ProStructures Connect, v. 10.5.2.50 and SDK v.10.00.00.26

    It sounds like incompatible combination. SDK must alwyas be equal to PowerPlatform version. So you should check ustation.dll version (or to use "version" key-in in the product) to check what engine (PowerPlatform / MicroStation) version was used to build the product, and to use equal SDK.

    In fact, for NET, no SDK is necessary, because assemblies are delivered with the products, but it's about available documentation. And for some tasks (like to build ribbon definition in rsc format), SDK tools are required.

    And the documentation seems to be very incomplete.

    Yes. But you use the very first SDK version, which is very very very old and basic.

    I think the best for EC programming is MicroStation CE SDK Update 15 or 16.0, where EC APIs docs were included (for some reasons, they are not availble in the current SDK Update 16.2).

    With regards,

      Jan

  • Sorry, I've been out of town since Wednesday...

    My SDK version is 10.16.02.22 I downloaded and installed that in january, sorry I took that 10.00.00.26 ver number from the bmake.exe that is in the bin folder. I wasn't sure where else to get the ver num, but I do remember downloading 16, my previous version was 13. I guess I shoulda gone to apps and Features for the ver in the first place...

    I am not working in native for the ECData, I am only working in NET. which I guess is using the assemblies from ProStructures 10.5.2.50. but Prostructures 10.5.2.50 has about 0 documentation for ECData.

    I was only trying to use the OnInstanceUpdated because I was having so much trouble with the update process in the first place.

    i have tried to update the schema without updating the instances, then iterate the instances and try to resolve them, but even though it finds the instances, they now say that their schema version is the new version, and all values in them are null. You say they are now "disconnected records", do we just lose all that data?

    So, I am also trying to keep the old schema and import the new schema, so that I can iterate the old instances, get and resolve their data, rewrite them as the new schema, and finally delete the old schema, But it won't let me do that either. The import fails "Schema already exists". If I can't have multiple versions of the schema in the file at the same time, why are there SchemaMatchType.Latest and Exact types? Doesn't that imply there could be diff versions of the same schema?

    Do I need to read and resolve them all, keeping them in an enumeration, update the schema, and then rewrite them all? what if there's thousands? Wouldn't it be better to read and resolve, then rewrite each during the same iteration?

    is this process documented somewhere I haven't found? If so please point me in the right direction.

    What's weird is: I have another ECData schema, which is used as one single instance attached to the DGNFile (instead of to elements), and it updates correctly without any problems.

    I create the new schema and call update schema

    then I read the single instance, it still says it's schema version is the previous version number, and the values are all there.

    I add the new values that did not exist in the old schema and rewrite the instance.

    It all works perfectly. The only real diff I can see is that I use DgnECProviderId.ECXAttributes for the single instance DGNFile schema and I use DgnProviderId.ECXData for the element instances