예제 #1
0
 private void LoadConnectionsFromDisk()
 {
     //logger.Trace("ReadCacheFromDisk Path:{0}", cachePath.ToString());
     if (cachePath.FileExists())
     {
         var json = cachePath.ReadAllText();
         try
         {
             var conns = SimpleJson.DeserializeObject <Connection[]>(json);
             UpdateConnections(conns);
         }
         catch (IOException ex)
         {
             logger.Error(ex, "Error reading connection cache: {0}", cachePath);
         }
         catch (Exception ex)
         {
             logger.Error(ex, "Error deserializing connection cache: {0}", cachePath);
             // try to fix the corrupted file with the data we have
             SaveConnectionsToDisk(raiseChangedEvent: false);
         }
     }
 }
예제 #2
0
파일: GitClient.cs 프로젝트: rabca/Unity
        public ITask <ValidateGitInstallResult> ValidateGitInstall(NPath path)
        {
            if (!path.FileExists())
            {
                return(new FuncTask <ValidateGitInstallResult>(TaskEx.FromResult(new ValidateGitInstallResult(false, null, null))));
            }

            Version gitVersion    = null;
            Version gitLfsVersion = null;

            var gitVersionTask    = new GitVersionTask(cancellationToken).Configure(processManager, path);
            var gitLfsVersionTask = new GitLfsVersionTask(cancellationToken).Configure(processManager, path);

            return(gitVersionTask
                   .Then((result, version) => gitVersion = version)
                   .Then(gitLfsVersionTask)
                   .Then((result, version) => gitLfsVersion = version)
                   .Then(success => new ValidateGitInstallResult(success &&
                                                                 gitVersion?.CompareTo(Constants.MinimumGitVersion) >= 0 &&
                                                                 gitLfsVersion?.CompareTo(Constants.MinimumGitLfsVersion) >= 0,
                                                                 gitVersion, gitLfsVersion)
                         ));
        }
예제 #3
0
        private async Task <NPath> LookForSystemGit()
        {
            Logger.Trace("LookForSystemGit");

            NPath path = null;

            if (!environment.IsWindows)
            {
                var p = new NPath("/usr/local/bin/git");

                if (p.FileExists())
                {
                    path = p;
                }
            }

            if (path == null)
            {
                path = await new FindExecTask("git", taskManager.Token)
                       .Configure(processManager).StartAwait();
            }

            return(path);
        }
예제 #4
0
파일: Keychain.cs 프로젝트: knsh14/Unity
        private void ReadCacheFromDisk()
        {
            logger.Trace("ReadCacheFromDisk Path:{0}", cachePath.ToString());

            ConnectionCacheItem[] connections = null;

            if (cachePath.FileExists())
            {
                var json = cachePath.ReadAllText();
                try
                {
                    connections = SimpleJson.DeserializeObject <ConnectionCacheItem[]>(json);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Error deserializing connection cache: {0}", cachePath);
                    cachePath.Delete();
                }
            }

            if (connections != null)
            {
                connectionCache =
                    connections.Select(item => {
                    logger.Trace("ReadCacheFromDisk Item Host:{0} Username:{1}", item.Host, item.Username);
                    return(new Connection {
                        Host = new UriString(item.Host), Username = item.Username
                    });
                })
                    .ToDictionary(connection => connection.Host);
            }
            else
            {
                connectionCache = new Dictionary <UriString, Connection>();
            }
        }
예제 #5
0
        public NPath FindRoot(NPath path)
        {
            if (path == null)
            {
                return(null);
            }

            if (path.FileExists())
            {
                path = path.Parent;
            }

            if (path.Combine(".git").DirectoryExists())
            {
                return(path);
            }

            if (path.IsEmpty)
            {
                return(null);
            }

            return(FindRoot(path.Parent));
        }
예제 #6
0
        public static NPath Resolve(this NPath path)
        {
            // Add a reference to Mono.Posix with an .rsp file in the Assets folder with the line "-r:Mono.Posix.dll" for this to work
#if ENABLE_MONO
            if (!path.IsInitialized || !NPath.IsLinux /* nothing to resolve on windows */ || path.IsRelative || !path.FileExists())
            {
                return(path);
            }
            return(new NPath(Mono.Unix.UnixPath.GetCompleteRealPath(path.ToString())));
#else
            return(path);
#endif
        }
