Esempio n. 1
0
        public void Run()
        {
            try {
                //init request
                HttpWebRequest httpWebRequest = HttpWebRequest.Create(this.url) as HttpWebRequest;
                httpWebRequest.Method        = "POST";
                httpWebRequest.ContentLength = this.data.Length;
                httpWebRequest.ContentType   = "application/x-www-form-urlencoded";
                using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream())) {
                    sw.Write(this.data);
                }
                //get response
                HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
                using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream())) {
                    this.response = sr.ReadToEnd();
                }
            }
            catch (Exception) {
                this.response  = "{\"status\":\"failure\",\"message\":\"Http client error check connection\"}";
                this.has_error = true;
            }

            if (HttpClientWrapper.getNotificationReceiver() != null)
            {
                LogServiceResponse formated_response = this.parent.unpackData(this.response);
                HttpClientWrapper.getNotificationReceiver().LoggingClientCompleted(formated_response, this.has_error);
            }
        }
        public LogServiceResponse unpackData(String response)
        {
            LogServiceResponse formated_response = null;

            if (String.Equals(response, "404"))
            {
                formated_response = new LogServiceResponse("failure", "Missing required parameter");
                return(formated_response);
            }

            if (String.Equals(response, "401"))
            {
                formated_response = new LogServiceResponse("failure", "Authentication error, check your credentials");
                return(formated_response);
            }

            try {
                formated_response = JsonConvert.DeserializeObject <LogServiceResponse>(response);

                if (formated_response.Data != null)
                {
                    Log    log = null;
                    int    level;
                    String title;
                    String description;
                    String emiter;
                    Dictionary <String, String> custom_fields;
                    String stack_trace;

                    List <Object> log_list = new List <object>();
                    Newtonsoft.Json.Linq.JToken value;
                    foreach (System.Collections.Generic.ICollection <System.Collections.Generic.KeyValuePair <System.String, Newtonsoft.Json.Linq.JToken> > item in formated_response.Data)
                    {
                        var p = item.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value);
                        value       = (p.TryGetValue("level", out value)) ? value : null;
                        level       = Int16.Parse((String)value);
                        value       = (p.TryGetValue("title", out value)) ? value : null;
                        title       = (String)value;
                        value       = (p.TryGetValue("description", out value)) ? value : null;
                        description = (String)value;
                        value       = (p.TryGetValue("emiter_email", out value)) ? value : null;
                        emiter      = (String)value;
                        //we dont send back custome field for now
                        //value = (p.TryGetValue("custom_fields", out value)) ? value : null;
                        custom_fields = null;
                        value         = (p.TryGetValue("stack_trace", out value)) ? value : null;
                        stack_trace   = (String)value;

                        log = new Log(level, title, description, emiter, custom_fields, stack_trace);
                        log_list.Add(log);
                    }
                    formated_response.Data = log_list;
                }
            }catch (Exception) {}

            return(formated_response);
        }
Esempio n. 3
0
        public void Run()
        {
            try {
                using (WebClient client = new WebClient()) {
                    this.response = client.DownloadString(this.url);
                }
            }
            catch (Exception) {
                this.response  = "{\"status\":\"failure\",\"message\":\"Http client error check connection\"}";
                this.has_error = true;
            }

            if (HttpClientWrapper.getNotificationReceiver() != null)
            {
                LogServiceResponse formated_response = this.parent.unpackData(this.response);
                HttpClientWrapper.getNotificationReceiver().LoggingClientCompleted(formated_response, this.has_error);
            }
        }