private byte[] ConvertToBytes(CampfireMessage campfireMessage) { return Encoding.UTF8.GetBytes(campfireMessage.ToString()); }
private void Log(CampfireMessage campfireMessage) { if (campfireMessage is PasteMessage) { StringReader strReader = new StringReader(campfireMessage.ToString()); var firstLine = strReader.ReadLine(); var logString = string.Format("Posting message {0}", firstLine); _log.Debug(logString); } else { var logString = string.Format("Posting message {0}", campfireMessage); _log.Info(logString); } }
private string Post(CampfireMessage campfireMessage) { Log(campfireMessage); byte[] campfireMessageBytes = ConvertToBytes(campfireMessage); WebRequest request = CreateNewWebRequest(campfireMessageBytes); WriteDataToRequest(campfireMessageBytes, request); try { return GetCampfireWebResponse(request); } catch(WebException e) { return HandleError(e, string.Format("Problems connecting to Campfire: {0}", e)); } catch (Exception e) { return HandleError(e, string.Format("Internal Camp4Net error: {0}", e)); } }