Example #1
0
        private int FireEvents(HashSet <EventType> events)
        {
            int eventsProcessed = 0;

            if (events.Contains(EventType.ConfigChanged))
            {
                //Logger.Trace("ConfigChanged");
                ConfigChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.HeadChanged))
            {
                //Logger.Trace("HeadChanged");
                HeadChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.LocalBranchesChanged))
            {
                //Logger.Trace("LocalBranchesChanged");
                LocalBranchesChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.RemoteBranchesChanged))
            {
                //Logger.Trace("RemoteBranchesChanged");
                RemoteBranchesChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.IndexChanged))
            {
                if (!events.Contains(EventType.RepositoryChanged))
                {
                    //Logger.Trace("IndexChanged");
                    IndexChanged?.Invoke();
                    eventsProcessed++;
                }
            }

            if (events.Contains(EventType.RepositoryChanged))
            {
                //Logger.Trace("RepositoryChanged");
                RepositoryChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.RepositoryCommitted))
            {
                //Logger.Trace("RepositoryCommitted");
                RepositoryCommitted?.Invoke();
                eventsProcessed++;
            }

            return(eventsProcessed);
        }
Example #2
0
 public void Reset()
 {
     HeadChanged.Reset();
     ConfigChanged.Reset();
     RepositoryCommitted.Reset();
     IndexChanged.Reset();
     RepositoryChanged.Reset();
     LocalBranchesChanged.Reset();
     RemoteBranchesChanged.Reset();
 }
Example #3
0
        private int FireEvents(Dictionary <EventType, List <EventData> > events)
        {
            int eventsProcessed = 0;

            if (events.ContainsKey(EventType.ConfigChanged))
            {
                Logger.Trace("ConfigChanged");
                ConfigChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.HeadChanged))
            {
                Logger.Trace("HeadChanged");
                HeadChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.LocalBranchesChanged))
            {
                Logger.Trace("LocalBranchesChanged");
                LocalBranchesChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.RemoteBranchesChanged))
            {
                Logger.Trace("RemoteBranchesChanged");
                RemoteBranchesChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.IndexChanged))
            {
                Logger.Trace("IndexChanged");
                IndexChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.RepositoryChanged))
            {
                Logger.Trace("RepositoryChanged");
                RepositoryChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.RepositoryCommitted))
            {
                Logger.Trace("RepositoryCommitted");
                RepositoryCommitted?.Invoke();
                eventsProcessed++;
            }

            return(eventsProcessed);
        }
Example #4
0
        private int FireEvents(HashSet <EventType> events)
        {
            int eventsProcessed = 0;

            if (events.Contains(EventType.ConfigChanged))
            {
                ConfigChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.HeadChanged))
            {
                HeadChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.LocalBranchesChanged))
            {
                LocalBranchesChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.RemoteBranchesChanged))
            {
                RemoteBranchesChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.IndexChanged))
            {
                if (!events.Contains(EventType.RepositoryChanged))
                {
                    IndexChanged?.Invoke();
                    eventsProcessed++;
                }
            }

            if (events.Contains(EventType.RepositoryChanged))
            {
                RepositoryChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.Contains(EventType.RepositoryCommitted))
            {
                RepositoryCommitted?.Invoke();
                eventsProcessed++;
            }

            return(eventsProcessed);
        }
Example #5
0
 void InvokeChange()
 {
     if (Repository == null)
     {
         return;
     }
     if (IsValidRepository(Repository.Info.Path) == RepositoryValidation.Valid)
     {
         RepositoryChangedPreview?.Invoke();
         if (Repository != null)
         {
             RepositoryChanged?.Invoke();
             CheckBranch();
         }
     }
     else
     {
         Program.GetInstance().CloseCurrentRepository();
     }
 }
