コード例 #1
0
ファイル: OpenFromSubversion.cs プロジェクト: necora/ank_git
        public override void OnExecute(CommandEventArgs e)
        {
            Uri selectedUri = null;
            Uri rootUri = null;

            if (e.Argument is string && Uri.TryCreate((string)e.Argument, UriKind.Absolute, out selectedUri))
            { }
            else if (e.Argument is SvnOrigin)
            {
                SvnOrigin origin = (SvnOrigin)e.Argument;
                selectedUri = origin.Uri;
                rootUri = origin.RepositoryRoot;
            }
            else if (e.Argument is Uri)
                selectedUri = (Uri)e.Argument;

            IAnkhSolutionSettings settings = e.GetService<IAnkhSolutionSettings>();

            if (e.PromptUser || selectedUri == null)
            {
                using (RepositoryOpenDialog dlg = new RepositoryOpenDialog())
                {
                    dlg.Context = e.Context;
                    dlg.Filter = settings.OpenProjectFilterName + "|" + settings.AllProjectExtensionsFilter + "|All Files (*.*)|*";

                    if (selectedUri != null)
                        dlg.SelectedUri = selectedUri;

                    if (e.Command != AnkhCommand.FileFileOpenFromSubversion && e.Command != AnkhCommand.FileSccOpenFromSubversion)
                    {
                        foreach (string ext in settings.SolutionFilter.Split(';'))
                        {
                            dlg.Filter = dlg.Filter.Replace(ext.Trim() + ';', "");
                        }
                    }

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

                    selectedUri = dlg.SelectedUri;
                    rootUri = dlg.SelectedRepositoryRoot;
                }
            }
            else if (rootUri == null)
            {
                if (!e.GetService<IProgressRunner>().RunModal("Retrieving Repository Root",
                    delegate(object sender, ProgressWorkerArgs a)
                    {

                        rootUri = a.Client.GetRepositoryRoot(selectedUri);

                    }).Succeeded)
                {
                    return;
                }
            }

            string path = settings.NewProjectLocation;

            string name = Path.GetFileNameWithoutExtension(SvnTools.GetFileName(selectedUri));

            string newPath;
            int n = 0;
            do
            {
                newPath = Path.Combine(path, name);
                if (n > 0)
                    newPath += string.Format("({0})", n);
                n++;
            }
            while (File.Exists(newPath) || Directory.Exists(newPath));

            using (CheckoutProject dlg = new CheckoutProject())
            {
                dlg.Context = e.Context;
                dlg.ProjectUri = selectedUri;
                dlg.RepositoryRootUri = rootUri;
                dlg.SelectedPath = newPath;
                dlg.SvnOrigin = new SvnOrigin(selectedUri, rootUri);
                dlg.HandleCreated += delegate
                {
                    FindRoot(e.Context, selectedUri, dlg);
                };

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

                IVsSolution2 sol = e.GetService<IVsSolution2>(typeof(SVsSolution));

                if (sol != null)
                {
                    sol.CloseSolutionElement(VSConstants.VSITEMID_ROOT, null, 0); // Closes the current solution
                }

                IAnkhSccService scc = e.GetService<IAnkhSccService>();

                if (scc != null)
                    scc.RegisterAsPrimarySccProvider(); // Make us the current SCC provider!

                CheckOutAndOpenSolution(e, dlg.ProjectTop, null, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri);

                sol = e.GetService<IVsSolution2>(typeof(SVsSolution));

                if (sol != null)
                {
                    string file, user, dir;

                    if (ErrorHandler.Succeeded(sol.GetSolutionInfo(out dir, out file, out user))
                        && !string.IsNullOrEmpty(file))
                    {
                        scc.SetProjectManaged(null, true);
                    }
                }
            }
        }
コード例 #2
0
ファイル: OpenFromSubversion.cs プロジェクト: necora/ank_git
        private static void FindRoot(IAnkhServiceProvider context, Uri selectedUri, CheckoutProject dlg)
        {
            AnkhAction ds = delegate
            {
                using (SvnClient client = context.GetService<ISvnClientPool>().GetClient())
                {
                    string value;
                    if (client.TryGetProperty(selectedUri, AnkhSccPropertyNames.ProjectRoot, out value))
                    {
                        if (dlg.IsHandleCreated)
                            dlg.Invoke((AnkhAction)delegate
                            {
                                try
                                {
                                    dlg.ProjectTop = new Uri(selectedUri, value);
                                }
                                catch { };
                            });
                    }
                }
            };

            ds.BeginInvoke(null, null);
        }