Beispiel #1
0
        public bool Send(JsonPacket jp, DSN dsn)
        {
            //try
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(dsn.SentryURI);
                request.Method      = "POST";
                request.Accept      = "application/json";
                request.ContentType = "application/json; charset=utf-8";
                request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
                request.UserAgent = "RavenSharp/1.0";
                request.Timeout   = 2000;

                //Console.WriteLine("Header: " + PacketBuilder.CreateAuthenticationHeader(dsn));
                //Console.WriteLine("Packet: " + jp.Serialize());

                // Write the messagebody.
                using (Stream s = request.GetRequestStream())
                {
                    string data = jp.Serialize();
                    if (LogScrubber != null)
                    {
                        data = LogScrubber.Scrub(data);
                    }
                    byte[] byteArray = Encoding.UTF8.GetBytes(data);

                    s.Write(byteArray, 0, byteArray.Length);
                }

                using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
                {
                }
            }            /*
                          * catch (WebException e)
                          * {
                          *     Console.ForegroundColor = ConsoleColor.Red;
                          *     Console.Write("[ERROR] ");
                          *     Console.ForegroundColor = ConsoleColor.Gray;
                          *     Console.WriteLine(e.Message);
                          *
                          *     if (e.Response != null)
                          *     {
                          *             string messageBody = String.Empty;
                          *             using (StreamReader sw = new StreamReader(e.Response.GetResponseStream()))
                          *             {
                          *                     messageBody = sw.ReadToEnd();
                          *             }
                          *             Console.WriteLine("[MESSAGE BODY] " + messageBody);
                          *     }
                          *
                          *     return false;
                          * }*/

            return(true);
        }
