Exemple #1
0
        private MemoryStream GetSVNFileStream(SvnRevisionId changeset, string path)
        {
            var       memoryStream = new MemoryStream();
            SvnTarget target;

            //If you use Uri you should encode '#' as %23, as Uri's define the # as Fragment separator.
            //And in this case the fragment is not send to the server.
            path = path.Replace("#", "%23");
            if (SvnTarget.TryParse(GetPath(path).AbsolutePath, out target))
            {
                if (FileWasDeleted(path, changeset))
                {
                    return(new MemoryStream());
                }

                var uriTarget    = new SvnUriTarget(_root + path, changeset.Value);
                var svnWriteArgs = new SvnWriteArgs {
                    Revision = changeset.Value
                };

                Client.Write(uriTarget, memoryStream, svnWriteArgs);
                return(memoryStream);
            }
            return(new MemoryStream());
        }
Exemple #2
0
        public bool commit(UsuarioSVN usuSVN, string Mensaje)
        {
            bool            EsCorrecto = true;
            SvnUpdateResult result;
            SvnCommitArgs   ca = new SvnCommitArgs();

            using (SvnClient client = new SvnClient())
            {
                try
                {
                    client.Authentication.ForceCredentials(usuSVN.Nombre, usuSVN.Contraseña);
                    //SvnUriTarget is a wrapper class for SVN repository URIs
                    SvnUriTarget target = new SvnUriTarget(usuSVN.URL);
                    client.Authentication.SslServerTrustHandlers += new EventHandler <SharpSvn.Security.SvnSslServerTrustEventArgs>(Authentication_SslServerTrustHandlers);

                    // Checkout the code to the specified directory
                    client.CheckOut(target, usuSVN.RutaLocal);

                    // Update the specified working copy path to the head revision
                    //client.Update("c:\\sharpsvn");

                    client.Update(usuSVN.RutaLocal, out result);



                    ca.LogMessage = "Mensaje";
                    client.Commit(usuSVN.RutaLocal, ca);
                }
                catch
                {
                    EsCorrecto = false;
                }
                return(EsCorrecto);
            }
        }
