@@ -62,10 +62,10 @@ public GXRouting(string baseURL)
6262		} 
6363
6464		static   public  List < ControllerInfo >  GetRouteController ( Dictionary < string ,  string >  apiPaths , 
65- 											Dictionary < string ,  List < string > >  sValid , 
66- 											Dictionary < string ,  Dictionary < string ,  SingleMap > >  sMap , 
67- 											Dictionary < string ,  Dictionary < Tuple < string ,  string > ,  string > >  sMapData , 
68- 											string  basePath ,  string  verb ,  string  path ) 
65+ 																				 Dictionary < string ,  List < string > >  sValid , 
66+ 																				 Dictionary < string ,  Dictionary < string ,  SingleMap > >  sMap , 
67+ 																				 Dictionary < string ,  Dictionary < Tuple < string ,  string > ,  string > >  sMapData , 
68+ 																				 string  basePath ,  string  verb ,  string  path ) 
6969		{ 
7070			List < ControllerInfo >  result  =  new  List < ControllerInfo > ( ) ; 
7171			string  parms  =  string . Empty ; 
@@ -78,10 +78,10 @@ static public List<ControllerInfo> GetRouteController(Dictionary<string, string>
7878					int  questionMarkIdx  =  path . IndexOf ( QUESTIONMARK ) ; 
7979					string  controller ; 
8080					if  ( apiPaths . ContainsKey ( basePath ) 
81- 						&&  sValid . ContainsKey ( basePath ) 
82- 						&&  sMap . ContainsKey ( basePath ) 
83- 						&&  sMapData . ContainsKey ( basePath ) 
84- 						) 
81+ 							 &&  sValid . ContainsKey ( basePath ) 
82+ 							 &&  sMap . ContainsKey ( basePath ) 
83+ 							 &&  sMapData . ContainsKey ( basePath ) 
84+ 							 ) 
8585					{ 
8686						if  ( sValid [ basePath ] . Contains ( path . ToLower ( ) ) ) 
8787						{ 
@@ -174,12 +174,12 @@ internal async Task RouteHttpService(HttpContext context)
174174				HandlerFactory  handlerFactory  =  new  HandlerFactory ( ) ; 
175175				await  handlerFactory . Invoke ( context ) ; 
176176			} 
177- 			catch   ( Exception   ex ) 
177+ 			catch 
178178			{ 
179- 				await   Task . FromException ( ex ) ; 
179+ 				throw ; 
180180			} 
181181		} 
182- 		public  Task  ProcessRestRequest ( HttpContext  context ) 
182+ 		public  async   Task  ProcessRestRequest ( HttpContext  context ) 
183183		{ 
184184			try 
185185			{ 
@@ -188,7 +188,6 @@ public Task ProcessRestRequest(HttpContext context)
188188					IHttpContextAccessor  contextAccessor  =  context . RequestServices . GetService < IHttpContextAccessor > ( ) ; 
189189					context  =  new  GxHttpContextAccesor ( contextAccessor ) ; 
190190				} 
191- 				Task  result  =  Task . CompletedTask ; 
192191				string  path  =  context . Request . Path . ToString ( ) ; 
193192				string  actualPath  =  string . Empty ; 
194193				bool  isServiceInPath  =  ServiceInPath ( path ,  out  actualPath ) ; 
@@ -220,37 +219,40 @@ public Task ProcessRestRequest(HttpContext context)
220219					else 
221220					{ 
222221						if  ( ( path . Contains ( oauthRoute )  &&  ( AzureDeploy . GAM  ==  "true" ) )  ||  path . Contains ( "gxmulticall" ) )  
223- 							return  ( RouteHttpService ( context ) ) ; 
222+ 						{ 
223+ 							await  ( RouteHttpService ( context ) ) ; 
224+ 							return ; 
225+ 						} 
224226						controllerWithParms  =  GetGxRouteValue ( path ) ; 
225227						GXLogging . Debug ( log ,  $ "Running Azure functions. ControllerWithParms :{ controllerWithParms }  path:{ path } ") ; 
226228					} 
227- 				 
229+ 
228230					List < ControllerInfo >  controllers  =  GetRouteController ( servicesPathUrl ,  servicesValidPath ,  servicesMap ,  servicesMapData ,  actualPath ,  context . Request . Method ,  controllerWithParms ) ; 
229231					GxRestWrapper  controller  =  null ; 
230232					ControllerInfo  controllerInfo  =  controllers . FirstOrDefault ( c =>  ( controller  =  GetController ( context ,  c ) )  !=  null ) ; 
231- 					 
233+ 
232234
233235					if  ( controller  !=  null ) 
234236					{ 
235237						if  ( HttpMethods . IsGet ( context . Request . Method )  &&  ( controllerInfo . Verb  ==  null  ||  HttpMethods . IsGet ( controllerInfo . Verb ) ) ) 
236238						{ 
237- 							result   =  controller . Get ( controllerInfo . Parameters ) ; 
239+ 							await  controller . Get ( controllerInfo . Parameters ) ; 
238240						} 
239241						else  if  ( HttpMethods . IsPost ( context . Request . Method )  &&  ( controllerInfo . Verb  ==  null  ||  HttpMethods . IsPost ( controllerInfo . Verb ) ) ) 
240242						{ 
241- 							result   =  controller . Post ( ) ; 
243+ 							await  controller . Post ( ) ; 
242244						} 
243245						else  if  ( HttpMethods . IsDelete ( context . Request . Method )  &&  ( controllerInfo . Verb  ==  null  ||  HttpMethods . IsDelete ( controllerInfo . Verb ) ) ) 
244246						{ 
245- 							result   =  controller . Delete ( controllerInfo . Parameters ) ; 
247+ 							await  controller . Delete ( controllerInfo . Parameters ) ; 
246248						} 
247249						else  if  ( HttpMethods . IsPut ( context . Request . Method )  &&  ( controllerInfo . Verb  ==  null  ||  HttpMethods . IsPut ( controllerInfo . Verb ) ) ) 
248250						{ 
249- 							result   =  controller . Put ( controllerInfo . Parameters ) ; 
251+ 							await  controller . Put ( controllerInfo . Parameters ) ; 
250252						} 
251253						else  if  ( HttpMethods . IsPatch ( context . Request . Method )  &&  ( controllerInfo . Verb  ==  null  ||  HttpMethods . IsPatch ( controllerInfo . Verb ) ) ) 
252254						{ 
253- 							result   =  controller . Patch ( controllerInfo . Parameters ) ; 
255+ 							await  controller . Patch ( controllerInfo . Parameters ) ; 
254256						} 
255257						else  if  ( HttpMethods . IsOptions ( context . Request . Method ) ) 
256258						{ 
@@ -284,18 +286,20 @@ public Task ProcessRestRequest(HttpContext context)
284286					{ 
285287						GXLogging . Error ( log ,  $ "ProcessRestRequest controller not found path:{ path }  controllerWithParms:{ controllerWithParms } ") ; 
286288						context . Response . Headers . Clear ( ) ; 
287- 						result   =   Task . FromException ( new  PageNotFoundException ( path ) ) ; 
289+ 						throw   new  PageNotFoundException ( path ) ; 
288290					} 
289291				} 
290- 				context . CommitSession ( ) ; 
291- 
292- 				return  result ; 
292+ 				
293293			} 
294294			catch  ( Exception  ex ) 
295295			{ 
296296				GXLogging . Error ( log ,  "ProcessRestRequest" ,  ex ) ; 
297297				HttpHelper . SetUnexpectedError ( context ,  HttpStatusCode . InternalServerError ,  ex ) ; 
298- 				return  Task . FromException ( ex ) ; 
298+ 				throw ; 
299+ 			} 
300+ 			finally 
301+ 			{ 
302+ 				await  context . CommitSessionAsync ( ) ; 
299303			} 
300304		} 
301305
@@ -374,20 +378,21 @@ public bool ServiceInPath(String path, out String actualPath)
374378					return  true ; 
375379				} 
376380			} 
377- 			else  { 
381+ 			else 
382+ 			{ 
378383				return  true ; 
379- 			} 						 
384+ 			} 
380385		} 
381386
382- 		private  String  FindPath ( string  innerPath ,  Dictionary < string , string   >  servicesPathUrl ,  bool  startTxt ) 
387+ 		private  String  FindPath ( string  innerPath ,  Dictionary < string ,   string >  servicesPathUrl ,  bool  startTxt ) 
383388		{ 
384389			string  actualPath  =  String . Empty ; 
385- 			foreach  ( string  subPath  in  from  String  subPath  in  servicesPathUrl . Keys 									 
386- 									select  subPath ) 
390+ 			foreach  ( string  subPath  in  from  String  subPath  in  servicesPathUrl . Keys 
391+ 									    select  subPath ) 
387392			{ 
388393				bool  match  =  false ; 
389394				innerPath  =  innerPath . ToLower ( ) ; 
390- 				match  =  ( startTxt ) ?  innerPath . StartsWith ( $ "/{ subPath . ToLower ( ) } ") :  innerPath . Contains ( $ "/{ subPath . ToLower ( ) } ") ; 
395+ 				match  =  ( startTxt )   ?  innerPath . StartsWith ( $ "/{ subPath . ToLower ( ) } ")   :  innerPath . Contains ( $ "/{ subPath . ToLower ( ) } ") ; 
391396				if  ( match ) 
392397				{ 
393398					actualPath  =  subPath . ToLower ( ) ; 
@@ -431,7 +436,7 @@ public GxRestWrapper GetController(HttpContext context, ControllerInfo controlle
431436			bool  privateDirExists  =  Directory . Exists ( privateDir ) ; 
432437
433438			GXLogging . Debug ( log ,  $ "PrivateDir:{ privateDir }  asssemblycontroller:{ asssemblycontroller } ") ; 
434- 			string  svcFile = null ; 
439+ 			string  svcFile   =   null ; 
435440			if  ( privateDirExists  &&  File . Exists ( Path . Combine ( privateDir ,  $ "{ asssemblycontroller . ToLower ( ) } .grp.json") ) ) 
436441			{ 
437442				controller  =  tmpController ; 
@@ -498,7 +503,7 @@ string SvcFile(string controller)
498503				GXLogging . Warn ( log ,  "Service file not found:"  +  controllerFullName ) ; 
499504				return  null ; 
500505			} 
501- 			 
506+ 
502507		} 
503508		public  void  ServicesGroupSetting ( ) 
504509		{ 
@@ -524,7 +529,7 @@ public void ServicesGroupSetting()
524529								string  mapPath  =  ( m . BasePath . EndsWith ( "/" ) )  ?  m . BasePath  :  m . BasePath  +  "/" ; 
525530								string  mapPathLower  =  mapPath . ToLower ( ) ; 
526531								string  mNameLower  =  m . Name . ToLower ( ) ; 
527- 								servicesPathUrl [ mapPathLower ] =  mNameLower ; 
532+ 								servicesPathUrl [ mapPathLower ]   =  mNameLower ; 
528533								if  ( ! RestAPIHelpers . ServiceAsController ( ) ) 
529534								{ 
530535									GXLogging . Debug ( log ,  $ "addServicesPathUrl key:{ mapPathLower }  value:{ mNameLower } ") ; 
@@ -575,7 +580,8 @@ public void ServicesGroupSetting()
575580						} 
576581					} 
577582				} 
578- 			} catch  ( Exception  ex ) 
583+ 			} 
584+ 			catch  ( Exception  ex ) 
579585			{ 
580586				GXLogging . Error ( log ,  $ "Error Loading Services Group Settings",  ex ) ; 
581587				throw ; 
@@ -676,7 +682,7 @@ public class Binding
676682
677683	[ DataContract ( ) ] 
678684	public  class  MapGroup 
679- 	{ 	 
685+ 	{ 
680686		String  _objectType ; 
681687		String  _name ; 
682688		String  _basePath ; 
0 commit comments