Skip to end of metadata
Go to start of metadata

Code Synchronization enables you to change certain pieces of code (user code) which will be synchronized back to your model.

You can enable/disable Code Synchronization in the Model Settings.


Supported Elements


The following Elements are supported for User Code Synchronization.

Model ElementProperty of Model ElementRemarks
OperationInitial CodeCheck your Model Setting: User Code storage field
OperationBehaviorCheck your Model Setting: User Code storage field
ActionEffectThe Effect of Opaque Actions is synchronized

User Code Section


Tag Update

Because of previouse ambiguous usage and misconceptions we changed the User Code Section tag from:

/* UserCode{GUID}:Hash */ and /* UserCode{GUID} */

to:

/* SyncableUserCode{GUID}:Hash */ and /* SyncableUserCode{GUID} */

to avoid loosing any unsaved changes in your user code, sync your code before installing version 2.2

Areas of user code are enclosed by comments (/* UserCode{GUID}:Hash */ and /* UserCode{GUID} */) and so can be easily identified.

Enterprise ArchitectMagicDraw
User Code Example
if (SystemTime % 1000 > 980)
{
    /* UserCode{D3D29825-6C47-40c4-ABD5-AFFD9A839A06}:kcv02M1fSt */
    me->winState = FirstPrize;
    /* UserCode{D3D29825-6C47-40c4-ABD5-AFFD9A839A06} */
}
User Code Example
if (test2)
{
    /* SyncableUserCode_19_0_16d30428_1549438128016_79363_7688:1Ro4d5hC1y */
    test1++;
    /* SyncableUserCode_19_0_16d30428_1549438128016_79363_7688 */
}


Model → Code (Regular Code Generation)

With Code Synchronization you can edit the generated source code within your accustomed IDE or editor, as well as directly within your model.

For example if you create an action you will probably implement the effect directly in your model. The code from the action is generated as part of a user code section.

Enterprise ArchitectMagicDraw


Code → Model Synchronization

Due to the lack of syntax highlighting in the model, and also due to the fact that you might have refactorings/changes spanning multiple files/actions, it is often easier to make these changes in your source code editor.

Just edit the generated code, save it and start the code generator.

Code Synchronization will examine the model and the already existing code, and detects changes in the user code sections. There are three interesting cases to consider:

The model has changed since generating code.The code in the section is discarded, as it did not change.
The code has changed since generating code.The model is updated with the code changes in that user code section.
Both, the model and the code, have changed.Code Synchronization has detected conflicting changes. See Conflicts for more information.

When code generation is completed, a code change report is available which lists the changes and the impact in the model.

Opening the effect shows the successfully synchronized code.

Conflicts

In case of conflicts caused by changing code directly in the model as well as editing the same code section in your editor, the code generator identifies those conflicts and marks them for you.
Conflicting areas are marked with conflict markers (<<<<<<< .model / ======= / >>>>>>> .code) to make them easily discoverable. After resolving these conflicts, be it in the model or directly in the code, start the code generator again to get the changes synchronized.

The conflict markers used are the same as in git, Mercurial, SVN, ... so merge tools can parse them and offer advanced editing modes for these conflicts.

Code Change Report

The code change report is written whenever the code generated in a user code section changed due to a manual change in the code, or a change in the model.
For newly introduced model elements (Operations, Actions), no report is generated.

Sample Report

Tag Update

Because of previouse ambiguous usage and misconceptions we changed the User Code Section tag from:

/* UserCode{GUID}:Hash */ and /* UserCode{GUID} */

to:

/* SyncableUserCode{GUID}:Hash */ and /* SyncableUserCode{GUID} */

to avoid loosing any unsaved changes in your user code, sync your code before installing version 2.2

See also

User Code

  • No labels