@@ -38,6 +38,7 @@ public class BuildsManagerMobalytics : IBuildsManagerMobalytics
3838 private List < AspectInfo > _aspects = new List < AspectInfo > ( ) ;
3939 private List < string > _aspectNames = new List < string > ( ) ;
4040 private Dictionary < string , string > _aspectMapNameToId = new Dictionary < string , string > ( ) ;
41+ private string _buildUrl = string . Empty ;
4142 private object _lockTimerTimeout = new ( ) ;
4243 private List < MobalyticsBuild > _mobalyticsBuilds = new ( ) ;
4344 private List < MobalyticsProfile > _mobalyticsProfiles = new ( ) ;
@@ -234,44 +235,52 @@ private void InitDevTools()
234235 // Create a dynamic handler using a lambda
235236 var handler = ( EventHandler ) ( ( sender , e ) =>
236237 {
237- lock ( _lockTimerTimeout )
238+ try
238239 {
239- // Reset timeout timer
240- _timerTimeout . Stop ( ) ;
241- _timerTimeout . Start ( ) ;
242- }
243-
244- dynamic args = e ; // Use dynamic since we don’t know the exact type
245- //System.Diagnostics.Debug.WriteLine($"ResponseReceived: requestId={args.RequestId}, url={args.Response.Url}");
246-
247- if ( args . Response . MimeType . Equals ( "application/json" ) && args . Response . Url . Contains ( "api/diablo4" ) )
248- {
249- // Give some time for the response body to be ready.
250- Thread . Sleep ( 1000 ) ;
251-
252- // GetResponseBody method
253- var getResponseBodyMethod = networkAdapterType . GetMethod ( "GetResponseBody" ) ;
254- var getResponseBodyCommandSettingsType = DevToolsHelper . GetTypeFromNetworkNamespaceByName ( _devToolsSession , "GetResponseBodyCommandSettings" ) ;
255- var getResponseBodyCommandSettings = Activator . CreateInstance ( getResponseBodyCommandSettingsType ) ;
256- getResponseBodyCommandSettingsType . GetProperty ( "RequestId" ) ? . SetValue ( getResponseBodyCommandSettings , args . RequestId ) ;
257- // Call GetResponseBody
258- var task = ( Task ? ) getResponseBodyMethod ? . Invoke ( networkAdapter , new [ ] { getResponseBodyCommandSettings , CancellationToken . None , null , true } ) ;
259- task ? . Wait ( ) ;
260- var resultProperty = task ? . GetType ( ) . GetProperty ( "Result" ) ;
261- dynamic ? body = resultProperty ? . GetValue ( task ) ;
262-
263- //System.Diagnostics.Debug.WriteLine($"Response body for {args.Response.Url}: {body?.Body}");
264- string json = body ? . Body ?? string . Empty ;
265-
266- if ( json . StartsWith ( "{\" data\" :{\" game\" :{\" documents\" :{\" userGeneratedDocumentById\" :" ) )
240+ lock ( _lockTimerTimeout )
267241 {
268- ParseJsonBuild ( json ) ;
242+ // Reset timeout timer
243+ _timerTimeout . Stop ( ) ;
244+ _timerTimeout . Start ( ) ;
269245 }
270- else if ( json . StartsWith ( "{\" data\" :{\" game\" :{\" documents\" :{\" userGeneratedDocuments\" :" ) )
246+
247+ dynamic args = e ; // Use dynamic since we don’t know the exact type
248+ //System.Diagnostics.Debug.WriteLine($"ResponseReceived: requestId={args.RequestId}, url={args.Response.Url}");
249+
250+ if ( args . Response . MimeType . Equals ( "application/json" ) && args . Response . Url . Contains ( "api/diablo4" ) )
271251 {
272- ParseJsonProfile ( json ) ;
252+ // Give some time for the response body to be ready.
253+ Thread . Sleep ( 1000 ) ;
254+
255+ // GetResponseBody method
256+ var getResponseBodyMethod = networkAdapterType . GetMethod ( "GetResponseBody" ) ;
257+ var getResponseBodyCommandSettingsType = DevToolsHelper . GetTypeFromNetworkNamespaceByName ( _devToolsSession , "GetResponseBodyCommandSettings" ) ;
258+ var getResponseBodyCommandSettings = Activator . CreateInstance ( getResponseBodyCommandSettingsType ) ;
259+ getResponseBodyCommandSettingsType . GetProperty ( "RequestId" ) ? . SetValue ( getResponseBodyCommandSettings , args . RequestId ) ;
260+ // Call GetResponseBody
261+ var task = ( Task ? ) getResponseBodyMethod ? . Invoke ( networkAdapter , new [ ] { getResponseBodyCommandSettings , CancellationToken . None , null , true } ) ;
262+ task ? . Wait ( ) ;
263+ var resultProperty = task ? . GetType ( ) . GetProperty ( "Result" ) ;
264+ dynamic ? body = resultProperty ? . GetValue ( task ) ;
265+
266+ //System.Diagnostics.Debug.WriteLine($"Response body for {args.Response.Url}: {body?.Body}");
267+ string json = body ? . Body ?? string . Empty ;
268+
269+ if ( json . StartsWith ( "{\" data\" :{\" game\" :{\" documents\" :{\" userGeneratedDocumentById\" :" ) )
270+ {
271+ ParseJsonBuild ( json ) ;
272+ }
273+ else if ( json . StartsWith ( "{\" data\" :{\" game\" :{\" documents\" :{\" userGeneratedDocuments\" :" ) )
274+ {
275+ ParseJsonProfile ( json ) ;
276+ }
273277 }
274278 }
279+ catch ( Exception )
280+ {
281+ // Ignore exceptions in event handler
282+ // Failed processes will be handled by the timeout timer.
283+ }
275284 } ) ;
276285
277286 // Convert the lambda to the correct delegate type
@@ -664,6 +673,8 @@ public void DownloadMobalyticsBuild(string buildUrl)
664673 {
665674 _eventAggregator . GetEvent < MobalyticsStatusUpdateEvent > ( ) . Publish ( new MobalyticsStatusUpdateEventParams { Status = $ "Preparing browser instance." } ) ;
666675
676+ _buildUrl = buildUrl ;
677+
667678 if ( _webDriver == null ) InitSelenium ( ) ;
668679 if ( _webDriver == null ) throw new Exception ( "WebDriver initialization failed." ) ;
669680 if ( _webDriverWait == null ) throw new Exception ( "WebDriverWait initialization failed." ) ;
@@ -1225,7 +1236,7 @@ private void ParseJsonBuild(string json)
12251236 MobalyticsBuild mobalyticsBuild = new MobalyticsBuild
12261237 {
12271238 Id = mobalyticsBuildJson . Data . Game . Documents . UserGeneratedDocumentById . Data . Id ,
1228- Url = _webDriver ? . Url ?? string . Empty ,
1239+ Url = _buildUrl ,
12291240 Name = mobalyticsBuildJson . Data . Game . Documents . UserGeneratedDocumentById . Data . Data . Name ,
12301241 Date = mobalyticsBuildJson . Data . Game . Documents . UserGeneratedDocumentById . Data . UpdatedAt
12311242 } ;
0 commit comments