示例#1
0
 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);
        }
        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;
        }
示例#4
0
        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;
        }
        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;
                SourceLogLogger.LogInformation("Creating LogEntry for Changeset " + changesetId, "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 static void SetChangeType(ChangedFileDto changedFile, Change change)
 {
     if (change.ChangeType.HasFlag(ChangeType.Add))
         changedFile.ChangeType = CoreChangeType.Added;
     else if (change.ChangeType.HasFlag(ChangeType.Delete))
         changedFile.ChangeType = CoreChangeType.Deleted;
     else
         changedFile.ChangeType = CoreChangeType.Modified;
 }
        private void ProcessChangedPaths(SvnLoggingEventArgs svnLogEntry, long revision, LogEntryDto logEntry)
        {
            svnLogEntry.ChangedPaths.AsParallel().WithDegreeOfParallelism(1).ForAll(changedPath =>
            {
                SourceLogLogger.LogInformation($"Processing path {changedPath.Path}", $"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)
                        {
                            SourceLogLogger.LogWarning(svnRepositoryIoException.ToString(), "Plugin.Subversion");
                        }

                    }

                    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)
                            {
                                SourceLogLogger.LogError("SvnRepositoryIOException: " + e, "Plugin.Subversion");
                                changedFile.OldVersion = new byte[0];
                            }
                            catch (SvnFileSystemException ex)
                            {
                                // http://stackoverflow.com/questions/12939642/sharpsvn-getinfo-lastchangerevision-is-wrong
                                SourceLogLogger.LogWarning("SvnFileSystemException: " + ex, "Plugin.Subversion");
                                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);
                }
            });
        }
 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);
 }
示例#10
0
        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);
        }