Exemple #3
0
        public void OnNavigatedTo(FirstFloor.ModernUI.Windows.Navigation.NavigationEventArgs e)
        {
            try
            {
                if (e.NavigationType == FirstFloor.ModernUI.Windows.Navigation.NavigationType.New)
                {
                    if (string.IsNullOrWhiteSpace(Properties.Settings.Default.ServerUri) == false)
                    {
                        projectsUri = new SvnUriTarget(Properties.Settings.Default.ServerUri + "/projects");

                        textBoxWorkSpace.Text = textBoxProjectRoot.Text + @"\";
                        if (backgroundWorkerCheckOut.IsBusy == false)
                        {
                            progressBarMain.Visibility = System.Windows.Visibility.Visible;

                            backgroundWorkerCheckOut.RunWorkerAsync(new CheckOutArguments(JobType.Load));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ModernDialog.ShowMessage(ex.Message, "Error Loading Page", MessageBoxButton.OK);
                logger.Error(ex, "Error Loading Page");
            }
        }
Exemple #4
0
        public SvnUriTarget GetCopyOrigin(SvnItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // TODO: Maybe handle cases where the parent was copied instead of the child?

            SvnUriTarget copiedFrom = null;

            using (SvnClient client = GetService <ISvnClientPool>().GetNoUIClient())
            {
                SvnInfoArgs ia = new SvnInfoArgs();
                ia.ThrowOnError = false;
                ia.Depth        = SvnDepth.Empty;

                client.Info(item.FullPath, ia,
                            delegate(object sender, SvnInfoEventArgs ee)
                {
                    if (ee.CopyFromUri != null)
                    {
                        copiedFrom = new SvnUriTarget(ee.CopyFromUri, ee.CopyFromRevision);
                    }
                });
            }
            return(copiedFrom);
        }
        public override string[] GetAvailableRevisions()
        {
            string url = Url.TrimEnd('/');

            using (SvnClient client = new SvnClient())
            {
                client.LoadConfiguration("path");
                client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password);
                SvnUriTarget target = new SvnUriTarget(url);

                List <String> filesFound = new List <String>();
                Collection <SvnListEventArgs> listResults;

                if (client.GetList(target, out listResults))
                {
                    foreach (SvnListEventArgs item in listResults)
                    {
                        if (item.Entry.NodeKind == SvnNodeKind.Directory && !string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Path))
                        {
                            filesFound.Add(item.Path);
                        }
                    }

                    return(filesFound.ToArray());
                }
            }

            return(new string[0]);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="strFileName"></param>
        /// <param name="strOutputFileDirectory"></param>
        /// <param name="strOutputName"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public Globals.ResultType DownloadFile(string strFileName, string strOutputFileDirectory, string strOutputName, ref string strError)
        {
            try
            {
                // Validation
                if (strFileName == "" || strOutputFileDirectory == "" || strOutputName == "")
                {
                    return(Globals.ResultType.Failure);
                }

                SvnUriTarget uri = new SvnUriTarget(strFileName);
                string       strOutputFileName = strOutputFileDirectory + strOutputName;

                // Download File
                System.Net.WebClient client = new System.Net.WebClient();

                // Download File
                client.DownloadFile(strFileName, strOutputFileName);

                return(Globals.ResultType.Success);
            }
            catch (Exception ex)
            {
                strError = ex.ToString();
                Console.WriteLine(strError);

                return(Globals.ResultType.Failure);
            }
        }
Exemple #7
0
        internal List <SvnListEventArgs> GetFolderList(SvnUriTarget targetUri)
        {
            try
            {
                List <SvnListEventArgs> folderList = new List <SvnListEventArgs>();

                using (SvnClient client = new SvnClient())
                {
                    // Bind the SharpSvn UI to our client for SSL certificate and credentials
                    SvnUIBindArgs bindArgs = new SvnUIBindArgs();
                    SvnUI.Bind(client, bindArgs);

                    if (this.CheckUrlValide(client, targetUri))
                    {
                        Collection <SvnListEventArgs> itemList;
                        if (client.GetList(targetUri, out itemList))
                        {
                            foreach (SvnListEventArgs component in itemList)
                            {
                                if (component.Entry.NodeKind == SvnNodeKind.Directory)
                                {
                                    folderList.Add(component);
                                }
                            }
                        }
                    }
                }

                return(folderList);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private static SvnUriTarget CreateSvnUriTarget(string uriString, SvnRevision revision)
        {
            Uri          uri    = new Uri(uriString);
            SvnUriTarget target = new SvnUriTarget(uri, revision);

            return(target);
        }
Exemple #9
0
        private async Task LoadRevisions(string path)
        {
            Revisions = new List <Revision>();
            SvnTarget target;

            if (path.Contains("://"))
            {
                target = new SvnUriTarget(path);
            }
            else
            {
                target = new SvnPathTarget(path);
            }
            var svnFileVersionsArgs = new SvnFileVersionsArgs {
                Start = SvnRevision.Zero, End = SvnRevision.Head
            };

            svnClient.FileVersions(target, svnFileVersionsArgs, (sender, args) =>
            {
                var revision = new Revision
                {
                    Author       = args.Author,
                    Message      = args.LogMessage,
                    RevisionId   = args.Revision.ToString(CultureInfo.InvariantCulture),
                    RevisionTime = args.Time,
                };

                using (TextReader reader = new StreamReader(args.GetContentStream()))
                {
                    revision.Content = reader.ReadToEnd();
                }

                Revisions.Insert(0, revision); // Put them in newest-to-oldest order
            });
        }
Exemple #10
0
        public void List_TestLowerDrive()
        {
            SvnSandBox sbox   = new SvnSandBox(this);
            string     tmpDir = sbox.GetTempDir();

            if (tmpDir.Contains(":"))
            {
                return; // Testing on UNC share
            }
            Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.Greek);

            using (SvnClient client = NewSvnClient(false, false))
            {
                Uri          origUri   = ReposUrl;
                string       uriString = origUri.AbsoluteUri;
                SvnUriTarget target    = new SvnUriTarget("file:///" + char.ToLower(uriString[8]) + uriString.Substring(9));

                client.List(target, delegate(object sender, SvnListEventArgs e)
                {
                });

                target = new SvnUriTarget("file://localhost/" + char.ToLower(uriString[8]) + uriString.Substring(9));

                client.List(target, delegate(object sender, SvnListEventArgs e)
                {
                });
            }
        }
Exemple #11
0
        public void SetUris(IEnumerable <SvnOrigin> uris)
        {
            deleteList.ClearSelected();

            SortedDictionary <Uri, SvnOrigin> d = new SortedDictionary <Uri, SvnOrigin>(UriComparer.Default);

            foreach (SvnOrigin o in uris)
            {
                SvnUriTarget ut = o.Target as SvnUriTarget;
                if (ut != null)
                {
                    d[ut.Uri] = o;
                }
                else
                {
                    d[o.Uri] = o;
                }
            }

            _uris = new Uri[d.Count];
            List <Uri> newUris = new List <Uri>();

            foreach (SvnOrigin o in d.Values)
            {
                deleteList.Items.Add(o.Uri);
                newUris.Add(SvnTools.GetNormalizedUri(o.Uri));
            }
            _uris = newUris.ToArray();
        }
Exemple #12
0
        protected override void FetchRepository(Arguments arg)
        {
            Guard.AssertNotNullOrEmpty(arg.Url, "SVN URL must be set.");

            SvnUpdateResult result;

            SvnUriTarget target = new SvnUriTarget(arg.Url);

            SvnCheckOutArgs args = new SvnCheckOutArgs();

            if (arg.Revision.HasValue)
            {
                args.Revision = new SvnRevision(arg.Revision.Value);
            }

            args.AllowObstructions = true;
            args.IgnoreExternals   = true;

            using (SvnClient client = new SvnClient())
            {
                client.Progress += ClientOnProgress;
                client.Cancel   += ClientOnCancel;
                try
                {
                    client.CheckOut(target, RootPath, args, out result);
                }
                catch (Exception e)
                {
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SvnOrigin"/> class from a SvnTarget
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="target">The target.</param>
        /// <param name="reposRoot">The repos root or <c>null</c> to retrieve the repository root from target</param>
        public SvnOrigin(IAnkhServiceProvider context, SvnTarget target, Uri reposRoot)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            else if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            SvnPathTarget pt = target as SvnPathTarget;

            if (pt != null)
            {
                SvnItem item = context.GetService <ISvnStatusCache>()[pt.FullPath];

                if (item == null || !item.IsVersioned)
                {
                    throw new InvalidOperationException("Can only create a SvnOrigin from versioned items");
                }

                _target    = target;
                _uri       = item.Status.Uri;
                _reposRoot = item.WorkingCopy.RepositoryRoot; // BH: Prefer the actual root over the provided
                return;
            }

            SvnUriTarget ut = target as SvnUriTarget;

            if (ut != null)
            {
                _target = ut;
                _uri    = ut.Uri;
                if (reposRoot != null)
                {
                    _reposRoot = reposRoot;
                }
                else
                {
                    using (SvnClient client = context.GetService <ISvnClientPool>().GetClient())
                    {
                        _reposRoot = client.GetRepositoryRoot(ut.Uri);

                        if (_reposRoot == null)
                        {
                            throw new InvalidOperationException("Can't retrieve the repository root of the UriTarget");
                        }

#if DEBUG
                        Debug.Assert(!_reposRoot.MakeRelativeUri(_uri).IsAbsoluteUri);
#endif
                    }
                }

                return;
            }

            throw new InvalidOperationException("Invalid target type");
        }
Exemple #14
0
        public bool checkedOut(UsuarioSVN usuSVN)
        {
            SvnUpdateResult result;

            SvnCheckOutArgs args = new SvnCheckOutArgs();

            using (SvnClient client = new SvnClient())
            {
                try
                {
                    client.Authentication.ForceCredentials(usuSVN.Nombre, usuSVN.Contraseña);
                    //SvnUriTarget is a wrapper class for SVN repository URIs
                    SvnUriTarget target = new SvnUriTarget(usuSVN.URL);
                    client.Authentication.SslServerTrustHandlers += new EventHandler <SharpSvn.Security.SvnSslServerTrustEventArgs>(Authentication_SslServerTrustHandlers);


                    if (client.CheckOut(target, usuSVN.RutaLocal, args, out result))
                    {
                        return(true);
                    }
                }
                catch (SvnException se)
                {
                    return(false);
                }
                catch (UriFormatException ufe)
                {
                    return(false);
                }
            }
            return(true);
        }
        public IList <string> GetCurrentVersionOfFile(long revision, string filename)
        {
            IList <string> lines = new List <string>();

            using (SvnClient client = new SvnClient())
            {
                client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);
                client.Authentication.ForceCredentials(Username, Password);
                SvnTarget target = new SvnUriTarget(new Uri(RemoteReproAuthority + filename), revision);

                using (MemoryStream ms = new MemoryStream())
                {
                    client.Write(target,
                                 ms,
                                 new SvnWriteArgs()
                    {
                        Revision = new SvnRevision(revision)
                    });

                    ms.Position = 0;
                    using (StreamReader reader = new StreamReader(ms))
                    {
                        string line = reader.ReadLine();
                        while (line != null)
                        {
                            lines.Add(line);
                            line = reader.ReadLine();
                        }
                    }
                }
            }

            return(lines);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="strFileFrom"></param>
        /// <param name="strFileTo"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        private bool CheckFileDifference(string strFileFrom, string strFileTo, ref string strError)
        {
            try
            {
                bool boolIsDifferent = false;

                // Create New Memory Stream
                using (System.IO.MemoryStream result = new System.IO.MemoryStream())
                {
                    // Create New SVN Target
                    SvnUriTarget fileFrom = new SvnUriTarget(strFileFrom);

                    // Get Target
                    SvnUriTarget fileTo = new SvnUriTarget(strFileTo);

                    // Check Differences
                    boolIsDifferent = this.Connection.Diff(fileFrom, fileTo, result);
                    System.IO.StreamReader strReader = new System.IO.StreamReader(result);

                    // Read File
                    string str = strReader.ReadToEnd();
                }

                return(boolIsDifferent);
            }
            catch (Exception ex)
            {
                strError = ex.ToString();
                Console.WriteLine(strError);

                return(false);
            }
        }
Exemple #17
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="fileName">文件夹名称</param>
        /// <returns></returns>
        public JsonResult UpdateSvn(string fileName, string user, string pwd, string type)
        {
            string result = string.Empty;

            using (SvnClient client = new SvnClient())
            {
                try
                {
                    GetPermission(client, user, pwd);
                    SvnInfoEventArgs serverInfo;
                    SvnInfoEventArgs clientInfo;
                    SvnUriTarget     repos = new SvnUriTarget("https://" + (type == "local" ? localSVN : onlineSVN) + fileName);
                    SvnPathTarget    local = new SvnPathTarget(localPath + "\\" + fileName);

                    client.GetInfo(repos, out serverInfo);

                    client.Update(localPath + "\\" + fileName);

                    client.GetInfo(local, out clientInfo);
                    if (serverInfo.Revision > 0 && clientInfo.Revision > 0)
                    {
                        result = serverInfo.Revision.ToString() + "-" + clientInfo.Revision.ToString();
                    }
                    return(Json(new { result = true }));
                }
                catch (Exception ex)
                {
                    return(Json(new { result = false, msg = ex.Message.ToString() }));
                }
            }
        }
        /// <summary>
        /// Gets the svn log entries from the repository.
        /// </summary>
        /// <returns>An IEnumerable of the QvxDataRows.</returns>
        private IEnumerable<QvxDataRow> GetSvnLogEntries()
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "GetSvnLogEntries()");

            string username, password, server;
            this.MParameters.TryGetValue("UserId", out username);
            this.MParameters.TryGetValue("Password", out password);
            this.MParameters.TryGetValue("Server", out server);
            System.Net.NetworkCredential creds = new System.Net.NetworkCredential(username, password);

            SvnClient client = new SvnClient();
            client.Authentication.DefaultCredentials = creds;

            SvnUriTarget target = new SvnUriTarget(server);

            Collection<SvnLogEventArgs> logEntries = new Collection<SvnLogEventArgs>();
            bool result = client.GetLog(target.Uri, out logEntries);

            if(!result)
            {
                throw new SvnClientException("Retrieving Subversion log failed");
            }

            foreach(SvnLogEventArgs entry in logEntries)
            {
                yield return MakeEntry(entry, FindTable("SvnLogEntries", MTables));
            }
        }
        private void EnsureCredentials(ScmUserNamePasswordEventArgs e)
        {
            ISvnClientPool pool = (Context != null) ? Context.GetService <ISvnClientPool>() : null;

            if (pool != null)
            {
                using (SvnPoolClient client = pool.GetNoUIClient())
                {
                    EventHandler <SvnUserNamePasswordEventArgs> handler = delegate(object sender, SvnUserNamePasswordEventArgs args)
                    {
                        args.Save     = true;
                        args.UserName = e.UserName;
                        args.Password = e.Password;
                    };
                    client.Authentication.UserNamePasswordHandlers += handler;
                    try
                    {
                        SvnInfoArgs infoArgs = new SvnInfoArgs();
                        infoArgs.ThrowOnError = false;
                        System.Collections.ObjectModel.Collection <SvnInfoEventArgs> info;
                        if (client.GetInfo(SvnUriTarget.FromString(e.RepositoryUri), infoArgs, out info))
                        {
                        }
                    }
                    finally
                    {
                        client.Authentication.UserNamePasswordHandlers -= handler;
                    }
                }
            }
        }
Exemple #20
0
        private void ExportDirectoryListItem(SvnListEventArgs e, SvnRevision revision, string destinationPath)
        {
            if (_g.StopRequested)
            {
                e.Cancel = true;
                return;
            }
            destinationPath = Path.Combine(destinationPath, e.Path);
            var  source = new SvnUriTarget(e.Uri, revision);
            bool exists;

            if (e.Entry.NodeKind == SvnNodeKind.Directory)
            {
                exists = Directory.Exists(destinationPath);
                if (!exists)
                {
                    Directory.CreateDirectory(destinationPath);
                }
            }
            else
            {
                exists = File.Exists(destinationPath);
                _g.Svn.Export(source, destinationPath, _infiniteOverwriteExport);
            }
            if (destinationPath != _g.WorkingDir)
            {
                _g.Svn.Add(destinationPath, _forceAdd);
                _g.Interaction.Trace((exists ? ActionModified : ActionCreated) + destinationPath);
            }
            CopyProperties(source, destinationPath);
        }
Exemple #21
0
        /// <summary>
        /// Checks out the latest from the Server, and updates the local working copy.
        /// </summary>
        /// <returns></returns>
        public bool CheckOut(string localRepo)
        {
            var localUri     = _svnClient.GetUriFromWorkingCopy(localRepo);
            var svnUriTarget = new SvnUriTarget(localUri);   //TODO: why is this the only place URI is used?

            _repo = localRepo;
            return(_svnClient.CheckOut(svnUriTarget, _repo));
        }
Exemple #22
0
        private SvnInfoEventArgs GetSourceInfo(long revision)
        {
            SvnInfoEventArgs info;
            var sourceTarget = new SvnUriTarget(_source, revision == -1 ? SvnRevision.Head : revision);

            using (var svn = new SvnClient()) svn.GetInfo(sourceTarget, out info);
            return(info);
        }
        private bool FullCheckout(int revision)
        {
            CleanFolder();
            var target = new SvnUriTarget(RepositoryUrl, revision);
            var result = _SvnClient.CheckOut(target, LocalPath);

            return(result);
        }
        /// <summary>
        /// Actual method to be executed for the implementing task
        /// </summary>
        /// <param name="client">The instance of the SVN client</param>
        /// <returns></returns>
        public override bool ExecuteCommand(SvnClient client)
        {
            SvnTarget target = new SvnUriTarget(RepositoryPath);
            SvnListArgs args = new SvnListArgs();
            args.Depth = Recursive ? SvnDepth.Infinity : SvnDepth.Children;

            return client.List(target, args, listHandler);
        }
Exemple #25
0
        private bool CheckUrlValide(SvnClient client, SvnUriTarget uri)
        {
            Collection <SvnInfoEventArgs> info = new Collection <SvnInfoEventArgs>();

            return(client.GetInfo(uri, new SvnInfoArgs {
                ThrowOnError = false
            }, out info));
        }
        private static void PerformCheckout(ProgressWorkerArgs e, SvnUriTarget projectTop, SvnRevision revision, string localDir)
        {
            SvnCheckOutArgs a = new SvnCheckOutArgs();

            a.Revision = revision;

            e.Client.CheckOut(projectTop, localDir, a);
        }
Exemple #27
0
 internal IfsSvn()
 {
     if (string.IsNullOrWhiteSpace(Properties.Settings.Default.ServerUri) == false)
     {
         this.componentsUri = new SvnUriTarget(Properties.Settings.Default.ServerUri + "/applications");
         this.projectsUri   = new SvnUriTarget(Properties.Settings.Default.ServerUri + "/projects");
     }
 }
        /// <summary>
        /// Shows the log viewer and sets the revision cell value to the selected revision
        /// </summary>
        /// <param name="row"></param>
        private void SelectRevision(DataGridViewRow row)
        {
            IAnkhServiceProvider context = Context;

            if (context != null)
            {
                string selectedUriString = row.Cells[0].Value as string;

                Uri selectedUri;
                if (!string.IsNullOrEmpty(selectedUriString) &&
                    Uri.TryCreate(selectedUriString, UriKind.Absolute, out selectedUri)
                    )
                {
                    Uri repoRoot = string.Equals(_lastUsedUriString, selectedUriString) ? _lastRepositoryRoot : null;
                    if (repoRoot == null)
                    {
                        if (context.GetService <IProgressRunner>().RunModal(
                                PropertyEditStrings.RetrievingRepositoryRoot,
                                delegate(object sender, ProgressWorkerArgs a)
                        {
                            repoRoot = a.Client.GetRepositoryRoot(selectedUri);
                        }).Succeeded)
                        {
                            //cache the last used repo uri string and the fetched repository root uri
                            _lastRepositoryRoot = repoRoot;
                            _lastUsedUriString  = selectedUriString;
                        }
                    }
                    if (repoRoot != null)
                    {
                        try
                        {
                            // set the current revision value as the initial selection
                            string             rev       = row.Cells[2].Value as string;
                            SvnRevision        rr        = string.IsNullOrEmpty(rev) ? SvnRevision.None : long.Parse(rev);
                            SvnUriTarget       svnTarget = new SvnUriTarget(selectedUri, rr);
                            Ankh.Scc.SvnOrigin origin    = new Ankh.Scc.SvnOrigin(svnTarget, repoRoot);
                            using (Ankh.UI.SvnLog.LogViewerDialog dlg = new Ankh.UI.SvnLog.LogViewerDialog(origin))
                            {
                                if (dlg.ShowDialog(Context) == DialogResult.OK)
                                {
                                    Ankh.Scc.ISvnLogItem li = EnumTools.GetSingle(dlg.SelectedItems);
                                    rev = li == null ? null : li.Revision.ToString();
                                    //set the revision cell value to the selection revision
                                    row.Cells[2].Value = rev ?? string.Empty;
                                }
                            }
                        }
                        catch
                        {
                            // clear cache in case of error
                            _lastUsedUriString  = null;
                            _lastRepositoryRoot = null;
                        }
                    }
                }
            }
        }
        private void checkout(string alias)
        {
            string projectUrl = Url.TrimEnd('/') + "/" + alias;
            string tempFolder = TempFolderPath(alias);

            bool workingCopy = false;

            if (Directory.Exists(Path.Combine(tempFolder, ".svn")))
            {
                workingCopy = true;
            }

            using (SvnClient client = new SvnClient())
            {
                client.LoadConfiguration("path");
                client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password);

                if (!workingCopy)
                {
                    if (Directory.Exists(Path.Combine(TempFolderPath(string.Empty), ".svn")))
                    {
                        SvnUriTarget target = new SvnUriTarget(projectUrl);

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

                        Collection <SvnInfoEventArgs> info;
                        bool res = client.GetInfo(target, new SvnInfoArgs {
                            ThrowOnError = false
                        }, out info);
                        if (res)
                        {
                            client.CheckOut(target, tempFolder);
                        }
                    }
                    else
                    {
                        SvnUriTarget target = new SvnUriTarget(Url);
                        Collection <SvnInfoEventArgs> info;
                        bool res = client.GetInfo(target, new SvnInfoArgs {
                            ThrowOnError = false
                        }, out info);

                        if (res)
                        {
                            client.CheckOut(target, TempFolderPath(string.Empty));
                        }
                    }
                }
                else
                {
                    client.Update(tempFolder);
                }
            }
        }
Exemple #30
0
 private static byte[] ReadFileVersion(SvnClient svnClient, string uriString, long revision)
 {
     using (var versionStream = new MemoryStream())
     {
         var versionTarget = new SvnUriTarget(uriString, revision);
         svnClient.Write(versionTarget, versionStream);
         return(versionStream.ToArray());
     }
 }
Exemple #31
0
 public void CheckOut(string repositoryURL, string localPath)
 {
     using (SvnClient client = new SvnClient())
     {
         SvnCheckOutArgs args   = new SvnCheckOutArgs();
         SvnUriTarget    target = new SvnUriTarget(repositoryURL);
         client.CheckOut(target, localPath, args);
     }
 }
Exemple #32
0
        public SvnCheckoutResult Checkout(string from, string to, SvnCheckoutSettings settings)
        {
            var arguments = settings.ToSharpSvn();

            SharpSvn.SvnUpdateResult result;
            CheckOut(SvnUriTarget.FromString(from), to, arguments, out result);

            return(new SvnCheckoutResult(result.Revision));
        }
 private static byte[] ReadFileVersion(SvnClient svnClient, string uriString, long revision)
 {
     using (var versionStream = new MemoryStream())
     {
         var versionTarget = new SvnUriTarget(uriString, revision);
         svnClient.Write(versionTarget, versionStream);
         return versionStream.ToArray();
     }
 }
        /// <summary>
        /// Create a new repository view 
        /// </summary>
        /// <param name="repo"> URI of the repo we want to work with. </param>
        /// <param name="working_dir"></param>
        public RepositoryView(Uri repo, string working_dir)
        {

            InitializeComponent();

            // Setup the repository.             
            this.client = new SvnClient(); 
            SvnUpdateResult res; 
            SvnUriTarget repo_target = new SvnUriTarget(repo.ToString());
            this.client.CheckOut(repo_target, working_dir, out res); 

        }
Exemple #35
0
        public SVNUtils()
        {
            svnurl = "svn://127.0.0.1:" + TCS.Config.AppConfig.RunTime.SVNPort.ToString();
            SC = new SvnClient();
            SvnUriTarget rem = new SvnUriTarget(svnurl);
            SC.Authentication.ClearAuthenticationCache();
            SC.Authentication.Clear();
            SC.Authentication.DefaultCredentials = new SvnCredentialProvider(
                  TCS.Config.AppConfig.RunTime.SVNUsername,
                   TCS.Config.AppConfig.RunTime.SVNPassword,
                    svnurl);//默认用户名密码
        }
Exemple #36
0
        private static void createSVNTag(SvnClient client, SvnUriTarget source)
        {
            ConsoleLogStartAction(Resources.UILogging.CreateSvnTag);

            Console.WriteLine(Resources.Questions.SVNDestination);
            var uriDestination = Console.ReadLine();

            var destination = new Uri(uriDestination);
            client.RemoteCopy(source, destination);

            ConsoleEndAction();
        }
Exemple #37
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkerArguments arguments = (WorkerArguments)e.Argument;

            using (SvnClient client = new SvnClient())
            {
                SvnUI.Bind(client, this);
                SvnUriTarget svnUri = new SvnUriTarget(arguments.uri);
                SvnUpdateResult result;
                client.CheckOut(svnUri, arguments.checkoutFolder, arguments.checkoutArgs, out result);
                e.Result = result;
            }
        }
        /// <summary>
        /// Actual method to be executed for the implementing task
        /// </summary>
        /// <param name="client">The instance of the SVN client</param>
        /// <returns></returns>
        public override bool ExecuteCommand(SvnClient client)
        {
            SvnUriTarget uriTarget = new SvnUriTarget(FromRepositoryUrl);

            SvnMergeArgs args = new SvnMergeArgs();
            args.Depth = GetDepth();
            args.DryRun = DryRun;
            args.Force = Force;
            args.IgnoreAncestry = IgnoreAncestry;

            SvnRevisionRange revisionRange = GetRevisionRange();

            return client.Merge(RepositoryPath, uriTarget, revisionRange, args);
        }
        private SvnTarget GetTarget()
        {
            SvnTarget target;
            SvnRevision revision = RevisionParser.SafeParse(Revision);
            if (Uri.IsWellFormedUriString(RepositoryPath, UriKind.Absolute))
            {
                target = new SvnUriTarget(RepositoryPath, revision);
            }
            else
            {
                target = new SvnPathTarget(RepositoryPath, revision);
            }

            return target;
        }
Exemple #40
0
        public void Mergeinfo_MergesApplied()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri reposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario);
            // Extended version of GetSuggestedMergeSourcesTests:VerifyCollabNetRepos

            SvnAppliedMergeInfo applied;

            SvnTarget me = new SvnUriTarget(new Uri(reposUri, "trunk/"), 16);

            Assert.That(Client.GetAppliedMergeInfo(me, out applied));

            Assert.That(applied, Is.Not.Null);
            Assert.That(applied.AppliedMerges.Count, Is.EqualTo(3));

            foreach (SvnMergeItem mi in applied.AppliedMerges)
            {
                if (mi.Uri == new Uri(reposUri, "trunk"))
                {
                    Assert.That(mi.MergeRanges.Count, Is.EqualTo(1));
                    Assert.That(mi.MergeRanges[0].Start, Is.EqualTo(1));
                    Assert.That(mi.MergeRanges[0].End, Is.EqualTo(2));
                    Assert.That(mi.MergeRanges[0].Inheritable, Is.True);
                }
                else if (mi.Uri == new Uri(reposUri, "branches/a"))
                {
                    Assert.That(mi.MergeRanges.Count, Is.EqualTo(1));
                    Assert.That(mi.MergeRanges[0].Start, Is.EqualTo(2));
                    Assert.That(mi.MergeRanges[0].End, Is.EqualTo(11));
                    Assert.That(mi.MergeRanges[0].Inheritable, Is.True);
                }
                else if (mi.Uri == new Uri(reposUri, "branches/b"))
                {
                    Assert.That(mi.MergeRanges.Count, Is.EqualTo(1));
                    Assert.That(mi.MergeRanges[0].Start, Is.EqualTo(9));
                    Assert.That(mi.MergeRanges[0].End, Is.EqualTo(13));
                    Assert.That(mi.MergeRanges[0].Inheritable, Is.True);
                }
                else
                    Assert.That(false, "Strange applied merge");
            }
        }
