public override void Send(string pCorrespondence, string pSignature) { Console.WriteLine("This is try #" + (currentRetry + 1)); try { CMessageEnvelope theEnvelope = new CMessageEnvelope(pCorrespondence, pSignature); lastMessageEnvelope = theEnvelope; WebRequest request = WebRequest.Create(string.Format("{0}{1}:{2}/{3}", scheme, serverAddress, port, webSubdomain)); request.Method = httpMethod; request.Timeout = (int)requestTimeout; string postData = theEnvelope.ToJSON(); byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = httpContentType; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); Console.WriteLine(responseFromServer); reader.Close(); dataStream.Close(); response.Close(); } catch (UriFormatException) { Console.WriteLine("UriFormatException"); } catch (System.Net.WebException exception) { if (exception.Status == WebExceptionStatus.Timeout) { OnTimeout(); } else { if (exception.Status == WebExceptionStatus.ConnectFailure) { OnConnectFailure(); } else { if (exception.Status == WebExceptionStatus.ProtocolError) { OnProtocolError(); } else { OnErrorDelivery(); } } } } }
public override string SendCommand(string pCorrespondence, string pSignature) { Console.WriteLine("[tilli]: CheckToken start"); try { CMessageEnvelope theEnvelope = new CMessageEnvelope(pCorrespondence, pSignature); lastMessageEnvelope = theEnvelope; WebRequest request = WebRequest.Create(string.Format("{0}{1}:{2}/{3}", scheme, serverAddress, port, webSubdomain)); //Console.WriteLine("[tilli]: After creating WebRequest.Create"); //if(httpMethod == null) // Console.WriteLine("[tilli]: httpMethod is null "); //Console.WriteLine("[tilli]: httpMethod " + httpMethod); request.Method = httpMethod; request.Timeout = (int)requestTimeout; //Console.WriteLine("[tilli]: Timeout " + request.Timeout); string postData = theEnvelope.ToJSON(); //string postData = JsonConvert.SerializeObject(new CMessageEnvelope("x", "signature")); //Console.WriteLine("[tilli]: postData\n" + postData + "\n\n"); byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = httpContentType; //request.ContentType = "application/json"; //Console.WriteLine("[tilli]: ContentType " + httpContentType); request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = request.GetResponse(); //Console.WriteLine(((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); //Console.WriteLine(responseFromServer); reader.Close(); dataStream.Close(); response.Close(); //Console.WriteLine("[tilli]: SendPing end"); return(responseFromServer); } catch (UriFormatException) { return(null); } catch (Exception e) { //Console.WriteLine("[tilli]: SendPing Exception"); //Console.WriteLine("[tilli]: SendPing Error: " + e.Message); return(null); } }
public override bool SendLogs(string pCorrespondence, string pSignature) { Console.WriteLine("[log2serv]:[Postman]:[SendLogs]:started"); try { CMessageEnvelope theEnvelope = new CMessageEnvelope(pCorrespondence, pSignature); lastMessageEnvelope = theEnvelope; WebRequest request = WebRequest.Create(string.Format("{0}{1}:{2}/{3}", scheme, serverAddress, port, webSubdomain)); request.Method = httpMethod; request.Timeout = (int)requestTimeout; string postData = theEnvelope.ToJSON(); //Console.WriteLine("[log2serv]:[Postman]:[SendLogs]:postData:\n\n" + postData + "\n\n"); byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = httpContentType; //request.ContentType = "application/json"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); Console.WriteLine(responseFromServer); reader.Close(); dataStream.Close(); response.Close(); Console.WriteLine("[log2serv]:[Postman]:[SendLogs]:finished-successfully"); return(true); } catch (Exception e) { //Console.BackgroundColor = ConsoleColor.DarkRed; Console.WriteLine("[log2serv]:[Postman]:[SendLogs]:error:\n" + e.Message + "\n"); //Console.BackgroundColor = ConsoleColor.Black; Console.WriteLine("[log2serv]:[Postman]:[SendLogs]:failed"); return(false); } }
public void MessageReturn(CMessageEnvelope pMessageEnvelope) { archiveService.ArchiveOfNewsFeed(pMessageEnvelope.message); }
public abstract bool ArchiveOfNewsFeed(CMessageEnvelope pMessageEnvelope);
public override bool ArchiveOfNewsFeed(CMessageEnvelope pMessageEnvelope) { return(ArchiveOfNewsFeed(pMessageEnvelope.message)); //throw new NotImplementedException("ArchiveOfNewsFeed"); }