internal void ScheduleMonitor(IEnumerable <string> paths)
        {
            lock (_toRefresh)
            {
                _toMonitor.AddRange(paths);

                if (!_isActive || !_solutionOpen)
                {
                    return;
                }

                _toRefresh.UniqueAddRange(paths);

                ScheduleRefreshPreLocked();
            }
        }
Beispiel #2
0
        public PendingCommitState(IAnkhServiceProvider context, IEnumerable <PendingChange> changes)
            : base(context)
        {
            if (changes == null)
            {
                throw new ArgumentNullException("changes");
            }

            _changes.UniqueAddRange(changes);

            foreach (PendingChange pc in _changes)
            {
                if (!_commitPaths.Contains(pc.FullPath))
                {
                    _commitPaths.Add(pc.FullPath);
                }
            }
        }
Beispiel #3
0
        public bool SaveAllDocumentsExcept(IEnumerable <string> paths)
        {
            if (paths == null)
            {
                throw new ArgumentNullException("paths");
            }

            HybridCollection <string> openDocs = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
            HybridCollection <string> dontSave = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);

            openDocs.UniqueAddRange(_docMap.Keys);
            dontSave.UniqueAddRange(paths);

            bool ok = true;

            foreach (string name in openDocs)
            {
                SccDocumentData data;

                if (dontSave.Contains(name))
                {
                    continue;
                }

                if (!_docMap.TryGetValue(name, out data))
                {
                    continue; // File closed through saving another one
                }
                if (!data.SaveDocument(RunningDocumentTable))
                {
                    ok = false;
                }
            }

            return(ok);
        }
        public bool SaveAllDocumentsExcept(IEnumerable<string> paths)
        {
            if (paths == null)
                throw new ArgumentNullException("paths");

            HybridCollection<string> pathsCol = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase);

            pathsCol.UniqueAddRange(paths);

            bool ok = true;
            foreach (SccDocumentData data in _docMap.Values)
            {
                if (!pathsCol.Contains(data.Name))
                {
                    if (!data.SaveDocument(RunningDocumentTable))
                        ok = false;
                }
            }

            return ok;
        }
Beispiel #5
0
        /// <summary>
        /// Returns false if the AddToSubversionDialog has been cancelled, true otherwise
        /// </summary>
        /// <param name="e"></param>
        /// <param name="projectInfo"></param>
        /// <param name="solutionReposRoot"></param>
        /// <param name="shouldMarkAsManaged"></param>
        /// <param name="storeReference"></param>
        /// <returns></returns>
        static bool CheckoutWorkingCopyForProject(CommandEventArgs e, SccProject project, ISccProjectInfo projectInfo, Uri solutionReposRoot, out bool shouldMarkAsManaged, out bool storeReference)
        {
            shouldMarkAsManaged = false;
            storeReference      = false;
            using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient())
                using (AddProjectToSubversion dialog = new AddProjectToSubversion())
                {
                    dialog.Context          = e.Context;
                    dialog.PathToAdd        = projectInfo.ProjectDirectory;
                    dialog.RepositoryAddUrl = solutionReposRoot;

                    if (e.Argument is IAnkhSccService)
                    {
                        dialog.CommitAllVisible = false;
                        dialog.CommitAllFiles   = false;
                    }
                    else
                    {
                        dialog.CommitAllFiles = true;
                    }

                    if (dialog.ShowDialog(e.Context) != DialogResult.OK)
                    {
                        return(false); // User cancelled the "Add to subversion" dialog, don't set as managed by Ankh
                    }
                    if (!dialog.CommitAllFiles)
                    {
                        Collection <SvnInfoEventArgs> info;
                        SvnInfoArgs ia = new SvnInfoArgs();
                        ia.ThrowOnError = false;
                        if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info))
                        {
                            // Target uri doesn't exist in the repository, let's create
                            if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl))
                            {
                                return(false); // Create failed; bail out
                            }
                        }

                        // Create working copy
                        SvnCheckOutArgs coArg = new SvnCheckOutArgs();
                        coArg.AllowObstructions = true;
                        cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg);
                    }
                    else
                    {
                        // Cache some values before thread marshalling
                        HybridCollection <string> projectFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
                        string wcDir    = dialog.WorkingCopyDir;
                        Uri    reposUrl = dialog.RepositoryAddUrl;
                        string logMessage;

                        projectFiles.UniqueAddRange(e.GetService <IProjectFileMapper>().GetAllFilesOf(project));
                        using (CreateDirectoryDialog dlg = new CreateDirectoryDialog())
                        {
                            dlg.Text                 = CommandStrings.ImportingTitle;
                            dlg.NewDirectoryName     = reposUrl.ToString();
                            dlg.NewDirectoryReadonly = true;

                            if (dlg.ShowDialog(e.Context) != DialogResult.OK)
                            {
                                return(false);
                            }

                            logMessage = dlg.LogMessage;
                        }
                        IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>();

                        documentTracker.SaveDocuments(projectFiles); // Make sure all files are saved before updating/merging!

                        using (DocumentLock lck = documentTracker.LockDocuments(projectFiles, DocumentLockType.NoReload))
                            using (lck.MonitorChangesForReload())
                            {
                                e.GetService <IProgressRunner>().RunModal(CommandStrings.ImportingTitle,
                                                                          delegate(object sender, ProgressWorkerArgs a)
                                {
                                    SvnImportArgs importArgs = new SvnImportArgs();
                                    importArgs.LogMessage    = logMessage;
                                    importArgs.Filter       +=
                                        delegate(object ieSender, SvnImportFilterEventArgs ie)
                                    {
                                        if (ie.NodeKind != SvnNodeKind.Directory)
                                        {
                                            ie.Filter = !projectFiles.Contains(ie.FullPath);
                                        }
                                        else
                                        {
                                            bool filter = true;
                                            foreach (string p in projectFiles)
                                            {
                                                if (SvnItem.IsBelowRoot(p, ie.FullPath))
                                                {
                                                    filter = false;
                                                    break;
                                                }
                                            }
                                            if (filter)
                                            {
                                                ie.Filter = true;
                                            }
                                        }
                                    };
                                    a.Client.Import(wcDir, reposUrl, importArgs);
                                });
                            }
                    }

                    shouldMarkAsManaged = dialog.MarkAsManaged;
                    storeReference      = dialog.WriteCheckOutInformation;
                }
            return(true);
        }