Example #6
0
        public int CheckAndProcessEvents()
        {
            if (processingEvents)
            {
                signalProcessingEventsDone.Wait(cancellationToken);
                return(lastCountOfProcessedEvents);
            }

            signalProcessingEventsDone.Reset();
            processingEvents           = true;
            lastCountOfProcessedEvents = 0;
            var fileEvents = nativeInterface.GetEvents();

            if (fileEvents.Length > 0)
            {
                Logger.Trace("Processing {0} Events", fileEvents.Length);
            }

            var repositoryChanged = false;

            foreach (var fileEvent in fileEvents)
            {
                if (!running)
                {
                    break;
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    Stop();
                    break;
                }

                //Logger.Trace(fileEvent.Describe());

                var eventDirectory = new NPath(fileEvent.Directory);
                var fileA          = eventDirectory.Combine(fileEvent.FileA);

                NPath fileB = null;
                if (fileEvent.FileB != null)
                {
                    fileB = eventDirectory.Combine(fileEvent.FileB);
                }

                // handling events in .git/*
                if (fileA.IsChildOf(paths.DotGitPath))
                {
                    HandleEventInDotGit(fileEvent, fileA, fileB);
                }
                else
                {
                    if (repositoryChanged || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
                    {
                        continue;
                    }

                    repositoryChanged = true;
                }
                lastCountOfProcessedEvents++;
            }

            if (repositoryChanged)
            {
                Logger.Trace("RepositoryChanged");
                RepositoryChanged?.Invoke();
            }

            processingEvents = false;
            signalProcessingEventsDone.Set();
            return(lastCountOfProcessedEvents);
        }
Example #7
0
        private void WatcherLoop()
        {
            Logger.Trace("Starting watcher");

            while (running)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    Stop();
                    break;
                }

                var fileEvents = nativeInterface.GetEvents();

                if (fileEvents.Any())
                {
                    Logger.Trace("Processing {0} Events", fileEvents.Length);
                }

                var repositoryChanged = false;

                foreach (var fileEvent in fileEvents)
                {
                    if (!running)
                    {
                        break;
                    }

                    if (cancellationToken.IsCancellationRequested)
                    {
                        Stop();
                        break;
                    }

                    //Logger.Trace(fileEvent.Describe());

                    var eventDirectory = new NPath(fileEvent.Directory);
                    var fileA          = eventDirectory.Combine(fileEvent.FileA);

                    NPath fileB = null;
                    if (fileEvent.FileB != null)
                    {
                        fileB = eventDirectory.Combine(fileEvent.FileB);
                    }

                    // handling events in .git/*
                    if (fileA.IsChildOf(paths.DotGitPath))
                    {
                        HandleEventInDotGit(fileEvent, fileA, fileB);
                    }
                    else
                    {
                        if (repositoryChanged || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
                        {
                            continue;
                        }

                        repositoryChanged = true;
                    }
                }

                if (repositoryChanged)
                {
                    Logger.Trace("RepositoryChanged");
                    RepositoryChanged?.Invoke();
                }

                if (pauseEvent.Wait(200))
                {
                    break;
                }
            }
        }
