Code Synchronization
Code Synchronization enables you to change user code and synchronize it back to your model.
You can enable/disable Code Synchronization in with the Sync User Code
Model Settings.
When the Sync User Code
setting is disabled, user code changes made in the generated files as well as changes made in the model are not modified.
For further information see code model synchronization.
Supported Elements
Only Opaque Model elements are supported for code Synchronization, a list of all supported elements can be found in User Code.
User Code section
Update
Because of previouse ambiguous usage and misconceptions we changed the User Code Section tag
/* UserCode{GUID}:Hash */
and
/* UserCode{GUID} */
/* SyncableUserCode{GUID}:Hash */
and
/* SyncableUserCode{GUID} */
to avoid losing any unsaved changes in your user code, sync your code before installing version >= 2.2
Areas of user code are enclosed by comments (/* SyncableUserCode{GUID}:Hash */
and /* SyncableUserCode{GUID} */
) and so can be easily identified.
Example User Code
if (SystemTime % 1000 > 980)
{
/* SyncableUserCode{D3D29825-6C47-40c4-ABD5-AFFD9A839A06}:kcv02M1fSt */
me->winState = FirstPrize;
/* SyncableUserCode{D3D29825-6C47-40c4-ABD5-AFFD9A839A06} */
}
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 (Code Editor).
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.
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. Conflicts for more information. |
Code Generation with the setting turning on/off:
Sync: On | The code is synced both ways. |
Sync: Off | Code changes in model and file are not synced. And will not be modified by the code generator. (This might lead to a divergence between model and file code!) |
Sync: On (again) | If there is a difference in model/file user code, the conflict will be shown in the log and the report. 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.
Warning
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
See also