protected bool DescendsFrom(TfsGitCommit commit, byte[] ancestorCommitId, TeamFoundationRequestContext requestContext) { var comparer = new CommitHashEqualityComparer(); // classic breadth first search in graph var queue = new List <TfsGitCommit> { commit }; var visited = new HashSet <TfsGitCommit>(comparer); visited.Add(commit); while (queue.Any()) { // Get current node, and remove it from the to-do-list var currentCommit = queue.First(); queue.RemoveAt(0); // ancestor found? if (currentCommit.ObjectId.SequenceEqual(ancestorCommitId)) { return(true); } // Now see, if the node has any parents to handle foreach (var parent in currentCommit.GetParents(requestContext)) { if (!visited.Contains(parent)) { queue.Add(parent); visited.Add(parent); } //if } //for } //while return(false); }
private static CommitRow CreateCommitRow(IVssRequestContext requestContext, ITeamFoundationGitCommitService commitService, ITfsGitRepository repository, TfsGitCommit gitCommit, CommitRowType rowType, PushNotification pushNotification, Dictionary <Sha1Id, List <GitRef> > refLookup) { var commitManifest = commitService.GetCommitManifest(requestContext, repository, gitCommit.ObjectId); string repoUri = repository.GetRepositoryUri(); var commitRow = new CommitRow() { CommitId = gitCommit.ObjectId, Type = rowType, CommitUri = repoUri + "/commit/" + gitCommit.ObjectId.ToHexString(), AuthorTime = gitCommit.GetAuthor().LocalTime, Author = gitCommit.GetAuthor().NameAndEmail, AuthorName = gitCommit.GetAuthor().Name, AuthorEmail = gitCommit.GetAuthor().Email, Comment = gitCommit.GetComment(), ChangeCounts = commitManifest.ChangeCounts }; List <GitRef> refs; refLookup.TryGetValue(gitCommit.ObjectId, out refs); commitRow.Refs = refs; return(commitRow); }
private static CommitRow CreateCommitRow(TeamFoundationRequestContext requestContext, TeamFoundationGitCommitService commitService, TfsGitCommit gitCommit, CommitRowType rowType, PushNotification pushNotification, Dictionary <byte[], List <string> > refNames) { var commitManifest = commitService.GetCommitManifest(requestContext, gitCommit.Repository, gitCommit.ObjectId); string repoUri = gitCommit.Repository.GetRepositoryUri(requestContext); var commitRow = new CommitRow() { CommitId = gitCommit.ObjectId, Type = rowType, CommitUri = repoUri + "/commit/" + gitCommit.ObjectId.ToHexString(), AuthorTime = gitCommit.GetLocalAuthorTime(requestContext), Author = gitCommit.GetAuthor(requestContext), AuthorName = gitCommit.GetAuthorName(requestContext), AuthorEmail = gitCommit.GetAuthorEmail(requestContext), Comment = gitCommit.GetComment(requestContext), ChangeCounts = commitManifest.ChangeCounts }; List <string> refs = null; refNames.TryGetValue(gitCommit.ObjectId, out refs); commitRow.RefNames = refs; return(commitRow); }
public static bool IsForceRequired(this PushNotification pushNotification, TeamFoundationRequestContext requestContext, TfsGitRepository repository) { foreach (var refUpdateResult in pushNotification.RefUpdateResults.Where(r => r.Succeeded)) { // Don't bother with new or deleted refs if (refUpdateResult.OldObjectId.IsEmpty || refUpdateResult.NewObjectId.IsEmpty) { continue; } TfsGitObject gitObject = repository.LookupObject(requestContext, refUpdateResult.NewObjectId); if (gitObject.ObjectType != GitObjectType.Commit) { continue; } TfsGitCommit gitCommit = (TfsGitCommit)gitObject; if (!gitCommit.IsDescendantOf(requestContext, refUpdateResult.OldObjectId)) { return(true); } } return(false); }
protected bool RequiresForcePush(PushNotification pushNotification, TeamFoundationRequestContext requestContext, TfsGitRepository repository) { foreach (var refUpdateResult in pushNotification.RefUpdateResults) { // new or deleted refs have id==0 if (IsNullHash(refUpdateResult.OldObjectId) || IsNullHash(refUpdateResult.NewObjectId)) { continue; } TfsGitCommit gitCommit = repository.LookupObject(requestContext, refUpdateResult.NewObjectId) as TfsGitCommit; if (gitCommit == null) { continue; } if (!DescendsFrom(gitCommit, refUpdateResult.OldObjectId, requestContext)) { // aha! no common node return(true); } } return(false); }
public static bool IsDescendantOf(this TfsGitCommit commit, TeamFoundationRequestContext requestContext, Sha1Id ancestorId) { Queue <TfsGitCommit> q = new Queue <TfsGitCommit>(); HashSet <Sha1Id> visited = new HashSet <Sha1Id>(); q.Enqueue(commit); while (q.Count > 0) { TfsGitCommit current = q.Dequeue(); if (!visited.Add(current.ObjectId)) { continue; } if (current.ObjectId.Equals(ancestorId)) { return(true); } foreach (var c in current.GetParents(requestContext)) { q.Enqueue(c); } } return(false); }
long GetCommitSize(TfsGitCommit gitCommit, TeamFoundationRequestContext requestContext) { var tree = gitCommit.GetTree(requestContext); if (tree == null) return 0; long totalSize = tree.GetBlobs(requestContext).Aggregate( 0L, (size, blob) => size + blob.GetLength(requestContext)); return totalSize; }
public override Validation CheckRule(TeamFoundationRequestContext requestContext, PushNotification pushNotification, TfsGitRepository repository) { var result = new Validation(); long totalSize = 0; foreach (var commitId in pushNotification.IncludedCommits) { TfsGitCommit gitCommit = repository.LookupObject(requestContext, commitId) as TfsGitCommit; if (gitCommit == null) { continue; } long size = GetCommitSize(gitCommit, requestContext); totalSize += size; }//for // convert to MB totalSize = totalSize / (1024 * 1024); if (totalSize < this.Megabytes) { Logger.Log(string.Format( "Push request is {0} MB, below the {1} MB limit." , totalSize, this.Megabytes , "Limit Size")); } else { if (IsUserExempted(requestContext, pushNotification)) { Logger.Log(string.Format( "Push request is {0} MB, above or equal to the {1} MB limit, but user is exempted." , totalSize, this.Megabytes , "Limit Size")); } else { result.Fails = true; result.ReasonCode = 2; result.ReasonMessage = string.Format( "Push request is {0} MB, above or equal to the {1} MB limit: refused." , totalSize, this.Megabytes); } }//if return(result); }
long GetCommitSize(TfsGitCommit gitCommit, TeamFoundationRequestContext requestContext) { var tree = gitCommit.GetTree(requestContext); if (tree == null) { return(0); } long totalSize = tree.GetBlobs(requestContext).Aggregate( 0L, (size, blob) => size + blob.GetLength(requestContext)); return(totalSize); }
public override Validation CheckRule(TeamFoundationRequestContext requestContext, PushNotification pushNotification, TfsGitRepository repository) { var result = new Validation(); foreach (var refUpdateResult in pushNotification.RefUpdateResults) { // new or deleted refs have id==0 if (IsNullHash(refUpdateResult.OldObjectId) || IsNullHash(refUpdateResult.NewObjectId)) { continue; } TfsGitCommit gitCommit = repository.LookupObject(requestContext, refUpdateResult.NewObjectId) as TfsGitCommit; if (gitCommit == null) { continue; } string authorEmail = gitCommit.GetAuthorEmail(requestContext); if (!AuthorEmail.Any(pattern => Regex.IsMatch(authorEmail, pattern))) { result.Fails = true; result.ReasonCode = 2; result.ReasonMessage = string.Format( "Author email '{0}' on commit {1} is not admitted", authorEmail, gitCommit.ObjectId.DisplayHash()); break; } string committerEmail = gitCommit.GetCommitterEmail(requestContext); if (!CommitterEmail.Any(pattern => Regex.IsMatch(committerEmail, pattern))) { result.Fails = true; result.ReasonCode = 3; result.ReasonMessage = string.Format( "Committer email '{0}' on commit {1} is not admitted", authorEmail, gitCommit.ObjectId.DisplayHash()); break; } //if } //for changes return(result); }
private string CommitToString(TeamFoundationRequestContext requestContext, TfsGitCommit gitCommit, string action, PushNotification pushNotification, Dictionary <byte[], List <string> > refNames) { DateTime authorTime = gitCommit.GetLocalAuthorTime(requestContext); string authorName = gitCommit.GetAuthor(requestContext); string comment = gitCommit.GetComment(requestContext); StringBuilder sb = new StringBuilder(); List <string> names = null; if (refNames.TryGetValue(gitCommit.ObjectId, out names)) { sb.AppendFormat("{0} ", String.Join("", names)); } sb.AppendFormat("{0} {1} {2} {3} {4}", action, gitCommit.ObjectId.ToShortHexString(), authorTime.ToString(), authorName, comment.Truncate(COMMENT_MAX_LENGTH)); return(sb.ToString()); }
protected override IEnumerable <INotification> CreateNotifications(IVssRequestContext requestContext, PushNotification pushNotification, int maxLines) { var repositoryService = requestContext.GetService <ITeamFoundationGitRepositoryService>(); var commonService = requestContext.GetService <CommonStructureService>(); var commitService = requestContext.GetService <ITeamFoundationGitCommitService>(); var identityService = requestContext.GetService <TeamFoundationIdentityService>(); var identity = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, pushNotification.Pusher.Identifier); var teamNames = GetUserTeamsByProjectUri(requestContext, pushNotification.TeamProjectUri, pushNotification.Pusher); using (ITfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, pushNotification.RepositoryId)) { var pushRow = new PushRow() { UniqueName = pushNotification.AuthenticatedUserName, DisplayName = identity.DisplayName, RepoName = pushNotification.RepositoryName, RepoUri = repository.GetRepositoryUri(), ProjectName = commonService.GetProject(requestContext, pushNotification.TeamProjectUri).Name, IsForcePush = Settings.IdentifyForcePush && pushNotification.IsForceRequired(requestContext, repository) }; var notification = new GitPushNotification(requestContext.ServiceHost.Name, pushRow.ProjectName, pushRow.RepoName, pushNotification.AuthenticatedUserName, teamNames, pushNotification.RefUpdateResults.Where(r => r.Succeeded).Select(r => new GitRef(r))); notification.Add(pushRow); notification.TotalLineCount++; var refLookup = new Dictionary <Sha1Id, List <GitRef> >(); var deletedRefs = new List <GitRef>(); var oldCommits = new HashSet <TfsGitCommit>(new TfsGitObjectEqualityComparer()); var unknowns = new List <TfsGitRefUpdateResult>(); // Associate refs (branch, lightweight and annotated tag) with corresponding commit foreach (var refUpdateResult in pushNotification.RefUpdateResults.Where(r => r.Succeeded)) { var newObjectId = refUpdateResult.NewObjectId; TfsGitCommit commit = null; if (newObjectId.IsEmpty) { deletedRefs.Add(new GitRef(refUpdateResult)); continue; } TfsGitObject gitObject = repository.LookupObject(newObjectId); if (gitObject.ObjectType == WebApi.GitObjectType.Commit) { commit = gitObject as TfsGitCommit; } else if (gitObject.ObjectType == WebApi.GitObjectType.Tag) { var tag = (TfsGitTag)gitObject; commit = tag.TryResolveToCommit(); } if (commit != null) { List <GitRef> refs; if (!refLookup.TryGetValue(commit.ObjectId, out refs)) { refs = new List <GitRef>(); refLookup.Add(commit.ObjectId, refs); } refs.Add(new GitRef(refUpdateResult)); if (!pushNotification.IncludedCommits.Contains(commit.ObjectId)) { oldCommits.Add(commit); } } else { unknowns.Add(refUpdateResult); } } notification.TotalLineCount += pushNotification.IncludedCommits.Count() + oldCommits.Count + unknowns.Count; // Add new commits with refs var pushCommits = pushNotification.IncludedCommits.Select(commitId => (TfsGitCommit)repository.LookupObject(commitId)).OrderByDescending(c => c.GetCommitter().Time); foreach (var commit in pushCommits.TakeWhile(c => notification.Count < maxLines)) { notification.Add(CreateCommitRow(requestContext, commitService, repository, commit, CommitRowType.Commit, pushNotification, refLookup)); } // Add updated refs to old commits foreach (TfsGitCommit gitCommit in oldCommits.OrderByDescending(c => c.GetCommitter().Time).TakeWhile(c => notification.Count < maxLines)) { notification.Add(CreateCommitRow(requestContext, commitService, repository, gitCommit, CommitRowType.RefUpdate, pushNotification, refLookup)); } // Add deleted refs if any if (deletedRefs.Any() && notification.Count < maxLines) { notification.Add(new DeleteRow() { Refs = deletedRefs }); } // Add "unknown" refs foreach (var refUpdateResult in unknowns.TakeWhile(c => notification.Count < maxLines)) { var newObjectId = refUpdateResult.NewObjectId; TfsGitObject gitObject = repository.LookupObject(newObjectId); notification.Add(new RefUpdateRow() { NewObjectId = newObjectId, ObjectType = gitObject.ObjectType, Refs = new[] { new GitRef(refUpdateResult) } }); } yield return(notification); } }
protected override IEnumerable <INotification> CreateNotifications(TeamFoundationRequestContext requestContext, PushNotification pushNotification, int maxLines) { var repositoryService = requestContext.GetService <TeamFoundationGitRepositoryService>(); var commonService = requestContext.GetService <CommonStructureService>(); var commitService = requestContext.GetService <TeamFoundationGitCommitService>(); var identityService = requestContext.GetService <TeamFoundationIdentityService>(); var identity = identityService.ReadIdentity(requestContext, IdentitySearchFactor.Identifier, pushNotification.Pusher.Identifier); var teamNames = GetUserTeamsByProjectUri(requestContext, pushNotification.TeamProjectUri, pushNotification.Pusher); using (TfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, pushNotification.RepositoryId)) { var pushRow = new PushRow() { UniqueName = pushNotification.AuthenticatedUserName, DisplayName = identity.DisplayName, RepoName = pushNotification.RepositoryName, RepoUri = repository.GetRepositoryUri(requestContext), ProjectName = commonService.GetProject(requestContext, pushNotification.TeamProjectUri).Name, IsForcePush = settings.IdentifyForcePush ? pushNotification.IsForceRequired(requestContext, repository) : false }; var notification = new GitPushNotification(requestContext.ServiceHost.Name, pushRow.ProjectName, pushRow.RepoName, teamNames); notification.Add(pushRow); notification.TotalLineCount++; var refNames = new Dictionary <byte[], List <string> >(new ByteArrayComparer()); var oldCommits = new HashSet <byte[]>(new ByteArrayComparer()); var unknowns = new List <RefUpdateResultGroup>(); // Associate refs (branch, lightweight and annotated tag) with corresponding commit var refUpdateResultGroups = pushNotification.RefUpdateResults .Where(r => r.Succeeded) .GroupBy(r => r.NewObjectId, (key, items) => new RefUpdateResultGroup(key, items), new ByteArrayComparer()); foreach (var refUpdateResultGroup in refUpdateResultGroups) { byte[] newObjectId = refUpdateResultGroup.NewObjectId; byte[] commitId = null; if (newObjectId.IsZero()) { commitId = newObjectId; } else { TfsGitObject gitObject = repository.LookupObject(requestContext, newObjectId); if (gitObject.ObjectType == TfsGitObjectType.Commit) { commitId = newObjectId; } else if (gitObject.ObjectType == TfsGitObjectType.Tag) { var tag = (TfsGitTag)gitObject; var commit = tag.TryResolveToCommit(requestContext); if (commit != null) { commitId = commit.ObjectId; } } } if (commitId != null) { List <string> names; if (!refNames.TryGetValue(commitId, out names)) { names = new List <string>(); refNames.Add(commitId, names); } names.AddRange(RefsToStrings(refUpdateResultGroup.RefUpdateResults)); if (commitId.IsZero() || !pushNotification.IncludedCommits.Any(r => r.SequenceEqual(commitId))) { oldCommits.Add(commitId); } } else { unknowns.Add(refUpdateResultGroup); } } notification.TotalLineCount += pushNotification.IncludedCommits.Count() + oldCommits.Count + unknowns.Count; // Add new commits with refs foreach (byte[] commitId in pushNotification.IncludedCommits.TakeWhile(c => notification.Count < maxLines)) { TfsGitCommit gitCommit = (TfsGitCommit)repository.LookupObject(requestContext, commitId); notification.Add(CreateCommitRow(requestContext, commitService, gitCommit, CommitRowType.Commit, pushNotification, refNames)); } // Add updated refs to old commits foreach (byte[] commitId in oldCommits.TakeWhile(c => notification.Count < maxLines)) { if (commitId.IsZero()) { notification.Add(new DeleteRow() { RefNames = refNames[commitId] }); } else { TfsGitCommit gitCommit = (TfsGitCommit)repository.LookupObject(requestContext, commitId); notification.Add(CreateCommitRow(requestContext, commitService, gitCommit, CommitRowType.RefUpdate, pushNotification, refNames)); } } // Add "unknown" refs foreach (var refUpdateResultGroup in unknowns.TakeWhile(c => notification.Count < maxLines)) { byte[] newObjectId = refUpdateResultGroup.NewObjectId; TfsGitObject gitObject = repository.LookupObject(requestContext, newObjectId); notification.Add(new RefUpdateRow() { NewObjectId = newObjectId, ObjectType = gitObject.ObjectType, RefNames = RefsToStrings(refUpdateResultGroup.RefUpdateResults) }); } yield return(notification); } }
protected override PolicyEvaluationResult EvaluateInternal(IVssRequestContext requestContext, PushNotification push) { var repositoryService = requestContext.GetService <ITeamFoundationGitRepositoryService>(); var newBranches = push.RefUpdateResults.Where(r => r.OldObjectId == Sha1Id.Empty && r.Name.StartsWith(Constants.BranchPrefix)); var branch = newBranches.SingleOrDefault(b => b.Name == Constants.BranchPrefix + "master"); if (branch != null) { using (ITfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, push.RepositoryId)) { TfsGitCommit commit = (TfsGitCommit)repository.LookupObject(branch.NewObjectId); if (commit != null) { var tree = commit.GetTree(); var treeEntries = tree.GetTreeEntries(); if (treeEntries.Any()) { bool includesGitignore = false; bool includesGitattributes = false; foreach (var entry in treeEntries) { if (entry.ObjectType == GitObjectType.Blob && entry.Name.Equals(".gitignore", StringComparison.OrdinalIgnoreCase)) { includesGitignore = true; } if (entry.ObjectType == GitObjectType.Blob && entry.Name.Equals(".gitattributes", StringComparison.OrdinalIgnoreCase)) { using (var reader = new StreamReader(entry.Object.GetContent())) { var gitattributesContents = reader.ReadToEnd(); // Make sure .gitattributes file has a '* text=auto' line for eol normalization if (!Regex.IsMatch(gitattributesContents, @"^\*\s+text=auto\s*$", RegexOptions.Multiline)) { Logger.Log("pushNotification:", push); var statusMessage = $".gitattributes is missing '* text=auto'. See {Settings.DocsBaseUrl}/guidelines/scm/git-conventions/#mandatory-files."; Logger.Log(statusMessage); return(new PolicyEvaluationResult(false, push.Pusher, statusMessage)); } includesGitattributes = true; } } } if (!includesGitignore || !includesGitattributes) { Logger.Log("pushNotification:", push); var statusMessage = $"Mandatory files missing. See {Settings.DocsBaseUrl}/guidelines/scm/git-conventions/#mandatory-files."; Logger.Log(statusMessage); return(new PolicyEvaluationResult(false, push.Pusher, statusMessage)); } } else { Logger.Log("Commit without tree entries: " + branch.NewObjectId); } } else { Logger.Log("Unable to find commit " + branch.NewObjectId); } } } return(new PolicyEvaluationResult(true)); }
private string CommitToString(TeamFoundationRequestContext requestContext, TfsGitCommit gitCommit, string action, PushNotification pushNotification, Dictionary<byte[], List<string>> refNames) { DateTime authorTime = gitCommit.GetLocalAuthorTime(requestContext); string authorName = gitCommit.GetAuthor(requestContext); string comment = gitCommit.GetComment(requestContext); StringBuilder sb = new StringBuilder(); List<string> names = null; if (refNames.TryGetValue(gitCommit.ObjectId, out names)) sb.AppendFormat("{0} ", String.Join("", names)); sb.AppendFormat("{0} {1} {2} {3} {4}", action, gitCommit.ObjectId.ToShortHexString(), authorTime.ToString(), authorName, comment.Truncate(COMMENT_MAX_LENGTH)); return sb.ToString(); }
public EventNotificationStatus ProcessEvent(TeamFoundationRequestContext requestContext, NotificationType notificationType, object notificationEventArgs, out int statusCode, out string statusMessage, out Microsoft.TeamFoundation.Common.ExceptionPropertyCollection properties) { statusCode = 0; statusMessage = string.Empty; properties = null; try { if (notificationType == NotificationType.Notification && notificationEventArgs is PushNotification) { Stopwatch timer = new Stopwatch(); timer.Start(); PushNotification pushNotification = notificationEventArgs as PushNotification; var repositoryService = requestContext.GetService <TeamFoundationGitRepositoryService>(); var commonService = requestContext.GetService <CommonStructureService>(); using (TfsGitRepository repository = repositoryService.FindRepositoryById(requestContext, pushNotification.RepositoryId)) { string repoName = pushNotification.RepositoryName; string projectName = commonService.GetProject(requestContext, pushNotification.TeamProjectUri).Name; string userName = pushNotification.AuthenticatedUserName.Replace(DOMAIN_PREFIX, ""); var lines = new List <string>(); string pushText = pushNotification.IsForceRequired(requestContext, repository) ? "FORCE push" : "push"; lines.Add(String.Format("{0} by {1} to {2}/{3}", pushText, userName, projectName, repoName)); var refNames = new Dictionary <byte[], List <string> >(new ByteArrayComparer()); var oldCommits = new HashSet <byte[]>(new ByteArrayComparer()); var unknowns = new List <RefUpdateResultGroup>(); // Associate refs (branch, ligtweight and annotated tag) with corresponding commit var refUpdateResultGroups = pushNotification.RefUpdateResults .Where(r => r.Succeeded) .GroupBy(r => r.NewObjectId, (key, items) => new RefUpdateResultGroup(key, items), new ByteArrayComparer()); foreach (var refUpdateResultGroup in refUpdateResultGroups) { byte[] newObjectId = refUpdateResultGroup.NewObjectId; byte[] commitId = null; if (newObjectId.IsZero()) { commitId = newObjectId; } else { TfsGitObject gitObject = repository.LookupObject(requestContext, newObjectId); if (gitObject.ObjectType == TfsGitObjectType.Commit) { commitId = newObjectId; } else if (gitObject.ObjectType == TfsGitObjectType.Tag) { var tag = (TfsGitTag)gitObject; var commit = tag.TryResolveToCommit(requestContext); if (commit != null) { commitId = commit.ObjectId; } } } if (commitId != null) { List <string> names; if (!refNames.TryGetValue(commitId, out names)) { names = new List <string>(); refNames.Add(commitId, names); } names.AddRange(RefsToStrings(refUpdateResultGroup.RefUpdateResults)); if (commitId.IsZero() || !pushNotification.IncludedCommits.Any(r => r.SequenceEqual(commitId))) { oldCommits.Add(commitId); } } else { unknowns.Add(refUpdateResultGroup); } } // Display new commits with refs foreach (byte[] commitId in pushNotification.IncludedCommits) { TfsGitCommit gitCommit = (TfsGitCommit)repository.LookupObject(requestContext, commitId); string line = CommitToString(requestContext, gitCommit, "commit", pushNotification, refNames); lines.Add(line); } // Display updated refs to old commits foreach (byte[] commitId in oldCommits) { string line = null; if (commitId.IsZero()) { line = String.Format("{0} deleted", String.Join("", refNames[commitId])); } else { TfsGitCommit gitCommit = (TfsGitCommit)repository.LookupObject(requestContext, commitId); line = CommitToString(requestContext, gitCommit, "->", pushNotification, refNames); } lines.Add(line); } // Display "unknown" refs foreach (var refUpdateResultGroup in unknowns) { byte[] newObjectId = refUpdateResultGroup.NewObjectId; TfsGitObject gitObject = repository.LookupObject(requestContext, newObjectId); string line = String.Format("{0} -> {1} {2}", RefsToString(refUpdateResultGroup.RefUpdateResults), gitObject.ObjectType, newObjectId.ToHexString()); lines.Add(line); } //Log(lines); List <string> sendLines = lines; if (lines.Count > MAX_LINES) { sendLines = lines.Take(MAX_LINES).ToList(); sendLines.Add(String.Format("{0} more line(s) suppressed.", lines.Count - MAX_LINES)); } Task.Run(() => SendToBot(sendLines)); } timer.Stop(); //Log("Time spent in ProcessEvent: " + timer.Elapsed); } } catch (Exception ex) { Log(ex.Message); Log(ex.StackTrace); } return(EventNotificationStatus.ActionPermitted); }