Example #8
0
        private int FireEvents(Dictionary <EventType, List <EventData> > events)
        {
            int eventsProcessed = 0;

            if (events.ContainsKey(EventType.ConfigChanged))
            {
                Logger.Trace("ConfigChanged");
                ConfigChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.HeadChanged))
            {
                Logger.Trace("HeadChanged");
                HeadChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.IndexChanged))
            {
                Logger.Trace("IndexChanged");
                IndexChanged?.Invoke();
                eventsProcessed++;
            }

            if (events.ContainsKey(EventType.RepositoryChanged))
            {
                Logger.Trace("RepositoryChanged");
                RepositoryChanged?.Invoke();
                eventsProcessed++;
            }

            List <EventData> localBranchesCreated;

            if (events.TryGetValue(EventType.LocalBranchCreated, out localBranchesCreated))
            {
                foreach (var evt in localBranchesCreated)
                {
                    Logger.Trace($"LocalBranchCreated: {evt.Branch}");
                    LocalBranchCreated?.Invoke(evt.Branch);
                    eventsProcessed++;
                }
            }

            List <EventData> localBranchesChanged;

            if (events.TryGetValue(EventType.LocalBranchChanged, out localBranchesChanged))
            {
                foreach (var evt in localBranchesChanged)
                {
                    Logger.Trace($"LocalBranchChanged: {evt.Branch}");
                    LocalBranchChanged?.Invoke(evt.Branch);
                    eventsProcessed++;
                }
            }

            List <EventData> localBranchesDeleted;

            if (events.TryGetValue(EventType.LocalBranchDeleted, out localBranchesDeleted))
            {
                foreach (var evt in localBranchesDeleted)
                {
                    Logger.Trace($"LocalBranchDeleted: {evt.Branch}");
                    LocalBranchDeleted?.Invoke(evt.Branch);
                    eventsProcessed++;
                }
            }

            List <EventData> remoteBranchesCreated;

            if (events.TryGetValue(EventType.RemoteBranchCreated, out remoteBranchesCreated))
            {
                foreach (var evt in remoteBranchesCreated)
                {
                    Logger.Trace($"RemoteBranchCreated: {evt.Origin}/{evt.Branch}");
                    RemoteBranchCreated?.Invoke(evt.Origin, evt.Branch);
                    eventsProcessed++;
                }
            }

            List <EventData> remoteBranchesDeleted;

            if (events.TryGetValue(EventType.RemoteBranchDeleted, out remoteBranchesDeleted))
            {
                foreach (var evt in remoteBranchesDeleted)
                {
                    Logger.Trace($"RemoteBranchDeleted: {evt.Origin}/{evt.Branch}");
                    RemoteBranchDeleted?.Invoke(evt.Origin, evt.Branch);
                    eventsProcessed++;
                }
            }
            return(eventsProcessed);
        }
