Пример #1
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;
        }
Пример #2
0
        public bool CheckoutRepository(CheckoutRepositoryRequest request)
        {
            var projectFolder = DirectoryHelper.GetRepositoryFolder(request.ProjectName, request.Branch);

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

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

            using (var client = createClient())
            {

                try
                {
                    if(ClientProgress != null)
                        client.Progress += ClientProgress;

                    var repositoryUri =
                        $"{request.SvnServerUrl}/";

                    if (request.Branch.IsNotBlank())
                    {
                        Collection<SvnListEventArgs> rootList;

                        if (!client.GetList(request.SvnServerUrl, out rootList))
                            return false;

                        repositoryUri = request.SvnServerUrl + "/" +
                                          rootList.First(f => f.Name.ToLower().StartsWith("branch"))
                                          .Name + "/" + request.Branch;
                    }
                    else
                    {

                        repositoryUri += SettingsService.Current.DefaultSvnPath;
                    }

                    var result =
                        client.CheckOut(
                            new SvnUriTarget(repositoryUri),
                            projectFolder);
                }
                catch (SvnRepositoryIOException ex)
                {
                    if (ex.SvnErrorCode == SvnErrorCode.SVN_ERR_RA_ILLEGAL_URL)
                    {
                        //default path does not exist, checkout the root
                        var result =
                        client.CheckOut(
                            new SvnUriTarget($"{request.SvnServerUrl}"),
                            projectFolder);
                        return result;
                    }

                    if (ex.SvnErrorCode == SvnErrorCode.SVN_ERR_RA_CANNOT_CREATE_SESSION)
                    {
                        request.Credentials = RequestCredentials(request.SvnServerUrl);

                        if (request.Credentials != null)
                        {
                            return CheckoutRepository(request);
                        }
                    }

                    NotificationHelper.Show(SvnErrorHandling.FormatError(ex.Message));
                    return false;
                }
                catch (Exception ex)
                {
                    NotificationHelper.Show(SvnErrorHandling.FormatError(ex.Message));
                    return false;
                }
            }

            NotificationHelper.Show($"{request.ProjectName} checked out",
                onActivate: (sender, args) =>
                {
                    //When the toast is clicked, open the newly checked out folder
                    Process.Start(projectFolder);
                });
            return true;
        }