Beispiel #6
0
        static bool CheckoutWorkingCopyForSolution(CommandEventArgs e, ref bool confirmed)
        {
            using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient())
                using (AddToSubversion dialog = new AddToSubversion())
                {
                    dialog.PathToAdd = e.Selection.SolutionFilename;
                    if (e.Argument is IAnkhSccService)
                    {
                        dialog.CommitAllVisible = false;
                        dialog.CommitAllFiles   = false;
                    }
                    else
                    {
                        dialog.CommitAllFiles = true;
                    }

                    if (dialog.ShowDialog(e.Context) != DialogResult.OK)
                    {
                        return(false); // Don't set as managed by AnkhSVN
                    }
                    confirmed = true;

                    if (dialog.CommitAllFiles)
                    {
                        HybridCollection <string> allFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);

                        string logMessage;
                        string wcPath   = dialog.WorkingCopyDir;
                        Uri    reposUrl = dialog.RepositoryAddUrl;

                        allFiles.UniqueAddRange(e.GetService <IProjectFileMapper>().GetAllFilesOfAllProjects(true));
                        using (CreateDirectoryDialog dlg = new CreateDirectoryDialog())
                        {
                            dlg.Text                 = CommandStrings.ImportingTitle;
                            dlg.NewDirectoryName     = dialog.RepositoryAddUrl.ToString();
                            dlg.NewDirectoryReadonly = true;

                            if (dlg.ShowDialog(e.Context) != DialogResult.OK)
                            {
                                return(false);
                            }

                            logMessage = dlg.LogMessage;
                        }


                        IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>();

                        documentTracker.SaveDocuments(allFiles); // Make sure all files are saved before updating/merging!

                        using (DocumentLock lck = documentTracker.LockDocuments(allFiles, DocumentLockType.NoReload))
                            using (lck.MonitorChangesForReload())
                            {
                                e.GetService <IProgressRunner>().RunModal(CommandStrings.ImportingTitle,
                                                                          delegate(object sender, ProgressWorkerArgs a)
                                {
                                    SvnImportArgs importArgs = new SvnImportArgs();
                                    importArgs.LogMessage    = logMessage;
                                    importArgs.Filter       +=
                                        delegate(object ieSender, SvnImportFilterEventArgs ie)
                                    {
                                        if (ie.NodeKind != SvnNodeKind.Directory)
                                        {
                                            ie.Filter = !allFiles.Contains(ie.FullPath);
                                        }
                                        else
                                        {
                                            bool filter = true;
                                            foreach (string p in allFiles)
                                            {
                                                if (SvnItem.IsBelowRoot(p, ie.FullPath))
                                                {
                                                    filter = false;
                                                    break;
                                                }
                                            }
                                            if (filter)
                                            {
                                                ie.Filter = true;
                                            }
                                        }
                                    };
                                    a.Client.Import(wcPath, reposUrl, importArgs);
                                });
                            }
                    }
                    else
                    {
                        Collection <SvnInfoEventArgs> info;
                        SvnInfoArgs ia = new SvnInfoArgs();
                        ia.ThrowOnError = false;
                        if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info))
                        {
                            // Target uri doesn't exist in the repository, let's create
                            if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl))
                            {
                                return(false); // Create failed; bail out
                            }
                        }

                        // Create working copy
                        SvnCheckOutArgs coArg = new SvnCheckOutArgs();
                        coArg.AllowObstructions = true;
                        cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg);

                        // Add solutionfile so we can set properties (set managed)
                        AddPathToSubversion(e, e.Selection.SolutionFilename);

                        IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>();
                        IProjectFileMapper    mapper   = e.GetService <IProjectFileMapper>();
                        IFileStatusMonitor    monitor  = e.GetService <IFileStatusMonitor>();

                        settings.ProjectRoot = SvnTools.GetNormalizedFullPath(dialog.WorkingCopyDir);

                        if (monitor != null && mapper != null)
                        {
                            // Make sure all visible glyphs are updated to reflect a new working copy
                            monitor.ScheduleSvnStatus(mapper.GetAllFilesOfAllProjects());
                        }
                    }

                    return(true);
                }
        }