public ChangedFile(ChangedFileDto dto) { ChangeType = dto.ChangeType; FileName = dto.FileName; OldVersionBytes = dto.OldVersion; NewVersionBytes = dto.NewVersion; }
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; }
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; }
private static void SetChangeType(ChangedFileDto changedFile, Change change) { if (change.ChangeType.HasFlag(TFS.ChangeType.Add)) { changedFile.ChangeType = Interface.ChangeType.Added; } else if (change.ChangeType.HasFlag(TFS.ChangeType.Delete)) { changedFile.ChangeType = Interface.ChangeType.Deleted; } else { changedFile.ChangeType = Interface.ChangeType.Modified; } }
internal static ChangedFileDto ParseP4File(string file) { Logger.Write(new LogEntry { Message = "Parsing file: " + file, Categories = { "Plugin.Perforce" } }); var changedFile = new ChangedFileDto(); const string pattern = @"(?<filename>[^#]*)#(?<revision>\d+)\s-\s(?<action>\w+)\schange\s(?<changeNumber>\d+)\s\((?<filetype>\w+(\+\w+)?)\)"; var r = new Regex(pattern); var match = r.Match(file); if (match.Success) { changedFile.FileName = match.Groups["filename"].Value; switch (match.Groups["action"].Value) { case "add": changedFile.ChangeType = ChangeType.Added; break; case "edit": changedFile.ChangeType = ChangeType.Modified; break; case "delete": changedFile.ChangeType = ChangeType.Deleted; break; case "branch": changedFile.ChangeType = ChangeType.Copied; break; case "integrate": changedFile.ChangeType = ChangeType.Modified; break; } } else { Logger.Write(new LogEntry { Message = "Parsing file failed: " + file, Categories = { "Plugin.Perforce" }, Severity = TraceEventType.Error }); } return(changedFile); }
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); }
internal static ChangedFileDto ParseP4File(string file) { SourceLogLogger.LogInformation("Parsing file: " + file, "Plugin.Perforce"); var changedFile = new ChangedFileDto(); const string pattern = @"(?<filename>[^#]*)#(?<revision>\d+)\s-\s(?<action>\w+)\schange\s(?<changeNumber>\d+)\s\((?<filetype>\w+(\+\w+)?)\)"; var r = new Regex(pattern); var match = r.Match(file); if (match.Success) { changedFile.FileName = match.Groups["filename"].Value; switch (match.Groups["action"].Value) { case "add": changedFile.ChangeType = ChangeType.Added; break; case "edit": changedFile.ChangeType = ChangeType.Modified; break; case "delete": changedFile.ChangeType = ChangeType.Deleted; break; case "branch": changedFile.ChangeType = ChangeType.Copied; break; case "integrate": changedFile.ChangeType = ChangeType.Modified; break; } } else { SourceLogLogger.LogError("Parsing file failed: " + file, "Plugin.Perforce"); } return(changedFile); }
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); }
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")); }
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); }
protected override void CheckForNewLogEntriesImpl() { var p4 = new p4(); p4.Connect(); var repoPath = SettingsXml; if (repoPath.EndsWith(@"/")) { repoPath += "..."; } var p4Changes = p4.run("changes -t -l -s submitted -m 30 \"" + repoPath + "\""); var logEntries = p4Changes.Cast <string>().Select(PerforceLogParser.Parse) .Where(logEntry => logEntry.CommittedDate > MaxDateTimeRetrieved).ToList(); foreach (var logEntry in logEntries.OrderByDescending(le => le.CommittedDate)) { logEntry.ChangedFiles = new List <ChangedFileDto>(); // grab changed files var p4Files = p4.run("files @=" + logEntry.Revision); foreach (string file in p4Files) { ChangedFileDto changedFile = PerforceLogParser.ParseP4File(file); if (changedFile.ChangeType == ChangeType.Added || changedFile.ChangeType == ChangeType.Copied || changedFile.ChangeType == ChangeType.Modified || changedFile.ChangeType == ChangeType.Moved) { //if (changedFile.ChangeType == ChangeType.Copied // || changedFile.ChangeType == ChangeType.Moved) //{ // // TODO: Add new path to top of NewVersion // changedFile.NewVersion = String.Empty; //} //else //{ // changedFile.NewVersion = String.Empty; //} LoadNewVersion(logEntry, changedFile); } else { changedFile.NewVersion = new byte[0]; } if (changedFile.ChangeType == ChangeType.Deleted || changedFile.ChangeType == ChangeType.Modified) { LoadOldVersion(logEntry, changedFile); } //else if (changedFile.ChangeType == ChangeType.Copied // || changedFile.ChangeType == ChangeType.Moved) //{ // // TODO: get previous path and contents and put both in OldVersion // changedFile.OldVersion = String.Empty; //} else { changedFile.OldVersion = new byte[0]; } logEntry.ChangedFiles.Add(changedFile); } var args = new NewLogEntryEventArgs { LogEntry = logEntry }; OnNewLogEntry(args); } p4.Disconnect(); if (logEntries.Count > 0) { MaxDateTimeRetrieved = logEntries.Max(x => x.CommittedDate); } }
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; } } }
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); } }); }