Skip to content

Commit c6b50e4

Browse files
committed
de-namespaced Core Handlers
1 parent f419f47 commit c6b50e4

6 files changed

Lines changed: 177 additions & 189 deletions

File tree

Synapse.Core/Handlers/EchoHandler.cs

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,76 +4,73 @@
44
using Synapse.Core;
55
using Synapse.Core.Utilities;
66

7-
namespace Synapse.Handlers
7+
public class EchoHandler : HandlerRuntimeBase
88
{
9-
public class EchoHandler : HandlerRuntimeBase
10-
{
11-
string _config = null;
9+
string _config = null;
1210

13-
public override object GetConfigInstance() { return null; }
14-
public override object GetParametersInstance() { return null; }
11+
public override object GetConfigInstance() { return null; }
12+
public override object GetParametersInstance() { return null; }
1513

16-
public override IHandlerRuntime Initialize(string config)
17-
{
18-
_config = config;
19-
return base.Initialize( config );
20-
}
14+
public override IHandlerRuntime Initialize(string config)
15+
{
16+
_config = config;
17+
return base.Initialize( config );
18+
}
2119

22-
public override ExecuteResult Execute(HandlerStartInfo startInfo)
20+
public override ExecuteResult Execute(HandlerStartInfo startInfo)
21+
{
22+
EchoHandlerResult r = new EchoHandlerResult( startInfo, _config );
23+
ExecuteResult result = new ExecuteResult()
2324
{
24-
EchoHandlerResult r = new Handlers.EchoHandlerResult( startInfo, _config );
25-
ExecuteResult result = new ExecuteResult()
26-
{
27-
Status = StatusType.Complete,
28-
ExitData = r
29-
};
25+
Status = StatusType.Complete,
26+
ExitData = r
27+
};
3028

31-
OnProgress( "Execute", result.ExitData.ToString(), result.Status, startInfo.InstanceId, Int32.MaxValue );
29+
OnProgress( "Execute", result.ExitData.ToString(), result.Status, startInfo.InstanceId, Int32.MaxValue );
3230

33-
return result;
34-
}
31+
return result;
3532
}
33+
}
3634

37-
public class EchoHandlerResult : HandlerStartInfo
35+
public class EchoHandlerResult : HandlerStartInfo
36+
{
37+
public EchoHandlerResult(HandlerStartInfo hsi, string config)
3838
{
39-
public EchoHandlerResult(HandlerStartInfo hsi, string config)
40-
{
41-
InstanceId = hsi.InstanceId;
42-
IsDryRun = hsi.IsDryRun;
43-
RequestUser = hsi.RequestUser;
44-
RequestNumber = hsi.RequestNumber;
45-
ParentExitData = hsi.ParentExitData;
46-
Parameters = hsi.Parameters;
47-
RunAs = hsi.RunAs;
48-
Config = config;
49-
CurrentPrincipal = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
50-
}
39+
InstanceId = hsi.InstanceId;
40+
IsDryRun = hsi.IsDryRun;
41+
RequestUser = hsi.RequestUser;
42+
RequestNumber = hsi.RequestNumber;
43+
ParentExitData = hsi.ParentExitData;
44+
Parameters = hsi.Parameters;
45+
RunAs = hsi.RunAs;
46+
Config = config;
47+
CurrentPrincipal = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
48+
}
5149

52-
public string Config { get; internal set; }
53-
public string CurrentPrincipal { get; internal set; }
50+
public string Config { get; internal set; }
51+
public string CurrentPrincipal { get; internal set; }
5452

55-
public override string ToString()
56-
{
57-
StringBuilder s = new StringBuilder();
53+
public override string ToString()
54+
{
55+
StringBuilder s = new StringBuilder();
5856

59-
s.AppendFormat( "InstanceId: {0}\r\n", InstanceId );
60-
s.AppendFormat( "IsDryRun: {0}\r\n", IsDryRun );
61-
s.AppendFormat( "RequestUser: {0}\r\n", RequestUser );
62-
s.AppendFormat( "RequestNumber: {0}\r\n", RequestNumber );
63-
s.AppendFormat( "ParentExitData: {0}\r\n", ParentExitData );
64-
s.AppendFormat( "RunAs: {0}\r\n", RunAs );
65-
s.AppendLine( $"CurrentPrincipal:{CurrentPrincipal}");
66-
s.AppendLine( "Config:" );
67-
s.AppendLine( Config );
68-
s.AppendLine( "Parameters:" );
69-
s.AppendLine( Parameters );
57+
s.AppendFormat( "InstanceId: {0}\r\n", InstanceId );
58+
s.AppendFormat( "IsDryRun: {0}\r\n", IsDryRun );
59+
s.AppendFormat( "RequestUser: {0}\r\n", RequestUser );
60+
s.AppendFormat( "RequestNumber: {0}\r\n", RequestNumber );
61+
s.AppendFormat( "ParentExitData: {0}\r\n", ParentExitData );
62+
s.AppendFormat( "RunAs: {0}\r\n", RunAs );
63+
s.AppendLine( $"CurrentPrincipal:{CurrentPrincipal}" );
64+
s.AppendLine( "Config:" );
65+
s.AppendLine( Config );
66+
s.AppendLine( "Parameters:" );
67+
s.AppendLine( Parameters );
7068

71-
return s.ToString();
72-
}
69+
return s.ToString();
70+
}
7371

74-
public string ToYaml()
75-
{
76-
return YamlHelpers.Serialize( this );
77-
}
72+
public string ToYaml()
73+
{
74+
return YamlHelpers.Serialize( this );
7875
}
7976
}