Exemple #41
0
        static public void CreateBranch(Uri fromUri, Uri toUri)
        {
            using (SvnClient svnClient = new SvnClient())
            {
                try
                {
                    SvnTarget target = SvnTarget.FromUri(fromUri);
                    SvnUriTarget targetBranch = new SvnUriTarget(toUri);

                    SvnCopyArgs args = new SvnCopyArgs();
                    args.LogMessage = Properties.Settings.Default.SVN_Commit_Msg;

                    svnClient.RemoteCopy(target, toUri, args);
                }
                catch (Exception ex)
                {
                    LogMessage(ex.Message);
                }
            }
        }
        public void MergeSources_VerifyCollabNetRepos()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario);

            string dir = sbox.GetTempDir();
            SvnMergeSourcesCollection msc;

            SvnTarget me = new SvnUriTarget(new Uri(CollabReposUri, "trunk/"), 16);
            Assert.That(Client.GetSuggestedMergeSources(me, out msc));

            Assert.That(msc, Is.Not.Null);
            Assert.That(msc.Count, Is.EqualTo(3));
            foreach (SvnMergeSource ms in msc)
            {
                Collection<SvnMergesEligibleEventArgs> info;

                Assert.That(Client.GetMergesEligible(me, ms.Uri, out info));
                Assert.That(info, Is.Not.Null);

                if (ms.Uri == new Uri(CollabReposUri, "trunk"))
                {
                    Assert.That(info.Count, Is.EqualTo(1));
                }
                else if (ms.Uri == new Uri(CollabReposUri, "branches/a"))
                {
                    Assert.That(info.Count, Is.EqualTo(0));
                }
                else if (ms.Uri == new Uri(CollabReposUri, "branches/b"))
                {
                    Assert.That(info.Count, Is.EqualTo(0));
                }
                else
                    Assert.That(false, "Strange branch found");
            }
        }
        /// <summary>
        /// Actual method to be executed for the implementing task
        /// </summary>
        /// <param name="client">The instance of the SVN client</param>
        /// <returns></returns>
        public override bool ExecuteCommand(SvnClient client)
        {
            SvnUriTarget uriTarget = new SvnUriTarget(RepositoryUrl);
            SvnCheckOutArgs checkOutArgs = new SvnCheckOutArgs();
            checkOutArgs.Depth = GetDepth();
            checkOutArgs.IgnoreExternals = IgnoreExternals;
            checkOutArgs.Revision = RevisionParser.SafeParse(Revision);

            SvnUpdateResult result;

            bool success = client.CheckOut(uriTarget, RepositoryPath, checkOutArgs, out result);

            if (result.HasRevision)
            {
                CheckedRevision = result.Revision;
                Log.LogMessage(MessageImportance.Normal, "Checked revision: {0}", CheckedRevision);
            }
            if (result.HasResultMap)
            {
                ReadResults(result);
            }

            return success;
        }
 private static SvnUriTarget CreateSvnUriTarget(string uriString, SvnRevision revision)
 {
     Uri uri = new Uri(uriString);
     SvnUriTarget target = new SvnUriTarget(uri, revision);
     return target;
 }