Example #9
0
        private int ProcessEvents(Event[] fileEvents)
        {
            var eventsProcessed   = 0;
            var configChanged     = false;
            var headChanged       = false;
            var repositoryChanged = false;
            var indexChanged      = false;

            string headContent = null;

            foreach (var fileEvent in fileEvents)
            {
                if (!running)
                {
                    break;
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    Stop();
                    break;
                }

                //Logger.Trace(fileEvent.Describe());

                var eventDirectory = new NPath(fileEvent.Directory);
                var fileA          = eventDirectory.Combine(fileEvent.FileA);

                NPath fileB = null;
                if (fileEvent.FileB != null)
                {
                    fileB = eventDirectory.Combine(fileEvent.FileB);
                }

                // handling events in .git/*
                if (fileA.IsChildOf(paths.DotGitPath))
                {
                    if (!configChanged && fileA.Equals(paths.DotGitConfig))
                    {
                        configChanged = true;
                    }
                    else if (!headChanged && fileA.Equals(paths.DotGitHead))
                    {
                        if (fileEvent.Type != EventType.DELETED)
                        {
                            headContent = paths.DotGitHead.ReadAllLines().FirstOrDefault();
                        }

                        headChanged = true;
                    }
                    else if (!indexChanged && fileA.Equals(paths.DotGitIndex))
                    {
                        indexChanged = true;
                    }
                    else if (fileA.IsChildOf(paths.RemotesPath))
                    {
                        var relativePath         = fileA.RelativeTo(paths.RemotesPath);
                        var relativePathElements = relativePath.Elements.ToArray();

                        if (!relativePathElements.Any())
                        {
                            continue;
                        }

                        var origin = relativePathElements[0];

                        if (fileEvent.Type == EventType.DELETED)
                        {
                            if (fileA.ExtensionWithDot == ".lock")
                            {
                                continue;
                            }

                            var branch = string.Join(@"/", relativePathElements.Skip(1).ToArray());

                            Logger.Trace("RemoteBranchDeleted: {0}/{1}", origin, branch);
                            RemoteBranchDeleted?.Invoke(origin, branch);
                            eventsProcessed++;
                        }
                        else if (fileEvent.Type == EventType.RENAMED)
                        {
                            if (fileA.ExtensionWithDot != ".lock")
                            {
                                continue;
                            }

                            if (fileB != null && fileB.FileExists())
                            {
                                if (fileA.FileNameWithoutExtension == fileB.FileNameWithoutExtension)
                                {
                                    var branchPathElement = relativePathElements
                                                            .Skip(1).Take(relativePathElements.Length - 2)
                                                            .Union(new[] { fileA.FileNameWithoutExtension }).ToArray();

                                    var branch = string.Join(@"/", branchPathElement);

                                    Logger.Trace("RemoteBranchCreated: {0}/{1}", origin, branch);
                                    RemoteBranchCreated?.Invoke(origin, branch);
                                    eventsProcessed++;
                                }
                            }
                        }
                    }
                    else if (fileA.IsChildOf(paths.BranchesPath))
                    {
                        if (fileEvent.Type == EventType.MODIFIED)
                        {
                            if (fileA.DirectoryExists())
                            {
                                continue;
                            }

                            if (fileA.ExtensionWithDot == ".lock")
                            {
                                continue;
                            }

                            var relativePath         = fileA.RelativeTo(paths.BranchesPath);
                            var relativePathElements = relativePath.Elements.ToArray();

                            if (!relativePathElements.Any())
                            {
                                continue;
                            }

                            var branch = string.Join(@"/", relativePathElements.ToArray());

                            Logger.Trace("LocalBranchChanged: {0}", branch);
                            LocalBranchChanged?.Invoke(branch);
                            eventsProcessed++;
                        }
                        else if (fileEvent.Type == EventType.DELETED)
                        {
                            if (fileA.ExtensionWithDot == ".lock")
                            {
                                continue;
                            }

                            var relativePath         = fileA.RelativeTo(paths.BranchesPath);
                            var relativePathElements = relativePath.Elements.ToArray();

                            if (!relativePathElements.Any())
                            {
                                continue;
                            }

                            var branch = string.Join(@"/", relativePathElements.ToArray());

                            Logger.Trace("LocalBranchDeleted: {0}", branch);
                            LocalBranchDeleted?.Invoke(branch);
                            eventsProcessed++;
                        }
                        else if (fileEvent.Type == EventType.RENAMED)
                        {
                            if (fileA.ExtensionWithDot != ".lock")
                            {
                                continue;
                            }

                            if (fileB != null && fileB.FileExists())
                            {
                                if (fileA.FileNameWithoutExtension == fileB.FileNameWithoutExtension)
                                {
                                    var relativePath         = fileB.RelativeTo(paths.BranchesPath);
                                    var relativePathElements = relativePath.Elements.ToArray();

                                    if (!relativePathElements.Any())
                                    {
                                        continue;
                                    }

                                    var branch = string.Join(@"/", relativePathElements.ToArray());

                                    Logger.Trace("LocalBranchCreated: {0}", branch);
                                    LocalBranchCreated?.Invoke(branch);
                                    eventsProcessed++;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (repositoryChanged || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
                    {
                        continue;
                    }

                    repositoryChanged = true;
                }
            }

            if (configChanged)
            {
                Logger.Trace("ConfigChanged");
                ConfigChanged?.Invoke();
                eventsProcessed++;
            }

            if (headChanged)
            {
                Logger.Trace("HeadChanged: {0}", headContent ?? "[null]");
                HeadChanged?.Invoke(headContent);
                eventsProcessed++;
            }

            if (indexChanged)
            {
                Logger.Trace("IndexChanged");
                IndexChanged?.Invoke();
                eventsProcessed++;
            }

            if (repositoryChanged)
            {
                Logger.Trace("RepositoryChanged");
                RepositoryChanged?.Invoke();
                eventsProcessed++;
            }

            return(eventsProcessed);
        }
 protected void InvokeRepositoryChanged()
 {
     RepositoryChanged?.Invoke(this, new RepositoryChangedEventArgs(repositoryPath));
 }
Example #11
0
 private static void NotifyRepositoryChanged(T entity = null)
 {
     Application.Current.Dispatcher.BeginInvoke((Action) delegate { RepositoryChanged?.Invoke(entity); });
 }
Example #12
0
 protected virtual void OnRepositoryChanged(string operation, string name)
 {
     RepositoryChanged?.Invoke(operation, name);
 }