This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
When a diagram is saved in XML format, the ID's for nodes and shapes are changed on every save. As our output files go into version control, this isnt really suitable. Is there a way to prevent mindscape from creating new ID's when the shape is saved? |
|
|
Hello Richard I have now added a way for you to override the ID logic for elements when serializing a diagram. This will be available through the nightly builds from tomorrow the 30th of July. Here is the nightly builds page: http://www.mindscapehq.com/products/wpfdiagrams/nightly-builds Once you install the nightly builds from tomorrow, the DiagramXmlSerializer will have a protected virtual method called GetId which you can override to return an ID for the given diagram model object. There are 2 ways you can use this to get the desired effect: 1) Use this custom serializer:
public class PersistentDiagramXmlSerializer : DiagramXmlSerializer Here you can see I have overriden the GetId method to return a very simple ID based on the number of times the method is called. This means that every time you serialize the same diagram, the IDs will always be the same too. You can of course change this implementation to return whatever ID you prefer, as long as the IDs are unique, and are based on the number of times the method is called so they can stay the same every time the diagram is saved. This will ensure that saving the same diagram will not indicate a change for the output file in your source control. Just be aware that there isn't a good place to reset the _id variable, so you should create a new instance of the custom serializer every time you save a diagram. 2) If for some reason you don't want to have IDs based on the call count, or you have a specific ID format that you are required to use, then there is this slightly more complex approach you can take: Your model objects for nodes and connections will need to store the ID that they should be serialized with. This will allow the serializer to use the same ID for the same elements no matter how many times they are seriaialized or deserialized. Setting the ID should be done in the constructor of the model objects. Then you can extend the DiagramXmlSerializer and override the GetId method. This time the ID returned will be based on the ID stored in the model object. You will also need to set the ID back to the model objects when deserializing. Let me know if you need help with this approach if this is the path you decide to take. Let us know how it goes - Jason |
|