public void PostAlert(string name, Specie specie, Role role)
        {
            try
            {
                var data = new SkywalkerAlert()
                {
                    Timestamp = DateTime.Now,
                    Name      = name,
                    Specie    = specie,
                    Role      = role,
                    ClientIP  =
                        HttpContext.Current.Request.UserHostName + " (" + HttpContext.Current.Request.UserHostAddress +
                        ")",
                    BrowserInfo = HttpContext.Current.Request.UserAgent
                };

                var client = new HttpClient();
                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["DeathstarServoceBaseUrl"]);

                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                var response = client.PostAsJsonAsync(API_POST_SKYWALKERALERT, data).Result;
                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception("Couldn't connect with the Deathstar service!");
                }
            }
            catch (Exception ex)
            {
                BaseException.HandleException(ex);
            }
        }
 // POST api/skywalkeralert
 /// <summary>
 /// WebMethod that registers any attempt to register a citizen with Skywalker string on it...
 /// </summary>
 /// <param name="entity">Information entered by the user, ip, browser, etc..</param>
 /// <returns></returns>
 public JsonResult Post([FromBody] SkywalkerAlert entity)
 {
     Writer.Current.Write(entity);
     return(new JsonResult()
     {
         Data = new { ok = true }, JsonRequestBehavior = JsonRequestBehavior.DenyGet
     });
 }
        public void Write(SkywalkerAlert alert)
        {
            var output = String.Format("{0:G} | {1} | {2} | {3} | {4} | {5}",
                                       alert.Timestamp,
                                       alert.Name,
                                       (alert.Specie ?? new Specie()).Description,
                                       (alert.Role ?? new Role()).Description,
                                       alert.ClientIP,
                                       alert.BrowserInfo);

            using (StreamWriter w = File.AppendText(FileName))
                w.WriteLine(output);
        }
 // POST api/skywalkeralert
 public void Post([FromBody] SkywalkerAlert entity)
 {
 }
示例#5
0
 public void Write(SkywalkerAlert alert)
 {
     using (StreamWriter w = File.AppendText(FileName))
         w.WriteLine(alert.ToString());
 }