u s i n g   S y s t e m . D i a g n o s t i c s ; 
 
 u s i n g   S y s t e m . T e x t ; 
 
 u s i n g   S T A R T U P I N F O W   =   A p p B o t P i p e . S T A R T U P I N F O W ; 
 
 u s i n g   P R O C E S S _ I N F O R M A T I O N   =   A p p B o t P i p e . P R O C E S S _ I N F O R M A T I O N ; 
 
 
 
 n a m e s p a c e   W K A p p B o t . L a u n c h e r ; 
 
 
 
 p a r t i a l   c l a s s   P r o g r a m 
 
 { 
 
         / / /   < s u m m a r y > 
 
         / / /   M C P   s t d i o   p r o x y   l o o p . 
 
         / / /   L a u n c h e r   h o l d s   t h e   s t d i o   p i p e   t o   C l a u d e   C o d e   p e r m a n e n t l y . 
 
         / / /   C o r e   r u n s   b e h i n d   t h e   p r o x y      i f   i t   e x i t s   w i t h   c o d e   4 2 ,   i t   i s   r e s t a r t e d   a u t o m a t i c a l l y . 
 
         / / /   s t d i n   b r o a d c a s t e r   r o u t e s   b y t e s   t o   w h i c h e v e r   C o r e   i n s t a n c e   i s   c u r r e n t . 
 
         / / /   < / s u m m a r y > 
 
         s t a t i c   i n t   R u n M c p P r o x y ( s t r i n g [ ]   a r g s ) 
 
         { 
 
                 v a r   d i r     =   P a t h . G e t D i r e c t o r y N a m e ( E n v i r o n m e n t . P r o c e s s P a t h )   ? ?   " . " ; 
 
                 v a r   c o r e   =   R e s o l v e C o r e E x e ( ) ; 
 
 
 
                 i f   ( ! F i l e . E x i s t s ( c o r e ) ) 
 
                 { 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   w k a p p b o t - c o r e . e x e   n o t   f o u n d   a t :   { c o r e } " ) ; 
 
                         r e t u r n   1 ; 
 
                 } 
 
 
 
                 i n t   t i m e o u t S e c     =   0 ; 
 
                 i n t   t i m e o u t E x i t   =   2 ; 
 
                 b o o l   s h o w W t           =   a r g s . A n y ( a   = >   a   = =   " - - w t " ) ; 
 
                 f o r   ( i n t   i   =   0 ;   i   <   a r g s . L e n g t h   -   1 ;   i + + ) 
 
                 { 
 
                         i f   ( a r g s [ i ]   = =   " - - t i m e o u t "             & &   i n t . T r y P a r s e ( a r g s [ i   +   1 ] ,   o u t   v a r   t )   & &   t   >   0 )   t i m e o u t S e c     =   t ; 
 
                         i f   ( a r g s [ i ]   = =   " - - t i m e o u t - e x i t "   & &   i n t . T r y P a r s e ( a r g s [ i   +   1 ] ,   o u t   v a r   e ) )                       t i m e o u t E x i t   =   e ; 
 
                 } 
 
 
 
                 / /   - - w t :   r e d i r e c t   C o r e   s t d e r r   t o   a   t e m p   l o g   a n d   o p e n   a   W i n d o w s   T e r m i n a l   t a b   t a i l i n g   i t 
 
                 s t r i n g ?   w t L o g F i l e   =   n u l l ; 
 
                 i f   ( s h o w W t ) 
 
                 { 
 
                         w t L o g F i l e   =   P a t h . C o m b i n e ( P a t h . G e t T e m p P a t h ( ) ,   $ " w k a p p b o t - m c p - { E n v i r o n m e n t . P r o c e s s I d } . l o g " ) ; 
 
                         F i l e . W r i t e A l l T e x t ( w t L o g F i l e ,   " " ) ;   / /   c r e a t e   e m p t y   l o g 
 
                         v a r   w t T i t l e   =   $ " W K A p p B o t   M C P   ( { E n v i r o n m e n t . P r o c e s s I d } ) " ; 
 
                         v a r   p s C m d   =   $ " G e t - C o n t e n t   - W a i t   - P a t h   ' { w t L o g F i l e } ' " ; 
 
                         t r y 
 
                         { 
 
                                 / /   [ F O C U S - G U A R D ]   C a p t u r e   f o r e g r o u n d   b e f o r e   w t . e x e   l a u n c h ;   r e s t o r e   i f   s t o l e n . 
 
                                 v a r   f g B e f o r e W t   =   F o c u s G u a r d . G e t F o r e g r o u n d W i n d o w ( ) ; 
 
                                 P r o c e s s . S t a r t ( n e w   P r o c e s s S t a r t I n f o 
 
                                 { 
 
                                         F i l e N a m e                 =   " w t . e x e " , 
 
                                         A r g u m e n t s               =   $ " - - w i n d o w   0   n e w - t a b   - - t i t l e   \ " { w t T i t l e } \ "   - -   p o w e r s h e l l   - N o E x i t   - C o m m a n d   \ " { p s C m d } \ " " , 
 
                                         U s e S h e l l E x e c u t e   =   t r u e , 
 
                                 } ) ; 
 
                                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   W T   m o n i t o r   t a b   o p e n e d   !  { w t L o g F i l e } " ) ; 
 
                                 T h r e a d . S l e e p ( 6 0 0 ) ; 
 
                                 i f   ( f g B e f o r e W t   ! =   I n t P t r . Z e r o   & &   F o c u s G u a r d . G e t F o r e g r o u n d W i n d o w ( )   ! =   f g B e f o r e W t ) 
 
                                 { 
 
                                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ L A U N C H E R : M C P ]   w t . e x e   s t o l e   f o c u s      r e s t o r i n g " ) ; 
 
                                         F o c u s G u a r d . S e t F o r e g r o u n d W i n d o w ( f g B e f o r e W t ) ; 
 
                                 } 
 
                         } 
 
                         c a t c h   ( E x c e p t i o n   e x )   {   C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   w t . e x e   f a i l e d :   { e x . M e s s a g e } " ) ;   w t L o g F i l e   =   n u l l ;   } 
 
                 } 
 
 
 
                 v a r   d o t n e t R o o t   =   E n v i r o n m e n t . G e t E n v i r o n m e n t V a r i a b l e ( " D O T N E T _ R O O T " ) ; 
 
 
 
                 / /   M C P   m o d e :   p i p e - b a s e d   r e l a y   ( s a m e   p a t t e r n   a s   E y e !C o r e ) . 
 
                 / /   C o n P T Y   d o e s n ' t   p a s s   s t d i n   t o   g r a n d c h i l d ,   s o   w e   p i p e   e x p l i c i t l y : 
 
                 / /       C l a u d e   C o d e   !  C o n P T Y   !  L a u n c h e r   ( R e a d F i l e   s t d i n   !  W r i t e F i l e   p i p e )   !  C o r e 
 
                 / /       C o r e   !  p i p e   !  L a u n c h e r   ( R e a d F i l e   p i p e   !  W r i t e F i l e   s t d o u t )   !  C o n P T Y   !  C l a u d e   C o d e 
 
 
 
                 / /   C r e a t e   s t d i n   p i p e :   L a u n c h e r   w r i t e s   !  C o r e   r e a d s 
 
                 i f   ( ! C r e a t e P i p e ( o u t   v a r   h C o r e S t d i n R e a d ,   o u t   v a r   h C o r e S t d i n W r i t e ,   I n t P t r . Z e r o ,   0 ) ) 
 
                 {   C o n s o l e . E r r o r . W r i t e L i n e ( " [ L A U N C H E R : M C P ]   C r e a t e P i p e ( s t d i n )   f a i l e d " ) ;   r e t u r n   1 ;   } 
 
                 S e t H a n d l e I n f o r m a t i o n ( h C o r e S t d i n R e a d ,   H A N D L E _ F L A G _ I N H E R I T ,   H A N D L E _ F L A G _ I N H E R I T ) ; 
 
 
 
                 / /   C r e a t e   s t d o u t   p i p e :   C o r e   w r i t e s   !  L a u n c h e r   r e a d s 
 
                 i f   ( ! C r e a t e P i p e ( o u t   v a r   h C o r e S t d o u t R e a d ,   o u t   v a r   h C o r e S t d o u t W r i t e ,   I n t P t r . Z e r o ,   0 ) ) 
 
                 {   C l o s e H a n d l e ( h C o r e S t d i n R e a d ) ;   C l o s e H a n d l e ( h C o r e S t d i n W r i t e ) ;   C o n s o l e . E r r o r . W r i t e L i n e ( " [ L A U N C H E R : M C P ]   C r e a t e P i p e ( s t d o u t )   f a i l e d " ) ;   r e t u r n   1 ;   } 
 
                 S e t H a n d l e I n f o r m a t i o n ( h C o r e S t d o u t W r i t e ,   H A N D L E _ F L A G _ I N H E R I T ,   H A N D L E _ F L A G _ I N H E R I T ) ; 
 
 
 
                 v a r   c m d S b   =   n e w   S t r i n g B u i l d e r ( $ " \ " { c o r e . R e p l a c e ( " \ " " ,   " \ \ \ " " ) } \ " " ) ; 
 
                 f o r e a c h   ( v a r   a   i n   a r g s )   c m d S b . A p p e n d ( "   \ " " ) . A p p e n d ( a . R e p l a c e ( " \ " " ,   " \ \ \ " " ) ) . A p p e n d ( ' " ' ) ; 
 
                 v a r   c m d A r r   =   ( c m d S b . T o S t r i n g ( )   +   " \ 0 " ) . T o C h a r A r r a y ( ) ; 
 
                 v a r   s i   =   n e w   S T A R T U P I N F O W 
 
                 { 
 
                         c b   =   S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . M a r s h a l . S i z e O f < S T A R T U P I N F O W > ( ) , 
 
                         d w F l a g s   =   S T A R T F _ U S E S T D H A N D L E S , 
 
                         h S t d I n p u t     =   h C o r e S t d i n R e a d ,       / /   C o r e   r e a d s   f r o m   t h i s   p i p e 
 
                         h S t d O u t p u t   =   h C o r e S t d o u t W r i t e ,     / /   C o r e   w r i t e s   t o   t h i s   p i p e 
 
                         h S t d E r r o r     =   G e t S t d H a n d l e ( - 1 2 ) ,   / /   s t d e r r   i n h e r i t e d   d i r e c t l y 
 
                 } ; 
 
                 i f   ( ! C r e a t e P r o c e s s W ( n u l l ,   c m d A r r ,   I n t P t r . Z e r o ,   I n t P t r . Z e r o ,   t r u e , 
 
                         C R E A T E _ U N I C O D E _ E N V I R O N M E N T ,   I n t P t r . Z e r o ,   E n v i r o n m e n t . C u r r e n t D i r e c t o r y ,   r e f   s i ,   o u t   v a r   p i ) ) 
 
                 { 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   C r e a t e P r o c e s s   f a i l e d   ( e r r = { S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . M a r s h a l . G e t L a s t W i n 3 2 E r r o r ( ) } ) " ) ; 
 
                         C l o s e H a n d l e ( h C o r e S t d i n R e a d ) ;   C l o s e H a n d l e ( h C o r e S t d i n W r i t e ) ; 
 
                         C l o s e H a n d l e ( h C o r e S t d o u t R e a d ) ;   C l o s e H a n d l e ( h C o r e S t d o u t W r i t e ) ; 
 
                         r e t u r n   1 ; 
 
                 } 
 
                 / /   C l o s e   c h i l d - s i d e   h a n d l e s   i n   p a r e n t 
 
                 C l o s e H a n d l e ( h C o r e S t d i n R e a d ) ; 
 
                 C l o s e H a n d l e ( h C o r e S t d o u t W r i t e ) ; 
 
                 C l o s e H a n d l e ( p i . h T h r e a d ) ; 
 
                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   c o r e   s t a r t e d   v i a   p i p e   ( p i d = { p i . d w P r o c e s s I d } ) " ) ; 
 
 
 
                 / /    % %  S t a t e   m a c h i n e   f o r   M C P   r e l a y    % %
 
                 / /   T r a c k s   J S O N - R P C   r e q u e s t s   b y   i d   f o r   r o u t i n g   d u r i n g   e l e v a t i o n   h a n d o f f   A N D   h o t - s w a p 
 
                 v a r   _ i n f l i g h t   =   n e w   D i c t i o n a r y < s t r i n g ,   s t r i n g > ( ) ;   / /   i d   !  r a w   r e q u e s t   l i n e 
 
                 v a r   _ g a t e   =   n e w   o b j e c t ( ) ; 
 
                 v a r   _ o u t L o c k   =   n e w   o b j e c t ( ) ; 
 
                 s t r i n g ?   _ i n i t i a l i z e L i n e   =   n u l l ;   / /   c a c h e d   f o r   a d m i n / n e w   C o r e   s y n t h e t i c   i n i t 
 
                 s t r i n g ?   _ t o o l s L i s t L i n e   =   n u l l ;     / /   c a c h e d   t o o l s / l i s t   f o r   n e w   C o r e   r e p l a y 
 
                 I n t P t r   _ a c t i v e S t d i n W r i t e   =   h C o r e S t d i n W r i t e ;   / /   c u r r e n t   t a r g e t   f o r   n e w   r e q u e s t s 
 
                 S y s t e m . I O . T e x t W r i t e r ?   _ a c t i v e S t d i n W r i t e r   =   n u l l ;   / /   c u r r e n t   l i n e   w r i t e r   a f t e r   a d m i n   h a n d o f f 
 
                 I n t P t r   _ a d m i n S t d i n W r i t e   =   I n t P t r . Z e r o ; 
 
                 I n t P t r   _ a d m i n S t d o u t R e a d   =   I n t P t r . Z e r o ; 
 
                 I n t P t r   _ a d m i n P r o c   =   I n t P t r . Z e r o ; 
 
                 s t r i n g ?   _ e l e v a t i o n R e q u e s t L i n e   =   n u l l ;   / /   s a v e d   f o r   r e - s e n d   t o   a d m i n   C o r e 
 
                 b o o l   _ a d m i n M o d e   =   f a l s e ; 
 
 
 
                 / /   s t d o u t   h a n d l e   ( n e e d e d   e a r l y   f o r   h o t - s w a p   F S W   c l o s u r e ) 
 
                 v a r   h O u t   =   G e t S t d H a n d l e ( - 1 1 ) ; 
 
 
 
                 / /    % %  H o t - s w a p :   F S W   w a t c h e s   f o r   . n e w . e x e    % %
 
                 I n t P t r   _ o l d C o r e S t d i n W r i t e   =   I n t P t r . Z e r o ;   / /   d r a i n   p i p e   f o r   o l d   C o r e   d u r i n g   s w a p 
 
                 I n t P t r   _ o l d C o r e S t d o u t R e a d   =   I n t P t r . Z e r o ; 
 
                 v a r   _ o l d I n f l i g h t   =   n e w   D i c t i o n a r y < s t r i n g ,   s t r i n g > ( ) ;   / /   r e q u e s t s   s t i l l   i n   o l d   C o r e 
 
                 b o o l   _ s w a p I n P r o g r e s s   =   f a l s e ; 
 
                 b o o l   _ p e n d i n g S w a p W h i l e A d m i n   =   f a l s e ; 
 
                 v a r   _ s w a p D r a i n E v e n t   =   n e w   M a n u a l R e s e t E v e n t S l i m ( f a l s e ) ;   / /   s i g n a l e d   w h e n   o l d   C o r e   d r a i n   c o m p l e t e s 
 
 
 
                 v a r   e x e P a t h   =   c o r e ;   / /   p a t h   t o   w k a p p b o t - c o r e . e x e 
 
                 v a r   e x e D i r   =   S y s t e m . I O . P a t h . G e t D i r e c t o r y N a m e ( e x e P a t h )   ? ?   " . " ; 
 
                 v a r   e x e N a m e   =   S y s t e m . I O . P a t h . G e t F i l e N a m e ( e x e P a t h ) ; 
 
                 v a r   n e w E x e P a t h   =   S y s t e m . I O . P a t h . C o m b i n e ( e x e D i r ,   S y s t e m . I O . P a t h . G e t F i l e N a m e W i t h o u t E x t e n s i o n ( e x e N a m e )   +   " . n e w . e x e " ) ; 
 
 
 
                 / /   F S W   f o r   . n e w . e x e   d e t e c t i o n   ( 5 0 0 m s   d e b o u n c e ,   s a m e   a s   E y e ) 
 
                 S y s t e m . T h r e a d i n g . T i m e r ?   _ f s w D e b o u n c e   =   n u l l ; 
 
                 v a r   f s w   =   n e w   F i l e S y s t e m W a t c h e r ( e x e D i r ) 
 
                 { 
 
                         N o t i f y F i l t e r   =   N o t i f y F i l t e r s . F i l e N a m e   |   N o t i f y F i l t e r s . C r e a t i o n T i m e   |   N o t i f y F i l t e r s . L a s t W r i t e , 
 
                         F i l t e r   =   " * c o r e * . e x e " , 
 
                         E n a b l e R a i s i n g E v e n t s   =   t r u e 
 
                 } ; 
 
                 / /   T r i g g e r   o n :   c o r e   e x e   r e p l a c e d   a t   o r i g i n a l   p a t h   ( E y e   r e n a m e - s w a p   o r   e x t e r n a l   o v e r w r i t e ) 
 
                 f s w . C r e a t e d   + =   O n F s w E v e n t ; 
 
                 f s w . C h a n g e d   + =   O n F s w E v e n t ; 
 
                 v o i d   O n F s w E v e n t ( o b j e c t ?   _ ,   F i l e S y s t e m E v e n t A r g s   e ) 
 
                 { 
 
                         v a r   f n   =   e . N a m e   ? ?   " " ; 
 
                         / /   D e t e c t :   c o r e   e x e   w a s   r e p l a c e d   a t   o r i g i n a l   p a t h   ( E y e   d i d   r e n a m e - s w a p ,   o r   e x t e r n a l   t o o l   r e p l a c e d   i t ) 
 
                         b o o l   i s C o r e R e p l a c e d   =   s t r i n g . E q u a l s ( S y s t e m . I O . P a t h . G e t F u l l P a t h ( e . F u l l P a t h ) ,   S y s t e m . I O . P a t h . G e t F u l l P a t h ( c o r e ) ,   S t r i n g C o m p a r i s o n . O r d i n a l I g n o r e C a s e ) ; 
 
                         i f   ( ! i s C o r e R e p l a c e d )   r e t u r n ; 
 
                         / /   D e b o u n c e :   5 0 0 m s   a f t e r   l a s t   e v e n t 
 
                         _ f s w D e b o u n c e ? . D i s p o s e ( ) ; 
 
                         _ f s w D e b o u n c e   =   n e w   S y s t e m . T h r e a d i n g . T i m e r ( _   = > 
 
                         { 
 
                                 l o c k   ( _ g a t e ) 
 
                                 { 
 
                                         i f   ( _ a d m i n M o d e   | |   _ a c t i v e S t d i n W r i t e r   ! =   n u l l ) 
 
                                         { 
 
                                                 _ p e n d i n g S w a p W h i l e A d m i n   =   t r u e ; 
 
                                                 C o n s o l e . E r r o r . W r i t e L i n e ( " [ H O T - S W A P ]   a d m i n   e n d p o i n t   a c t i v e      d e f e r r i n g   n o r m a l   c o r e   s w a p " ) ; 
 
                                                 r e t u r n ; 
 
                                         } 
 
                                 } 
 
                                 i f   ( _ s w a p I n P r o g r e s s )   {   C o n s o l e . E r r o r . W r i t e L i n e ( " [ H O T - S W A P ]   A l r e a d y   i n   p r o g r e s s      i g n o r i n g " ) ;   r e t u r n ;   } 
 
                                 _ s w a p I n P r o g r e s s   =   t r u e ; 
 
                                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ H O T - S W A P ]   c o r e   e x e   c h a n g e d      s t a r t i n g   g r a c e f u l   s w a p " ) ; 
 
 
 
                                 t r y 
 
                                 { 
 
                                         / /   E x t e r n a l   t o o l   ( E y e   o r   p u b l i s h )   a l r e a d y   d i d   t h e   r e n a m e - s w a p . 
 
                                         / /   W e   j u s t   n e e d   t o   d r a i n   o l d   C o r e   a n d   s p a w n   n e w   o n e   f r o m   t h e   u p d a t e d   p a t h . 
 
 
 
                                         / /   2 .   M o v e   c u r r e n t   C o r e   t o   o l d   p i p e   ( d r a i n   m o d e ) 
 
                                         l o c k   ( _ g a t e ) 
 
                                         { 
 
                                                 _ o l d C o r e S t d i n W r i t e   =   _ a c t i v e S t d i n W r i t e ; 
 
                                                 _ a c t i v e S t d i n W r i t e   =   I n t P t r . Z e r o ; 
 
                                                 _ a c t i v e S t d i n W r i t e r   =   n u l l ; 
 
                                                 / /   M o v e   i n f l i g h t   t o   o l d 
 
                                                 f o r e a c h   ( v a r   k v   i n   _ i n f l i g h t ) 
 
                                                         _ o l d I n f l i g h t [ k v . K e y ]   =   k v . V a l u e ; 
 
                                                 _ i n f l i g h t . C l e a r ( ) ; 
 
                                         } 
 
                                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ H O T - S W A P ]   o l d   C o r e   d r a i n i n g   ( { _ o l d I n f l i g h t . C o u n t }   i n f l i g h t ) " ) ; 
 
 
 
                                         / /   3 .   S p a w n   n e w   C o r e   w i t h   f r e s h   p i p e s 
 
                                         i f   ( ! C r e a t e P i p e ( o u t   v a r   h N e w S t d i n R e a d ,   o u t   v a r   h N e w S t d i n W r i t e ,   I n t P t r . Z e r o ,   0 ) ) 
 
                                         {   C o n s o l e . E r r o r . W r i t e L i n e ( " [ H O T - S W A P ]   C r e a t e P i p e ( s t d i n )   f a i l e d " ) ;   _ s w a p I n P r o g r e s s   =   f a l s e ;   r e t u r n ;   } 
 
                                         S e t H a n d l e I n f o r m a t i o n ( h N e w S t d i n R e a d ,   H A N D L E _ F L A G _ I N H E R I T ,   H A N D L E _ F L A G _ I N H E R I T ) ; 
 
 
 
                                         i f   ( ! C r e a t e P i p e ( o u t   v a r   h N e w S t d o u t R e a d ,   o u t   v a r   h N e w S t d o u t W r i t e ,   I n t P t r . Z e r o ,   0 ) ) 
 
                                         {   C l o s e H a n d l e ( h N e w S t d i n R e a d ) ;   C l o s e H a n d l e ( h N e w S t d i n W r i t e ) ;   C o n s o l e . E r r o r . W r i t e L i n e ( " [ H O T - S W A P ]   C r e a t e P i p e ( s t d o u t )   f a i l e d " ) ;   _ s w a p I n P r o g r e s s   =   f a l s e ;   r e t u r n ;   } 
 
                                         S e t H a n d l e I n f o r m a t i o n ( h N e w S t d o u t W r i t e ,   H A N D L E _ F L A G _ I N H E R I T ,   H A N D L E _ F L A G _ I N H E R I T ) ; 
 
 
 
                                         v a r   n e w S i   =   n e w   S T A R T U P I N F O W 
 
                                         { 
 
                                                 c b   =   S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . M a r s h a l . S i z e O f < S T A R T U P I N F O W > ( ) , 
 
                                                 d w F l a g s   =   S T A R T F _ U S E S T D H A N D L E S , 
 
                                                 h S t d I n p u t   =   h N e w S t d i n R e a d , 
 
                                                 h S t d O u t p u t   =   h N e w S t d o u t W r i t e , 
 
                                                 h S t d E r r o r   =   G e t S t d H a n d l e ( - 1 2 ) , 
 
                                         } ; 
 
                                         v a r   n e w C m d S b   =   n e w   S t r i n g B u i l d e r ( $ " \ " { c o r e . R e p l a c e ( " \ " " ,   " \ \ \ " " ) } \ " " ) ; 
 
                                         f o r e a c h   ( v a r   a   i n   a r g s )   n e w C m d S b . A p p e n d ( "   \ " " ) . A p p e n d ( a . R e p l a c e ( " \ " " ,   " \ \ \ " " ) ) . A p p e n d ( ' " ' ) ; 
 
                                         v a r   n e w C m d A r r   =   ( n e w C m d S b . T o S t r i n g ( )   +   " \ 0 " ) . T o C h a r A r r a y ( ) ; 
 
 
 
                                         i f   ( ! C r e a t e P r o c e s s W ( n u l l ,   n e w C m d A r r ,   I n t P t r . Z e r o ,   I n t P t r . Z e r o ,   t r u e , 
 
                                                 C R E A T E _ U N I C O D E _ E N V I R O N M E N T ,   I n t P t r . Z e r o ,   E n v i r o n m e n t . C u r r e n t D i r e c t o r y ,   r e f   n e w S i ,   o u t   v a r   n e w P i ) ) 
 
                                         { 
 
                                                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ H O T - S W A P ]   C r e a t e P r o c e s s   f a i l e d      r e s t o r i n g   o l d   C o r e " ) ; 
 
                                                 l o c k   ( _ g a t e )   {   _ a c t i v e S t d i n W r i t e   =   _ o l d C o r e S t d i n W r i t e ;   _ o l d C o r e S t d i n W r i t e   =   I n t P t r . Z e r o ;   f o r e a c h   ( v a r   k v   i n   _ o l d I n f l i g h t )   _ i n f l i g h t [ k v . K e y ]   =   k v . V a l u e ;   _ o l d I n f l i g h t . C l e a r ( ) ;   } 
 
                                                 _ s w a p I n P r o g r e s s   =   f a l s e ;   r e t u r n ; 
 
                                         } 
 
                                         C l o s e H a n d l e ( h N e w S t d i n R e a d ) ; 
 
                                         C l o s e H a n d l e ( h N e w S t d o u t W r i t e ) ; 
 
                                         C l o s e H a n d l e ( n e w P i . h T h r e a d ) ; 
 
                                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ H O T - S W A P ]   n e w   C o r e   s t a r t e d   ( p i d = { n e w P i . d w P r o c e s s I d } ) " ) ; 
 
 
 
                                         / /   4 .   R e p l a y   i n i t i a l i z e   +   t o o l s / l i s t   t o   n e w   C o r e 
 
                                         l o c k   ( _ g a t e ) 
 
                                         { 
 
                                                 _ a c t i v e S t d i n W r i t e   =   h N e w S t d i n W r i t e ; 
 
                                                 i f   ( _ i n i t i a l i z e L i n e   ! =   n u l l ) 
 
                                                 { 
 
                                                         v a r   i n i t B y t e s   =   S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t B y t e s ( _ i n i t i a l i z e L i n e   +   " \ n " ) ; 
 
                                                         W r i t e F i l e ( h N e w S t d i n W r i t e ,   i n i t B y t e s ,   ( u i n t ) i n i t B y t e s . L e n g t h ,   o u t   u i n t   _ i g n 1 ,   I n t P t r . Z e r o ) ; 
 
                                                         F l u s h F i l e B u f f e r s ( h N e w S t d i n W r i t e ) ; 
 
                                                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ H O T - S W A P ]   r e p l a y e d   i n i t i a l i z e " ) ; 
 
                                                 } 
 
                                                 i f   ( _ t o o l s L i s t L i n e   ! =   n u l l ) 
 
                                                 { 
 
                                                         v a r   t l B y t e s   =   S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t B y t e s ( _ t o o l s L i s t L i n e   +   " \ n " ) ; 
 
                                                         W r i t e F i l e ( h N e w S t d i n W r i t e ,   t l B y t e s ,   ( u i n t ) t l B y t e s . L e n g t h ,   o u t   u i n t   _ i g n 2 ,   I n t P t r . Z e r o ) ; 
 
                                                         F l u s h F i l e B u f f e r s ( h N e w S t d i n W r i t e ) ; 
 
                                                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ H O T - S W A P ]   r e p l a y e d   t o o l s / l i s t " ) ; 
 
                                                 } 
 
                                         } 
 
 
 
                                         / /   5 .   S t a r t   n e w   C o r e   s t d o u t   r e l a y   t h r e a d 
 
                                         n e w   T h r e a d ( ( )   = >   R e l a y S t d o u t ( h N e w S t d o u t R e a d ,   " n e w - c o r e " ,   d e t e c t E l e v a t i o n :   t r u e ) ) 
 
                                         {   I s B a c k g r o u n d   =   t r u e ,   N a m e   =   " m c p - n e w c o r e - s t d o u t "   } . S t a r t ( ) ; 
 
 
 
                                         / /   6 .   W a i t   f o r   o l d   C o r e   d r a i n   ( 6 0 s   t i m e o u t ) 
 
                                         v a r   d r a i n S w   =   S y s t e m . D i a g n o s t i c s . S t o p w a t c h . S t a r t N e w ( ) ; 
 
                                         w h i l e   ( d r a i n S w . E l a p s e d . T o t a l S e c o n d s   <   6 0 ) 
 
                                         { 
 
                                                 l o c k   ( _ g a t e )   {   i f   ( _ o l d I n f l i g h t . C o u n t   = =   0 )   b r e a k ;   } 
 
                                                 T h r e a d . S l e e p ( 5 0 0 ) ; 
 
                                         } 
 
 
 
                                         l o c k   ( _ g a t e ) 
 
                                         { 
 
                                                 i f   ( _ o l d I n f l i g h t . C o u n t   >   0 ) 
 
                                                 { 
 
                                                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ H O T - S W A P ]   d r a i n   t i m e o u t      { _ o l d I n f l i g h t . C o u n t }   r e q u e s t s   o r p h a n e d ,   r e - r o u t i n g   t o   n e w   C o r e " ) ; 
 
                                                         f o r e a c h   ( v a r   k v   i n   _ o l d I n f l i g h t ) 
 
                                                         { 
 
                                                                 v a r   r e B y t e s   =   S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t B y t e s ( k v . V a l u e   +   " \ n " ) ; 
 
                                                                 W r i t e F i l e ( _ a c t i v e S t d i n W r i t e ,   r e B y t e s ,   ( u i n t ) r e B y t e s . L e n g t h ,   o u t   u i n t   _ i g n 3 ,   I n t P t r . Z e r o ) ; 
 
                                                                 _ i n f l i g h t [ k v . K e y ]   =   k v . V a l u e ; 
 
                                                         } 
 
                                                         F l u s h F i l e B u f f e r s ( _ a c t i v e S t d i n W r i t e ) ; 
 
                                                 } 
 
                                                 _ o l d I n f l i g h t . C l e a r ( ) ; 
 
                                         } 
 
 
 
                                         / /   7 .   C l o s e   o l d   C o r e   s t d i n   !  g r a c e f u l   e x i t 
 
                                         i f   ( _ o l d C o r e S t d i n W r i t e   ! =   I n t P t r . Z e r o ) 
 
                                         {   C l o s e H a n d l e ( _ o l d C o r e S t d i n W r i t e ) ;   _ o l d C o r e S t d i n W r i t e   =   I n t P t r . Z e r o ;   } 
 
                                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ H O T - S W A P ]   o l d   C o r e   s t d i n   c l o s e d      g r a c e f u l   e x i t " ) ; 
 
 
 
                                         _ s w a p I n P r o g r e s s   =   f a l s e ; 
 
                                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ H O T - S W A P ]   s w a p   c o m p l e t e ! " ) ; 
 
                                 } 
 
                                 c a t c h   ( E x c e p t i o n   e x ) 
 
                                 { 
 
                                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ H O T - S W A P ]   e r r o r :   { e x . M e s s a g e } " ) ; 
 
                                         _ s w a p I n P r o g r e s s   =   f a l s e ; 
 
                                 } 
 
                         } ,   n u l l ,   5 0 0 ,   T i m e o u t . I n f i n i t e ) ; 
 
                 } ; 
 
 
 
                 / /   S t d i n   r o u t e r :   l i n e - b u f f e r e d ,   t r a c k s   J S O N - R P C   i d ,   r o u t e s   t o   a c t i v e   C o r e 
 
                 v a r   s t d i n R e l a y   =   n e w   T h r e a d ( ( )   = > 
 
                 { 
 
                         v a r   h I n   =   G e t S t d H a n d l e ( - 1 0 ) ; 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   s t d i n   r e l a y   s t a r t e d   ( h I n = 0 x { h I n : X } ) " ) ; 
 
                         v a r   b u f   =   n e w   b y t e [ 4 0 9 6 ] ; 
 
                         v a r   l i n e B u f   =   n e w   S y s t e m . T e x t . S t r i n g B u i l d e r ( ) ; 
 
 
 
                         w h i l e   ( R e a d F i l e ( h I n ,   b u f ,   ( u i n t ) b u f . L e n g t h ,   o u t   u i n t   n ,   I n t P t r . Z e r o )   & &   n   >   0 ) 
 
                         { 
 
                                 l i n e B u f . A p p e n d ( S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t S t r i n g ( b u f ,   0 ,   ( i n t ) n ) ) ; 
 
                                 v a r   a c c   =   l i n e B u f . T o S t r i n g ( ) ; 
 
                                 i n t   n l I d x ; 
 
                                 w h i l e   ( ( n l I d x   =   a c c . I n d e x O f ( ' \ n ' ) )   > =   0 ) 
 
                                 { 
 
                                         v a r   l i n e   =   a c c [ . . n l I d x ] . T r i m E n d ( ' \ r ' ) ; 
 
                                         a c c   =   a c c [ ( n l I d x   +   1 ) . . ] ; 
 
 
 
                                         i f   ( s t r i n g . I s N u l l O r W h i t e S p a c e ( l i n e ) )   c o n t i n u e ; 
 
 
 
                                         / /   E x t r a c t   J S O N - R P C   i d 
 
                                         v a r   i d   =   E x t r a c t J s o n R p c I d ( l i n e ) ; 
 
 
 
                                         l o c k   ( _ g a t e ) 
 
                                         { 
 
                                                 / /   C a c h e   i n i t i a l i z e   +   t o o l s / l i s t   f o r   h o t - s w a p / a d m i n   C o r e   r e p l a y 
 
                                                 i f   ( l i n e . C o n t a i n s ( " \ " m e t h o d \ " : \ " i n i t i a l i z e \ " " ) ) 
 
                                                         _ i n i t i a l i z e L i n e   =   l i n e ; 
 
                                                 e l s e   i f   ( l i n e . C o n t a i n s ( " \ " m e t h o d \ " : \ " t o o l s / l i s t \ " " ) ) 
 
                                                         _ t o o l s L i s t L i n e   =   l i n e ; 
 
 
 
                                                 / /   T r a c k   i n - f l i g h t   r e q u e s t s 
 
                                                 i f   ( i d   ! =   n u l l ) 
 
                                                         _ i n f l i g h t [ i d ]   =   l i n e ; 
 
 
 
                                                 / /   R o u t e   t o   a c t i v e   C o r e 
 
                                                 i f   ( _ a c t i v e S t d i n W r i t e r   ! =   n u l l ) 
 
                                                 { 
 
                                                         _ a c t i v e S t d i n W r i t e r . W r i t e L i n e ( l i n e ) ; 
 
                                                         _ a c t i v e S t d i n W r i t e r . F l u s h ( ) ; 
 
                                                 } 
 
                                                 e l s e 
 
                                                 { 
 
                                                         v a r   t a r g e t   =   _ a c t i v e S t d i n W r i t e ; 
 
                                                         i f   ( t a r g e t   ! =   I n t P t r . Z e r o ) 
 
                                                         { 
 
                                                                 v a r   l i n e B y t e s   =   S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t B y t e s ( l i n e   +   " \ n " ) ; 
 
                                                                 W r i t e F i l e ( t a r g e t ,   l i n e B y t e s ,   ( u i n t ) l i n e B y t e s . L e n g t h ,   o u t   _ ,   I n t P t r . Z e r o ) ; 
 
                                                                 F l u s h F i l e B u f f e r s ( t a r g e t ) ; 
 
                                                                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   s t d i n !c o r e :   { l i n e [ . . S y s t e m . M a t h . M i n ( 6 0 ,   l i n e . L e n g t h ) ] } " ) ; 
 
                                                         } 
 
                                                         e l s e 
 
                                                                 C o n s o l e . E r r o r . W r i t e L i n e ( " [ L A U N C H E R : M C P ]   s t d i n   r e l a y :   t a r g e t   h a n d l e   i s   Z E R O ! " ) ; 
 
                                                 } 
 
                                         } 
 
                                 } 
 
                                 l i n e B u f . C l e a r ( ) ; 
 
                                 i f   ( a c c . L e n g t h   >   0 )   l i n e B u f . A p p e n d ( a c c ) ; 
 
                         } 
 
 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   s t d i n   r e l a y :   R e a d F i l e   l o o p   e n d e d   ( E O F   o r   e r r o r ) " ) ; 
 
                         / /   C o n P T Y   s t d i n   E O F   !  c l o s e   a l l   C o r e   s t d i n s 
 
                         l o c k   ( _ g a t e ) 
 
                         { 
 
                                 i f   ( _ a c t i v e S t d i n W r i t e   ! =   I n t P t r . Z e r o )   {   C l o s e H a n d l e ( _ a c t i v e S t d i n W r i t e ) ;   _ a c t i v e S t d i n W r i t e   =   I n t P t r . Z e r o ;   } 
 
                                 i f   ( _ a c t i v e S t d i n W r i t e r   i s   I D i s p o s a b l e   d )   {   t r y   {   d . D i s p o s e ( ) ;   }   c a t c h   {   }   _ a c t i v e S t d i n W r i t e r   =   n u l l ;   } 
 
                                 i f   ( _ a d m i n S t d i n W r i t e   ! =   I n t P t r . Z e r o )   {   C l o s e H a n d l e ( _ a d m i n S t d i n W r i t e ) ;   _ a d m i n S t d i n W r i t e   =   I n t P t r . Z e r o ;   } 
 
                         } 
 
                 } )   {   I s B a c k g r o u n d   =   t r u e ,   N a m e   =   " m c p - s t d i n - r o u t e r "   } ; 
 
                 s t d i n R e l a y . S t a r t ( ) ; 
 
 
 
                 / /    % %  N o r m a l   C o r e   s t d o u t   r e l a y   ( m a i n   t h r e a d )    % %
 
 
 
                 / /   S h a r e d   h e l p e r :   r e l a y   o n e   C o r e ' s   s t d o u t   t o   h O u t ,   w i t h   e l e v a t i o n   d e t e c t i o n 
 
                 v o i d   R e l a y S t d o u t ( I n t P t r   h R e a d ,   s t r i n g   l a b e l ,   b o o l   d e t e c t E l e v a t i o n ) 
 
                 { 
 
                         v a r   o u t B u f   =   n e w   b y t e [ 4 0 9 6 ] ; 
 
                         v a r   o u t L i n e B u f   =   n e w   S y s t e m . T e x t . S t r i n g B u i l d e r ( ) ; 
 
                         w h i l e   ( R e a d F i l e ( h R e a d ,   o u t B u f ,   ( u i n t ) o u t B u f . L e n g t h ,   o u t   u i n t   o u t N ,   I n t P t r . Z e r o )   & &   o u t N   >   0 ) 
 
                         { 
 
                                 o u t L i n e B u f . A p p e n d ( S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t S t r i n g ( o u t B u f ,   0 ,   ( i n t ) o u t N ) ) ; 
 
                                 v a r   a c c   =   o u t L i n e B u f . T o S t r i n g ( ) ; 
 
                                 i n t   n l I d x ; 
 
                                 w h i l e   ( ( n l I d x   =   a c c . I n d e x O f ( ' \ n ' ) )   > =   0 ) 
 
                                 { 
 
                                         v a r   l i n e   =   a c c [ . . n l I d x ] . T r i m E n d ( ' \ r ' ) ; 
 
                                         a c c   =   a c c [ ( n l I d x   +   1 ) . . ] ; 
 
 
 
                                         / /   E l e v a t i o n   i n t e r c e p t 
 
                                         i f   ( d e t e c t E l e v a t i o n   & &   l i n e . C o n t a i n s ( " \ " _ e l e v a t i o n R e q u i r e d \ " : t r u e " ) ) 
 
                                         { 
 
                                                 v a r   f a i l e d I d   =   E x t r a c t J s o n R p c I d ( l i n e ) ; 
 
                                                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   E l e v a t i o n   r e q u i r e d   ( i d = { f a i l e d I d } )      s p a w n i n g   a d m i n   C o r e " ) ; 
 
 
 
                                                 / /   S a v e   t h e   o r i g i n a l   r e q u e s t   f o r   r e - s e n d 
 
                                                 s t r i n g ?   s a v e d R e q u e s t   =   n u l l ; 
 
                                                 l o c k   ( _ g a t e ) 
 
                                                 { 
 
                                                         i f   ( f a i l e d I d   ! =   n u l l   & &   _ i n f l i g h t . T r y G e t V a l u e ( f a i l e d I d ,   o u t   v a r   r e q ) ) 
 
                                                                 s a v e d R e q u e s t   =   r e q ; 
 
                                                 } 
 
                                                 _ e l e v a t i o n R e q u e s t L i n e   =   s a v e d R e q u e s t ; 
 
 
 
                                                 / /   S p a w n   a d m i n   C o r e   o n   b a c k g r o u n d   t h r e a d   ( r u n a s   b l o c k s   o n   U A C ) 
 
                                                 n e w   T h r e a d ( ( )   = >   S p a w n A d m i n C o r e ( c o r e ,   a r g s ,   _ i n i t i a l i z e L i n e ,   _ e l e v a t i o n R e q u e s t L i n e , 
 
                                                         r e f   _ a d m i n S t d i n W r i t e ,   r e f   _ a d m i n S t d o u t R e a d ,   r e f   _ a d m i n P r o c ,   r e f   _ a c t i v e S t d i n W r i t e , 
 
                                                         r e f   _ a c t i v e S t d i n W r i t e r ,   r e f   _ a d m i n M o d e ,   r e f   _ p e n d i n g S w a p W h i l e A d m i n ,   h C o r e S t d i n W r i t e ,   h O u t ,   _ g a t e ,   _ o u t L o c k ,   _ i n f l i g h t ) ) 
 
                                                 {   I s B a c k g r o u n d   =   t r u e ,   N a m e   =   " m c p - a d m i n - s p a w n "   } . S t a r t ( ) ; 
 
 
 
                                                 c o n t i n u e ;   / /   s u p p r e s s   e l e v a t i o n   e r r o r   f r o m   r e a c h i n g   c l i e n t 
 
                                         } 
 
 
 
                                         / /   R e m o v e   f r o m   i n f l i g h t   ( b o t h   c u r r e n t   a n d   o l d - d r a i n ) 
 
                                         v a r   i d   =   E x t r a c t J s o n R p c I d ( l i n e ) ; 
 
                                         i f   ( i d   ! =   n u l l ) 
 
                                                 l o c k   ( _ g a t e )   {   _ i n f l i g h t . R e m o v e ( i d ) ;   _ o l d I n f l i g h t . R e m o v e ( i d ) ;   } 
 
 
 
                                         / /   F o r w a r d   t o   c l i e n t 
 
                                         l o c k   ( _ o u t L o c k ) 
 
                                         { 
 
                                                 v a r   l i n e B y t e s   =   S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t B y t e s ( l i n e   +   " \ n " ) ; 
 
                                                 W r i t e F i l e ( h O u t ,   l i n e B y t e s ,   ( u i n t ) l i n e B y t e s . L e n g t h ,   o u t   _ ,   I n t P t r . Z e r o ) ; 
 
                                                 F l u s h F i l e B u f f e r s ( h O u t ) ; 
 
                                         } 
 
                                 } 
 
                                 o u t L i n e B u f . C l e a r ( ) ; 
 
                                 i f   ( a c c . L e n g t h   >   0 )   o u t L i n e B u f . A p p e n d ( a c c ) ; 
 
                         } 
 
                         / /   F l u s h   r e m a i n i n g 
 
                         i f   ( o u t L i n e B u f . L e n g t h   >   0 ) 
 
                         { 
 
                                 l o c k   ( _ o u t L o c k ) 
 
                                 { 
 
                                         v a r   r e m   =   S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t B y t e s ( o u t L i n e B u f . T o S t r i n g ( ) ) ; 
 
                                         W r i t e F i l e ( h O u t ,   r e m ,   ( u i n t ) r e m . L e n g t h ,   o u t   _ ,   I n t P t r . Z e r o ) ; 
 
                                         F l u s h F i l e B u f f e r s ( h O u t ) ; 
 
                                 } 
 
                         } 
 
                         C l o s e H a n d l e ( h R e a d ) ; 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   { l a b e l }   s t d o u t   E O F " ) ; 
 
                 } 
 
 
 
                 / /   R u n   n o r m a l   C o r e   r e l a y   o n   m a i n   t h r e a d 
 
                 R e l a y S t d o u t ( h C o r e S t d o u t R e a d ,   " n o r m a l - c o r e " ,   d e t e c t E l e v a t i o n :   t r u e ) ; 
 
 
 
                 / /   I f   a d m i n   C o r e   w a s   s p a w n e d ,   w a i t   f o r   i t   t o o 
 
                 i f   ( _ a d m i n P r o c   ! =   I n t P t r . Z e r o ) 
 
                 { 
 
                         W a i t F o r S i n g l e O b j e c t ( _ a d m i n P r o c ,   0 x F F F F F F F F ) ; 
 
                         G e t E x i t C o d e P r o c e s s ( _ a d m i n P r o c ,   o u t   u i n t   a d m i n E x i t ) ; 
 
                         C l o s e H a n d l e ( _ a d m i n P r o c ) ; 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   a d m i n   c o r e   e x i t e d   ( c o d e = { a d m i n E x i t } ) " ) ; 
 
                 } 
 
 
 
                 f s w . E n a b l e R a i s i n g E v e n t s   =   f a l s e ; 
 
                 f s w . D i s p o s e ( ) ; 
 
                 _ f s w D e b o u n c e ? . D i s p o s e ( ) ; 
 
 
 
                 W a i t F o r S i n g l e O b j e c t ( p i . h P r o c e s s ,   5 0 0 0 ) ; 
 
                 G e t E x i t C o d e P r o c e s s ( p i . h P r o c e s s ,   o u t   u i n t   e x i t C o d e 2 ) ; 
 
                 C l o s e H a n d l e ( p i . h P r o c e s s ) ; 
 
                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   c o r e   e x i t e d   ( c o d e = { e x i t C o d e 2 } ) " ) ; 
 
                 r e t u r n   ( i n t ) e x i t C o d e 2 ; 
 
         } 
 
 
 
         / / /   < s u m m a r y > E x t r a c t   J S O N - R P C   " i d "   f r o m   a   J S O N   l i n e   ( n a i v e   s t r i n g   s e a r c h ,   s u f f i c i e n t   f o r   M C P ) . < / s u m m a r y > 
 
         s t a t i c   s t r i n g ?   E x t r a c t J s o n R p c I d ( s t r i n g   l i n e ) 
 
         { 
 
                 / /   F i n d   " i d " :   f o l l o w e d   b y   v a l u e   ( n u m b e r   o r   s t r i n g ) 
 
                 v a r   i d x   =   l i n e . I n d e x O f ( " \ " i d \ " " ,   S t r i n g C o m p a r i s o n . O r d i n a l ) ; 
 
                 i f   ( i d x   <   0 )   r e t u r n   n u l l ; 
 
                 v a r   c o l o n I d x   =   l i n e . I n d e x O f ( ' : ' ,   i d x   +   4 ) ; 
 
                 i f   ( c o l o n I d x   <   0 )   r e t u r n   n u l l ; 
 
                 v a r   r e s t   =   l i n e [ ( c o l o n I d x   +   1 ) . . ] . T r i m S t a r t ( ) ; 
 
                 i f   ( r e s t . L e n g t h   = =   0 )   r e t u r n   n u l l ; 
 
                 i f   ( r e s t [ 0 ]   = =   ' " ' ) 
 
                 { 
 
                         v a r   e n d Q u o t e   =   r e s t . I n d e x O f ( ' " ' ,   1 ) ; 
 
                         r e t u r n   e n d Q u o t e   >   0   ?   r e s t [ 1 . . e n d Q u o t e ]   :   n u l l ; 
 
                 } 
 
                 / /   N u m e r i c   i d 
 
                 i n t   e n d   =   0 ; 
 
                 w h i l e   ( e n d   <   r e s t . L e n g t h   & &   ( c h a r . I s D i g i t ( r e s t [ e n d ] )   | |   r e s t [ e n d ]   = =   ' - ' ) )   e n d + + ; 
 
                 r e t u r n   e n d   >   0   ?   r e s t [ . . e n d ]   :   n u l l ; 
 
         } 
 
 
 
         [ S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . D l l I m p o r t ( " s h e l l 3 2 . d l l " ,   C h a r S e t   =   S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . C h a r S e t . U n i c o d e ,   S e t L a s t E r r o r   =   t r u e ) ] 
 
         s t a t i c   e x t e r n   b o o l   S h e l l E x e c u t e E x W ( r e f   S H E L L E X E C U T E I N F O W   l p E x e c I n f o ) ; 
 
 
 
         [ S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . S t r u c t L a y o u t ( S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . L a y o u t K i n d . S e q u e n t i a l ,   C h a r S e t   =   S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . C h a r S e t . U n i c o d e ) ] 
 
         s t r u c t   S H E L L E X E C U T E I N F O W 
 
         { 
 
                 p u b l i c   u i n t   c b S i z e ; 
 
                 p u b l i c   u i n t   f M a s k ; 
 
                 p u b l i c   I n t P t r   h w n d ; 
 
                 p u b l i c   s t r i n g   l p V e r b ; 
 
                 p u b l i c   s t r i n g   l p F i l e ; 
 
                 p u b l i c   s t r i n g   l p P a r a m e t e r s ; 
 
                 p u b l i c   s t r i n g ?   l p D i r e c t o r y ; 
 
                 p u b l i c   i n t   n S h o w ; 
 
                 p u b l i c   I n t P t r   h I n s t A p p ; 
 
                 p u b l i c   I n t P t r   l p I D L i s t ; 
 
                 p u b l i c   s t r i n g ?   l p C l a s s ; 
 
                 p u b l i c   I n t P t r   h k e y C l a s s ; 
 
                 p u b l i c   u i n t   d w H o t K e y ; 
 
                 p u b l i c   I n t P t r   h I c o n ;   / /   u n i o n   w i t h   h M o n i t o r 
 
                 p u b l i c   I n t P t r   h P r o c e s s ; 
 
         } 
 
 
 
         c o n s t   u i n t   S E E _ M A S K _ N O C L O S E P R O C E S S   =   0 x 0 0 0 0 0 0 4 0 ; 
 
 
 
         / / /   < s u m m a r y > S p a w n   e l e v a t e d   a d m i n   C o r e   w i t h   n a m e d   p i p e s   f o r   M C P   r e l a y . < / s u m m a r y > 
 
         s t a t i c   v o i d   S p a w n A d m i n C o r e ( s t r i n g   c o r e P a t h ,   s t r i n g [ ]   m c p A r g s , 
 
                 s t r i n g ?   i n i t L i n e ,   s t r i n g ?   e l e v a t i o n R e q u e s t L i n e , 
 
                 r e f   I n t P t r   a d m i n S t d i n W r i t e ,   r e f   I n t P t r   a d m i n S t d o u t R e a d ,   r e f   I n t P t r   a d m i n P r o c , 
 
                 r e f   I n t P t r   a c t i v e S t d i n W r i t e ,   r e f   S y s t e m . I O . T e x t W r i t e r ?   a c t i v e S t d i n W r i t e r ,   r e f   b o o l   a d m i n M o d e ,   r e f   b o o l   p e n d i n g S w a p W h i l e A d m i n , 
 
                 I n t P t r   o l d C o r e S t d i n W r i t e ,   I n t P t r   h O u t ,   o b j e c t   g a t e ,   o b j e c t   o u t L o c k , 
 
                 D i c t i o n a r y < s t r i n g ,   s t r i n g >   i n f l i g h t ) 
 
         { 
 
                 S y s t e m . I O . S t r e a m W r i t e r ?   s t d i n W r i t e r   =   n u l l ; 
 
                 S y s t e m . I O . S t r e a m R e a d e r ?   s t d o u t R e a d e r   =   n u l l ; 
 
                 v a r   p i p e N a m e   =   $ " w k a p p b o t - m c p - a d m i n - { E n v i r o n m e n t . P r o c e s s I d } " ; 
 
                 v a r   s t d i n P i p e N a m e   =   $ " { p i p e N a m e } - s t d i n " ; 
 
                 v a r   s t d o u t P i p e N a m e   =   $ " { p i p e N a m e } - s t d o u t " ; 
 
 
 
                 / /   L a u n c h   a d m i n   C o r e   v i a   S h e l l E x e c u t e E x W   r u n a s 
 
                 v a r   p a r a m S t r   =   $ " m c p   - - a d m i n - p i p e s   { s t d i n P i p e N a m e }   { s t d o u t P i p e N a m e } " ; 
 
                 v a r   s e i   =   n e w   S H E L L E X E C U T E I N F O W 
 
                 { 
 
                         c b S i z e   =   ( u i n t ) S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . M a r s h a l . S i z e O f < S H E L L E X E C U T E I N F O W > ( ) , 
 
                         f M a s k   =   S E E _ M A S K _ N O C L O S E P R O C E S S , 
 
                         l p V e r b   =   " r u n a s " , 
 
                         l p F i l e   =   c o r e P a t h , 
 
                         l p P a r a m e t e r s   =   p a r a m S t r , 
 
                         n S h o w   =   0 ,   / /   S W _ H I D E 
 
                 } ; 
 
 
 
                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   R e q u e s t i n g   a d m i n   e l e v a t i o n   ( r u n a s ) . . . " ) ; 
 
                 i f   ( ! S h e l l E x e c u t e E x W ( r e f   s e i ) ) 
 
                 { 
 
                         v a r   e r r   =   S y s t e m . R u n t i m e . I n t e r o p S e r v i c e s . M a r s h a l . G e t L a s t W i n 3 2 E r r o r ( ) ; 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   U A C   d e n i e d   o r   f a i l e d   ( e r r = { e r r } ) " ) ; 
 
                         / /   S e n d   e r r o r   f o r   t h e   e l e v a t i o n - f a i l e d   r e q u e s t 
 
                         i f   ( e l e v a t i o n R e q u e s t L i n e   ! =   n u l l ) 
 
                         { 
 
                                 v a r   f a i l I d   =   E x t r a c t J s o n R p c I d ( e l e v a t i o n R e q u e s t L i n e ) ; 
 
                                 v a r   e r r J s o n   =   $ " { { \ " j s o n r p c \ " : \ " 2 . 0 \ " , \ " i d \ " : { f a i l I d } , \ " e r r o r \ " : { { \ " c o d e \ " : - 3 2 0 0 1 , \ " m e s s a g e \ " : \ " E l e v a t i o n   d e n i e d   b y   u s e r \ " } } } } \ n " ; 
 
                                 l o c k   ( o u t L o c k ) 
 
                                 { 
 
                                         v a r   e r r B y t e s   =   S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t B y t e s ( e r r J s o n ) ; 
 
                                         W r i t e F i l e ( h O u t ,   e r r B y t e s ,   ( u i n t ) e r r B y t e s . L e n g t h ,   o u t   _ ,   I n t P t r . Z e r o ) ; 
 
                                         F l u s h F i l e B u f f e r s ( h O u t ) ; 
 
                                 } 
 
                                 l o c k   ( g a t e )   {   i f   ( f a i l I d   ! =   n u l l )   i n f l i g h t . R e m o v e ( f a i l I d ) ;   } 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
 
 
                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   A d m i n   C o r e   l a u n c h e d   ( p i d = ? )      w a i t i n g   f o r   p i p e   c o n n e c t i o n   ( 6 0 s ) . . . " ) ; 
 
                 a d m i n P r o c   =   s e i . h P r o c e s s ; 
 
 
 
                 / /   W a i t   f o r   a d m i n   C o r e   t o   c o n n e c t   t o   n a m e d   p i p e s   ( i t   u s e s   N a m e d P i p e C l i e n t S t r e a m ) 
 
                 / /   W e   c r e a t e   s e r v e r - s i d e   n a m e d   p i p e s   t h a t   a d m i n   C o r e   c o n n e c t s   t o 
 
                 t r y 
 
                 { 
 
                         u s i n g   v a r   p i p e S t d i n S e r v e r   =   n e w   S y s t e m . I O . P i p e s . N a m e d P i p e S e r v e r S t r e a m ( s t d i n P i p e N a m e , 
 
                                 S y s t e m . I O . P i p e s . P i p e D i r e c t i o n . O u t ,   1 ,   S y s t e m . I O . P i p e s . P i p e T r a n s m i s s i o n M o d e . B y t e ,   S y s t e m . I O . P i p e s . P i p e O p t i o n s . N o n e ) ; 
 
                         u s i n g   v a r   p i p e S t d o u t S e r v e r   =   n e w   S y s t e m . I O . P i p e s . N a m e d P i p e S e r v e r S t r e a m ( s t d o u t P i p e N a m e , 
 
                                 S y s t e m . I O . P i p e s . P i p e D i r e c t i o n . I n ,   1 ,   S y s t e m . I O . P i p e s . P i p e T r a n s m i s s i o n M o d e . B y t e ,   S y s t e m . I O . P i p e s . P i p e O p t i o n s . N o n e ) ; 
 
 
 
                         / /   W a i t   f o r   c o n n e c t i o n s   ( 6 0 s   t i m e o u t   f o r   U A C ) 
 
                         v a r   c t s   =   n e w   S y s t e m . T h r e a d i n g . C a n c e l l a t i o n T o k e n S o u r c e ( 6 0 _ 0 0 0 ) ; 
 
                         p i p e S t d i n S e r v e r . W a i t F o r C o n n e c t i o n A s y n c ( c t s . T o k e n ) . G e t A w a i t e r ( ) . G e t R e s u l t ( ) ; 
 
                         p i p e S t d o u t S e r v e r . W a i t F o r C o n n e c t i o n A s y n c ( c t s . T o k e n ) . G e t A w a i t e r ( ) . G e t R e s u l t ( ) ; 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ L A U N C H E R : M C P ]   A d m i n   C o r e   c o n n e c t e d   t o   p i p e s ! " ) ; 
 
 
 
                         / /   T r a n s i t i o n :   c l o s e   o l d   C o r e   s t d i n   ( d r a i n ) ,   s w i t c h   t o   a d m i n 
 
                         l o c k   ( g a t e ) 
 
                         { 
 
                                 C l o s e H a n d l e ( o l d C o r e S t d i n W r i t e ) ;   / /   E O F   t o   o l d   C o r e   !  d r a i n   r e m a i n i n g   w o r k 
 
                                 a c t i v e S t d i n W r i t e   =   I n t P t r . Z e r o ;   / /   t e m p o r a r i l y   n u l l   u n t i l   w e   s e t   u p   a d m i n   p i p e   h a n d l e 
 
                         } 
 
 
 
                         / /   S e n d   i n i t i a l i z e   +   e l e v a t i o n   r e q u e s t   t o   a d m i n   C o r e 
 
                         / /   N O T E :   N O T   u s i n g   ' u s i n g '      l i f e t i m e   m a n a g e d   b y   f i n a l l y   b l o c k   b e l o w . 
 
                         / /   ' u s i n g '   w o u l d   d i s p o s e   a t   m e t h o d   e x i t   w h i l e   _ a c t i v e S t d i n W r i t e r   s t i l l   r e f e r e n c e s   i t   ( r a c e ) . 
 
                         s t d i n W r i t e r   =   n e w   S y s t e m . I O . S t r e a m W r i t e r ( p i p e S t d i n S e r v e r ,   n e w   S y s t e m . T e x t . U T F 8 E n c o d i n g ( f a l s e ) )   {   A u t o F l u s h   =   t r u e   } ; 
 
                         i f   ( i n i t L i n e   ! =   n u l l ) 
 
                         { 
 
                                 l o c k   ( g a t e ) 
 
                                 { 
 
                                         s t d i n W r i t e r . W r i t e L i n e ( i n i t L i n e ) ; 
 
                                         s t d i n W r i t e r . F l u s h ( ) ; 
 
                                 } 
 
                         } 
 
                         / /   W a i t   b r i e f l y   f o r   i n i t i a l i z e   r e s p o n s e   ( r e a d   a n d   f o r w a r d ) 
 
                         s t d o u t R e a d e r   =   n e w   S y s t e m . I O . S t r e a m R e a d e r ( p i p e S t d o u t S e r v e r ,   S y s t e m . T e x t . E n c o d i n g . U T F 8 ) ; 
 
                         v a r   i n i t R e s p   =   s t d o u t R e a d e r . R e a d L i n e ( ) ;   / /   i n i t i a l i z e   r e s p o n s e 
 
                         i f   ( i n i t R e s p   ! =   n u l l ) 
 
                         { 
 
                                 / /   D o n ' t   f o r w a r d   i n i t   r e s p o n s e   ( c l i e n t   a l r e a d y   i n i t i a l i z e d ) 
 
                                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   A d m i n   i n i t   O K :   { i n i t R e s p [ . . M a t h . M i n ( 8 0 ,   i n i t R e s p . L e n g t h ) ] } . . . " ) ; 
 
                         } 
 
 
 
                         l o c k   ( g a t e ) 
 
                         { 
 
                                 a c t i v e S t d i n W r i t e r   =   s t d i n W r i t e r ; 
 
                                 a d m i n M o d e   =   t r u e ; 
 
                         } 
 
 
 
                         / /   R e - s e n d   t h e   e l e v a t i o n - f a i l e d   r e q u e s t 
 
                         i f   ( e l e v a t i o n R e q u e s t L i n e   ! =   n u l l ) 
 
                         { 
 
                                 l o c k   ( g a t e ) 
 
                                 { 
 
                                         s t d i n W r i t e r . W r i t e L i n e ( e l e v a t i o n R e q u e s t L i n e ) ; 
 
                                         s t d i n W r i t e r . F l u s h ( ) ; 
 
                                 } 
 
                                 C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   R e - s e n t   e l e v a t i o n   r e q u e s t   t o   a d m i n   C o r e " ) ; 
 
                         } 
 
 
 
                         / /   R e l a y   a d m i n   C o r e   s t d o u t   o n   t h i s   t h r e a d 
 
                         s t r i n g ?   a d m i n L i n e ; 
 
                         w h i l e   ( ( a d m i n L i n e   =   s t d o u t R e a d e r . R e a d L i n e ( ) )   ! =   n u l l ) 
 
                         { 
 
                                 v a r   i d   =   E x t r a c t J s o n R p c I d ( a d m i n L i n e ) ; 
 
                                 i f   ( i d   ! =   n u l l ) 
 
                                         l o c k   ( g a t e )   {   i n f l i g h t . R e m o v e ( i d ) ;   } 
 
 
 
                                 l o c k   ( o u t L o c k ) 
 
                                 { 
 
                                         v a r   l i n e B y t e s   =   S y s t e m . T e x t . E n c o d i n g . U T F 8 . G e t B y t e s ( a d m i n L i n e   +   " \ n " ) ; 
 
                                         W r i t e F i l e ( h O u t ,   l i n e B y t e s ,   ( u i n t ) l i n e B y t e s . L e n g t h ,   o u t   _ ,   I n t P t r . Z e r o ) ; 
 
                                         F l u s h F i l e B u f f e r s ( h O u t ) ; 
 
                                 } 
 
                         } 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ L A U N C H E R : M C P ]   A d m i n   C o r e   s t d o u t   E O F " ) ; 
 
                 } 
 
                 c a t c h   ( O p e r a t i o n C a n c e l e d E x c e p t i o n ) 
 
                 { 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ L A U N C H E R : M C P ]   A d m i n   C o r e   c o n n e c t i o n   t i m e o u t   ( 6 0 s )      e l e v a t i o n   f a i l e d " ) ; 
 
                         t r y   {   T e r m i n a t e P r o c e s s ( a d m i n P r o c ,   1 ) ;   }   c a t c h   {   } 
 
                 } 
 
                 c a t c h   ( E x c e p t i o n   e x ) 
 
                 { 
 
                         C o n s o l e . E r r o r . W r i t e L i n e ( $ " [ L A U N C H E R : M C P ]   A d m i n   C o r e   e r r o r :   { e x . M e s s a g e } " ) ; 
 
                 } 
 
                 f i n a l l y 
 
                 { 
 
                         l o c k   ( g a t e ) 
 
                         { 
 
                                 a c t i v e S t d i n W r i t e r   =   n u l l ;   / /   p r e v e n t   o t h e r   t h r e a d s   f r o m   w r i t i n g 
 
                                 i f   ( p e n d i n g S w a p W h i l e A d m i n ) 
 
                                 { 
 
                                         C o n s o l e . E r r o r . W r i t e L i n e ( " [ L A U N C H E R : M C P ]   d e f e r r e d   c o r e   s w a p   i s   s t i l l   p e n d i n g   a f t e r   a d m i n   e n d p o i n t   c l o s e d " ) ; 
 
                                         p e n d i n g S w a p W h i l e A d m i n   =   f a l s e ; 
 
                                 } 
 
                         } 
 
                         / /   D i s p o s e   a f t e r   n u l l i n g   r e f e r e n c e      n o   r a c e 
 
                         t r y   {   s t d i n W r i t e r ? . D i s p o s e ( ) ;   }   c a t c h   {   } 
 
                         t r y   {   s t d o u t R e a d e r ? . D i s p o s e ( ) ;   }   c a t c h   {   } 
 
                 } 
 
         } 
 
 } 
 
 