示例#1
1
        private static void CheckoutUpdate(Parameters parameters)
        {
            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

                var target = SvnTarget.FromString(parameters.Path);
                SvnInfoEventArgs svnInfoEventArgs;
                SvnUpdateResult svnUpdateResult;

                var nonExistentUrl = false;
                EventHandler<SvnErrorEventArgs> ignoreNonexistent = (o, eventArgs) =>
                                                                        {
                                                                            nonExistentUrl = false;
                                                                            //if (eventArgs.Exception.SubversionErrorCode == 170000)
                                                                            if(eventArgs.Exception.Message.Contains("non-existent in revision"))
                                                                            {
                                                                                nonExistentUrl = true;
                                                                                eventArgs.Cancel = true;
                                                                            }
                                                                        };

                if(client.GetWorkingCopyRoot(parameters.Path) == null)
                {
                    client.SvnError += ignoreNonexistent;
                    var getInfoSucceeded = client.GetInfo(SvnUriTarget.FromString(parameters.Url), out svnInfoEventArgs);
                    client.SvnError -= ignoreNonexistent;

                    if(!getInfoSucceeded)
                    {
                        if (nonExistentUrl)
                        {
                            Console.WriteLine("SVN info reported nonexistent URL; creating remote directory.");
                            if (!client.RemoteCreateDirectory(new Uri(parameters.Url), new SvnCreateDirectoryArgs {CreateParents = true, LogMessage = parameters.Message}))
                            {
                                throw new Exception("Create directory failed on " + parameters.Url);
                            }
                        }
                        else
                        {
                            throw new Exception("SVN info failed");
                        }
                    }

                    DebugMessage(parameters, "Checking out");
                    if (client.CheckOut(SvnUriTarget.FromString(parameters.Url), parameters.Path, out svnUpdateResult))
                    {
                        DebugMessage(parameters, "Done");
                        Console.WriteLine("Checked out r" + svnUpdateResult.Revision);
                        return;
                    }

                    throw new Exception("SVN checkout failed");
                }

                if(!client.GetInfo(target, out svnInfoEventArgs))
                {
                    throw new Exception("SVN info failed");
                }

                if(!UrlsMatch(svnInfoEventArgs.Uri.ToString(), parameters.Url))
                {
                    throw new Exception(string.Format("A different URL is already checked out ({0} != {1})", svnInfoEventArgs.Uri, parameters.Url));
                }

                if(parameters.Cleanup)
                {
                    DebugMessage(parameters, "Cleaning up");
                    client.CleanUp(parameters.Path);
                    DebugMessage(parameters, "Done");
                }

                if(parameters.Revert)
                {
                    DebugMessage(parameters, "Reverting");
                    client.Revert(parameters.Path);
                    DebugMessage(parameters, "Done");
                }

                if (parameters.DeleteUnversioned)
                {
                    DebugMessage(parameters, "Deleting unversioned files");
                    Collection<SvnStatusEventArgs> changedFiles;
                    client.GetStatus(parameters.Path, out changedFiles);
                    foreach (var changedFile in changedFiles)
                    {
                        if(changedFile.LocalContentStatus == SvnStatus.NotVersioned)
                        {
                            if(changedFile.NodeKind == SvnNodeKind.Directory)
                            {
                                DebugMessage(parameters, "NodeKind is directory for [" + changedFile.FullPath + "]");
                            }
                            if ((File.GetAttributes(changedFile.FullPath) & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                DebugMessage(parameters, "Deleting directory [" + changedFile.FullPath + "] recursively!");
                                Directory.Delete(changedFile.FullPath, true);
                            }
                            else
                            {
                                DebugMessage(parameters, "Deleting file [" + changedFile.FullPath + "]");
                                File.Delete(changedFile.FullPath);
                            }
                        }
                    }
                    DebugMessage(parameters, "Done");
                }

                DebugMessage(parameters, "Updating");
                if(client.Update(parameters.Path, out svnUpdateResult))
                {
                    DebugMessage(parameters, "Done");
                    Console.WriteLine("Updated to r" + svnUpdateResult.Revision);
                    return;
                }

                throw new Exception("SVN update failed");
            }
        }