Beispiel #2
0
        public bool Send(JsonPacket packet, DSN dsn)
        {
            packet.Logger = Logger;

            try {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(dsn.SentryURI);
                request.Method      = "POST";
                request.Accept      = "application/json";
                request.ContentType = "application/json; charset=utf-8";
                request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
                request.UserAgent = "RavenSharp/1.0";

                Debug.Log("Header: " + PacketBuilder.CreateAuthenticationHeader(dsn));
                Debug.Log("Packet: " + packet.Serialize());

                // Write the messagebody.
                using (Stream s = request.GetRequestStream()) {
                    using (StreamWriter sw = new StreamWriter(s)) {
                        // Compress and encode.
                        //string data = Utilities.GzipUtil.CompressEncode(packet.Serialize());
                        //Console.WriteLine("Writing: " + data);
                        // Write to the JSON script when ready.
                        string data = packet.Serialize();
                        if (LogScrubber != null)
                        {
                            data = LogScrubber.Scrub(data);
                        }

                        sw.Write(data);
                        // Close streams.
                        sw.Flush();
                        sw.Close();
                    }
                    s.Flush();
                    s.Close();
                }

                using (HttpWebResponse wr = (HttpWebResponse)request.GetResponse())
                {
                    wr.Close();
                }
            } catch (WebException e) {
                /*
                 * Console.ForegroundColor = ConsoleColor.Red;
                 * Console.Write("[ERROR] ");
                 * Console.ForegroundColor = ConsoleColor.Gray;
                 */
                Debug.Log("[ERROR] " + e.Message);

                string messageBody = String.Empty;
                if (e.Response != null)
                {
                    using (StreamReader sw = new StreamReader(e.Response.GetResponseStream()))
                    {
                        messageBody = sw.ReadToEnd();
                    }
                    Debug.Log("[MESSAGE BODY] " + messageBody);
                }

                return(false);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Sends the specified packet to Sentry.
        /// </summary>
        /// <param name="packet">The packet to send.</param>
        /// <param name="dsn">The Data Source Name in Sentry.</param>
        /// <returns>
        /// The <see cref="JsonPacket.EventID"/> of the successfully captured JSON packet, or <c>null</c> if it fails.
        /// </returns>
        protected virtual string Send(JsonPacket packet, Dsn dsn)
        {
            packet.Logger = Logger;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(dsn.SentryUri);
                request.Method = "POST";
                request.Accept = "application/json";
                request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

                // Added to disable self signed certificate
                ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);

                request.UserAgent = PacketBuilder.UserAgent;

                if (Compression)
                {
                    request.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip");
                    request.AutomaticDecompression = DecompressionMethods.Deflate;
                    request.ContentType            = "application/octet-stream";
                }
                else
                {
                    request.ContentType = "application/json; charset=utf-8";
                }

                /*string data = packet.ToString(Formatting.Indented);
                 * Console.WriteLine(data);*/

                string data = packet.ToString(Formatting.None);

                if (LogScrubber != null)
                {
                    data = LogScrubber.Scrub(data);
                }

                // Write the messagebody.
                using (Stream s = request.GetRequestStream())
                {
                    if (Compression)
                    {
                        GzipUtil.Write(data, s);
                    }
                    else
                    {
                        using (StreamWriter sw = new StreamWriter(s))
                            sw.Write(data);
                    }
                }

                using (HttpWebResponse wr = (HttpWebResponse)request.GetResponse())
                    using (Stream responseStream = wr.GetResponseStream())
                    {
                        if (responseStream == null)
                        {
                            return(null);
                        }

                        using (StreamReader sr = new StreamReader(responseStream))
                        {
                            string content  = sr.ReadToEnd();
                            var    response = JsonConvert.DeserializeObject <dynamic>(content);
                            return(response.id);
                        }
                    }
            }
            catch (Exception exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("[ERROR] ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(exception);

                WebException webException = exception as WebException;
                if (webException != null && webException.Response != null)
                {
                    string messageBody;
                    using (Stream stream = webException.Response.GetResponseStream())
                    {
                        if (stream == null)
                        {
                            return(null);
                        }

                        using (StreamReader sw = new StreamReader(stream))
                            messageBody = sw.ReadToEnd();
                    }

                    Console.WriteLine("[MESSAGE BODY] " + messageBody);
                }
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Sends the specified packet to Sentry.
        /// </summary>
        /// <param name="packet">The packet to send.</param>
        /// <param name="dsn">The Data Source Name in Sentry.</param>
        /// <returns>
        /// The <see cref="JsonPacket.EventID"/> of the successfully captured JSON packet, or <c>null</c> if it fails.
        /// </returns>
        protected virtual string Send(JsonPacket packet, Dsn dsn)
        {
            packet.Logger = Logger;

            var request = (HttpWebRequest)WebRequest.Create(dsn.SentryUri);

            request.Timeout          = (int)Timeout.TotalMilliseconds;
            request.ReadWriteTimeout = (int)Timeout.TotalMilliseconds;
            request.Method           = "POST";
            request.Accept           = "application/json";
            request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
            request.UserAgent = PacketBuilder.UserAgent;

            if (Compression)
            {
                request.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip");
                request.AutomaticDecompression = DecompressionMethods.Deflate;
                request.ContentType            = "application/octet-stream";
            }
            else
            {
                request.ContentType = "application/json; charset=utf-8";
            }

            /*string data = packet.ToString(Formatting.Indented);
             * Console.WriteLine(data);*/

            string data = packet.ToString(Formatting.None);

            if (LogScrubber != null)
            {
                data = LogScrubber.Scrub(data);
            }

            // Write the messagebody.
            using (Stream s = request.GetRequestStream())
            {
                if (Compression)
                {
                    GzipUtil.Write(data, s);
                }
                else
                {
                    using (StreamWriter sw = new StreamWriter(s))
                        sw.Write(data);
                }
            }

            using (HttpWebResponse wr = (HttpWebResponse)request.GetResponse())
                using (Stream responseStream = wr.GetResponseStream())
                {
                    if (responseStream == null)
                    {
                        return(null);
                    }

                    using (StreamReader sr = new StreamReader(responseStream))
                    {
                        string content  = sr.ReadToEnd();
                        var    response = JsonConvert.DeserializeObject <dynamic>(content);
                        return(response.id);
                    }
                }
        }
Beispiel #5
0
        /// <summary>Sends the specified packet to Sentry.</summary>
        /// <param name="packet">The packet to send.</param>
        /// <returns>
        /// The <see cref="JsonPacket.EventID" /> of the successfully captured JSON packet, or <c>null</c> if it fails.
        /// </returns>
        protected virtual string Send(JsonPacket packet)
        {
            try
            {
                // TODO(dcramer): moving this out of Send makes it easier to test the final
                // generated packet
                packet = PreparePacket(packet);

                var request = (HttpWebRequest)WebRequest.Create(this.currentDsn.SentryUri);
                request.Timeout          = (int)Timeout.TotalMilliseconds;
                request.ReadWriteTimeout = (int)Timeout.TotalMilliseconds;
                request.Method           = "POST";
                request.Accept           = "application/json";
                request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(this.currentDsn));
                request.UserAgent = PacketBuilder.UserAgent;

                if (Compression)
                {
                    request.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip");
                    request.AutomaticDecompression = DecompressionMethods.Deflate;
                    request.ContentType            = "application/octet-stream";
                }
                else
                {
                    request.ContentType = "application/json; charset=utf-8";
                }

                /*string data = packet.ToString(Formatting.Indented);
                 *  Console.WriteLine(data);*/

                var data = packet.ToString(Formatting.None);

                if (LogScrubber != null)
                {
                    data = LogScrubber.Scrub(data);
                }

                // Write the messagebody.
                using (var s = request.GetRequestStream())
                {
                    if (Compression)
                    {
                        GzipUtil.Write(data, s);
                    }
                    else
                    {
                        using (var sw = new StreamWriter(s))
                        {
                            sw.Write(data);
                        }
                    }
                }

                using (var wr = (HttpWebResponse)request.GetResponse())
                {
                    using (var responseStream = wr.GetResponseStream())
                    {
                        if (responseStream == null)
                        {
                            return(null);
                        }

                        using (var sr = new StreamReader(responseStream))
                        {
                            var content  = sr.ReadToEnd();
                            var response = JsonConvert.DeserializeObject <dynamic>(content);
                            return(response.id);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }