@@ -66,66 +66,62 @@ public static ActionResult GetAPIsListCA(Session session)
6666 public static ActionResult InstallCA ( Session session )
6767 {
6868 Session = session ;
69-
7069 try
7170 {
72- ResetProgressBar ( session , 10 ) ;
73-
7471 if ( session . CustomActionData [ "INSTMODE" ] != "Install" )
7572 return ActionResult . Success ;
7673
77- var tmpDir = session . CustomActionData [ "INSTALLFOLDER" ] + "microtingTemp" ;
74+ ResetProgressBar ( session , 10 ) ;
7875
76+ var installFolder = session . CustomActionData [ "INSTALLFOLDER" ] ;
7977 var customerNumber = session . CustomActionData [ "CUSTOMERNUMBER" ] ;
8078 var domain = session . CustomActionData [ "DOMAINNAME" ] ;
8179
82- session . Log ( "Get latest product version called" ) ;
83- GetProductLatestVersion ( tmpDir ) ;
80+ session . Log ( "Get web api port" ) ;
81+ var webApiPort = GetWebApiPort ( ) ;
82+ var webApiName = $ "{ customerNumber } _{ domain } _{ webApiPort } ";
8483 IncrementProgressBar ( session ) ;
8584
86- var webApiPort = GetWebApiPort ( ) ;
87- var nextUiPort = webApiPort - 2000 ;
88- var uiName = $ "{ customerNumber } _{ domain } _client_{ nextUiPort } ";
89- var uiIisDir = session . CustomActionData [ "INSTALLFOLDER" ] + uiName ;
90- var angularSolutionLocation = $@ "{ tmpDir } \eform-client";
91- session . Log ( "Build Angullar app task started" ) ;
92- BuildAngularApp ( uiIisDir , angularSolutionLocation ) ;
85+ session . Log ( "Get ui port" ) ;
86+ var uiPort = webApiPort - 2000 ;
87+ var uiName = $ "{ customerNumber } _{ domain } _client_{ uiPort } ";
9388 IncrementProgressBar ( session ) ;
9489
95- var webApiLocation = $@ "{ tmpDir } \eFormAPI\eFormAPI";
96- var webApiName = $ "{ customerNumber } _{ domain } _{ webApiPort } ";
97- var webApiIisDir = session . CustomActionData [ "INSTALLFOLDER" ] + webApiName ;
98- session . Log ( "Build WebAPI called" ) ;
90+ var clientLocation = Path . Combine ( installFolder , uiName ) ;
91+ var webApiLocation = Path . Combine ( installFolder , webApiName ) ;
9992
100- BuildWebApi ( webApiLocation , webApiIisDir ) ;
93+ session . Log ( "Set proper names to folders" ) ;
94+ RenameFolders ( installFolder , webApiLocation , clientLocation ) ;
10195 IncrementProgressBar ( session ) ;
96+
97+ session . Log ( "Build Angullar app task started" ) ;
98+ BuildAngularApp ( clientLocation ) ;
99+ IncrementProgressBar ( session ) ;
100+
102101 session . Log ( "Host WebAPI called" ) ;
103- HostWebApi ( webApiName , webApiPort , webApiIisDir ) ;
102+ HostWebApi ( webApiName , webApiPort , webApiLocation ) ;
104103 IncrementProgressBar ( session ) ;
105104
106105 session . Log ( "RunAngularAsWinService called" ) ;
107- RunAngularAsWinService ( webApiPort , nextUiPort , uiIisDir , uiName ) ;
106+ RunAngularAsWinService ( webApiPort , uiPort , clientLocation , uiName ) ;
108107 IncrementProgressBar ( session ) ;
109108
110109 session . Log ( "HostAngularApp called" ) ;
111- HostAngularApp ( uiIisDir , domain , uiName ) ;
110+ HostAngularApp ( clientLocation , domain , uiName ) ;
112111 IncrementProgressBar ( session ) ;
113112
114113 session . Log ( "AddRedirectionRules called" ) ;
115- AddRedirectionRules ( uiName , $ "http://localhost:{ nextUiPort } ") ;
114+ AddRedirectionRules ( uiName , $ "http://localhost:{ uiPort } ") ;
116115 IncrementProgressBar ( session ) ;
117116
118117 session . Log ( "SaveInstances called" ) ;
119118 SaveInstances ( webApiName ) ;
120119 IncrementProgressBar ( session ) ;
121120
122121 if ( session . CustomActionData [ "GENERATESSL" ] == "1" )
123- RunProcess ( $@ "{ tmpDir } \eFormAPI\Installation\letsencrypt\letsencrypt.exe", $ "--plugin manual --manualhost { uiName } --webroot { session . CustomActionData [ "INSTALLFOLDER" ] . TrimEnd ( '\\ ' ) } ") ;
124-
125- IncrementProgressBar ( session ) ;
122+ RunProcess ( Path . Combine ( installFolder , "letsencrypt\\ letsencrypt.exe" ) , $ "--plugin manual --manualhost { uiName } --webroot { session . CustomActionData [ "INSTALLFOLDER" ] . TrimEnd ( '\\ ' ) } ") ;
126123
127- session . Log ( "Clear temp dir called" ) ;
128- DeleteDirectory ( tmpDir ) ;
124+ DeleteDirectory ( Path . Combine ( installFolder , "letsencrypt" ) ) ;
129125 IncrementProgressBar ( session ) ;
130126
131127 return ActionResult . Success ;
@@ -162,55 +158,56 @@ public static ActionResult UpdateCA(Session session)
162158
163159 try
164160 {
165- ResetProgressBar ( session , 8 ) ;
166161 if ( session . CustomActionData [ "INSTMODE" ] != "Update" )
167162 return ActionResult . Success ;
168163
164+ ResetProgressBar ( session , 8 ) ;
165+
169166 var domainName = session . CustomActionData [ "DOMAINNAME" ] ;
170167 var api = domainName . Split ( '_' ) ;
171168 var domain = api [ 1 ] ;
172169 var customerNumber = api . First ( ) ;
173170 var apiPort = int . Parse ( api . Last ( ) ) ;
174171 var uiPort = apiPort - 2000 ;
175172
176- var installDir = GetInstallDirrectory ( domainName ) ;
177- var tmpDir = Path . Combine ( installDir + "microtingTemp" ) ;
173+ var siteDir = GetInstallDirrectory ( domainName ) ;
178174
179175 // stop sites
180176 ControlSites ( customerNumber , domain , apiPort , uiPort , false ) ;
181177 IncrementProgressBar ( session ) ;
182178
183- GetProductLatestVersion ( tmpDir ) ;
184- IncrementProgressBar ( session ) ;
185-
186179 // client update
187180 var uiName = $ "{ customerNumber } _{ domain } _client_{ uiPort } ";
188- var uiIisDir = Path . Combine ( installDir + uiName ) ;
181+ var uiIisDir = Path . Combine ( siteDir + uiName ) ;
182+ var webApiLocation = Path . Combine ( siteDir , domainName ) ;
189183
190184 RunProcess ( @"sc" , $ "stop eformangular{ uiName . Replace ( "." , "" ) } .exe") ;
191185 Thread . Sleep ( 1000 ) ;
192186 RunProcess ( @"C:\Program Files\nodejs\node.exe" , "svc.js uninstall" , uiIisDir ) ;
193187 IncrementProgressBar ( session ) ;
194188
195- BuildAngularApp ( uiIisDir , tmpDir + "\\ eform-client" ) ;
196- IncrementProgressBar ( session ) ;
189+ DeleteDirectory ( webApiLocation ) ;
190+ DeleteDirectory ( uiIisDir ) ;
191+
192+ session . Log ( "Set proper names to folders" ) ;
193+
194+ DirectoryCopy ( Path . Combine ( session . CustomActionData [ "INSTALLFOLDER" ] , "eform-api" ) , webApiLocation ) ;
195+ DirectoryCopy ( Path . Combine ( session . CustomActionData [ "INSTALLFOLDER" ] , "eform-client" ) , uiIisDir ) ;
197196
198-
199- RunAngularAsWinService ( apiPort , uiPort , uiIisDir , uiName ) ;
200197 IncrementProgressBar ( session ) ;
201198
202- // api update
203- var webApiName = $ "{ customerNumber } _{ domain } _{ apiPort } ";
204- var webApiIisDir = Path . Combine ( installDir + webApiName ) ;
205- BuildWebApi ( tmpDir + "\\ eFormAPI\\ eFormAPI" , webApiIisDir ) ;
199+ session . Log ( "Build Angullar app task started" ) ;
200+ BuildAngularApp ( uiIisDir ) ;
206201 IncrementProgressBar ( session ) ;
207202
208- ControlSites ( customerNumber , domain , apiPort , uiPort , true ) ;
203+ session . Log ( "RunAngularAsWinService called" ) ;
204+ RunAngularAsWinService ( apiPort , uiPort , uiIisDir , uiName ) ;
209205 IncrementProgressBar ( session ) ;
210206
211- DeleteDirectory ( tmpDir ) ;
207+ ControlSites ( customerNumber , domain , apiPort , uiPort , true ) ;
212208 IncrementProgressBar ( session ) ;
213209
210+ DeleteDirectory ( session . CustomActionData [ "INSTALLFOLDER" ] ) ;
214211 return ActionResult . Success ;
215212 }
216213 catch ( Exception ex )
@@ -313,40 +310,21 @@ private static string GetServiceList()
313310 return ui ;
314311 }
315312
316- private static void GetProductLatestVersion ( string directory )
313+ private static void RenameFolders ( string location , string apiName , string uiName )
317314 {
318- RunProcess ( "git" , $ "clone https://github.com/microting/eform-angular-frontend.git { directory } ") ;
315+ Directory . Move ( Path . Combine ( location , "eform-api" ) , apiName ) ;
316+ Directory . Move ( Path . Combine ( location , "eform-client" ) , uiName ) ;
319317 }
320318
321- private static void BuildAngularApp ( string appLocation , string appSolutionLocation )
319+ private static void BuildAngularApp ( string appLocation )
322320 {
323- if ( Directory . Exists ( appLocation ) )
324- DeleteDirectory ( appLocation ) ;
325-
326- Session . Log ( "BuildAngularApp -> DirectoryCopy" ) ;
327- DirectoryCopy ( appSolutionLocation , appLocation ) ;
328-
329321 Session . Log ( "BuildAngularApp -> npm install" ) ;
330322 RunProcess ( @"C:\Program Files\nodejs\npm.cmd" , "install" , appLocation ) ;
331323
332324 Session . Log ( "BuildAngularApp -> npm run build" ) ;
333325 RunProcess ( @"C:\Program Files\nodejs\npm.cmd" , "run build" , appLocation ) ;
334326 }
335327
336- private static void BuildWebApi ( string solutionLocation , string iisDir )
337- {
338- var parentDir = new DirectoryInfo ( solutionLocation ) . Parent . FullName ;
339- RunProcess ( parentDir + @"\installation\nuget\nuget.exe" , "restore -PackagesDirectory packages" , parentDir ) ;
340- RunProcess ( parentDir + @"\installation\msbuild\msbuild.exe" , $@ "{ solutionLocation } \eFormAPI.Web.csproj /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml /p:Platform=x64", killChildProcess : true ) ;
341-
342- if ( Directory . Exists ( iisDir ) )
343- DeleteDirectory ( iisDir ) ;
344-
345- var newLocation = Directory . CreateDirectory ( iisDir ) ;
346-
347- DirectoryCopy ( $@ "{ solutionLocation } \bin\Release\PublishOutput", newLocation . FullName ) ;
348- }
349-
350328 private static void HostWebApi ( string webApiName , int port , string iisDir )
351329 {
352330 using ( var serverManager = new ServerManager ( ) )
@@ -496,49 +474,6 @@ private static void CreateAppPool(ServerManager serverManager, string name)
496474 serverManager . CommitChanges ( ) ;
497475 }
498476
499- static void RunProcess ( string fileName , string arguments , string workingDirrectory = null , bool killChildProcess = false )
500- {
501- using ( var process = Process . Start ( new ProcessStartInfo
502- {
503- FileName = fileName ,
504- Arguments = arguments ,
505- WindowStyle = ProcessWindowStyle . Hidden ,
506- UseShellExecute = false ,
507- WorkingDirectory = workingDirrectory
508- } ) )
509- {
510- process . WaitForExit ( ) ;
511- if ( killChildProcess )
512- KillAllProcessesSpawnedBy ( ( UInt32 ) process . Id ) ;
513- }
514- }
515-
516- private static void KillAllProcessesSpawnedBy ( UInt32 parentProcessId )
517- {
518-
519- // NOTE: Process Ids are reused!
520- ManagementObjectSearcher searcher = new ManagementObjectSearcher (
521- "SELECT * " +
522- "FROM Win32_Process " +
523- "WHERE ParentProcessId=" + parentProcessId ) ;
524- ManagementObjectCollection collection = searcher . Get ( ) ;
525- if ( collection . Count > 0 )
526- {
527- foreach ( var item in collection )
528- {
529- UInt32 childProcessId = ( UInt32 ) item [ "ProcessId" ] ;
530- if ( ( int ) childProcessId != Process . GetCurrentProcess ( ) . Id )
531- {
532- KillAllProcessesSpawnedBy ( childProcessId ) ;
533-
534- Process childProcess = Process . GetProcessById ( ( int ) childProcessId ) ;
535- childProcess . Kill ( ) ;
536- Thread . Sleep ( 1000 ) ;
537- }
538- }
539- }
540- }
541-
542477 private static void DirectoryCopy ( string sourceDirName , string destDirName )
543478 {
544479 // Get the subdirectories for the specified directory.
@@ -575,6 +510,21 @@ private static void DirectoryCopy(string sourceDirName, string destDirName)
575510
576511 }
577512
513+ static void RunProcess ( string fileName , string arguments , string workingDirrectory = null )
514+ {
515+ using ( var process = Process . Start ( new ProcessStartInfo
516+ {
517+ FileName = fileName ,
518+ Arguments = arguments ,
519+ WindowStyle = ProcessWindowStyle . Hidden ,
520+ UseShellExecute = false ,
521+ WorkingDirectory = workingDirrectory
522+ } ) )
523+ {
524+ process . WaitForExit ( ) ;
525+ }
526+ }
527+
578528 private static void ControlSites ( string customerNumber , string domain , int apiPort , int uiPort , bool shouldSiteBeStarted )
579529 {
580530 using ( var serverManager = new ServerManager ( ) )
0 commit comments