Skip to content

Commit 8009a5a

Browse files
Optimize code
1 parent d41085c commit 8009a5a

30 files changed

Lines changed: 480 additions & 634 deletions

SdkTestAutomation.Sdk/Core/SdkFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using SdkTestAutomation.Sdk.Core.Interfaces;
2-
using SdkTestAutomation.Sdk.Implementations.CSharp;
2+
using SdkTestAutomation.Sdk.Implementations.CSharp.Adapters;
33
using SdkTestAutomation.Sdk.Implementations.Java.Conductor;
4-
using SdkTestAutomation.Sdk.Implementations.Python;
5-
using SdkTestAutomation.Sdk.Implementations.Go;
4+
using SdkTestAutomation.Sdk.Implementations.Python.Adapters;
5+
using SdkTestAutomation.Sdk.Implementations.Go.Adapters;
66
using SdkTestAutomation.Sdk.Implementations.Java.Orkes;
77

88
namespace SdkTestAutomation.Sdk.Core;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using SdkTestAutomation.Sdk.Core.Interfaces;
2+
using SdkTestAutomation.Sdk.Core.Models;
3+
4+
namespace SdkTestAutomation.Sdk.Implementations.CSharp.Adapters;
5+
6+
public class CSharpEventAdapter : BaseCSharpAdapter, IEventAdapter
7+
{
8+
public SdkResponse AddEvent(string name, string eventType, bool active = true)
9+
{
10+
return ExecuteCSharpOperation(() =>
11+
{
12+
var eventHandler = new Conductor.Client.Models.EventHandler
13+
{
14+
Name = name,
15+
_Event = eventType,
16+
Active = active,
17+
Actions = new List<Action>()
18+
};
19+
20+
_client.EventApi.AddEventHandler(eventHandler);
21+
}, "AddEvent");
22+
}
23+
24+
public SdkResponse GetEvents()
25+
{
26+
return ExecuteCSharpOperation(() =>
27+
{
28+
return _client.EventApi.GetEventHandlers();
29+
}, "GetEvents");
30+
}
31+
32+
public SdkResponse GetEventByName(string eventName)
33+
{
34+
return ExecuteCSharpOperation(() =>
35+
{
36+
return _client.EventApi.GetEventHandlersForEvent(eventName, false);
37+
}, "GetEventByName");
38+
}
39+
40+
public SdkResponse UpdateEvent(string name, string eventType, bool active = true)
41+
{
42+
return ExecuteCSharpOperation(() =>
43+
{
44+
var eventHandler = new Conductor.Client.Models.EventHandler
45+
{
46+
Name = name,
47+
_Event = eventType,
48+
Active = active,
49+
Actions = new List<Action>()
50+
};
51+
52+
_client.EventApi.UpdateEventHandler(eventHandler);
53+
}, "UpdateEvent");
54+
}
55+
56+
public SdkResponse DeleteEvent(string name)
57+
{
58+
return ExecuteCSharpOperation(() =>
59+
{
60+
_client.EventApi.RemoveEventHandlerStatus(name);
61+
}, "DeleteEvent");
62+
}
63+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using SdkTestAutomation.Sdk.Core.Interfaces;
2+
using SdkTestAutomation.Sdk.Core.Models;
3+
4+
namespace SdkTestAutomation.Sdk.Implementations.CSharp.Adapters;
5+
6+
public class CSharpTokenAdapter : BaseCSharpAdapter, ITokenAdapter
7+
{
8+
public SdkResponse GenerateToken(string keyId, string keySecret)
9+
{
10+
return ExecuteCSharpOperation(() =>
11+
{
12+
var generateTokenRequest = new Conductor.Client.Models.GenerateTokenRequest(keyId, keySecret);
13+
return _client.TokenApi.GenerateToken(generateTokenRequest);
14+
}, "GenerateToken");
15+
}
16+
17+
public SdkResponse GetUserInfo()
18+
{
19+
throw new NotImplementedException();
20+
}
21+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Conductor.Client.Models;
2+
using SdkTestAutomation.Sdk.Core.Interfaces;
3+
using SdkTestAutomation.Sdk.Core.Models;
4+
5+
namespace SdkTestAutomation.Sdk.Implementations.CSharp.Adapters;
6+
7+
public class CSharpWorkflowAdapter : BaseCSharpAdapter, IWorkflowAdapter
8+
{
9+
public SdkResponse GetWorkflow(string workflowId)
10+
{
11+
return ExecuteCSharpOperation(() =>
12+
{
13+
return _client.WorkflowApi.GetExecutionStatus(workflowId);
14+
}, "GetWorkflow");
15+
}
16+
17+
public SdkResponse GetWorkflows()
18+
{
19+
return ExecuteCSharpOperation(() =>
20+
{
21+
return _client.WorkflowApi.GetRunningWorkflow("", null, 100, 0);
22+
}, "GetWorkflows");
23+
}
24+
25+
public SdkResponse StartWorkflow(string name, int version, string correlationId = null)
26+
{
27+
return ExecuteCSharpOperation(() =>
28+
{
29+
var startWorkflowRequest = new StartWorkflowRequest
30+
{
31+
Name = name,
32+
Version = version,
33+
CorrelationId = correlationId
34+
};
35+
36+
return _client.WorkflowApi.StartWorkflow(startWorkflowRequest);
37+
}, "StartWorkflow");
38+
}
39+
40+
public SdkResponse TerminateWorkflow(string workflowId, string reason = null)
41+
{
42+
return ExecuteCSharpOperation(() =>
43+
{
44+
_client.WorkflowApi.Terminate(workflowId, reason);
45+
}, "TerminateWorkflow");
46+
}
47+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using SdkTestAutomation.Sdk.Core.Models;
2+
3+
namespace SdkTestAutomation.Sdk.Implementations.CSharp;
4+
5+
public abstract class BaseCSharpAdapter
6+
{
7+
protected readonly CSharpClient _client;
8+
9+
protected BaseCSharpAdapter()
10+
{
11+
_client = new CSharpClient();
12+
}
13+
14+
public string SdkType => "csharp";
15+
16+
public bool Initialize(string serverUrl)
17+
{
18+
try
19+
{
20+
_client.Initialize(serverUrl);
21+
return _client.IsInitialized;
22+
}
23+
catch (Exception ex)
24+
{
25+
throw new InvalidOperationException($"Failed to initialize C# adapter: {ex.Message}", ex);
26+
}
27+
}
28+
29+
protected SdkResponse ExecuteCSharpOperation(Func<object> operation, string operationName)
30+
{
31+
try
32+
{
33+
if (_client == null || !_client.IsInitialized)
34+
{
35+
return SdkResponse.CreateError("C# client is not initialized");
36+
}
37+
38+
var result = operation();
39+
return SdkResponse.CreateSuccess(result);
40+
}
41+
catch (Exception ex)
42+
{
43+
return SdkResponse.CreateError($"{operationName} failed: {ex.Message}");
44+
}
45+
}
46+
47+
protected SdkResponse ExecuteCSharpOperation(Action operation, string operationName)
48+
{
49+
try
50+
{
51+
if (_client == null || !_client.IsInitialized)
52+
{
53+
return SdkResponse.CreateError("C# client is not initialized");
54+
}
55+
56+
operation();
57+
return SdkResponse.CreateSuccess();
58+
}
59+
catch (Exception ex)
60+
{
61+
return SdkResponse.CreateError($"{operationName} failed: {ex.Message}");
62+
}
63+
}
64+
65+
public void Dispose()
66+
{
67+
_client?.Dispose();
68+
}
69+
}

SdkTestAutomation.Sdk/Implementations/CSharp/CSharpEventAdapter.cs

Lines changed: 0 additions & 111 deletions
This file was deleted.

SdkTestAutomation.Sdk/Implementations/CSharp/CSharpTokenAdapter.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)