Пример #1
0
        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);
                }
            });
        }