@@ -307,7 +307,7 @@ internal MLNodeAutoCompletionRequest GenerateRequestForMLAutocomplete()
307307 return request ;
308308 }
309309
310- internal void ShowNodeAutocompleMLResults ( )
310+ internal void ShowNodeAutocompleMLResults ( Action ? afterLoaded )
311311 {
312312 //this should run on the UI thread, so thread safety is not a concern
313313 LastRequestGuid = Guid . NewGuid ( ) ;
@@ -326,24 +326,25 @@ internal void ShowNodeAutocompleMLResults()
326326 try
327327 {
328328 MLresults = GetMLNodeAutocompleteResults ( jsonRequest ) ;
329- this . dynamoViewModel . UIDispatcher . BeginInvoke ( ( ) => UpdateUIWithRresults ( MLresults , myRequest ) ) ;
329+ this . dynamoViewModel . UIDispatcher . BeginInvoke ( ( ) => UpdateUIWithRresults ( MLresults , myRequest , afterLoaded ) ) ;
330330 }
331331 catch ( Exception ex )
332332 {
333333 this . dynamoViewModel . UIDispatcher . BeginInvoke ( ( ) =>
334334 {
335+ if ( LastRequestGuid != myRequest || ! IsOpen ) return ;
335336 ResultsLoaded = true ; //fail gracefully
337+ afterLoaded ? . Invoke ( ) ;
336338 dynamoViewModel . Model . Logger . Log ( "Unable to fetch ML Node autocomplete results: " + ex . Message ) ;
337339 DisplayAutocompleteMLStaticPage = true ;
338340 AutocompleteMLTitle = Resources . LoginNeededTitle ;
339341 AutocompleteMLMessage = Resources . LoginNeededMessage ;
340342 Analytics . TrackEvent ( Actions . View , Categories . NodeAutoCompleteOperations , "UnabletoFetch" ) ;
341- return ;
342343 } ) ;
343344 }
344345 } ) ;
345346 }
346- private void UpdateUIWithRresults ( MLNodeAutoCompletionResponse MLresults , Guid myRequest )
347+ private void UpdateUIWithRresults ( MLNodeAutoCompletionResponse MLresults , Guid myRequest , Action ? afterLoaded )
347348 {
348349 if ( LastRequestGuid != myRequest )
349350 {
@@ -358,6 +359,7 @@ private void UpdateUIWithRresults(MLNodeAutoCompletionResponse MLresults, Guid m
358359 return ;
359360 }
360361 ResultsLoaded = true ;
362+ afterLoaded ? . Invoke ( ) ;
361363 // no results
362364 if ( MLresults == null || MLresults . Results . Count ( ) == 0 )
363365 {
@@ -455,6 +457,9 @@ private void UpdateUIWithRresults(MLNodeAutoCompletionResponse MLresults, Guid m
455457
456458 OrganizeConfidenceSection ( results ) ;
457459 }
460+
461+ // Save the filtered results for search.
462+ searchElementsCache = FilteredResults . ToList ( ) ;
458463 }
459464
460465 /// <summary>
@@ -588,15 +593,15 @@ internal HostNames GetHostNameEnum(string HostName)
588593 /// <summary>
589594 /// Key function to populate node autocomplete results to display
590595 /// </summary>
591- internal void PopulateAutoCompleteCandidates ( )
596+ internal void PopulateAutoCompleteCandidates ( Action afterLoaded = null )
592597 {
593598 if ( PortViewModel == null ) return ;
594599
595600 ResetAutoCompleteSearchViewState ( ) ;
596601
597602 if ( IsDisplayingMLRecommendation )
598603 {
599- ShowNodeAutocompleMLResults ( ) ;
604+ ShowNodeAutocompleMLResults ( afterLoaded ) ;
600605 //Tracking Analytics when raising Node Autocomplete with the Recommended Nodes option selected (Machine Learning)
601606 Analytics . TrackEvent (
602607 Actions . Show ,
@@ -622,10 +627,9 @@ internal void PopulateAutoCompleteCandidates()
622627 {
623628 FilteredResults = GetViewModelForNodeSearchElements ( objectTypeMatchingElements ) ;
624629 }
630+ // Save the filtered results for search.
631+ searchElementsCache = FilteredResults . ToList ( ) ;
625632 }
626-
627- // Save the filtered results for search.
628- searchElementsCache = FilteredResults . ToList ( ) ;
629633 }
630634
631635 internal void PopulateDefaultAutoCompleteCandidates ( )
0 commit comments