Synapse.Core/Handlers/EmptyHandler.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,28 @@
22

33
using Synapse.Core;
44

5-
namespace Synapse.Handlers
5+
public class EmptyHandler : HandlerRuntimeBase
66
{
7-
public class EmptyHandler : HandlerRuntimeBase
7+
public override object GetConfigInstance() { return null; }
8+
public override object GetParametersInstance() { return new EmptyHandlerParameters() { ReturnStatus = StatusType.Success, ExitData = "Sample Value" }; }
9+
override public ExecuteResult Execute(HandlerStartInfo startInfo)
810
{
9-
public override object GetConfigInstance() { return null; }
10-
public override object GetParametersInstance() { return new EmptyHandlerParameters() { ReturnStatus = StatusType.Success, ExitData = "Sample Value" }; }
11-
override public ExecuteResult Execute(HandlerStartInfo startInfo)
12-
{
13-
EmptyHandlerParameters parms = DeserializeOrNew<EmptyHandlerParameters>( startInfo.Parameters );
11+
EmptyHandlerParameters parms = DeserializeOrNew<EmptyHandlerParameters>( startInfo.Parameters );
1412

15-
OnProgress( "Execute", parms.ReturnStatus.ToString(), parms.ReturnStatus, startInfo.InstanceId, Int32.MaxValue );
13+
OnProgress( "Execute", parms.ReturnStatus.ToString(), parms.ReturnStatus, startInfo.InstanceId, Int32.MaxValue );
1614

17-
return new ExecuteResult() { Status = parms.ReturnStatus, ExitData = parms.ExitData };
18-
}
15+
return new ExecuteResult() { Status = parms.ReturnStatus, ExitData = parms.ExitData };
1916
}
17+
}
2018

21-
public class EmptyHandlerParameters
19+
public class EmptyHandlerParameters
20+
{
21+
public EmptyHandlerParameters()
2222
{
23-
public EmptyHandlerParameters()
24-
{
25-
ReturnStatus = StatusType.None;
26-
ExitData = "EmptyHandler ExitData default value.";
27-
}
28-
29-
public StatusType ReturnStatus { get; set; }
30-
public string ExitData { get; set; }
23+
ReturnStatus = StatusType.None;
24+
ExitData = "EmptyHandler ExitData default value.";
3125
}
26+
27+
public StatusType ReturnStatus { get; set; }
28+
public string ExitData { get; set; }
3229
}

Synapse.Core/Handlers/FooBarHandler.cs

Lines changed: 65 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,88 @@
44

55
using Synapse.Core;
66

