Inheritance: System.EventArgs
        public void FireNewLogEntry()
        {
            var args = new NewLogEntryEventArgs
                {
                    LogEntry = new LogEntryDto
                        {
                            Author = "Tom",
                            CommittedDate = DateTime.Now,
                            Message = "Test message..",
                            ChangedFiles = new List<ChangedFileDto>
                                {
                                    new ChangedFileDto
                                        {
                                            ChangeType = ChangeType.Modified,
                                            FileName = "C:\\temp\\file.ext",
                                            OldVersion = System.Text.Encoding.UTF8.GetBytes("Old"),
                                            NewVersion = System.Text.Encoding.UTF8.GetBytes("New")
                                        }
                                }
                        }
                };

            if (NewLogEntry != null)
                NewLogEntry(this, args);
        }
Example #2
0
 protected void OnNewLogEntry(NewLogEntryEventArgs e)
 {
     if (NewLogEntry != null)
     {
         NewLogEntry(this, e);
     }
 }
        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);
            }
        }
        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);
        }
Example #5
0
 protected void OnNewLogEntry(NewLogEntryEventArgs e)
 {
     if (NewLogEntry != null)
         NewLogEntry(this, e);
 }
        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;
        }
Example #7
0
        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);
            }
        }
        public void AddNewLogEntry(object sender, NewLogEntryEventArgs e)
        {
            var logEntry = new LogEntry(e.LogEntry);
            if (Log.Count(l => l.Revision == logEntry.Revision) > 0)
            {
                Logger.Write(new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry
                    {
                        Message = String.Format("Subscription \"{2}\" already contains revision {0}, date (ticks) {1}", logEntry.Revision, logEntry.CommittedDate.Ticks, Name),
                        Severity = TraceEventType.Error
                    });
            }

            logEntry.GenerateFlowDocuments();

            using (var db = SourceLogContextProvider())
            {
                logEntry.LogSubscription = db.LogSubscriptions.Find(LogSubscriptionId);
                db.LogEntries.Add(logEntry);
                db.SaveChanges();
            }

            logEntry.UnloadChangedFiles();

            if (_uiThread != null)
            {
                _uiThread.Post(entry =>
                    {
                        Log.Add((LogEntry)entry);
                        NotifyPropertyChanged("Log");
                        var logEntryInfo = new NewLogEntryInfoEventHandlerArgs
                            {
                                LogSubscriptionName = Name,
                                Author = ((LogEntry)entry).Author,
                                Message = ((LogEntry)entry).Message
                            };
                        NewLogEntry(this, logEntryInfo);
                    }, logEntry);
            }
        }
Example #9
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;
        }