-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOM_TransitionScriptWithErrorHandling.xml
More file actions
74 lines (68 loc) · 2.52 KB
/
DOM_TransitionScriptWithErrorHandling.xml
File metadata and controls
74 lines (68 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<DMSScript options="272" xmlns="http://www.skyline.be/automation">
<Name>DOM_TransitionScriptWithErrorHandling</Name>
<Description>Example DOM action script that transitions a DOM instance. It catches CrudFailedExceptions and throws a custom error instead.</Description>
<Type>Automation</Type>
<Author>SKYLINE2\ThomasGH</Author>
<CheckSets>FALSE</CheckSets>
<Folder>
</Folder>
<Interactivity>Auto</Interactivity>
<Protocols>
</Protocols>
<Memory>
</Memory>
<Parameters>
</Parameters>
<Script>
<Exe id="1" type="csharp">
<Value><![CDATA[using System.Linq;
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net.Apps.DataMinerObjectModel;
using Skyline.DataMiner.Net.Apps.DataMinerObjectModel.Actions;
using Skyline.DataMiner.Net.Apps.DataMinerObjectModel.Status;
using Skyline.DataMiner.Net.ManagerStore;
namespace DOM_TransitionAction
{
public class Script
{
[AutomationEntryPoint(AutomationEntryPointType.Types.OnDomAction)]
public void OnDomActionMethod(IEngine engine, ExecuteScriptDomActionContext context)
{
var helper = new DomHelper(engine.SendSLNetMessages, "my_module_id");
try
{
helper.DomInstances.DoStatusTransition(context.ContextId as DomInstanceId, "transition_one");
}
catch (CrudFailedException e)
{
if (!TryHandleCrudFailedException(engine, e))
{
// If we do not know the error, pass the exception to SLAutomation
throw;
}
}
}
private bool TryHandleCrudFailedException(IEngine engine, CrudFailedException e)
{
var error = e.TraceData?.ErrorData.OfType<DomStatusTransitionError>().FirstOrDefault();
if (error == null)
{
return false;
}
switch (error.ErrorReason)
{
case DomStatusTransitionError.Reason.DomInstanceHasMissingRequiredFieldsForNextStatus:
var message = $"The DOM instance does not contain a value for all required fields. ({error.AssociatedFields.Count} missing field(s))";
engine.AddError(message);
return true;
// ... handle other errors if needed ...
}
return false;
}
}
}]]></Value>
<Message>
</Message>
</Exe>
</Script>
</DMSScript>