You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// <returns>A task that represents the asynchronous operation. The task result contains a boolean indicating whether the connection was successful.</returns>
// check if the response is successful and contains a healthy status
139
+
// if the response is not successful, we assume the connection is not healthy
140
+
if(!response.IsSuccessStatusCode)
138
141
{
139
-
varstatus=awaitJsonSerializer.DeserializeAsync(
142
+
m_logger.LogWarning("Failed to connect to {ClientName}-client at {BaseAddress}, Reason: {ReasonPhrase}",ClientName,m_httpClient.BaseAddress,response.ReasonPhrase);
143
+
m_isConnected=null;// set connection state to null if we cannot connect
144
+
returnfalse;// connection failed
145
+
}
146
+
147
+
// Deserialize the response content to check the status
m_logger.LogWarning("Failed to connect to {ClientName}-client at {BaseAddress}, Reason: {String}",ClientName,m_httpClient.BaseAddress,"Server Status Check Failed");
157
+
m_isConnected=null;// set connection state to null if we cannot connect
158
+
returnfalse;// connection failed
147
159
}
148
160
149
-
if(m_isConnected==null||(m_isConnected!=null&&m_isConnected!=blnIsConnected))// first time after connection change or when connection is lost
161
+
// If the connection is already healthy, we can return true immediately
162
+
if(m_isConnected==true)
150
163
{
151
-
if(!blnIsConnected)
152
-
{
153
-
m_logger.LogWarning("Failed to connect to {ClientName}-client at {BaseAddress}, Reason: {ReasonPhrase}",ClientName,m_httpClient.BaseAddress,response.ReasonPhrase);
m_logger.LogInformation("Successfully connected to {ClientName}-client: {ProductName} {ProductVersion} on {BaseAddress}",ClientName,prodInfo?.ProductName,prodInfo?.ProductVersion,m_httpClient.BaseAddress);
// If we do not have valid credentials, we assume the connection is not healthy
182
+
if(m_hasValidCredentials!=true)
183
+
{
184
+
m_isConnected=null;// set connection state to null if we cannot connect or credentials are invalid
185
+
m_logger.LogWarning("Connection to {ClientName}-client at {BaseAddress} failed because credentials are invalid",ClientName,m_httpClient.BaseAddress);
186
+
returnfalse;
187
+
}
188
+
189
+
m_logger.LogInformation("Successfully connected to {ClientName}-client: {ProductName} {ProductVersion} on {BaseAddress}",ClientName,prodInfo?.ProductName,prodInfo?.ProductVersion,m_httpClient.BaseAddress);
190
+
191
+
m_isConnected=true;// set connection state to true if we have a valid product info and credentials
192
+
returnm_isConnected.Value;// return true if we have a valid connection
193
+
163
194
}
164
195
catch(HttpRequestExceptionhttpEx)
165
196
{
166
197
if(m_isConnected==null||m_isConnected==true)// first time after connection change or when connection is lost
167
198
m_logger.LogWarning(httpEx,"Failed to connect to {ClientName}-client at {BaseAddress}",ClientName,m_httpClient.BaseAddress);
0 commit comments