Exemple #45
0
        public void Path_SshUsernameTests()
        {
            Assert.That(SvnTools.GetNormalizedUri(new Uri(new Uri("http://[email protected]/"), "/trunk")).AbsoluteUri, Is.EqualTo("http://[email protected]/trunk"));

            SvnUriTarget target = new SvnUriTarget(new Uri("http://[email protected]/home/user/repos/"), 1234);

            Assert.That(target.Revision.RevisionType, Is.EqualTo(SvnRevisionType.Number));
            Assert.That(target.Uri.AbsoluteUri, Is.EqualTo("http://[email protected]/home/user/repos"));

            SvnUriTarget target2 = new SvnUriTarget(new Uri("http://[email protected]:123/home/user/repos/"), SvnRevisionType.Head);

            Assert.That(target2.Revision, Is.EqualTo(SvnRevision.Head));
            Assert.That(target2.Uri.AbsoluteUri, Is.EqualTo("http://[email protected]:123/home/user/repos"));
        }
Exemple #46
0
        public void FileVersions_WalkChange()
        {
            SvnFileVersionsArgs a = new SvnFileVersionsArgs();
            SvnUriTarget me = new SvnUriTarget(new Uri("https://ctf.open.collab.net/svn/repos/sharpsvn/trunk/src/SharpSvn.Tests/Commands/FileVersions.cs"), 931);
            a.Start = 927;
            a.End = 928;
            int n = 0;

            Client.FileVersions(me, a,
                delegate(object sender, SvnFileVersionEventArgs e)
                {
                    GC.KeepAlive(e);
                    e.WriteTo(GetTempFile());
                    n++;
                });

            Assert.That(n, Is.EqualTo(2));
        }
