44
55using 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 \n status:{ 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 \n status:{ 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 \n status:{ 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 \n status:{ st } \r \n -->CurrentPrincipal:{ System . Security . Principal . WindowsIdentity . GetCurrent ( ) . Name } " ) ;
89+ return new ExecuteResult ( ) { Status = st , ExitData = "bar" } ;
9390 }
9491}
0 commit comments