Q42.HueApi.LocalHueClient.CheckConnection C# (CSharp) Method

CheckConnection() public method

public CheckConnection ( ) : Task
return Task
    public async Task<bool> CheckConnection()
    {
      HttpClient client = await GetHttpClient().ConfigureAwait(false);

      try
      {
        //Check if there is a hue bridge on the specified IP by checking the content of description.xml
        var result = await client.GetAsync(string.Format("http://{0}/description.xml", _ip)).ConfigureAwait(false);
        if (result.IsSuccessStatusCode)
        {
          string res = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
          if (!string.IsNullOrWhiteSpace(res))
          {
            if (!res.ToLower().Contains("philips hue bridge"))
              return false;
          }
        }
        else
        {
          return false;
        }
      }
      catch(Exception e)
      {
        return false;
      }

      try
      {
        //Check if app is registered
        var test = await this.GetBridgeAsync().ConfigureAwait(false);
      }
      catch 
      {
        return false;
      }
      
      return true;
    }
  }