Exemple #47
0
        public DateTime GetLastModifiedDateTimeOfEntity(TrackingTargetEntity entity)
        {
            if ((this.isWorking) && (!this.isPrivateWork))
                return DateTime.MinValue;

            if (!this.isPrivateWork)
                this.isWorking = true;
            
            DateTime ret;

            SvnInfoEventArgs infoEventArgs;
            SvnUriTarget target;

            try
            {
                target = new SvnUriTarget(entity.path);
                svnClient.GetInfo(target, out infoEventArgs);
                ret = infoEventArgs.LastChangeTime;
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.ToString());
                ret = DateTime.MinValue;
            }

            if (!this.isPrivateWork)
                this.isWorking = false;
            return ret;

        }
Exemple #48
0
        private static long getSVNVersion(SvnClient client, SvnUriTarget source)
        {
            ConsoleLogStartAction(Resources.UILogging.GetSvnVersion);

            SvnInfoEventArgs infos;
            client.GetInfo(source, out infos);

            Console.WriteLine(string.Format(Resources.UILogging.FoundSVNVersion, infos.Revision));

            ConsoleEndAction();

            return infos.Revision;
        }
Exemple #49
0
        public IEnumerable<BranchInfo> GetBranches(Uri branchesBaseUrl)
        {
            var files = new List<BranchInfo>();
            var branchesTarget = new SvnUriTarget(branchesBaseUrl);
            Collection<SvnListEventArgs> svnList;
            bool gotList = _client.GetList(branchesTarget, out svnList);
            if (gotList)
            {
                files.AddRange(from svnItem in svnList
                               where IsBranch(svnItem)
                               select MapToBranchInfo(svnItem));
            }

            return files;
        }
