public override void Post(Event eventObj, bool async)
        {
            // remember client choice
            WasAsync = async;

            // testing is easier with non-async
            base.Post(eventObj, false);
        }
 public void LogClient_Post()
 {
     TestLogClient client = new TestLogClient();
     Event ev = new Event();
     ev.Text = "foo";
     client.Post(ev);
     client.AssertPostWasValid();
     Assert.IsTrue(client.HttpClient.Data["text"] == ev.Text);
 }
Exemple #3
0
 protected void PostEventBase(Event eventObj)
 {
     if (!string.IsNullOrEmpty(this.ApiKey) && !string.IsNullOrEmpty(this.LogKey))
     {
         string url = string.Format("http://{0}/{1}/logs/{2}/events", this.Server, this.Version, this.LogKey);
         string postStr = string.Format("{0}&apikey={1}", CreateEventQuerystring(eventObj), this.ApiKey);
         LogWebClient cli = new LogWebClient();
         cli.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
         try
         {
             cli.UploadData(new Uri(url), "POST", System.Text.Encoding.ASCII.GetBytes(postStr));
         }
         catch (Exception)
         {
             // ignore ex from post
         }
     }
 }
Exemple #4
0
        protected void MergeConfigurationWithEvent(Event eventObj)
        {
            // merge in default tags from config file
            if (!string.IsNullOrEmpty(Utility.Configuration.Tags))
            {
                eventObj.Tags.AddRange(Utility.Tags.TokenizeAndFormat(Utility.Configuration.Tags));
            }

            // overwrite default source from config file
            if (!string.IsNullOrEmpty(Utility.Configuration.Source))
            {
                eventObj.Source = Utility.Configuration.Source;
            }

            // overwrite default user from config file
            if (!string.IsNullOrEmpty(Utility.Configuration.User))
            {
                eventObj.User = Utility.Configuration.User;
            }
        }
Exemple #5
0
 protected string CreateEventQuerystring(Event eventObj)
 {
     string qs = "";
     AppendQuerystringNameValue("text", eventObj.Text, ref qs, 500);
     AppendQuerystringNameValue("link", eventObj.Link, ref qs, 200);
     AppendQuerystringNameValueList("tags", eventObj.Tags, ref qs, 200);
     AppendQuerystringNameValue("source", eventObj.Source, ref qs, 200);
     AppendQuerystringNameValue("user", eventObj.User, ref qs, 200);
     if (eventObj.DataType == DataType.html)
     {
         AppendQuerystringNameValue("data", "@html" + Environment.NewLine + eventObj.Data, ref qs, 5120);
     }
     else if (eventObj.DataType == DataType.json)
     {
         AppendQuerystringNameValue("data", "@json" + Environment.NewLine + eventObj.Data, ref qs, 5120);
     }
     else
     {
         AppendQuerystringNameValue("data", eventObj.Data, ref qs, 5120);
     }
     if (eventObj.Timestamp.HasValue)
     {
         AppendQuerystringNameValueDate("timestamp", eventObj.Timestamp, ref qs, 30);
     }
     if (eventObj.Value.HasValue)
     {
         AppendQuerystringNameValueObject("value", eventObj.Value.Value, ref qs, 30);
     }
     if (eventObj.Geo != null)
     {
         AppendQuerystringNameValueObject("geo", eventObj.Geo, ref qs, 30);
     }
     return qs;
 }
Exemple #6
0
        /// <summary>
        /// Posts the specified event to Loggr
        /// </summary>
        /// <param name="eventObj">A Loggr.Event that contains the event to send</param>
        /// <param name="async">A bool that specifies how the event should be posted. Typically an application will post asynchronously for best performance, but sometimes an event needs to be posted synchronously if the application needs to block until the event has completed posting</param>
        public void Post(Event eventObj, bool async)
        {
            // modify event based on configuration
            MergeConfigurationWithEvent(eventObj);

            // post async or sync
            if (async)
            {
                PostEventDelegate del = new PostEventDelegate(PostEventBase);
                del.BeginInvoke(eventObj, null, null);
            }
            else PostEventBase(eventObj);
        }
Exemple #7
0
 /// <summary>
 /// Posts the specified event to Loggr (posts asynchronously)
 /// </summary>
 /// <param name="eventObj">A Loggr.Event that contains the event to send</param>
 public void Post(Event eventObj)
 {
     this.Post(eventObj, true);
 }
 protected void PostEventBase(Event eventObj)
 {
     if (!string.IsNullOrEmpty(this.ApiKey) && !string.IsNullOrEmpty(this.LogKey))
     {
         string url = string.Format("{3}://{0}/{1}/logs/{2}/events", this.Server, this.Version, this.LogKey, this.Secure ? "https" : "http");
         string postStr = string.Format("{0}&apikey={1}", CreateEventQuerystring(eventObj), this.ApiKey);
         try
         {
             HttpClient.PostData(url, postStr);
         }
         catch (Exception)
         {
             // ignore ex from post
         }
     }
 }
        /// <summary>
        /// Posts the specified event to Loggr
        /// </summary>
        /// <param name="eventObj">A Loggr.Event that contains the event to send</param>
        /// <param name="async">A bool that specifies how the event should be posted. Typically an application will post asynchronously for best performance, but sometimes an event needs to be posted synchronously if the application needs to block until the event has completed posting</param>
        public virtual void Post(Event eventObj, bool async)
        {
            // make sure our event has at least a text field
            if (string.IsNullOrEmpty(eventObj.Text))
                throw new ApplicationException("Event cannot have an empty Text field");

            // modify event based on configuration
            MergeConfigurationWithEvent(eventObj);

            // post async or sync
            if (async)
            {
                PostEventDelegate del = new PostEventDelegate(PostEventBase);
                del.BeginInvoke(eventObj, null, null);
            }
            else PostEventBase(eventObj);
        }