Exemplo n.º 1
0
        public RepositoryListItem(RepositoryListView view, SharpSvn.Remote.ISvnRepositoryListItem listItem, SvnOrigin dirOrigin, IFileIconMapper iconMapper)
            : base(view)
        {
            if (listItem == null)
            {
                throw new ArgumentNullException("listItem");
            }
            else if (dirOrigin == null)
            {
                throw new ArgumentNullException("dirOrigin");
            }

            SvnDirEntry entry    = listItem.Entry;
            Uri         entryUri = listItem.Uri;

            _entry  = entry;
            _origin = new SvnOrigin(entryUri, dirOrigin);

            string name = SvnTools.GetFileName(entryUri);

            bool isFile = (entry.NodeKind == SvnNodeKind.File);

            string extension = isFile ? Path.GetExtension(name) : "";

            if (iconMapper != null)
            {
                if (isFile)
                {
                    ImageIndex = iconMapper.GetIconForExtension(extension);
                }
                else
                {
                    ImageIndex = iconMapper.DirectoryIcon;
                }
            }

            SvnLockInfo      lockInfo = null;
            SvnListEventArgs lea      = listItem as SvnListEventArgs;

            if (lea != null)
            {
                lockInfo = lea.Lock;
            }

            SetValues(
                name,
                IsFolder ? RepositoryStrings.ExplorerDirectoryName : view.Context.GetService <IFileIconMapper>().GetFileType(extension),
                entry.Revision.ToString(),
                entry.Author,
                IsFolder ? "" : entry.FileSize.ToString(),
                entry.Time.ToLocalTime().ToString("g"),
                (lockInfo != null) ? lockInfo.Owner : "");
        }
Exemplo n.º 2
0
    static void Main(string[] args)
    {
        Uri uri = null;

        if (args.Length < 2 ||
            !Uri.TryCreate(args[0], UriKind.Absolute, out uri))
        {
            Console.Error.WriteLine("Usage: SvnDumpFileToRepository URL PATH");
        }
        using (SvnRepositoryClient repos = new SvnRepositoryClient())
        {
            repos.CreateRepository(args[1]);
        }
        Uri reposUri = SvnTools.LocalPathToUri(args[1], true);

        using (SvnClient client = new SvnClient())
            using (SvnClient client2 = new SvnClient())
            {
                SvnUI.Bind(client, new SvnUIBindArgs());
                string fileName = SvnTools.GetFileName(uri);
                bool   create   = true;
                client.FileVersions(uri,
                                    delegate(object sender, SvnFileVersionEventArgs e)
                {
                    Console.Write("Copying {0} in r{1}", fileName, e.Revision);
                    using (MemoryStream ms = new MemoryStream())
                    {
                        e.WriteTo(ms);     // Write full text to memory stream
                        ms.Position = 0;
                        // And now use 'svnmucc' to update repository
                        client2.RepositoryOperation(reposUri,
                                                    new SvnRepositoryOperationArgs {
                            LogMessage = e.LogMessage
                        },
                                                    delegate(SvnMultiCommandClient mucc)
                        {
                            if (create)
                            {
                                mucc.CreateFile(fileName, ms);
                                create = false;
                            }
                            else
                            {
                                mucc.UpdateFile(fileName, ms);
                            }
                        });
                    }
                });
            }
    }
Exemplo n.º 3
0
        public void TestUriCanonicalization()
        {
            Assert.That(new Uri("svn://127.0.0.1:1234").ToString(), Is.EqualTo("svn://127.0.0.1:1234/"));
            Assert.That(new SvnUriTarget(new Uri("svn://127.0.0.1:1234")).TargetName, Is.EqualTo("svn://127.0.0.1:1234/"));

            Assert.That(SvnTools.GetFileName(new Uri("http://svn/dir/File%23%25q/")), Is.EqualTo("File#%q"));
            Assert.That(SvnTools.GetFileName(new Uri("http://svn/dir/File%23%25q?abc")), Is.EqualTo("File#%q"));

            Assert.That(SvnTools.GetFileName(new Uri("http://svn/File%23%25q/")), Is.EqualTo("File#%q"));
            Assert.That(SvnTools.GetFileName(new Uri("http://user@svn/File%23%25q?abc")), Is.EqualTo("File#%q"));

            Assert.That(SvnTools.GetFileName(new Uri("http://svn/")), Is.EqualTo(""));
            Assert.That(SvnTools.GetFileName(new Uri("http://user@svn")), Is.EqualTo(""));

            Assert.That(SvnTools.GetFileName(new Uri("http://svn/q/")), Is.EqualTo("q"));
            Assert.That(SvnTools.GetFileName(new Uri("http://user@svn/r#")), Is.EqualTo("r"), "# is not part of the repository url");
            Assert.That(SvnTools.GetFileName(new Uri("http://svn/s")), Is.EqualTo("s"));
        }