Exemple #50
0
 public string GetMergeInfo(Uri url)
 {
     var target = new SvnUriTarget(url);
     return GetMergeInfo(target);
 }
		private MemoryStream GetSVNFileStream(SvnRevisionId changeset, string path)
		{
			var memoryStream = new MemoryStream();
			SvnTarget target;
			//If you use Uri you should encode '#' as %23, as Uri's define the # as Fragment separator.
			//And in this case the fragment is not send to the server.
			path = path.Replace("#", "%23");
			if (SvnTarget.TryParse(GetPath(path).AbsolutePath, out target))
			{
				if (FileWasDeleted(path, changeset))
				{
					return new MemoryStream();
				}

				var uriTarget = new SvnUriTarget(_root + path, changeset.Value);
				var svnWriteArgs = new SvnWriteArgs {Revision = changeset.Value};

				Client.Write(uriTarget, memoryStream, svnWriteArgs);
				return memoryStream;
			}
			return new MemoryStream();
		}
Exemple #52
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string localProdDirectoryRootedPath = @"C:\Code\PROD";
            string repositorySourceDirectoryUri = @"https://github.com/CosimoDeMedici/Duomo/trunk/Source"; // NOTE, http:// requires final '/' whereas svn:// does not.
            int repositorySourceDirectoryUriLength = repositorySourceDirectoryUri.Length;

            // TODO, will need to ensure no duplicate repository solution URIs.
            Dictionary<string, int> repositorySolutionUrisAndRevisions = new Dictionary<string, int>();
            repositorySolutionUrisAndRevisions.Add(@"https://github.com/CosimoDeMedici/Duomo/trunk/Source/Common/Applications/Gunther/Duomo.Common.Gunther.sln", 17);

            // Ensure that all repository solution URIs are in the source directory.
            Dictionary<string, int> repositorySolutionRelativeUrisAndRevisions = new Dictionary<string, int>();
            foreach (string curUri in repositorySolutionUrisAndRevisions.Keys)
            {
                if (curUri.Substring(0, repositorySourceDirectoryUriLength) == repositorySourceDirectoryUri)
                {
                    string solutionRelativeUri = curUri.Substring(repositorySourceDirectoryUriLength);
                    repositorySolutionRelativeUrisAndRevisions.Add(solutionRelativeUri, repositorySolutionUrisAndRevisions[curUri]);
                }
                else
                {
                    throw new ApplicationException(String.Format("Repository solution URI '{0}' was not within the repositoryl source directory URI '{1}'.", curUri, repositorySourceDirectoryUri));
                }
            }

            // Checkout (the checkout command will update if the directory already exists) the Lib directory. This assumes there is a 'Lib' directory as a sibling to the main 'Source' directory.
            string libFolderName = @"Lib";
            string localLibDirectoryRootedPath = Path.Combine(localProdDirectoryRootedPath, libFolderName);

            Uri uri = new Uri(repositorySourceDirectoryUri);
            string repositorySourceParentDirectoryUri = uri.GetParentUriString();
            uri = new Uri(repositorySourceParentDirectoryUri);
            string repositoryLibDirectoryUri = uri.AppendSegment(libFolderName);

            using (SvnClient client = new SvnClient())
            {
                SvnUriTarget target = new SvnUriTarget(repositoryLibDirectoryUri);
                client.CheckOut(new SvnUriTarget(repositoryLibDirectoryUri), localLibDirectoryRootedPath);
            }

            // For each solution, check out the solution's directory to the proper local path.
            WshShell wshShell = new WshShellClass(); // For creating a short-cut to the solution.
            foreach (string curRelativeUri in repositorySolutionRelativeUrisAndRevisions.Keys)
            {
                // Check out the solution.
                string curRepoRootedUri = repositorySourceDirectoryUri + curRelativeUri;
                Uri curRepoUri = new Uri(curRepoRootedUri);

                string solutionFileName = curRepoUri.GetLeaf();
                string solutionName = solutionFileName.Substring(0, solutionFileName.Length - 4);

                string localFolderName = Path.Combine(localProdDirectoryRootedPath, solutionName);
                if (!Directory.Exists(localFolderName))
                {
                    Directory.CreateDirectory(localFolderName);
                }

                string repoSolutionFolder = curRepoUri.GetParentUriString();
                string localSolutionFileRootedPath = localFolderName + curRelativeUri;
                FileInfo fInfo = new FileInfo(localSolutionFileRootedPath);
                string localSolutionDirectoryRootedPath = fInfo.DirectoryName;

                using (SvnClient client = new SvnClient())
                {
                    client.CheckOut(new SvnUriTarget(repoSolutionFolder), localSolutionDirectoryRootedPath);
                }

                // Create a short-cut to the solution file and place it in the local folder for the solution.
                string shortCutFileName = String.Format("{0} - Shortcut.lnk", solutionFileName);
                string shortCutFileRootedPath = Path.Combine(localFolderName, shortCutFileName);
                if (!System.IO.File.Exists(shortCutFileRootedPath))
                {
                    IWshShortcut shortCut = (IWshShortcut)wshShell.CreateShortcut(shortCutFileRootedPath);
                    shortCut.TargetPath = localSolutionFileRootedPath;
                    shortCut.Save();
                }

                // Now get the list of relative project paths by parsing the solution file.
                List<string> solutionFileLines = TextFileSerializer.DeserializeFromRootedPath(localSolutionFileRootedPath);

                List<string> projectLines = new List<string>();
                string projectSignifier = @"Project";
                foreach (string line in solutionFileLines)
                {
                    if (line.Length >= projectSignifier.Length && projectSignifier == line.Substring(0, projectSignifier.Length))
                    {
                        projectLines.Add(line);
                    }
                }

                List<string> relativeFilePaths = new List<string>();
                string[] separators = new string[] { "=", "," };
                foreach (string line in projectLines)
                {
                    string[] tokens = line.Split(separators, StringSplitOptions.None);
                    string relativePath = tokens[2].Trim().Trim('"');

                    if (@".." == relativePath.Substring(0, 2)) // Otherwise it's a subdirectory of the main solution directory, which has already been checked out.
                    {
                        relativeFilePaths.Add(relativePath);
                    }
                }

                // Now check out the folders containing each of the relative projects to their appropriate relative local paths.
                foreach (string relativeFilePath in relativeFilePaths)
                {
                    string relativeOtherProjectPath = Path.Combine(localSolutionDirectoryRootedPath, relativeFilePath);
                    string localOtherProjectRootedFilePath = Path.GetFullPath(relativeOtherProjectPath);
                    FileInfo localOtherProjectFileInfo = new FileInfo(localOtherProjectRootedFilePath);
                    string localOtherProjectDirectoryRootedPath = localOtherProjectFileInfo.DirectoryName;

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

                    Uri repoOtherProjectUri = new Uri(repoSolutionFolder + relativeFilePath);
                    string repoOtherProjectFolderUri = repoOtherProjectUri.GetParentUriString();

                    using (SvnClient client = new SvnClient())
                    {
                        client.CheckOut(new SvnUriTarget(repoOtherProjectFolderUri), localOtherProjectDirectoryRootedPath);
                    }
                }
            }
        }
 public PropertyEditorDialog(SvnUriTarget target, bool revisionProps)
     : this(target.Uri, target.Revision, revisionProps)
 {
     _currentNodeKind = SvnNodeKind.None;
     _revisionProps = revisionProps;
 }