示例#2
0
        public bool CheckoutRepository(CheckoutRepositoryRequest request)
        {
            var projectFolder = GetRepositoryFolder(request.ProjectName);

            if (!Directory.Exists(projectFolder))
            {
                Directory.CreateDirectory(projectFolder);
            }

            request.SvnServerUrl = request.SvnServerUrl.RemoveTrailing('/');

            using (var client = new SharpSvn.SvnClient())
            {
                try
                {
                    client.Authentication.ForceCredentials(request.SvnUsername, request.SvnPassword);
                    var result =
                        client.CheckOut(
                            new SvnUriTarget($"{request.SvnServerUrl}/{SettingsService.Current.DefaultSvnPath}"),
                            projectFolder);
                }
                catch (Exception ex)
                {
                    NotificationHelper.Show(SvnErrorHandling.FormatError(ex.Message));
                    return false;
                }
            }

            NotificationHelper.Show($"{request.ProjectName} checked out");
            return true;
        }
示例#3
0
        internal bool CheckOut(SvnUriTarget target, string path, SvnCheckOutArgs args, out SvnUpdateResult result)
        {
            bool checkoutResult;


            using (SharpSvn.SvnClient client = new SharpSvn.SvnClient())
            {
                client.Authentication.ForceCredentials("selin", "123456");

                checkoutResult = client.CheckOut(new Uri("https://DESKTOP-CK68HBF/svn/test"),
                                                 path, out result);
            }

            return(checkoutResult);
        }
