77using  Kantan . Model . MemberIndex ; 
88using  Kantan . Utilities ; 
99using  Microsoft . Extensions . Configuration ; 
10+ using  Microsoft . Extensions . Logging ; 
11+ using  SmartImage . Lib . Clients ; 
1012using  SmartImage . Lib . Cookies ; 
1113using  SmartImage . Lib . Engines ; 
1214using  SmartImage . Lib . Engines . Impl . Search ; 
1315using  SmartImage . Lib . Engines . Impl . Upload ; 
1416using  SmartImage . Lib . Results . Data ; 
17+ using  SmartImage . Lib . Utilities . Diagnostics ; 
1518using  Configuration  =  System . Configuration . Configuration ; 
1619using  ConfigurationManager  =  System . Configuration . ConfigurationManager ; 
1720using  ConfigurationSection  =  System . Configuration . ConfigurationSection ; 
@@ -21,7 +24,7 @@ namespace SmartImage.Lib;
2124public  sealed  class  SearchConfig  :  INotifyPropertyChanged 
2225{ 
2326
24- 	 #region Defaults
27+ #region Defaults
2528
2629	/// <summary> 
2730	/// Default value for <see cref="SearchEngines"/> 
@@ -57,7 +60,7 @@ public sealed class SearchConfig : INotifyPropertyChanged
5760
5861	public  const  UploadEngineOptions  UPLOAD_ENGINE_DEFAULT  =  UploadEngineOptions . Pomf ; 
5962
60- 	 #endregion
63+ #endregion
6164
6265	/// <summary> 
6366	/// Engines used to search. 
@@ -196,16 +199,69 @@ public UploadEngineOptions UploadEngine
196199
197200	public  static   readonly  SearchConfig  Default  =  new ( ) ; 
198201
202+ 	private  static   readonly  ILogger  s_logger  =  AppSupport . Factory . CreateLogger ( nameof ( SearchClient ) ) ; 
203+ 
204+ 	public  static   readonly  Configuration  Configuration  = 
205+ 		ConfigurationManager . OpenExeConfiguration ( ConfigurationUserLevel . None ) ; 
206+ 
199207	public  SearchConfig ( ) 
200208	{ 
201209		PropertyChanged  +=  static  ( sender ,  args )  => 
202210		{ 
203- 			Trace . WriteLine ( $ "Changed { args . PropertyName } ",  nameof ( SearchConfig ) ) ; 
211+ 			// 
212+ 			s_logger . LogTrace ( "Changed {PropName}" ,  args . PropertyName ) ; 
204213		} ; 
205214	} 
206215
207- 	public  static   readonly  Configuration  Configuration  = 
208- 		ConfigurationManager . OpenExeConfiguration ( ConfigurationUserLevel . None ) ; 
216+ 
217+ 	internal  async  ValueTask < bool >  TryReadCookiesAsync ( ) 
218+ 	{ 
219+ 		var  ok  =  false ; 
220+ 
221+ 		if  ( ReadCookies )  { 
222+ 			try  { 
223+ 				CookiesProvider  =  ICookiesProvider . GetProvider ( ) ; 
224+ 
225+ 				await  ( ( BrowserCookiesProvider )  CookiesProvider ) . OpenAsync ( ) ; 
226+ 				ok  =  true ; 
227+ 			} 
228+ 			catch  ( Exception  e )  { 
229+ 				s_logger . LogError ( e ,  "Error reading cookies" ) ; 
230+ 				ReadCookies  =  ok ; 
231+ 				CookiesProvider . Dispose ( ) ; 
232+ 			} 
233+ 		} 
234+ 
235+ 		return  ok ; 
236+ 	} 
237+ 
238+ 	internal  async  ValueTask < bool >  TryLoadFlareSolverrAsync ( CancellationToken  token ) 
239+ 	{ 
240+ 		bool  ok  =  false ; 
241+ 
242+ 		if  ( this . FlareSolverr  &&  ! FlareSolverrClient . Value . IsInitialized )  { 
243+ 
244+ 			ok  =  await  FlareSolverrClient . Value . ApplyConfigAsync ( this ,  token ) ; 
245+ 
246+ 			if  ( ! ok )  { 
247+ 				Debugger . Break ( ) ; 
248+ 			} 
249+ 			else  { 
250+ 				// Ensure FlareSolverr 
251+ 
252+ 				try  { 
253+ 					var  idx  =  await  FlareSolverrClient . Value . Clearance . Solverr . GetIndexAsync ( ) ; 
254+ 				} 
255+ 				catch  ( Exception  e )  { 
256+ 					s_logger . LogError ( e ,  "FlareSolverr error" ) ; 
257+ 					this . FlareSolverr  =  ok ; 
258+ 					FlareSolverrClient . Value . Dispose ( ) ; 
259+ 				} 
260+ 			} 
261+ 		} 
262+ 
263+ 		return  ok ; 
264+ 	} 
209265
210266	private  bool  Set < T > ( T  s  =  default ,  [ CMN ]  string  name  =  default ) 
211267	{ 
0 commit comments