Exemple #54
0
 public string GetMergeInfo(Uri url, long revision)
 {
     var target = new SvnUriTarget(url, revision);
     return GetMergeInfo(target);
 }
Exemple #55
0
        private static void PerformCheckout(ProgressWorkerArgs e, SvnUriTarget projectTop, SvnRevision revision, string localDir)
        {
            SvnCheckOutArgs a = new SvnCheckOutArgs();
            a.Revision = revision;

            e.Client.CheckOut(projectTop, localDir, a);
        }
Exemple #56
0
        private static void CheckOutAndOpenSolution(CommandEventArgs e, SvnUriTarget checkoutLocation, SvnRevision revision, Uri projectTop, string localDir, Uri projectUri)
        {
            IProgressRunner runner = e.GetService<IProgressRunner>();

            runner.RunModal("Checking Out Solution",
                delegate(object sender, ProgressWorkerArgs ee)
                    {
                        PerformCheckout(ee, checkoutLocation, revision, localDir);
                    });

            Uri file = projectTop.MakeRelativeUri(projectUri);

            string projectFile = SvnTools.GetNormalizedFullPath(Path.Combine(localDir, SvnTools.UriPartToPath(file.ToString())));

            OpenProject(e, projectFile);
        }
        private void ProcessChangedPaths(SvnLoggingEventArgs svnLogEntry, long revision, LogEntryDto logEntry)
        {
            svnLogEntry.ChangedPaths.AsParallel().WithDegreeOfParallelism(1).ForAll(changedPath =>
            {
                Logger.Write(new LogEntry { Message = "Processing path " + changedPath.Path, Categories = { "Plugin.Subversion" } });
                using (var parallelSvnClient = new SvnClient())
                {
                    var changedFile = new ChangedFileDto { FileName = changedPath.Path };

                    var nodeKind = changedPath.NodeKind;
                    if (nodeKind == SvnNodeKind.Unknown)
                    {
                        // Use GetInfo to get the NodeKind
                        SvnInfoEventArgs svnInfo;
                        try
                        {
                            parallelSvnClient.GetInfo(
                                new SvnUriTarget(
                                    SettingsXml + changedPath.Path,
                                // If the file is deleted then using revision causes an exception
                                    (changedPath.Action == SvnChangeAction.Delete ? revision - 1 : revision)
                                ),
                                out svnInfo);
                            nodeKind = svnInfo.NodeKind;
                        }
                        catch (SvnRepositoryIOException svnRepositoryIoException)
                        {
                            Logger.Write(new LogEntry
                                {
                                    Message = svnRepositoryIoException.ToString(),
                                    Categories = { "Plugin.Subversion" },
                                    Severity = TraceEventType.Warning
                                });
                        }

                    }

                    if (nodeKind != SvnNodeKind.File)
                    {
                        changedFile.OldVersion = new byte[0];
                        changedFile.NewVersion = new byte[0];
                    }
                    else
                    {
                        if (changedPath.Action == SvnChangeAction.Modify || changedPath.Action == SvnChangeAction.Delete)
                        {
                            // Use GetInfo to get the last change revision
                            var previousRevisionUri = new SvnUriTarget(SettingsXml + changedPath.Path, revision - 1);
                            try
                            {
                                // For some reason we seem to get an exception with a message stating that
                                // a previous version doesn't exist for a Modify action.  I'm not sure how
                                // you can have a modify without a previous version (surely everything
                                // starts with an add..?
                                SvnInfoEventArgs previousRevisionInfo;
                                parallelSvnClient.GetInfo(previousRevisionUri, out previousRevisionInfo);
                                changedFile.OldVersion = ReadFileVersion(
                                    parallelSvnClient, SettingsXml + changedPath.Path,
                                    previousRevisionInfo.LastChangeRevision);
                            }
                            catch (SvnRepositoryIOException e)
                            {
                                Logger.Write(new LogEntry { Message = "SvnRepositoryIOException: " + e, Categories = { "Plugin.Subversion" }, Severity = TraceEventType.Error });
                                changedFile.OldVersion = new byte[0];
                            }
                            catch (SvnFileSystemException ex)
                            {
                                // http://stackoverflow.com/questions/12939642/sharpsvn-getinfo-lastchangerevision-is-wrong
                                Logger.Write(new LogEntry { Message = "SvnFileSystemException: " + ex, Categories = { "Plugin.Subversion" }, Severity = TraceEventType.Warning });
                                changedFile.OldVersion = new byte[0];
                            }
                        }
                        else
                        {
                            changedFile.OldVersion = new byte[0];
                        }

                        if (changedPath.Action == SvnChangeAction.Modify || changedPath.Action == SvnChangeAction.Add)
                        {
                            changedFile.NewVersion = ReadFileVersion(parallelSvnClient, SettingsXml + changedPath.Path, revision);
                        }
                        else
                        {
                            changedFile.NewVersion = new byte[0];
                        }
                    }

                    switch (changedPath.Action)
                    {
                        case SvnChangeAction.Add:
                            changedFile.ChangeType = ChangeType.Added;
                            break;
                        case SvnChangeAction.Delete:
                            changedFile.ChangeType = ChangeType.Deleted;
                            break;
                        default:
                            changedFile.ChangeType = ChangeType.Modified;
                            break;
                    }

                    logEntry.ChangedFiles.Add(changedFile);
                }
            });
        }
