Exemplo n.º 1
0
        /// <summary>
        /// Handles creating an Event object from a GitHub commit which will be streamed into Splunk.
        /// </summary>
        /// <param name="githubCommit">The individual GithubCommit object which holds the data for a commit.</param>
        /// <param name="eventWriter">The EventWriter for streaming events to Splunk.</param>
        /// <param name="owner">The GitHub repository owner's name.</param>
        /// <param name="repositoryName">The GitHub repository's name.</param>
        public async Task StreamCommit(GitHubCommit githubCommit, EventWriter eventWriter, string owner, string repositoryName)
        {
            string authorName = githubCommit.Commit.Author.Name;
            DateTime date = githubCommit.Commit.Author.Date;

            // Replace any newlines with a space
            string commitMessage = Regex.Replace(githubCommit.Commit.Message, "\\n|\\r", " ");
           
            dynamic json = new JObject();
            json.sha = githubCommit.Sha;
            json.api_url = githubCommit.Url;
            json.url = "http://github.com/" + owner + "/" + repositoryName + "/commit/" + githubCommit.Sha;
            json.message = commitMessage;
            json.author = authorName;
            json.date = date.ToString();

            var commitEvent = new Event();
            commitEvent.Stanza = repositoryName;
            commitEvent.SourceType = "github_commits";
            commitEvent.Time = date;
            commitEvent.Data = json.ToString(Formatting.None);

            await eventWriter.QueueEventForWriting(commitEvent);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add an event to this EventWriter's shared queue to be written as soon
 /// as possible. This method is thread-safe, so multiple threads can 
 /// concurrently queue events without interfering with each other.
 /// </summary>
 /// <param name="e">The Event to write.</param>
 public async Task QueueEventForWriting(Event e)
 {
     if (completed)
         throw new ObjectDisposedException("EventWriter already disposed.");
     if (eventQueueMonitor == null)
         // Don't start the eventQueueMonitor up until we actually want to write
         // events so we don't get empty <stream/> elements in cases where
         // we don't actually queue anything.
         eventQueueMonitor = Task.Run(() => WriteEventsFromQueue());
     await Task.Run(() => eventQueue.Add(e));
 }