DynamoDS/Dynamo — pull request #2659 by ke-yu (2014-10-10 06:43:32+00:00)
Title: Fix magn-4837: nested custom node return nulls or crash on load/run of file IN revit any version 

This pull request tries to fix defect [MAGN-4837: nested custom node return nulls or crash on load/run of file IN revit any version] (http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-4837)

For the nested custom node that attached in this defect, the VM will execute following code snippets one by one:
* Outer custom node
```
def func_2b59b1a2bb5440c583fd528ec9abc36b: var[]..[](points4 : var[]..[])
{
var_5ccd62b860a44ea899bfdce64a4f0d7f = _SingleFunctionObject(func_a7c1ac96e3594097a9a162e56a4c7336, 1, {}, {null}, true);
...
}
```
* Inner custom node
```
def func_a7c1ac96e3594097a9a162e56a4c7336: var[]..[](x : var[]..[])
{
...
}
```
* Global nodes
```
temp_0_26078a96_2730_44d9_8f1e_8d54cc30b060_26078a96273044d98f1e8d54cc30b060 = (1..10);
...
```

When opening a .dyn or .dyf file, nested custom node will always be compiled *before* custom node in the outer scope. For this case, when compiling function ``func_2b59b1a2bb5440c583fd528ec9abc36b()`` the VM knows that ``func_a7c1ac96e3594097a9a162e56a4c7336`` is a function as it has been compiled, so a function pointer will be created.

But on Revit, ``DynamoModel.ResetEngine()`` is called at some point which consequently re-compiles all loaded custom nodes, so ``func_2b59b1a2bb5440c583fd528ec9abc36b()`` may be compiled *before* ``func_a7c1ac96e3594097a9a162e56a4c7336()``, therefore a null value is emitted.

It is not trivial to fundamentally fix the problem because essentially it is related to module management. Ideally the VM should maintain a dependency graph of modules and also needs to take module version and other information into account.

A workaround is to change the data structure that contains loaded custom node so that their loading order will be kept. Here, ``CustomManager.LoadedCustomNodes`` is changed to ``OrderedDictionary``. The other change is a custom node won't be added to ``CustomManager.LoadedCustomNodes`` until it is compiled.

To TD --

Please test the following cases:
1. Load nested custom nodes, run.
2. Debug -> Force re-execute. Like I said, this option will force re-compilation for all custom nodes and this defect is caused by compilation consequence.
3. Open nested custom node, modify and Run or Force re-execute.
4. Open outer scope custom node, modify and Run or Force re-execute.
5. Test on Revit and on Standalone.

@Steell, please review the change.