Exemplo n.º 1
0
        //static void OnFileChanged (object s, ProjectFileEventArgs args)
        //{
        //	Repository repo = GetRepository (args.Project);
        //	if (repo != null)
        //		NotifyFileStatusChanged (repo, args.ProjectFile.FilePath, false);
        //}

        static async void OnFileAdded(object s, ProjectFileEventArgs e)
        {
            var             vargs   = new FileUpdateEventArgs();
            ProgressMonitor monitor = null;

            try {
                foreach (var repoFiles in e.GroupBy(i => i.Project))
                {
                    var repo = GetRepository(repoFiles.Key);
                    if (repo == null)
                    {
                        continue;
                    }
                    var filePaths = repoFiles.Where(ShouldAddFile).Select(f => f.ProjectFile.FilePath);
                    foreach (var file in filePaths)
                    {
                        if (monitor == null)
                        {
                            monitor = GetStatusMonitor();
                        }

                        var gotInfo = repo.TryGetVersionInfo(file, out var versionInfo);
                        if (gotInfo == false || (versionInfo.Status & VersionStatus.Ignored) == 0 && versionInfo.CanAdd)
                        {
                            await repo.AddAsync(file, false, monitor);
                        }
                    }
                    vargs.AddRange(repoFiles.Select(i => new FileUpdateEventInfo(repo, i.ProjectFile.FilePath, i.ProjectFile.Subtype == Subtype.Directory)));
                }
                if (vargs.Count > 0)
                {
                    NotifyFileStatusChanged(vargs);
                }
            } catch (OperationCanceledException) {
                return;
            } catch (Exception ex) {
                LoggingService.LogInternalError(ex);
            } finally {
                monitor?.Dispose();
            }
        }
Exemplo n.º 2
0
        //static void OnFileChanged (object s, ProjectFileEventArgs args)
        //{
        //	Repository repo = GetRepository (args.Project);
        //	if (repo != null)
        //		NotifyFileStatusChanged (repo, args.ProjectFile.FilePath, false);
        //}

        static async void OnFileAdded(object s, ProjectFileEventArgs e)
        {
            var             vargs   = new FileUpdateEventArgs();
            ProgressMonitor monitor = null;

            try {
                foreach (var repoFiles in e.GroupBy(i => i.Project))
                {
                    var repo = GetRepository(repoFiles.Key);
                    if (repo == null)
                    {
                        continue;
                    }
                    var filePaths    = repoFiles.Where(ShouldAddFile).Select(f => f.ProjectFile.FilePath);
                    var versionInfos = await repo.GetVersionInfoAsync(filePaths, VersionInfoQueryFlags.IgnoreCache).ConfigureAwait(false);

                    var paths = versionInfos.Where(i => i.CanAdd).Select(i => i.LocalPath).ToArray();
                    if (paths.Length > 0)
                    {
                        if (monitor == null)
                        {
                            monitor = GetStatusMonitor();
                        }
                        await repo.AddAsync(paths, false, monitor);
                    }
                    vargs.AddRange(repoFiles.Select(i => new FileUpdateEventInfo(repo, i.ProjectFile.FilePath, i.ProjectFile.Subtype == Subtype.Directory)));
                }
                if (vargs.Count > 0)
                {
                    NotifyFileStatusChanged(vargs);
                }
            } catch (OperationCanceledException) {
                return;
            } catch (Exception ex) {
                LoggingService.LogInternalError(ex);
            } finally {
                monitor?.Dispose();
            }
        }
        //static void OnFileChanged (object s, ProjectFileEventArgs args)
        //{
        //	Repository repo = GetRepository (args.Project);
        //	if (repo != null)
        //		NotifyFileStatusChanged (repo, args.ProjectFile.FilePath, false);
        //}

        static void OnFileAdded(object s, ProjectFileEventArgs e)
        {
            FileUpdateEventArgs vargs   = new FileUpdateEventArgs();
            IProgressMonitor    monitor = null;

            try
            {
                foreach (var repoFiles in e.GroupBy(i => i.Project))
                {
                    Repository repo = GetRepository(repoFiles.Key);
                    if (repo == null)
                    {
                        continue;
                    }
                    var        versionInfos = repo.GetVersionInfo(repoFiles.Select(f => f.ProjectFile.FilePath));
                    FilePath[] paths        = versionInfos.Where(i => i.CanAdd).Select(i => i.LocalPath).ToArray();
                    if (paths.Length > 0)
                    {
                        if (monitor == null)
                        {
                            monitor = GetStatusMonitor();
                        }
                        repo.Add(paths, false, monitor);
                    }
                    vargs.AddRange(repoFiles.Select(i => new FileUpdateEventInfo(repo, i.ProjectFile.FilePath, i.ProjectFile.Subtype == Subtype.Directory)));
                }
            }
            finally
            {
                if (monitor != null)
                {
                    monitor.Dispose();
                }
            }
            if (vargs.Count > 0)
            {
                NotifyFileStatusChanged(vargs);
            }
        }