I’m getting happier and happier for reflection
I have hated the message in the “undo” pulldown for years, what does “Dynamo-51297CB5 Script” say!? Nothing at all, in fact, it is super annoying
First of all “Script”… come on, it is nearly never a script that causes a transaction, it is with 99.95% a node which needs a transaction in a graph… again it is super annoying
So for all programmers especially those who code using C# and build ZeroTouch nodes, If you what to help your users by informing them which node has caused a transaction or just want to inform your users in a better way what is going on like I show below… then use reflection
What I have done is coding a transaction method calling the Dynamo TransactionManager and then using reflection
internal static void TransactionEnsure(Document document, string transactionName)
{
TransactionManager.Instance.EnsureInTransaction(document);
// Set a proper name for the transaction
var name = string.Format("Dynamo node: {0}", transactionName);
typeof(TransactionWrapper).GetField("TransactionName").SetValue(null, name);
}
internal static void TransactionClose()
{
TransactionManager.Instance.ForceCloseTransaction();
}
Hereafter when I need a transaction I can do it as following… and yes I don’t want to write the name manually, so I also use reflection to get the class and the method
var transactionName = string.Format("{0}.{1}",
MethodBase.GetCurrentMethod().DeclaringType.Name,
MethodBase.GetCurrentMethod().Name);
Services.TransactionEnsure(document, transactionName);
...whatever is needing a transaction...
Services.TransactionClose();
The result is in my view exactly what we need to give better information to users
What do you think @solamour, @john_pierson
However, I would prefer that the ootb TransactionManager would take a string that could be used for naming the transaction to inform the user.