7-
namespace Synapse.Handlers
7+
public class FooHandler : EmptyHandler
88
{
9-
public class FooHandler : EmptyHandler
9+
override public ExecuteResult Execute(HandlerStartInfo startInfo)
1010
{
11-
override public ExecuteResult Execute(HandlerStartInfo startInfo)
12-
{
13-
int seq = 1;
14-
StatusType st = StatusType.Failed;
15-
16-
try
17-
{
18-
Dictionary<object, object> p = Core.Utilities.YamlHelpers.Deserialize( startInfo.Parameters );
19-
st = (StatusType)Enum.Parse( typeof( StatusType ), p.Values.ElementAt( 0 ).ToString() );
20-
}
21-
catch { }
22-
23-
string x = $"{startInfo.ParentExitData}";
11+
int seq = 1;
12+
StatusType st = StatusType.Failed;
2413

25-
OnLogMessage( "FooExecute", $" - [[id]:[{startInfo.InstanceId}]] - ---------- {startInfo.ParentExitData} ---------- working ----------" );
14+
try
15+
{
16+
Dictionary<object, object> p = Synapse.Core.Utilities.YamlHelpers.Deserialize( startInfo.Parameters );
17+
st = (StatusType)Enum.Parse( typeof( StatusType ), p.Values.ElementAt( 0 ).ToString() );
18+
}
19+
catch { }
2620

27-
System.Threading.Thread.Sleep( 3000 );
28-
//Int64 j = 0;
29-
//for( Int64 i = 0; i < 2000000000; i++ )
30-
// j = i - 1;
21+
string x = $"{startInfo.ParentExitData}";
3122

32-
bool cancel = OnProgress( "FooExecute", getMsg( StatusType.Initializing, startInfo ), StatusType.Initializing, startInfo.InstanceId, seq++ );
33-
OnLogMessage( "FooExecute", $" - [[id]:[{startInfo.InstanceId}]] - ---------- loop complete ---------- working ----------" );
23+
OnLogMessage( "FooExecute", $" - [[id]:[{startInfo.InstanceId}]] - ---------- {startInfo.ParentExitData} ---------- working ----------" );
3424

35-
if( !cancel )
36-
{
37-
OnProgress( "FooExecute", getMsg( StatusType.Running, startInfo ), StatusType.Running, startInfo.InstanceId, seq++ );
38-
if( !startInfo.IsDryRun ) { OnProgress( "FooExecute", "...Progress...", StatusType.Running, startInfo.InstanceId, seq++ ); }
39-
//throw new Exception( "quitting" );
40-
OnProgress( "FooExecute", "Finished", st, startInfo.InstanceId, seq++ );
41-
OnLogMessage( "FooExecute", $"Finished - [[id]:[{startInfo.InstanceId}]] -" );
42-
}
43-
else
44-
{
45-
st = StatusType.Cancelled;
46-
OnProgress( "FooExecute", "Cancelled", st, startInfo.InstanceId, seq++ );
47-
OnLogMessage( "FooExecute", $"Cancelled - [[id]:[{startInfo.InstanceId}]] -" );
48-
}
25+
System.Threading.Thread.Sleep( 3000 );
26+
//Int64 j = 0;
27+
//for( Int64 i = 0; i < 2000000000; i++ )
28+
// j = i - 1;
4929

50-
WriteFile( "FooHandler", $"parms:{startInfo.Parameters}\r\nstatus:{st}\r\n-->CurrentPrincipal:{System.Security.Principal.WindowsIdentity.GetCurrent().Name}" );
51-
return new ExecuteResult() { Status = st, ExitData = "foo" };
52-
}
30+
bool cancel = OnProgress( "FooExecute", getMsg( StatusType.Initializing, startInfo ), StatusType.Initializing, startInfo.InstanceId, seq++ );
31+
OnLogMessage( "FooExecute", $" - [[id]:[{startInfo.InstanceId}]] - ---------- loop complete ---------- working ----------" );
5332

54-
protected string getMsg(StatusType status, HandlerStartInfo si)
33+
if( !cancel )
5534
{
56-
return $"{status}-->dryRun:{si.IsDryRun}, ReqNum:{si.RequestNumber}";
35+
OnProgress( "FooExecute", getMsg( StatusType.Running, startInfo ), StatusType.Running, startInfo.InstanceId, seq++ );
36+
if( !startInfo.IsDryRun ) { OnProgress( "FooExecute", "...Progress...", StatusType.Running, startInfo.InstanceId, seq++ ); }
37+
//throw new Exception( "quitting" );
38+
OnProgress( "FooExecute", "Finished", st, startInfo.InstanceId, seq++ );
39+
OnLogMessage( "FooExecute", $"Finished - [[id]:[{startInfo.InstanceId}]] -" );
5740
}
58-
59-
protected void WriteFile(string handler, string message)
41+
else
6042
{
61-
//string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split( '\\' )[1];
62-
//string fn = $"{ActionName}_{user}_{handler}_{DateTime.Now.Ticks}_{Guid.NewGuid()}";
63-
//System.IO.File.AppendAllText( fn, message ); ;
43+
st = StatusType.Cancelled;
44+
OnProgress( "FooExecute", "Cancelled", st, startInfo.InstanceId, seq++ );
45+
OnLogMessage( "FooExecute", $"Cancelled - [[id]:[{startInfo.InstanceId}]] -" );
6446
}
47+
48+
WriteFile( "FooHandler", $"parms:{startInfo.Parameters}\r\nstatus:{st}\r\n-->CurrentPrincipal:{System.Security.Principal.WindowsIdentity.GetCurrent().Name}" );
49+
return new ExecuteResult() { Status = st, ExitData = "foo" };
6550
}
6651

67-
public class BarHandler : FooHandler
52+
protected string getMsg(StatusType status, HandlerStartInfo si)
6853
{
69-
override public ExecuteResult Execute(HandlerStartInfo startInfo)
70-
{
71-
int seq = 1;
54+
return $"{status}-->dryRun:{si.IsDryRun}, ReqNum:{si.RequestNumber}";
55+
}
7256

73-
string x = $"{startInfo.ParentExitData}";
57+
protected void WriteFile(string handler, string message)
58+
{
59+
//string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split( '\\' )[1];
60+
//string fn = $"{ActionName}_{user}_{handler}_{DateTime.Now.Ticks}_{Guid.NewGuid()}";
61+
//System.IO.File.AppendAllText( fn, message ); ;
62+
}
63+
}
64+
65+
public class BarHandler : FooHandler
66+
{
67+
override public ExecuteResult Execute(HandlerStartInfo startInfo)
68+
{
69+
int seq = 1;
7470

75-
System.Threading.Thread.Sleep( 5000 );
76-
StatusType st = StatusType.Complete;
77-
bool cancel = OnProgress( "BarExecute", getMsg( StatusType.Initializing, startInfo ), StatusType.Initializing, startInfo.InstanceId, seq++ );
78-
OnLogMessage( "BarExecute", $" ---------- {startInfo.ParentExitData} ---------- working ----------" );
79-
if( !cancel )
80-
{
81-
OnProgress( "BarExecute", getMsg( StatusType.Running, startInfo ), StatusType.Running, startInfo.InstanceId, seq++ );
82-
if( !startInfo.IsDryRun ) { OnProgress( "BarExecute", "...Progress...", StatusType.Running, startInfo.InstanceId, seq++ ); }
83-
OnProgress( "BarExecute", "Finished", st, startInfo.InstanceId, seq++ );
84-
}
85-
else
86-
{
87-
st = StatusType.Cancelled;
88-
OnProgress( "BarExecute", "Cancelled", st, startInfo.InstanceId, seq++ );
89-
}
90-
WriteFile( "BarHandler", $"parms:{startInfo.Parameters}\r\nstatus:{st}\r\n-->CurrentPrincipal:{System.Security.Principal.WindowsIdentity.GetCurrent().Name}" );
91-
return new ExecuteResult() { Status = st, ExitData = "bar" };
71+
string x = $"{startInfo.ParentExitData}";
72+
73+
System.Threading.Thread.Sleep( 5000 );
74+
StatusType st = StatusType.Complete;
75+
bool cancel = OnProgress( "BarExecute", getMsg( StatusType.Initializing, startInfo ), StatusType.Initializing, startInfo.InstanceId, seq++ );
76+
OnLogMessage( "BarExecute", $" ---------- {startInfo.ParentExitData} ---------- working ----------" );
77+
if( !cancel )
78+
{
79+
OnProgress( "BarExecute", getMsg( StatusType.Running, startInfo ), StatusType.Running, startInfo.InstanceId, seq++ );
80+
if( !startInfo.IsDryRun ) { OnProgress( "BarExecute", "...Progress...", StatusType.Running, startInfo.InstanceId, seq++ ); }
81+
OnProgress( "BarExecute", "Finished", st, startInfo.InstanceId, seq++ );
82+
}
83+
else
84+
{
85+
st = StatusType.Cancelled;
86+
OnProgress( "BarExecute", "Cancelled", st, startInfo.InstanceId, seq++ );
9287
}
88+
WriteFile( "BarHandler", $"parms:{startInfo.Parameters}\r\nstatus:{st}\r\n-->CurrentPrincipal:{System.Security.Principal.WindowsIdentity.GetCurrent().Name}" );
89+
return new ExecuteResult() { Status = st, ExitData = "bar" };
9390
}
9491
}

0 commit comments

Comments
 (0)