Exemplo n.º 4
0
        public void InfoTest2()
        {
            SvnSandBox sbox     = new SvnSandBox(this);
            Uri        ReposUrl = sbox.CreateRepository(SandBoxRepository.Default);

            using (SvnClient client = NewSvnClient(false, false))
            {
                Collection <SvnInfoEventArgs> items;
                client.GetInfo(ReposUrl, new SvnInfoArgs(), out items);

                Assert.That(items, Is.Not.Null, "Items retrieved");
                Assert.That(items.Count, Is.EqualTo(1), "1 info item");

                string fileName = SvnTools.GetFileName(ReposUrl);

                SvnInfoEventArgs info = items[0];
                Assert.That(info.Uri.AbsoluteUri, Is.EqualTo(ReposUrl.AbsoluteUri), "Repository uri matches");
                Assert.That(info.HasLocalInfo, Is.False, "No WC info");
                Assert.That(info.Path, Is.EqualTo(Path.GetFileName(ReposUrl.LocalPath.TrimEnd('\\'))), "Path is end of folder name");
            }
        }
Exemplo n.º 5
0
        void OnFill(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException();
            }

            try
            {
                using (SvnPoolRemoteSession session = GetSession(uri))
                {
                    string path = session.MakeRelativePath(uri);

                    SvnRemoteListArgs la = new SvnRemoteListArgs();
                    la.ThrowOnError    = false;
                    la.RetrieveEntries = SvnDirEntryItems.Kind;

                    Uri repositoryRoot        = null;
                    List <ListViewItem> items = new List <ListViewItem>();

                    SvnRemoteNodeKindArgs commonArgs = new SvnRemoteNodeKindArgs();
                    commonArgs.ThrowOnError = false;
                    SvnNodeKind kind;

                    session.GetNodeKind(path, commonArgs, out kind);

                    session.GetRepositoryRoot(out repositoryRoot);

                    bool ok = (kind == SvnNodeKind.File) || session.List(path, la,
                                                                         delegate(object sender, SvnRemoteListEventArgs e)
                    {
                        if (string.IsNullOrEmpty(e.Path))
                        {
                            return;
                        }

                        ListViewItem lvi = new ListViewItem();
                        lvi.Tag          = e.Uri;
                        lvi.Text         = SvnTools.GetFileName(e.Uri);
                        lvi.ImageIndex   = (e.Entry.NodeKind == SvnNodeKind.Directory) ? _dirOffset : _fileOffset;
                        items.Add(lvi);
                    });


                    if (IsHandleCreated)
                    {
                        Invoke((AnkhAction) delegate()
                        {
                            if (uri == _currentUri)
                            {
                                dirView.Items.Clear();

                                if (repositoryRoot != null && !_repositoryRoots.Contains(repositoryRoot))
                                {
                                    _repositoryRoots.Add(repositoryRoot);
                                }

                                if (ok)
                                {
                                    IFileIconMapper mapper = Context != null ? Context.GetService <IFileIconMapper>() : null;

                                    foreach (ListViewItem item in items)
                                    {
                                        if (item.ImageIndex == _fileOffset)
                                        {
                                            string ext = Path.GetExtension(item.Text);

                                            if (!string.IsNullOrEmpty(ext))
                                            {
                                                int n = mapper.GetIconForExtension(ext);

                                                if (n > 0)
                                                {
                                                    item.ImageIndex = n;
                                                }
                                            }
                                        }
                                    }

                                    SetView(items.ToArray());
                                    _walking[uri] = items;
                                }
                                else
                                {
                                    string message =
                                        string.Format("<{0}>",
                                                      la.LastException != null ? la.LastException.Message : "Nothing");
                                    dirView.Items.Add(message);
                                }
                            }
                        });
                    }
                }
            }
            catch (SvnException svnEx)
            {
                BeginInvoke((AnkhAction) delegate()
                {
                    dirView.Items.Clear();

                    string message =
                        string.Format("<{0}>", svnEx.Message);
                    dirView.Items.Add(message);
                });
            }
            finally
            {
                BeginInvoke((AnkhAction) delegate()
                {
                    lock (_running)
                    {
                        _running.Remove(uri);

                        if (_running.Count == 0)
                        {
                            if (_busy != null && _loading)
                            {
                                _loading = false;
                                _busy.Hide();
                            }
                        }
                    }
                });
                // Exception or something
            }
        }