示例#4
0
        private static void CheckoutUpdate(Parameters parameters)
        {
            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

                var target = SvnTarget.FromString(parameters.Path);
                SvnInfoEventArgs svnInfoEventArgs;
                SvnUpdateResult  svnUpdateResult;

                var nonExistentUrl = false;
                EventHandler <SvnErrorEventArgs> ignoreNonexistent = (o, eventArgs) =>
                {
                    nonExistentUrl = false;
                    //if (eventArgs.Exception.SubversionErrorCode == 170000)
                    if (eventArgs.Exception.Message.Contains("non-existent in revision"))
                    {
                        nonExistentUrl   = true;
                        eventArgs.Cancel = true;
                    }
                };

                if (client.GetWorkingCopyRoot(parameters.Path) == null)
                {
                    client.SvnError += ignoreNonexistent;
                    var getInfoSucceeded = client.GetInfo(SvnUriTarget.FromString(parameters.Url), out svnInfoEventArgs);
                    client.SvnError -= ignoreNonexistent;

                    if (!getInfoSucceeded)
                    {
                        if (nonExistentUrl)
                        {
                            Console.WriteLine("SVN info reported nonexistent URL; creating remote directory.");
                            if (!client.RemoteCreateDirectory(new Uri(parameters.Url), new SvnCreateDirectoryArgs {
                                CreateParents = true, LogMessage = parameters.Message
                            }))
                            {
                                throw new Exception("Create directory failed on " + parameters.Url);
                            }
                        }
                        else
                        {
                            throw new Exception("SVN info failed");
                        }
                    }

                    DebugMessage(parameters, "Checking out");
                    if (client.CheckOut(SvnUriTarget.FromString(parameters.Url), parameters.Path, out svnUpdateResult))
                    {
                        DebugMessage(parameters, "Done");
                        Console.WriteLine("Checked out r" + svnUpdateResult.Revision);
                        return;
                    }

                    throw new Exception("SVN checkout failed");
                }

                if (!client.GetInfo(target, out svnInfoEventArgs))
                {
                    throw new Exception("SVN info failed");
                }

                if (!UrlsMatch(svnInfoEventArgs.Uri.ToString(), parameters.Url))
                {
                    throw new Exception(string.Format("A different URL is already checked out ({0} != {1})", svnInfoEventArgs.Uri, parameters.Url));
                }

                if (parameters.Cleanup)
                {
                    DebugMessage(parameters, "Cleaning up");
                    client.CleanUp(parameters.Path);
                    DebugMessage(parameters, "Done");
                }

                if (parameters.Revert)
                {
                    DebugMessage(parameters, "Reverting");
                    client.Revert(parameters.Path);
                    DebugMessage(parameters, "Done");
                }

                if (parameters.DeleteUnversioned)
                {
                    DebugMessage(parameters, "Deleting unversioned files");
                    Collection <SvnStatusEventArgs> changedFiles;
                    client.GetStatus(parameters.Path, out changedFiles);
                    foreach (var changedFile in changedFiles)
                    {
                        if (changedFile.LocalContentStatus == SvnStatus.NotVersioned)
                        {
                            if (changedFile.NodeKind == SvnNodeKind.Directory)
                            {
                                DebugMessage(parameters, "NodeKind is directory for [" + changedFile.FullPath + "]");
                            }
                            if ((File.GetAttributes(changedFile.FullPath) & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                DebugMessage(parameters, "Deleting directory [" + changedFile.FullPath + "] recursively!");
                                Directory.Delete(changedFile.FullPath, true);
                            }
                            else
                            {
                                DebugMessage(parameters, "Deleting file [" + changedFile.FullPath + "]");
                                File.Delete(changedFile.FullPath);
                            }
                        }
                    }
                    DebugMessage(parameters, "Done");
                }

                DebugMessage(parameters, "Updating");
                if (client.Update(parameters.Path, out svnUpdateResult))
                {
                    DebugMessage(parameters, "Done");
                    Console.WriteLine("Updated to r" + svnUpdateResult.Revision);
                    return;
                }

                throw new Exception("SVN update failed");
            }
        }
        private void btnCheckout_Click(object sender, EventArgs e)
        {
            if (tbLocalPath.Text.Length == 0 || tbRepoURI.Text.Length == 0)
            {
                MessageBox.Show("The 'Repository URI' and 'Local Path' fields cannot be empty.");
                return;
            }

            //SvnUpdateResult provides info about what happened during a checkout
            SvnUpdateResult result;

            //we will use this to tell CheckOut() which revision to fetch
            long revision;

            //SvnCheckoutArgs wraps all of the options for the 'svn checkout' function
            SvnCheckOutArgs args = new SvnCheckOutArgs();

            //path is the path where the local working copy will end up
            string path = tbLocalPath.Text;

            if (long.TryParse(tbRevision.Text, out revision))
            {
                //set the revision number if the user entered a valid number
                args.Revision = new SvnRevision(revision);
            }
            //if args.Revision is not set, it defaults to fetch the HEAD revision.
            else
            {
                MessageBox.Show("Invalid Revision number, defaulting to HEAD");
            }

            //the using statement is necessary to ensure we are freeing up resources
            using (SharpSvn.SvnClient client = new SharpSvn.SvnClient())
            {
                try
                {
                    //SvnUriTarget is a wrapper class for SVN repository URIs
                    SvnUriTarget target = new SvnUriTarget(tbRepoURI.Text);

                    if (cbAuthenticate.Checked == true)
                    {
                        logMsg("Authenticating");
                        client.Authentication.Clear(); // Clear a previous authentication

                        client.Authentication.SslServerTrustHandlers += new EventHandler <SharpSvn.Security.SvnSslServerTrustEventArgs>(SVN_SSL_Override);

                        client.Authentication.UserNamePasswordHandlers += delegate(object obj, SharpSvn.Security.SvnUserNamePasswordEventArgs val)
                        {
                            val.UserName = textUserid.Text;
                            val.Password = textPassword.Text;
                            val.Save     = true;
                        };
                    }
                    logMsg("Checking out from:");
                    logMsg(tbRepoURI.Text);

                    //this is the where 'svn checkout' actually happens.

                    if (client.CheckOut(target, path, args, out result))
                    {
                        MessageBox.Show("Successfully checked out revision " + result.Revision + ".");
                        logMsg("Successfully checked out revision " + result.Revision + ".");
                    }
                }
                catch (SvnException se)
                {
                    MessageBox.Show(textUserid.Text + " " + textPassword.Text + " " + se.Message,
                                    "svn checkout error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    logMsg("svn error code: " + se.SubversionErrorCode);
                    logMsg("SvnErrorCategory: " + se.SvnErrorCategory);
                    logMsg(se.StackTrace);
                }
                catch (UriFormatException ufe)
                {
                    MessageBox.Show(ufe.Message,
                                    "svn checkout error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }