internal static LogEntryDto Parse(string changesetString) { SourceLogLogger.LogInformation("Parsing changeset: " + changesetString, "Plugin.Perforce"); var logEntry = new LogEntryDto(); const string pattern = @"Change\s(?<revision>\d+)\son\s(?<datetime>\d{4}/\d{2}/\d{2}\s\d{2}:\d{2}:\d{2})\sby\s(?<author>[^@]+)@\w+\n\n(?<message>.*?(?=\n([^\s]|$)))"; var r = new Regex(pattern, RegexOptions.Singleline); var match = r.Match(changesetString); if (match.Success) { int revision; if (Int32.TryParse(match.Groups["revision"].Value, out revision)) { logEntry.Revision = revision.ToString(CultureInfo.InvariantCulture); } DateTime datetime; if (DateTime.TryParse(match.Groups["datetime"].Value, out datetime)) { logEntry.CommittedDate = datetime; } logEntry.Author = match.Groups["author"].Value; var message = match.Groups["message"].Value; logEntry.Message = message.Trim().Replace("\n\t", "\n"); } else { SourceLogLogger.LogError("Parsing changeset: " + changesetString, "Plugin.Perforce"); } return(logEntry); }
private string GetLogEntryType(LogEntryDto dto) { if (dto.LogHeader == TheDashboardConstants.UmbracoLogHeaders.Publish) { return(TheDashboardConstants.ActivityTypes.Publish); } if (dto.LogHeader == TheDashboardConstants.UmbracoLogHeaders.Save && dto.NodeScheduledDate.HasValue) { return(TheDashboardConstants.ActivityTypes.SaveAndScheduled); } if (dto.LogHeader == TheDashboardConstants.UmbracoLogHeaders.Save) { return(TheDashboardConstants.ActivityTypes.Save); } if (dto.LogHeader == TheDashboardConstants.UmbracoLogHeaders.Unpublish) { return(TheDashboardConstants.ActivityTypes.Unpublish); } if (dto.LogHeader == TheDashboardConstants.UmbracoLogHeaders.RollBack) { return(TheDashboardConstants.ActivityTypes.RollBack); } if (dto.LogHeader == TheDashboardConstants.UmbracoLogHeaders.Delete && dto.LogComment.Contains("Trashed")) { return(TheDashboardConstants.ActivityTypes.RecycleBin); } // Empty string means this is a type of LogEntryDto that we don't care about. return(string.Empty); }
public void OldNewVersionTextStorageSizeThreshold() { //var mockContext = new Mock<ISourceLogContext>(); //var logSubscription = new LogSubscription (() => mockContext.Object) // { // LogSubscriptionId = 1, // Log = new TrulyObservableCollection<LogEntry>() // }; //var fakeLogSubscriptionDbSet = new FakeLogSubscriptionDbSet { logSubscription }; //mockContext.Setup(m => m.LogSubscriptions).Returns(fakeLogSubscriptionDbSet); //var logEntriesDbSet = new FakeDbSet<LogEntry>(); //mockContext.Setup(m => m.LogEntries).Returns(logEntriesDbSet); var changedFileDto = new ChangedFileDto(); using (var reader = new FileStream("jquery.signalR.core.js.oldversion", FileMode.Open)) { using (var memoryStream = new MemoryStream()) { reader.CopyTo(memoryStream); changedFileDto.OldVersion = memoryStream.ToArray(); } } using (var reader = new FileStream("jquery.signalR.core.js.newversion", FileMode.Open)) { using (var memoryStream = new MemoryStream()) { reader.CopyTo(memoryStream); changedFileDto.NewVersion = memoryStream.ToArray(); } } var logEntryDto = new LogEntryDto { ChangedFiles = new List <ChangedFileDto> { changedFileDto } }; //logSubscription.AddNewLogEntry(this, new NewLogEntryEventArgs { LogEntry = logEntryDto }); var logEntry = new LogEntry(logEntryDto); logEntry.GenerateFlowDocuments(); var changedFile = logEntry.ChangedFiles.First(); Assert.IsTrue(changedFile.LeftFlowDocumentData.Length <= 5388, "changedFile.LeftFlowDocumentData.Length: " + changedFile.LeftFlowDocumentData.Length); Assert.IsTrue(changedFile.RightFlowDocumentData.Length <= 5383, "changedFile.RightFlowDocumentData.Length: " + changedFile.RightFlowDocumentData.Length); }
private void ProcessLogEntry(IRepository repo, Commit commit) { var logEntryDto = new LogEntryDto { Revision = commit.Sha.Substring(0, 7), Author = commit.Author.Name, CommittedDate = commit.Committer.When.UtcDateTime, Message = commit.Message, ChangedFiles = new List <ChangedFileDto>() }; foreach (var change in repo.Diff.Compare(commit.Parents.First().Tree, commit.Tree)) { // For GitLinks there isn't really a file to compare // (actually I think there is but it comes in a separate change) // See for example: https://github.com/libgit2/libgit2sharp/commit/a2efc1a4d433b9e3056b17645c8c1f146fcceecb if (change.Mode == Mode.GitLink) { continue; } var changeFileDto = new ChangedFileDto { FileName = change.Path, ChangeType = GitChangeStatusToChangeType(change.Status) }; switch (changeFileDto.ChangeType) { case ChangeType.Added: changeFileDto.OldVersion = new byte[0]; changeFileDto.NewVersion = GetNewVersion(commit, change); break; case ChangeType.Deleted: changeFileDto.OldVersion = GetOldVersion(commit, change); changeFileDto.NewVersion = new byte[0]; break; default: changeFileDto.OldVersion = GetOldVersion(commit, change); changeFileDto.NewVersion = GetNewVersion(commit, change); break; } logEntryDto.ChangedFiles.Add(changeFileDto); } var args = new NewLogEntryEventArgs { LogEntry = logEntryDto }; OnNewLogEntry(args); MaxDateTimeRetrieved = logEntryDto.CommittedDate; }
public LogEntry(LogEntryDto dto) { Revision = dto.Revision; CommittedDate = dto.CommittedDate; Message = dto.Message; Author = dto.Author; ChangedFiles = new List <ChangedFile>(); dto.ChangedFiles.ForEach(changedFileDto => ChangedFiles.Add(new ChangedFile(changedFileDto))); }
public HttpResponseMessage CreateLogEntry([FromBody] LogEntryDto logEntryDto) { try { _logger.WriteLogEntry(_tenantId.ToString(), null, logEntryDto.Entry, logEntryDto.LogLevelType); return(this.Request.CreateResponse(HttpStatusCode.Created)); } catch (Exception) { throw; } }
protected override void CheckForNewLogEntriesImpl() { if (!Monitor.TryEnter(LockObject)) { return; } try { using (var svnClient = new SvnClient()) { var uri = new Uri(SettingsXml); Collection <SvnLogEventArgs> svnLogEntries; if (svnClient.GetLog(uri, new SvnLogArgs { Limit = 30 }, out svnLogEntries)) { var q = svnLogEntries .Where(e => e.Time.PrecisionFix() > MaxDateTimeRetrieved) .OrderBy(e => e.Time); foreach (var svnLogEntry in q) { var revision = svnLogEntry.Revision; Logger.Write(new LogEntry { Message = "Creating LogEntryDto for revision " + revision, Categories = { "Plugin." + GetType().Name } }); var logEntry = new LogEntryDto { Author = svnLogEntry.Author, CommittedDate = svnLogEntry.Time, Message = svnLogEntry.LogMessage, Revision = revision.ToString(CultureInfo.InvariantCulture), ChangedFiles = new List <ChangedFileDto>() }; ProcessChangedPaths(svnLogEntry, revision, logEntry); var args = new NewLogEntryEventArgs { LogEntry = logEntry }; OnNewLogEntry(args); } MaxDateTimeRetrieved = svnLogEntries.Max(x => x.Time).PrecisionFix(); } } } finally { Monitor.Exit(LockObject); } }
private void ProcessLogEntry(Repository repo, Changeset commit) { var logEntryDto = new LogEntryDto { Revision = commit.RevisionNumber.ToString(), Author = commit.AuthorName, CommittedDate = commit.Timestamp, Message = "(" + commit.Branch + ") " + commit.CommitMessage, ChangedFiles = new List <ChangedFileDto>() }; foreach (ChangesetPathAction change in commit.PathActions) { var changeFileDto = new ChangedFileDto { FileName = change.Path, ChangeType = MercurialChangeStatusToChangeType(change.Action) }; switch (changeFileDto.ChangeType) { case ChangeType.Added: changeFileDto.OldVersion = new byte[0]; changeFileDto.NewVersion = GetFile(repo, commit.RevisionNumber, change.Path); break; case ChangeType.Deleted: changeFileDto.OldVersion = GetFile(repo, commit.LeftParentRevision, change.Path); changeFileDto.NewVersion = new byte[0]; break; default: changeFileDto.OldVersion = GetFile(repo, commit.LeftParentRevision, change.Path); changeFileDto.NewVersion = GetFile(repo, commit.RevisionNumber, change.Path); break; } logEntryDto.ChangedFiles.Add(changeFileDto); } var args = new NewLogEntryEventArgs { LogEntry = logEntryDto }; OnNewLogEntry(args); MaxDateTimeRetrieved = logEntryDto.CommittedDate; }
/// <summary> /// Add a new log entry to the internal collection. /// </summary> /// <param name="dto">entry</param> public void Add(LogEntryDto dto) { if (dto == null) { throw new ArgumentNullException(nameof(dto)); } lock (Logs) { Logs.AddLast(dto); while (Logs.Count > 50) { Logs.RemoveLast(); } } }
/// <inheritdoc /> public void Emit(LogEvent logEvent) { var message = logEvent.RenderMessage(_formatProvider); var entry = new LogEntryDto(logEvent.Timestamp.ToUniversalTime().DateTime, ConvertLevel(logEvent.Level), message) { Exception = logEvent.Exception?.ToString(), }; LogsProvider.Instance.Add(entry); if (logEvent.Exception != null) { Err.Report(logEvent.Exception, entry); } }
public IActionResult Delete([FromBody] LogEntryDto projectDto) { // map dto to entity var logEntry = _mapper.Map <LogEntry>(projectDto); try { // save _logService.DeleteLogEntry(logEntry); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
private static void LoadOldVersion(LogEntryDto logEntry, ChangedFileDto changedFile) { var p4Print = new p4(); p4Print.Connect(); p4Print.run("print \"" + changedFile.FileName + "@" + (Int32.Parse(logEntry.Revision) - 1) + "\""); string tempFilename = ((dynamic)p4Print).TempFilename; using (var stream = new FileStream(tempFilename, FileMode.Open, FileAccess.Read)) { using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); changedFile.OldVersion = memoryStream.ToArray(); } } p4Print.Disconnect(); File.SetAttributes(tempFilename, FileAttributes.Normal); File.Delete(tempFilename); }
private static void LoadNewVersion(LogEntryDto logEntry, ChangedFileDto changedFile) { // Always create a new p4 object otherwise TempFilename doesn't always update var p4Print = new p4(); p4Print.Connect(); p4Print.run("print \"" + changedFile.FileName + "@" + logEntry.Revision + "\""); string tempFilename = ((dynamic)p4Print).TempFilename; using (var stream = new FileStream(tempFilename, FileMode.Open, FileAccess.Read)) { using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); changedFile.NewVersion = memoryStream.ToArray(); } } p4Print.Disconnect(); File.SetAttributes(tempFilename, FileAttributes.Normal); File.Delete(tempFilename); }
//[Ignore] //This will actually send an email so have it setup to be ran manually. public void CreateLogEntry() { //*** Arrange *** var log = new LogEntryDto { Entry = "testsksksks", LogLevelType = LogLevelType.Info }; var json = log.SerializeObjectToJsonString(); //*** Act *** //HttpResponseMessage response = _client.PostAsync("log/", new StringContent(json, Encoding.UTF8, "application/json")).Result; //var reasonPhrase = response.ReasonPhrase; //var myResponse = response.Content.ReadAsStringAsync(); //var result = myResponse.Result; //*** Assert *** Assert.IsNotNull(json); }
public void LeadingTabsAreDisplayed() { var changedFileDto = new ChangedFileDto { OldVersion = System.Text.Encoding.UTF8.GetBytes("\t@ ,"), NewVersion = System.Text.Encoding.UTF8.GetBytes("\t @ ") }; var logEntryDto = new LogEntryDto { ChangedFiles = new List <ChangedFileDto> { changedFileDto } }; //var mockContext = new Mock<ISourceLogContext>(); //var logSubscription = new LogSubscription(() => mockContext.Object) //{ // LogSubscriptionId = 1, // Log = new TrulyObservableCollection<LogEntry>() //}; //var fakeLogSubscriptionDbSet = new FakeLogSubscriptionDbSet { logSubscription }; //mockContext.Setup(m => m.LogSubscriptions).Returns(fakeLogSubscriptionDbSet); //var logEntriesDbSet = new FakeDbSet<LogEntry>(); //mockContext.Setup(m => m.LogEntries).Returns(logEntriesDbSet); //logSubscription.AddNewLogEntry(this, new NewLogEntryEventArgs { LogEntry = logEntry }); var logEntry = new LogEntry(logEntryDto); logEntry.GenerateFlowDocuments(); var changedFile = logEntry.ChangedFiles.First(); //var changedFile = logEntriesDbSet.First().ChangedFiles.First(); var textRange = new TextRange(changedFile.LeftFlowDocument.ContentStart, changedFile.LeftFlowDocument.ContentEnd); Assert.IsTrue(textRange.Text.StartsWith("\t")); }
public RecentActivityFrontendModel Map(LogEntryDto dto) { var dashboardLogEntryType = GetLogEntryType(dto); if (string.IsNullOrEmpty(dashboardLogEntryType)) { return(null); } return(new RecentActivityFrontendModel() { NodeId = dto.NodeId, NodeName = dto.NodeName, Datestamp = dto.Datestamp, ScheduledPublishDate = dto.NodeScheduledDate, ActivityType = dashboardLogEntryType, User = new UserFrontendModel() { Name = dto.UserName, Avatar = UserExtensions.GetUserAvatarUrls(dto.UserId, dto.UserEmail, dto.UserAvatar, _appCaches.RuntimeCache) } }); }
protected override void CheckForNewLogEntriesImpl() { var repoLog = JsonConvert.DeserializeObject <RepoLog>(GitHubApiGetString( "https://api.github.com/repos/" + _username + "/" + _reponame + "/commits" )); if (repoLog.Any()) { var maxDateTimeRetrievedAtStartOfProcessing = MaxDateTimeRetrieved; foreach (var commitEntry in repoLog.Where(x => DateTime.Parse(x.commit.committer.date) > maxDateTimeRetrievedAtStartOfProcessing) .OrderBy(x => DateTime.Parse(x.commit.committer.date))) { var logEntry = new LogEntryDto { Revision = commitEntry.sha.Substring(0, 7), Author = commitEntry.commit.committer.name, CommittedDate = DateTime.Parse(commitEntry.commit.committer.date), Message = commitEntry.commit.message, ChangedFiles = new List <ChangedFileDto>() }; var fullCommitEntry = JsonConvert.DeserializeObject <CommitEntry>( GitHubApiGetString( "https://api.github.com/repos/" + _username + "/" + _reponame + "/commits/" + commitEntry.sha ) ); // process changed files in parallel fullCommitEntry.files.AsParallel().ForAll(file => { var changedFile = new ChangedFileDto { FileName = file.filename, //NewVersion = GitHubApiGet(file.raw_url), //ChangeType = ChangeType.Modified }; if (file.status == "removed") { changedFile.ChangeType = ChangeType.Deleted; changedFile.OldVersion = GitHubApiGetBinary(file.raw_url); changedFile.NewVersion = new byte[0]; } else { changedFile.ChangeType = ChangeType.Modified; changedFile.NewVersion = GitHubApiGetBinary(file.raw_url); // get the previous version // first get the list of commits for the file var fileLog = JsonConvert.DeserializeObject <RepoLog>( GitHubApiGetString( "https://api.github.com/repos/" + _username + "/" + _reponame + "/commits?path=" + file.filename ) ); // get most recent commit before this one var previousCommit = fileLog.Where(f => DateTime.Parse(f.commit.committer.date) < logEntry.CommittedDate) .OrderByDescending(f => DateTime.Parse(f.commit.committer.date)) .FirstOrDefault(); if (previousCommit != null) { // get the raw contents of the path at the previous commit sha changedFile.OldVersion = GitHubApiGetBinary( "https://github.com/" + _username + "/" + _reponame + "/raw/" + previousCommit.sha + "/" + changedFile.FileName ); } else { changedFile.OldVersion = new byte[0]; changedFile.ChangeType = ChangeType.Added; } } logEntry.ChangedFiles.Add(changedFile); }); var args = new NewLogEntryEventArgs { LogEntry = logEntry }; OnNewLogEntry(args); MaxDateTimeRetrieved = logEntry.CommittedDate; } } }
protected override void CheckForNewLogEntriesImpl() { string collectionUrl; string sourceLocation; GetTfsSettings(out collectionUrl, out sourceLocation); var tfsUri = new Uri(collectionUrl); var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri); var vcs = projectCollection.GetService <VersionControlServer>(); var history = vcs.QueryHistory( path: sourceLocation, version: VersionSpec.Latest, deletionId: 0, recursion: RecursionType.Full, user: null, versionFrom: null, versionTo: null, maxCount: 30, includeChanges: true, slotMode: false ) .Cast <Changeset>() .ToList(); foreach (var changeset in history.Where(c => c.CreationDate > MaxDateTimeRetrieved).OrderBy(c => c.CreationDate)) { var changesetId = changeset.ChangesetId; Logger.Write(new LogEntry { Message = "Creating LogEntry for Changeset " + changesetId, Categories = { "Plugin.TFS2010" } }); var logEntry = new LogEntryDto { Author = changeset.Committer, CommittedDate = changeset.CreationDate, Message = changeset.Comment, Revision = changesetId.ToString(CultureInfo.InvariantCulture), ChangedFiles = new List <ChangedFileDto>() }; foreach (var change in changeset.Changes) { var changedFile = new ChangedFileDto { FileName = change.Item.ServerItem }; switch (change.Item.ItemType) { case ItemType.Folder: // XamlReader.Load seems to require UTF8 var folderStringBytes = System.Text.Encoding.UTF8.GetBytes("[Folder]"); if (change.ChangeType.HasFlag(TFS.ChangeType.Add)) { changedFile.OldVersion = new byte[0]; } else { changedFile.OldVersion = folderStringBytes; } if (change.ChangeType.HasFlag(TFS.ChangeType.Delete)) { changedFile.NewVersion = new byte[0]; } else { changedFile.NewVersion = folderStringBytes; } break; case ItemType.File: if (change.ChangeType.HasFlag(TFS.ChangeType.Delete)) { changedFile.NewVersion = new byte[0]; } else { using (var memoryStream = new MemoryStream()) { change.Item.DownloadFile().CopyTo(memoryStream); changedFile.NewVersion = memoryStream.ToArray(); } } var previousVersion = vcs.GetItem(change.Item.ItemId, changesetId - 1, true); if (previousVersion != null) { using (var previousVersionMemoryStream = new MemoryStream()) { previousVersion.DownloadFile().CopyTo(previousVersionMemoryStream); changedFile.OldVersion = previousVersionMemoryStream.ToArray(); } } else { changedFile.OldVersion = new byte[0]; } break; default: continue; } SetChangeType(changedFile, change); logEntry.ChangedFiles.Add(changedFile); } var args = new NewLogEntryEventArgs { LogEntry = logEntry }; OnNewLogEntry(args); } MaxDateTimeRetrieved = history.Max(c => c.CreationDate); }
private void ProcessChangedPaths(SvnLoggingEventArgs svnLogEntry, long revision, LogEntryDto logEntry) { svnLogEntry.ChangedPaths.AsParallel().WithDegreeOfParallelism(1).ForAll(changedPath => { Logger.Write(new LogEntry { Message = "Processing path " + changedPath.Path, Categories = { "Plugin.Subversion" } }); using (var parallelSvnClient = new SvnClient()) { var changedFile = new ChangedFileDto { FileName = changedPath.Path }; var nodeKind = changedPath.NodeKind; if (nodeKind == SvnNodeKind.Unknown) { // Use GetInfo to get the NodeKind SvnInfoEventArgs svnInfo; try { parallelSvnClient.GetInfo( new SvnUriTarget( SettingsXml + changedPath.Path, // If the file is deleted then using revision causes an exception (changedPath.Action == SvnChangeAction.Delete ? revision - 1 : revision) ), out svnInfo); nodeKind = svnInfo.NodeKind; } catch (SvnRepositoryIOException svnRepositoryIoException) { Logger.Write(new LogEntry { Message = svnRepositoryIoException.ToString(), Categories = { "Plugin.Subversion" }, Severity = TraceEventType.Warning }); } } if (nodeKind != SvnNodeKind.File) { changedFile.OldVersion = new byte[0]; changedFile.NewVersion = new byte[0]; } else { if (changedPath.Action == SvnChangeAction.Modify || changedPath.Action == SvnChangeAction.Delete) { // Use GetInfo to get the last change revision var previousRevisionUri = new SvnUriTarget(SettingsXml + changedPath.Path, revision - 1); try { // For some reason we seem to get an exception with a message stating that // a previous version doesn't exist for a Modify action. I'm not sure how // you can have a modify without a previous version (surely everything // starts with an add..? SvnInfoEventArgs previousRevisionInfo; parallelSvnClient.GetInfo(previousRevisionUri, out previousRevisionInfo); changedFile.OldVersion = ReadFileVersion( parallelSvnClient, SettingsXml + changedPath.Path, previousRevisionInfo.LastChangeRevision); } catch (SvnRepositoryIOException e) { Logger.Write(new LogEntry { Message = "SvnRepositoryIOException: " + e, Categories = { "Plugin.Subversion" }, Severity = TraceEventType.Error }); changedFile.OldVersion = new byte[0]; } catch (SvnFileSystemException ex) { // http://stackoverflow.com/questions/12939642/sharpsvn-getinfo-lastchangerevision-is-wrong Logger.Write(new LogEntry { Message = "SvnFileSystemException: " + ex, Categories = { "Plugin.Subversion" }, Severity = TraceEventType.Warning }); changedFile.OldVersion = new byte[0]; } } else { changedFile.OldVersion = new byte[0]; } if (changedPath.Action == SvnChangeAction.Modify || changedPath.Action == SvnChangeAction.Add) { changedFile.NewVersion = ReadFileVersion(parallelSvnClient, SettingsXml + changedPath.Path, revision); } else { changedFile.NewVersion = new byte[0]; } } switch (changedPath.Action) { case SvnChangeAction.Add: changedFile.ChangeType = ChangeType.Added; break; case SvnChangeAction.Delete: changedFile.ChangeType = ChangeType.Deleted; break; default: changedFile.ChangeType = ChangeType.Modified; break; } logEntry.ChangedFiles.Add(changedFile); } }); }