Exemplo n.º 6
0
        public override void OnExecute(CommandEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Uri selectedUri = null;
            Uri rootUri     = null;

            bool addingProject = (e.Command == AnkhCommand.FileFileAddFromSubversion ||
                                  e.Command == AnkhCommand.FileSccAddFromSubversion);

            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())
                {
                    if (addingProject)
                    {
                        dlg.Text = CommandStrings.AddProjectFromSubversion;
                    }

                    dlg.Filter = settings.OpenProjectFilterName + "|" + settings.AllProjectExtensionsFilter + "|All Files (*.*)|*";

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

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

                    selectedUri = dlg.SelectedUri;
                    rootUri     = dlg.SelectedRepositoryRoot;
                }
            }
            else if (rootUri == null)
            {
                if (!e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingRepositoryRoot,
                                                               delegate(object sender, ProgressWorkerArgs a)
                {
                    rootUri = a.Client.GetRepositoryRoot(selectedUri);
                }).Succeeded)
                {
                    return;
                }
            }

            string defaultPath = settings.NewProjectLocation;

            if (addingProject)
            {
                IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();

                if (!string.IsNullOrEmpty(ss.ProjectRoot))
                {
                    defaultPath = ss.ProjectRoot;
                }
            }

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

            string newPath;
            int    n = 0;

            do
            {
                newPath = Path.Combine(defaultPath, 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;

                if (addingProject)
                {
                    dlg.Text = CommandStrings.AddProjectFromSubversion;
                }
                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;
                }

                if (!addingProject)
                {
                    OpenSolution(e, dlg);
                }
                else
                {
                    CheckOutAndOpenProject(e, dlg.ProjectTop, dlg.Revision, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri);
                }
            }
        }
Exemplo n.º 7
0
        public void OnClientNotify(object sender, SvnNotifyEventArgs e)
        {
            //e.Detach();

            string          path   = e.FullPath;
            Uri             uri    = e.Uri;
            SvnNotifyAction action = e.Action;
            long            rev    = e.Revision;

            Enqueue(delegate()
            {
                ListViewItem item = null;
                string text       = GetActionText(action);

                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                item = new ListViewItem(text);

                switch (action)
                {
                case SvnNotifyAction.BlameRevision:
                    {
                        string file;
                        if (uri != null)
                        {
                            file = SvnTools.GetFileName(uri);
                        }
                        else
                        {
                            file = Path.GetFileName(path);
                        }

                        item.SubItems.Add(string.Format("{0} - r{1}", file, rev));
                        break;
                    }

                default:
                    if (uri != null)
                    {
                        item.SubItems.Add(uri.ToString());
                    }
                    else if (!string.IsNullOrEmpty(path))
                    {
                        string sr = SplitRoot;
                        if (!string.IsNullOrEmpty(sr) && SvnItem.IsBelowRoot(path, sr))
                        {
                            string np = SvnItem.SubPath(path, sr, true);

                            if (np.IndexOf(':') == 1)
                            {
                                path = np;     // Full path
                            }
                            else
                            {
                                path = np.Replace(Path.DirectorySeparatorChar, '/');
                            }
                        }

                        item.SubItems.Add(path);
                    }
                    break;
                }

                if (item != null)
                {
                    _toAdd.Add(item);
                }
            });
        }