예제 #7
0
        private void HandleEventInDotGit(Event fileEvent, NPath fileA, NPath fileB = null)
        {
            if (fileA.Equals(paths.DotGitConfig))
            {
                Logger.Trace("ConfigChanged");

                ConfigChanged?.Invoke();
            }
            else if (fileA.Equals(paths.DotGitHead))
            {
                string headContent = null;
                if (fileEvent.Type != EventType.DELETED)
                {
                    headContent = paths.DotGitHead.ReadAllLines().FirstOrDefault();
                }

                Logger.Trace("HeadChanged: {0}", headContent ?? "[null]");
                HeadChanged?.Invoke(headContent);
            }
            else if (fileA.Equals(paths.DotGitIndex))
            {
                Logger.Trace("IndexChanged");
                IndexChanged?.Invoke();
            }
            else if (fileA.IsChildOf(paths.RemotesPath))
            {
                var relativePath         = fileA.RelativeTo(paths.RemotesPath);
                var relativePathElements = relativePath.Elements.ToArray();

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

                var origin = relativePathElements[0];

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

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

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

                    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);
                        }
                    }
                }
            }
            else if (fileA.IsChildOf(paths.BranchesPath))
            {
                if (fileEvent.Type == EventType.MODIFIED)
                {
                    if (fileA.DirectoryExists())
                    {
                        return;
                    }

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

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

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

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

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

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

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

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

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

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

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

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

                            Logger.Trace("LocalBranchCreated: {0}", branch);
                            LocalBranchCreated?.Invoke(branch);
                        }
                    }
                }
            }
        }
예제 #8
0
 public bool ValidateGitInstall(NPath path)
 {
     return(path.FileExists());
 }
예제 #9
0
        private int ProcessEvents(Event[] fileEvents)
        {
            Dictionary <EventType, List <EventData> > events = new Dictionary <EventType, List <EventData> >();

            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 (!events.ContainsKey(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig))
                    {
                        events.Add(EventType.ConfigChanged, null);
                    }
                    else if (!events.ContainsKey(EventType.HeadChanged) && fileA.Equals(paths.DotGitHead))
                    {
                        events.Add(EventType.HeadChanged, null);
                    }
                    else if (!events.ContainsKey(EventType.IndexChanged) && fileA.Equals(paths.DotGitIndex))
                    {
                        events.Add(EventType.IndexChanged, null);
                    }
                    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 == sfw.net.EventType.DELETED)
                        {
                            if (fileA.ExtensionWithDot == ".lock")
                            {
                                continue;
                            }

                            var branch = string.Join(@"/", relativePathElements.Skip(1).ToArray());
                            AddOrUpdateEventData(events, EventType.RemoteBranchDeleted, new EventData {
                                Origin = origin, Branch = branch
                            });
                        }
                        else if (fileEvent.Type == sfw.net.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);
                                    AddOrUpdateEventData(events, EventType.RemoteBranchCreated, new EventData {
                                        Origin = origin, Branch = branch
                                    });
                                }
                            }
                        }
                    }
                    else if (fileA.IsChildOf(paths.BranchesPath))
                    {
                        if (fileEvent.Type == sfw.net.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());

                            AddOrUpdateEventData(events, EventType.LocalBranchChanged, new EventData {
                                Branch = branch
                            });
                        }
                        else if (fileEvent.Type == sfw.net.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());
                            AddOrUpdateEventData(events, EventType.LocalBranchDeleted, new EventData {
                                Branch = branch
                            });
                        }
                        else if (fileEvent.Type == sfw.net.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());
                                    AddOrUpdateEventData(events, EventType.LocalBranchCreated, new EventData {
                                        Branch = branch
                                    });
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (events.ContainsKey(EventType.RepositoryChanged) || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
                    {
                        continue;
                    }
                    events.Add(EventType.RepositoryChanged, null);
                }
            }

            return(FireEvents(events));
        }
예제 #10
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);
        }