示例#1
0
 public bool TryConnect(out ConnectionStatus status)
 {
     try
     {
         status = this.GetNodeInfo();
         return this.IsValid;
     }
     catch (Exception e)
     {
         status = new ConnectionStatus(e);
     }
     return false;
 }
示例#2
0
 private ConnectionStatus DoSynchronousRequest(HttpWebRequest request, string data = null)
 {
     request.Timeout = this._ConnectionSettings.TimeOut;
     Stream postStream = null;
     WebResponse response = null;
     try
     {
         if (!data.IsNullOrEmpty())
         {
             byte[] buffer = Encoding.UTF8.GetBytes(data);
             request.ContentLength = buffer.Length;
             postStream = request.GetRequestStream();
             postStream.Write(buffer, 0, buffer.Length);
             postStream.Close();
         }
         response = request.GetResponse();
         var result = new StreamReader(response.GetResponseStream()).ReadToEnd();
         response.Close();
         return new ConnectionStatus(result);
     }
     catch (WebException e)
     {
         string result;
         var error = this.GetConnectionErrorFromWebException(e, out result);
         var status = new ConnectionStatus(error);
         status.Result = result;
         return status;
     }
     catch (Exception e) { return new ConnectionStatus(new ConnectionError(e)); }
     finally
     {
         if (postStream != null)
             postStream.Close();
         if (response != null)
             response.Close();
     }
 }