Exemple #58
0
        /// <summary>
        /// 检查版本号,如果版本号不符, 则更新
        /// </summary>
        /// <returns></returns>
        public bool CheckVer()
        {
            bool result = true;
            var repos = new SvnUriTarget(svnurl);
            var local = new SvnPathTarget(GetAppLoc());
            try
            {
                notiny = "正在检查服务器版本...";
                ShowInfo();
                SvnInfoEventArgs serverInfo;
                bool oks = SC.GetInfo(repos, out serverInfo);
                notiny = "正在检查本地版本...";
                ShowInfo();
                SvnInfoEventArgs clientInfo;
                bool okc = SC.GetInfo(local, out clientInfo);
                if (oks && okc) //如果客户端服务端都会成功, 则对比服务器版本, 否则返回true 执行更新命令
                {
                    result = (serverInfo.Revision > clientInfo.Revision);
                }
                ShowInfo(string.Format("检查完毕,服务器版本{0}客户端版本{1}",
                                       (serverInfo != null ? serverInfo.Revision.ToString() : "(未知)"),
                                       (clientInfo != null ? clientInfo.Revision.ToString() : "(未知)")
                             ));
            }
            catch (Exception)
            {
                ShowInfo("检查文件是出现错误...");
            }
            return result;
        }
Exemple #59
0
 private bool Initialize(String user, String password)
 {
     if (m_strUser == "" && m_strPassword == "")
         return false;
     m_uriRepository = new SvnUriTarget(GetURLString());
     m_initialized = true;
     return true;
 }
Exemple #60
0
        /// <summary>
        /// Exports the revision range.
        /// </summary>
        /// <param name="repositoryUrl">The repository URL.</param>
        /// <param name="fromRevision">From revision.</param>
        /// <param name="toRevision">To revision.</param>
        /// <param name="exportFolder">The export folder.</param>
        public void ExportRevisionRange(
            Uri repositoryUrl, long fromRevision, long toRevision, string exportFolder)
        {
            SvnInfoEventArgs info;
            _client.GetInfo(new SvnUriTarget(repositoryUrl), out info);
            long maxRevision = Math.Min(info.LastChangeRevision, toRevision);
            var to = new SvnUriTarget(repositoryUrl, maxRevision);
            Collection<SvnDiffSummaryEventArgs> list;
            var from = new SvnUriTarget(repositoryUrl, fromRevision);
            _client.GetDiffSummary(from, to, out list);
            Console.WriteLine("Items in list: " + list.Count);
            var exceptions = new List<Exception>();

            foreach (SvnDiffSummaryEventArgs item in list)
            {
                if (item.DiffKind == SvnDiffKind.Deleted ||
                    item.NodeKind != SvnNodeKind.File)
                {
                    continue;
                }

                var target = new SvnUriTarget(item.ToUri);
                string exportPath = Path.Combine(exportFolder,
                                                 item.Path.Replace("/", "\\"));
                var fi = new FileInfo(exportPath);
                if (!fi.Directory.Exists)
                {
                    fi.Directory.Create();
                }

                Console.WriteLine("Exporting {0}", item.Path);
                try
                {
                    _client.Export(target,
                                   exportPath,
                                   new SvnExportArgs {Revision = maxRevision});
                }
                catch (Exception ex)
                {
                    exceptions.Add(ex);
                }
            }

            foreach (Exception ex in exceptions)
            {
                Console.WriteLine(ex);
            }

            if (exceptions.Count > 0)
            {
                throw new Exception("Found errors.");
            }
        }