Esempio n. 1
0
        } // end SVNListModle

        private void ReadFilesProperties(object sender, DoWorkEventArgs e)
        {
            SvnClient  client  = new SvnClient();
            SvnLogArgs logArgs = new SvnLogArgs();

            logArgs.RetrieveAllProperties = false;
            while (_stringToRead.Count > 0)
            {
                string path = _stringToRead[0];
                _stringToRead.RemoveAt(0);
                try {
                    Collection <SvnLogEventArgs> status;
                    if (!client.GetLog(leftRoot + path, logArgs, out status))
                    {
                        status = null;
                    } // end if
                    leftPathToStatus.Add(path, status);
                } catch (Exception) {
                } // end try
                try {
                    Collection <SvnLogEventArgs> status;
                    if (!client.GetLog(rightRoot + path, logArgs, out status))
                    {
                        status = null;
                    } // end if
                    rightPathToStatus.Add(path, status);
                } catch (Exception) {
                } // end try
                _worker.ReportProgress(0, path);
            }     // end while
            client.Dispose();
        }         // end ReadFilesProperties
Esempio n. 2
0
 /// <summary>
 /// 获取提交日志记录
 /// </summary>
 /// <param name="url"></param>
 /// <param name="startRevision"></param>
 /// <param name="endRevision"></param>
 public static string GetCommitLog(string url, SvnRevision startRevision, SvnRevision endRevision)
 {
     using (SvnClient client = GetSvnClient())
     {
         Collection <SvnLogEventArgs> logs;
         var totalLog = new StringBuilder();
         if (client.GetLog(new Uri(url), new SvnLogArgs(new SvnRevisionRange(startRevision, endRevision)), out logs))
         {
             //后续操作,可以获取作者,版本号,提交时间,提交的message和提交文件列表等信息
             foreach (var log in logs.OrderByDescending(x => x.Time))
             {
                 var stringBuilder = new StringBuilder();
                 foreach (var item in log.ChangedPaths.Distinct())
                 {
                     var operateMes = item.Action + "  " + item.RepositoryPath.ToString().Replace("branch/BiHu.BaoXian.ArtificialSubmit/BiHu.BaoXian.ArtificialSubmit.RB-08/", "");
                     stringBuilder.AppendLine(operateMes);
                 }
                 totalLog.AppendLine(string.Format("{0}  {1}  {2} {3}\r\n{4}",
                                                   log.Author,
                                                   log.Revision.ToString(),
                                                   log.Time,
                                                   log.LogMessage,
                                                   stringBuilder
                                                   ));
             }
         }
         return(totalLog.ToString());
     }
 }
        public List <Commit> GetCommits(string path, List <Commit> alreadyDeclaredCommits = null)
        {
            List <Commit> commits = new List <Commit>();

            using (SvnClient svnClient = new SvnClient())
            {
                System.Collections.ObjectModel.Collection <SvnLogEventArgs> logEventArgs;
                svnClient.GetLog(new Uri(path), out logEventArgs);
                logEventArgs.ForEach(commit =>
                {
                    if (alreadyDeclaredCommits != null &&
                        alreadyDeclaredCommits.Any(
                            declaredCommit => declaredCommit.Revision == commit.Revision.ToString()))
                    {
                        commits.Add(alreadyDeclaredCommits.Find(c => c.Revision == commit.Revision.ToString()));
                        return;
                    }
                    List <Changes> changes = GetChanges(commit.Revision, path);
                    Commit commitItem      = new Commit()
                    {
                        Author   = commit.Author,
                        Date     = commit.Time.Date,
                        Email    = " - ",
                        Message  = commit.LogMessage,
                        Revision = commit.Revision.ToString()
                    };
                    changes.ForEach(change => commitItem.AddChanges(change));
                    commits.Add(commitItem);
                });
            }

            return(commits);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取日志上改变的文件路径
        /// </summary>
        /// <param name="path">本地路径</param>
        /// <param name="version">某个具体版本</param>
        /// <param name="action">操作</param>
        /// <returns></returns>
        public static List <string> GetLogFPath(string path, int version, string action)
        {
            List <string> paths = new List <string>();

            using (SvnClient svn = new SvnClient())
            {
                try
                {
                    Collection <SvnLogEventArgs> logItems = new Collection <SvnLogEventArgs>();
                    svn.GetLog(path, out logItems);
                    //过滤版本
                    //logItems = (Collection<SvnLogEventArgs>)logItems.Where(o => o.Revision == version);
                    foreach (var log in logItems)
                    {
                        foreach (SvnChangeItem svnChangeItem in (Collection <SvnChangeItem>)log.ChangedPaths)
                        {
                            if (svnChangeItem.Action.ToString() == action && log.Revision == version)
                            {
                                paths.Add(svnChangeItem.Path);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    operSVN.lastErrMsg = ex.Message;
                    StackFrame frame = new StackTrace(new StackFrame(true)).GetFrame(0);
                    operSVN.wlog(ex.Message, frame.GetFileName() + (object)"|" + (string)(object)frame.GetMethod() + "|" + (string)(object)frame.GetFileLineNumber() + "|" + (string)(object)frame.GetFileColumnNumber());
                    return(null);
                }
            }
            return(paths);
        }
Esempio n. 5
0
        public List <RevisionData> GetRevisionData(int firstRevision, int lastRevision)
        {
            List <RevisionData> revisions = new List <RevisionData>();
            SvnClient           client    = AllocSvnClient();

            try
            {
                SvnLogArgs args = new SvnLogArgs(new SvnRevisionRange(firstRevision, lastRevision));
                args.StrictNodeHistory    = false;
                args.RetrieveChangedPaths = true;
                args.ThrowOnError         = true;
                args.ThrowOnCancel        = true;
                Collection <SvnLogEventArgs> logEvents;
                client.GetLog(_uri, args, out logEvents);
                foreach (SvnLogEventArgs e in logEvents)
                {
                    RevisionData data = new RevisionData();
                    data.Revision  = (int)e.Revision;
                    data.Author    = e.Author ?? "";
                    data.Message   = e.LogMessage ?? "";
                    data.Timestamp = e.Time;
                    AddChanges(data, e.ChangedPaths);
                    revisions.Add(data);

                    lock (_messages) _messages[data.Revision] = data.Message;
                }
            }
            finally
            {
                FreeSvnClient(client);
            }
            return(revisions);
        }
Esempio n. 6
0
        /// <summary>
        /// History of a file
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public Collection <SvnLogEventArgs> GetHistory(string filePath)
        {
            Collection <SvnLogEventArgs> logs;

            _svnClient.GetLog(filePath, out logs);
            return(logs);
        }
Esempio n. 7
0
        public static ICollection <SvnLogEventArgs> GetLogSince(string repositoryUri,
                                                                string target,
                                                                long revision)
        {
            var svnLogArgs = new SvnLogArgs
            {
                StrictNodeHistory = true,
                End     = revision,
                BaseUri = new Uri(repositoryUri)
            };

            Collection <SvnLogEventArgs> logItems;

            using (var svnClient = new SvnClient())
            {
                if (!svnClient.GetLog(new Uri(svnLogArgs.BaseUri,
                                              target),
                                      svnLogArgs,
                                      out logItems))
                {
                    logItems = new Collection <SvnLogEventArgs>();
                }
            }

            return(logItems);
        }
Esempio n. 8
0
        public static FileChanged[] GetChangeSetFromSvn(DateTime startDateTime, DateTime endDateTime, SvnConfig server)
        {
            SvnRevisionRange range = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));
            Collection<SvnLogEventArgs> logitems;

            var uri = new Uri(server.Url);
            FileChanged[] changed;
            using (SvnClient client = new SvnClient())
            {
                client.Authentication.Clear(); // Disable all use of the authentication area
                client.Authentication.UserNamePasswordHandlers +=
                    delegate(object sender, SvnUserNamePasswordEventArgs e)
                        {
                            e.UserName = server.UserName;
                            e.Password = server.Password;
                            e.Save = true;
                        };
                client.Authentication.SslServerTrustHandlers += delegate(object sender, SvnSslServerTrustEventArgs e)
                    {
                        e.AcceptedFailures = e.Failures;
                        e.Save = true; // Save acceptance to authentication store
                    };
                client.GetLog(uri, new SvnLogArgs(range), out logitems);
                foreach (var svnLogEventArgse in logitems)
                {
                    Console.WriteLine((string) WriteString(svnLogEventArgse));
                }
                changed = logitems.SelectMany<SvnLogEventArgs, FileChanged>(l => GetChangedFiles(l)).ToArray();
            }
            return changed;
        }
Esempio n. 9
0
        //获取SVN上最新50条的提交日志信息
        public string GetSvnLog(string path)
        {
            //string path = "D:\\Test";
            //SvnClient client = new SvnClient();

            var logArgs = new SvnLogArgs {
                RetrieveAllProperties = false
            };
            //不检索所有属性
            Collection <SvnLogEventArgs> status;

            _client.GetLog(path, logArgs, out status);
            int    messgNum = 0;
            string logText  = "";
            string lastLog  = "";

            foreach (var item in status)
            {
                if (messgNum > 50)
                {
                    break;
                }
                messgNum += 1;
                if (string.IsNullOrEmpty(item.LogMessage) || item.LogMessage == " " || lastLog == item.LogMessage)
                {
                    continue;
                }
                logText = item.Author + ":" + item.LogMessage + "\n" + logText;
                lastLog = item.LogMessage;
            }
            return(logText);
        }
Esempio n. 10
0
        public void Commit_WithAlternateUser()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty);
            string user = Guid.NewGuid().ToString();

            string dir = sbox.Wc;

            using (SvnClient client = new SvnClient())
            {
                client.Authentication.Clear();
                client.Configuration.LogMessageRequired = false;

                client.Authentication.UserNameHandlers +=
                    delegate(object sender, SvnUserNameEventArgs e)
                {
                    e.UserName = user;
                };

                client.SetProperty(dir, "a", "b");

                SvnCommitResult cr;
                client.Commit(dir, out cr);

                Collection <SvnLogEventArgs> la;
                client.GetLog(dir, out la);

                Assert.That(la.Count, Is.EqualTo(2));
                Assert.That(la[0].Revision, Is.EqualTo(cr.Revision));
                Assert.That(la[0].Author, Is.EqualTo(user));
                Assert.That(la[0].LogMessage, Is.EqualTo(""));
            }
        }
Esempio n. 11
0
        public static OutputModel GetLofInfo(string localPath)
        {
            OutputModel   output = new OutputModel();
            List <String> result = new List <string>();

            using (SvnClient svn = new SvnClient())
            {
                try
                {
                    //拿到所有的日志
                    Collection <SvnLogEventArgs> logItems = new Collection <SvnLogEventArgs>();
                    svn.GetLog(localPath, out logItems);
                    result.Add(logItems[0].LogMessage);
                    result.Add(logItems[0].Revision.ToString());
                    output.Status = "1";
                    output.Data   = result;
                }
                catch (Exception ex)
                {
                    operSVN.lastErrMsg = ex.Message;
                    StackFrame frame = new StackTrace(new StackFrame(true)).GetFrame(0);
                    operSVN.wlog(ex.Message, frame.GetFileName() + "|" + frame.GetMethod() + "|" + frame.GetFileLineNumber() + "|" + frame.GetFileColumnNumber() + "|");
                    output.Status  = "-1";
                    output.Message = ex.Message;
                    return(output);
                }

                return(output);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 执行获取本地项目svn信息的操作
        /// </summary>
        /// <param name="projectInfo">传入想要获取信息的projectInfo实例对象</param>
        /// <returns>获取完信息的projectInfo的实例对象</returns>
        public ProjectInfo GetLocalInfo(ProjectInfo projectInfo)
        {
            using (SvnClient svnClient = new SvnClient())
            {
                try
                {
                    SvnInfoEventArgs clientInfo;
                    SvnPathTarget    local = new SvnPathTarget(projectInfo.WorkDirectory);
                    svnClient.GetInfo(local, out clientInfo);
                    string author   = clientInfo.LastChangeAuthor;
                    string revision = clientInfo.LastChangeRevision.ToString();
                    projectInfo.Author = author;

                    SvnLogArgs getLogMessage = new SvnLogArgs();
                    Collection <SvnLogEventArgs> col;
                    getLogMessage.Start = int.Parse(revision);
                    getLogMessage.End   = int.Parse(revision);
                    bool gotLog = svnClient.GetLog(new Uri(projectInfo.RepositoryPath), getLogMessage, out col);
                    if (gotLog)
                    {
                        projectInfo.LogMessage = col[0].LogMessage;
                    }
                    return(projectInfo);
                }
                catch (Exception ex)
                {
                    return(projectInfo);
                }
            }
        }
        /// <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));
            }
        }
Esempio n. 14
0
        public static SvnLogEventArgs GetInitialLogItem(string repositoryUri,
                                                        string target)
        {
            var svnLogArgs = new SvnLogArgs
            {
                StrictNodeHistory = true,
                BaseUri           = new Uri(repositoryUri),
                Start             = SvnRevision.Zero,
                End   = SvnRevision.Head,
                Limit = 1
            };

            Collection <SvnLogEventArgs> logItems;

            using (var svnClient = new SvnClient())
            {
                if (!svnClient.GetLog(new Uri(svnLogArgs.BaseUri,
                                              target),
                                      svnLogArgs,
                                      out logItems))
                {
                    logItems = new Collection <SvnLogEventArgs>();
                }
            }

            var logItem = logItems.SingleOrDefault();

            return(logItem);
        }
Esempio n. 15
0
        public void ChangeInfo_GetInfoCompare()
        {
            SvnSandBox sbox      = new SvnSandBox(this);
            Uri        reposUri  = sbox.CreateRepository(SandBoxRepository.MergeScenario);
            string     reposPath = reposUri.LocalPath;

            using (SvnClient cl = new SvnClient())
            {
                SvnSetPropertyArgs sa = new SvnSetPropertyArgs();
                sa.BaseRevision = 17;
                sa.LogMessage   = "Message";
                cl.RemoteSetProperty(reposUri, "MyProp", "Value", sa);
            }

            for (long ii = 1; ii < 19; ii++)
            {
                using (SvnLookClient lcl = new SvnLookClient())
                    using (SvnClient cl = new SvnClient())
                    {
                        SvnChangeInfoEventArgs r;
                        SvnChangeInfoArgs      ia     = new SvnChangeInfoArgs();
                        SvnLookOrigin          origin = new SvnLookOrigin(reposPath, ii);

                        SvnLogArgs la = new SvnLogArgs();
                        la.Start = la.End = ii;

                        Collection <SvnLogEventArgs> lrc;
                        //ia.RetrieveChangedPaths = false; // Will fail if true
                        Assert.That(lcl.GetChangeInfo(origin, ia, out r));
                        Assert.That(cl.GetLog(reposUri, la, out lrc));

                        Assert.That(r, Is.Not.Null);
                        Assert.That(lrc.Count, Is.EqualTo(1));

                        SvnLogEventArgs lr = lrc[0];

                        Assert.That(r.Author, Is.EqualTo(lr.Author));
                        Assert.That(r.Revision, Is.EqualTo(lr.Revision));
                        Assert.That(r.BaseRevision, Is.EqualTo(lr.Revision - 1));
                        Assert.That(r.LogMessage, Is.EqualTo(lr.LogMessage));
                        Assert.That(r.Time, Is.EqualTo(lr.Time));

                        Assert.That(r.ChangedPaths, Is.Not.Null, "r.ChangedPaths({0})", ii);
                        Assert.That(lr.ChangedPaths, Is.Not.Null, "lr.ChangedPaths({0})", ii);

                        Assert.That(r.ChangedPaths.Count, Is.EqualTo(lr.ChangedPaths.Count));

                        for (int i = 0; i < r.ChangedPaths.Count; i++)
                        {
                            SvnChangeItem c  = r.ChangedPaths[i];
                            SvnChangeItem lc = lr.ChangedPaths[c.Path];

                            Assert.That(c.Path, Is.EqualTo(lc.Path));
                            Assert.That(c.Action, Is.EqualTo(lc.Action));
                            Assert.That(c.CopyFromPath, Is.EqualTo(lc.CopyFromPath));
                            Assert.That(c.CopyFromRevision, Is.EqualTo(lc.CopyFromRevision));
                        }
                    }
            }
        }
Esempio n. 16
0
        private int GetLatestRevisionNumber()
        {
            //Create the configuration that just queries the head revision record. disable all other options to ensure that the query is quick
            var logargs = new SvnLogArgs()
            {
                Start = new SvnRevision(SvnRevisionType.Head),
                End   = new SvnRevision(SvnRevisionType.Head),
                RetrieveAllProperties   = false,
                RetrieveChangedPaths    = false,
                RetrieveMergedRevisions = false,
            };

            //Execute the actual query
            Collection <SvnLogEventArgs> logItems;

            if (!m_client.GetLog(m_localPath, logargs, out logItems))
            {
                throw logargs.LastException;
            }

            //The repository is empty If we do not retrieve any results
            if (0 == logItems.Count)
            {
                Trace.TraceWarning("The repository '{0}' does not contain any changes", m_localPath);
                return(0);
            }

            return((int)(logItems.First().Revision));
        }
Esempio n. 17
0
        //获取SVN上最新150条的提交日志信息
        public static void GetSvnLog(string path, out Collection <SvnLogEventArgs> status)
        {
            SvnClient  client  = new SvnClient();
            SvnLogArgs logArgs = new SvnLogArgs();

            logArgs.RetrieveAllProperties = false; //不检索所有属性
            client.GetLog(path, logArgs, out status);
        }
        /// <exception cref="InvalidOperationException" />
        public override string[] GetCommitMessages()
        {
            SvnWorkingCopyVersion svnWorkingCopyVersion;

            using (var svnWorkingCopyClient = new SvnWorkingCopyClient())
            {
                if (!svnWorkingCopyClient.GetVersion(this.Path,
                                                     out svnWorkingCopyVersion))
                {
                    throw new InvalidOperationException($"Could not get version for {this.Path}.");
                }
            }

            if (svnWorkingCopyVersion.Modified)
            {
                throw new InvalidOperationException($"{this.Path} has uncommitted changes.");
            }

            Collection <SvnLogEventArgs> logItems;

            using (var svnClient = new SvnClient())
            {
                SvnRevision start;
                if (this.BaseRevision == null)
                {
                    start = SvnRevision.Zero;
                }
                else
                {
                    if (!int.TryParse(this.BaseRevision,
                                      out var startRevision))
                    {
                        throw new InvalidOperationException($"Could not parse {nameof(this.BaseRevision)}: {this.BaseRevision}");
                    }
                    start = startRevision;
                }

                var svnLogArgs = new SvnLogArgs
                {
                    StrictNodeHistory = false,
                    Range             = new SvnRevisionRange(start,
                                                             SvnRevision.Head)
                };
                if (!svnClient.GetLog(this.Path,
                                      svnLogArgs,
                                      out logItems))
                {
                    throw new InvalidOperationException($"Could not get log for {this.Path}.");
                }
            }

            var commitMessages = logItems.OrderBy(arg => arg.Revision)
                                 .Select(arg => arg.LogMessage)
                                 .ToArray();

            return(commitMessages);
        }
        public LoadSourcesInfoResult LoadSourcesInfo(SourceControlVersion sourceControlVersion, string path)
        {
            NetworkCredential credentials = new NetworkCredential(
                sourceControlVersion.SourceControl.GetStringProperty("Login"),
                sourceControlVersion.SourceControl.GetStringProperty("Password"));

            Revision latestRevision =
                sourceControlVersion.Revisions.OrderByDescending(r => r.CreatedDate).FirstOrDefault();

            if (latestRevision == null)
            {
                return(new LoadSourcesInfoResult
                {
                    SourcesInfos = new List <SourcesInfo>()
                });
            }

            SvnRevisionRange range = new SvnRevisionRange(long.Parse(latestRevision.Name), long.Parse(latestRevision.Name));

            if (latestRevision.ParentRevision != null)
            {
                range = new SvnRevisionRange(long.Parse(latestRevision.ParentRevision.Name) + 1, long.Parse(latestRevision.Name));
            }

            try
            {
                using (SvnClient client = new SvnClient())
                {
                    client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);

                    client.Authentication.DefaultCredentials = credentials;

                    Collection <SvnLogEventArgs> logEventArgs;

                    client.GetLog(path, new SvnLogArgs
                    {
                        Range = range
                    }, out logEventArgs);

                    return(new LoadSourcesInfoResult
                    {
                        SourcesInfos = logEventArgs.Select(e => new SourcesInfo
                        {
                            CreatedDate = e.Time,
                            Author = e.Author,
                            Message = e.LogMessage
                        }).ToList()
                    });
                }
            }
            catch (SvnException e)
            {
                throw new AspNetDeployException("SvnClient failed to load sources", e);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// 获取日志上改变的文件路径
        /// </summary>
        /// <param name="path">本地路径</param>
        /// <param name="startVersion">开始版本</param>
        /// <param name="endVersion">结束版本</param>
        /// <returns></returns>
        public static Dictionary <string, int> GetLogFPath(string path, int startVersion, int endVersion, List <string> formats, out Dictionary <string, string> logaction)
        {
            logaction = new Dictionary <string, string>();
            Dictionary <string, int> paths = new Dictionary <string, int>();

            using (SvnClient svn = new SvnClient())
            {
                try
                {
                    //拿到所有的日志
                    Collection <SvnLogEventArgs> logItems = new Collection <SvnLogEventArgs>();
                    svn.GetLog(path, out logItems);
                    foreach (var log in logItems)
                    {
                        foreach (SvnChangeItem svnChangeItem in (Collection <SvnChangeItem>)log.ChangedPaths)
                        {        //过滤版本
                            if ((log.Revision >= startVersion && log.Revision <= endVersion))
                            {
                                foreach (var temp in formats)
                                {
                                    if (Path.GetExtension(svnChangeItem.Path.ToLower()).Contains(temp.ToLower()))
                                    {
                                        if (paths.ContainsKey(svnChangeItem.Path))
                                        {
                                            if (paths[svnChangeItem.Path] < (int)log.Revision)
                                            {
                                                paths.Remove(svnChangeItem.Path);
                                            }
                                            else
                                            {
                                                continue;
                                            }
                                        }
                                        else if (svnChangeItem.Action.ToString().Equals("delete", StringComparison.OrdinalIgnoreCase))
                                        {
                                            continue;
                                        }
                                        paths.Add(svnChangeItem.Path, (int)log.Revision);
                                        logaction.Add(svnChangeItem.Path, svnChangeItem.Action.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    operSVN.lastErrMsg = ex.Message;
                    StackFrame frame = new StackTrace(new StackFrame(true)).GetFrame(0);
                    operSVN.wlog(ex.Message, frame.GetFileName() + "|" + frame.GetMethod() + "|" + frame.GetFileLineNumber() + "|" + frame.GetFileColumnNumber() + "|");
                    return(null);
                }
            }
            return(paths);
        }
Esempio n. 21
0
        public IEnumerable <IRevision> GetLog()
        {
            List <IRevision> result = new List <IRevision>();

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

            //the using statement is necessary to ensure we are freeing up resources
            using (SvnClient client = new SvnClient())
            {
                try
                {
                    client.Authentication.ForceCredentials(this.username, this.ownerPassword);
                    Collection <SvnLogEventArgs> changes = new Collection <SvnLogEventArgs>();
                    //this is the where 'svn checkout' actually happens.
                    if (client.GetLog(this.repoPath, args, out changes))
                    {
                        Logging.Log().Information("Successfully GetChangeList");
                        this.syncLogger.Log(this.sync, "Successfully GetChangeList");

                        // The oldest change does not contain useful information
                        for (int i = 1; i < changes.Count; i++)
                        {
                            var log = changes[i];

                            SvnRevision dto =
                                new SvnRevision
                            {
                                Author    = log.Author,
                                Id        = log.Revision.ToString(),
                                Message   = log.LogMessage,
                                LogObject = log
                            };

                            result.Add(dto);
                        }
                    }
                }
                catch (SvnException se)
                {
                    Logging.Log().Error(se, "SVN checkout failed.");
                    this.syncLogger.Log(this.sync, $"SVN checkout failed. {se}");
                    throw;
                }
                catch (UriFormatException ufe)
                {
                    Logging.Log().Error(ufe, "SVN uri format.");
                    this.syncLogger.Log(this.sync, $"SVN uri format. {ufe}");
                    throw;
                }
            }

            return(result);
        }
Esempio n. 22
0
        private IList <string> GetLatestCommitMessages(Uri repository)
        {
            using (var client = new SvnClient()) {
                System.Collections.ObjectModel.Collection <SvnLogEventArgs> logEntries;

                SvnRevisionRange range = new SvnRevisionRange(new SvnRevision(Start), new SvnRevision(End));
                var args = new SvnLogArgs(range);
                client.GetLog(repository, args, out logEntries);
                return(logEntries.Where(log => log.LogMessage.Contains("#SD-3606")).Select(log => log.LogMessage).ToList());
            }
        }
Esempio n. 23
0
        protected override void CheckForNewLogEntriesImpl()
        {
            if (!Monitor.TryEnter(LockObject))
            {
                return;
            }

            try
            {
                using (var svnClient = new SvnClient())
                {
                    var uri = new Uri(SettingsXml);
                    Collection <SvnLogEventArgs> svnLogEntries;
                    if (svnClient.GetLog(uri, new SvnLogArgs {
                        Limit = 30
                    }, out svnLogEntries))
                    {
                        var q = svnLogEntries
                                .Where(e => e.Time.PrecisionFix() > MaxDateTimeRetrieved)
                                .OrderBy(e => e.Time);
                        foreach (var svnLogEntry in q)
                        {
                            var revision = svnLogEntry.Revision;
                            Logger.Write(new LogEntry
                            {
                                Message    = "Creating LogEntryDto for revision " + revision,
                                Categories = { "Plugin." + GetType().Name }
                            });
                            var logEntry = new LogEntryDto
                            {
                                Author        = svnLogEntry.Author,
                                CommittedDate = svnLogEntry.Time,
                                Message       = svnLogEntry.LogMessage,
                                Revision      = revision.ToString(CultureInfo.InvariantCulture),
                                ChangedFiles  = new List <ChangedFileDto>()
                            };

                            ProcessChangedPaths(svnLogEntry, revision, logEntry);

                            var args = new NewLogEntryEventArgs {
                                LogEntry = logEntry
                            };
                            OnNewLogEntry(args);
                        }
                        MaxDateTimeRetrieved = svnLogEntries.Max(x => x.Time).PrecisionFix();
                    }
                }
            }
            finally
            {
                Monitor.Exit(LockObject);
            }
        }
Esempio n. 24
0
        //
        // 编写测试时,可以使用以下附加特性:
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // 在运行每个测试之前,使用 TestInitialize 来运行代码
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // 在每个测试运行完之后,使用 TestCleanup 来运行代码
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion


        public void TestMethod1()
        {
            //http://docs.sharpsvn.net/current/

            using (SvnClient client = new SvnClient())
            {
                // Checkout the code to the specified directory
                client.Authentication.Clear(); // Clear a previous authentication
                client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("", "");
                // client.CheckOut(new Uri("http://ip:9001/svn/CCMS/trunk/CCMS_V6/DOCUMENT/"),  "d:\\sharpsvn");


                Uri targetUri = new Uri("http://ip:9001/svn/CCMS/trunk/CCMS_V6/DOCUMENT");
                var target    = SvnTarget.FromUri(targetUri);
                Collection <SvnInfoEventArgs> info;//System.Collections.ObjectModel
                bool result2 = client.GetInfo(target, new SvnInfoArgs {
                    ThrowOnError = false
                }, out info);
                //Assert.AreEqual(result2, false);
                // Assert.Equals(info, "");


                SvnUpdateArgs ua    = new SvnUpdateArgs();
                SvnLogArgs    args2 = new SvnLogArgs(new SvnRevisionRange(500, new SvnRevision(SvnRevisionType.Head)));
                Collection <SvnLogEventArgs> logitems;
                ua.Notify += delegate(object sender, SvnNotifyEventArgs e)
                {
                    Console.WriteLine(e.Action);
                    Console.WriteLine(e.FullPath);
                };
                // Update the specified working copy path to the head revision
                client.Update("d:\\sharpsvn", ua);
                SvnUpdateResult result;

                client.Update("d:\\sharpsvn", out result);

                client.GetLog(targetUri, out logitems);
                foreach (var logentry in logitems)
                {
                    string   author      = logentry.Author;
                    string   message     = logentry.LogMessage;
                    DateTime checkindate = logentry.Time;
                }


                //  client.Move("c:\\sharpsvn\\from.txt", "c:\\sharpsvn\\new.txt");

                // Commit the changes with the specified logmessage
                //SvnCommitArgs ca = new SvnCommitArgs();
                // ca.LogMessage = "Moved from.txt to new.txt";
                // client.Commit("c:\\sharpsvn", ca);
            }
        }
Esempio n. 25
0
        public void TestChangeListAndLog()
        {
            var svnService = new Utry.Core.Services.SvnService();

            //http://docs.sharpsvn.net/current/

            using (SvnClient client = new SvnClient())
            {
                // Checkout the code to the specified directory
                client.Authentication.Clear(); // Clear a previous authentication
                client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("", "");
                //client.CheckOut(new Uri("http://ip:9001/svn/CCMS/trunk/CCMS_V6/DOCUMENT/"), "d:\\sharpsvn");

                Uri targetUri = new Uri("http://ip:9001/svn/CCMS/trunk/CCMS_V6/DOCUMENT");
                var target    = SvnTarget.FromUri(targetUri);
                Collection <SvnInfoEventArgs> info;//System.Collections.ObjectModel
                bool result2 = client.GetInfo(target, new SvnInfoArgs {
                    ThrowOnError = false
                }, out info);


                SvnUpdateArgs ua    = new SvnUpdateArgs();
                SvnLogArgs    args2 = new SvnLogArgs(new SvnRevisionRange(500, new SvnRevision(SvnRevisionType.Head)));
                var           sua   = new SvnUpdateArgs {
                    Revision = new SvnRevision(0)
                };

                Collection <SvnLogEventArgs> logitems;

                long version = 0;
                ua.Notify += delegate(object sender, SvnNotifyEventArgs e)
                {
                    Console.WriteLine(string.Format("{0}:{1}.", svnService.GetNotifyAction(e.Action), e.FullPath));
                    Console.WriteLine(e.Revision);
                    version = e.Revision;
                };

                client.Update("d:\\sharpsvn", ua);

                if (version > 0)
                {
                    client.GetLog(targetUri, new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems);
                    foreach (var logentry in logitems)
                    {
                        string   author      = logentry.Author;
                        string   message     = logentry.LogMessage;
                        DateTime checkindate = logentry.Time;
                        Console.WriteLine(string.Format("{0}  :  {1  }:  {2}", author, message, checkindate));
                    }
                }
            }
        }
Esempio n. 26
0
        /// <summary>
        /// 获取单个项目提交记录
        /// </summary>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        public List <Model.MessageModel> GetCommitAllLog(RepositoriesModel item, DateTime startTime, DateTime endTime)
        {
            endTime = endTime.AddDays(1);
            List <Model.MessageModel> result = new List <Model.MessageModel>();


            try
            {
                Collection <SvnLogEventArgs> logs;
                if (item.Url.StartsWith("https://"))
                {
                    _client.GetLog(new Uri(item.Url), new SvnLogArgs(new SvnRevisionRange(startTime, endTime)), out logs);
                }
                else
                {
                    _client.GetLog(item.Url, new SvnLogArgs(new SvnRevisionRange(startTime, endTime)), out logs);
                }


                //后续操作,可以获取作者,版本号,提交时间,提交的message和提交文件列表等信息
                foreach (var log in logs.Where(x => x.Time >= startTime && x.Time < endTime).OrderByDescending(x => x.Time))
                {
                    result.Add(new Model.MessageModel
                    {
                        UserName     = log.Author,
                        Message      = log.LogMessage,
                        SubmitTime   = log.Time,
                        Repositories = item,
                        Revision     = log.Revision,
                        ChangedPaths = log.ChangedPaths
                    });
                }
            }
            catch (Exception e)
            {
            }

            return(result);
        }
 private int GetCountOfCommitsInBranch(string path)
 {
     using (SvnClient svnClient = new SvnClient())
     {
         Collection <SvnLogEventArgs> logEventArgs;
         svnClient.GetLog(new Uri(path), out logEventArgs);
         if (logEventArgs != null)
         {
             return(logEventArgs.Count);
         }
         return(0);
     }
 }
        public override ReadOnlyObservableCollection <ICommitItem> GetLog(Repository repo, int limit = 30, string startRevision = null, string endRevision = null)
        {
            if (repo == null)
            {
                return(null);
            }

            // not reliable...unfortunately
            if (!WebAddressIsAccessible(repo))
            {
                _messageBoxService.ShowError(string.Format("Unable to connect to '{0}'.", repo.Path.ToString()));
                return(null);
            }

            SvnLogArgs args;
            long       start, end;

            if (long.TryParse(startRevision, out start) && long.TryParse(endRevision, out end))
            {
                args = new SvnLogArgs {
                    Limit = limit, Start = new SvnRevision(start), End = new SvnRevision(end)
                };
            }
            else
            {
                args = new SvnLogArgs {
                    Limit = limit
                };
            }

            using (var client = new SvnClient())
            {
                var allItems = new List <ICommitItem>();

                if (!string.IsNullOrWhiteSpace(repo.UserName))
                {
                    client.Authentication.DefaultCredentials = new NetworkCredential(repo.UserName, repo.Password);
                }

                Collection <SvnLogEventArgs> logItems;
                client.GetLog(repo.Path, args, out logItems);
                if (logItems != null)
                {
                    var rootIndex = repo.Path.ToString().IndexOf("svn/");
                    var root      = repo.Path.ToString().EndsWith("svn/") ? repo.Path.ToString() : repo.Path.ToString().Remove(rootIndex + 4);
                    allItems.AddRange(logItems.ToCommitItems(new Uri(root), _mediator, repo.SecondsToTimeoutDownload, OnViewChangeDetails, repo.Name));
                }
                return(new ReadOnlyObservableCollection <ICommitItem>(new ObservableCollection <ICommitItem>(allItems)));
            }
        }
Esempio n. 29
0
        public void RepositoryOperation_SetupRepository()
        {
            SvnSandBox      sbox = new SvnSandBox(this);
            Uri             uri  = sbox.CreateRepository(SandBoxRepository.Empty);
            SvnCommitResult cr;

            SvnRepositoryOperationArgs oa = new SvnRepositoryOperationArgs();

            oa.LogMessage = "Everything in one revision";

            using (SvnMultiCommandClient mucc = new SvnMultiCommandClient(uri, oa))
            {
                mucc.CreateDirectory("trunk");
                mucc.CreateDirectory("branches");
                mucc.CreateDirectory("tags");
                mucc.CreateDirectory("trunk/src");
                mucc.SetProperty("", "svn:auto-props", "*.cs = svn:eol-style=native");
                mucc.SetProperty("", "svn:global-ignores", "bin obj");

                mucc.CreateFile("trunk/README", new MemoryStream(Encoding.UTF8.GetBytes("Welcome to this project")));
                mucc.SetProperty("trunk/README", "svn:eol-style", "native");

                Assert.That(mucc.Commit(out cr)); // Commit r1
                Assert.That(cr, Is.Not.Null);
            }

            using (SvnClient svn = new SvnClient())
            {
                Collection <SvnListEventArgs> members;
                svn.GetList(uri, out members);

                Assert.That(members, Is.Not.Empty);

                MemoryStream          ms = new MemoryStream();
                SvnPropertyCollection props;
                svn.Write(new Uri(uri, "trunk/README"), ms, out props);

                Assert.That(props, Is.Not.Empty);
                Assert.That(Encoding.UTF8.GetString(ms.ToArray()), Is.EqualTo("Welcome to this project"));
                Assert.That(props.Contains("svn:eol-style"));


                Collection <SvnLogEventArgs> la;
                SvnLogArgs ll = new SvnLogArgs();
                ll.Start = 1;
                svn.GetLog(uri, ll, out la);
                Assert.That(la, Is.Not.Empty);
                Assert.That(la[0].LogMessage, Is.EqualTo("Everything in one revision"));
            }
        }
Esempio n. 30
0
        public HashSet <string> GetLogByTime(DateTime startDateTime, DateTime endDateTime)
        {
            long[] revisions = GetVersion(startDateTime, endDateTime);

            if (revisions == null)
            {
                return(null);
            }

            SvnRevisionRange range   = new SvnRevisionRange(revisions[0], revisions[1]);
            SvnLogArgs       logArgs = new SvnLogArgs()
            {
                Limit = 0,
                Range = range,
                RetrieveAllProperties = true,
            };

            Collection <SvnLogEventArgs> logs;

            client.GetLog(new Uri(serverPath), logArgs, out logs);

            HashSet <string> fetchFiles = new HashSet <string>();

            foreach (var log in logs)
            {
                foreach (var changeItem in log.ChangedPaths)
                {
                    if (changeItem.Action == SvnChangeAction.Modify ||
                        changeItem.Action == SvnChangeAction.Add ||
                        changeItem.Action == SvnChangeAction.Replace)
                    {
                        fetchFiles.Add(ChangeToLocalPath(changeItem.Path));
                    }
                }
            }
            return(fetchFiles);
        }
Esempio n. 31
0
        private Collection <SvnLogEventArgs> getLog(int limit, SvnRevision rev)
        {
            var arg = new SvnLogArgs()
            {
                Limit = limit
                ,
                Start = rev
            };
            Collection <SvnLogEventArgs> results;

            if (!_svncl.GetLog(_uri, arg, out results))
            {
                return(null);
            }
            return(results);
        }
Esempio n. 32
0
        protected override void CheckForNewLogEntriesImpl()
        {
            if (!Monitor.TryEnter(LockObject))
                return;

            try
            {
                using (var svnClient = new SvnClient())
                {
                    var uri = new Uri(SettingsXml);
                    Collection<SvnLogEventArgs> svnLogEntries;
                    if (svnClient.GetLog(uri, new SvnLogArgs { Limit = 30 }, out svnLogEntries))
                    {
                        var q = svnLogEntries
                            .Where(e => e.Time.PrecisionFix() > MaxDateTimeRetrieved)
                            .OrderBy(e => e.Time);
                        foreach (var svnLogEntry in q)
                        {
                            var revision = svnLogEntry.Revision;
                            Logger.Write(new LogEntry
                                {
                                    Message = "Creating LogEntryDto for revision " + revision,
                                    Categories = { "Plugin." + GetType().Name }
                                });
                            var logEntry = new LogEntryDto
                                {
                                    Author = svnLogEntry.Author,
                                    CommittedDate = svnLogEntry.Time,
                                    Message = svnLogEntry.LogMessage,
                                    Revision = revision.ToString(CultureInfo.InvariantCulture),
                                    ChangedFiles = new List<ChangedFileDto>()
                                };

                            ProcessChangedPaths(svnLogEntry, revision, logEntry);

                            var args = new NewLogEntryEventArgs { LogEntry = logEntry };
                            OnNewLogEntry(args);
                        }
                        MaxDateTimeRetrieved = svnLogEntries.Max(x => x.Time).PrecisionFix();
                    }
                }
            }
            finally
            {
                Monitor.Exit(LockObject);
            }
        }
Esempio n. 33
0
        public override IEnumerable <WorkItem> GetHistory(int maxRevisions)
        {
            var args = new SvnLogArgs {
                Limit = maxRevisions
            };

            Collection <SvnLogEventArgs> entries;

            _svn.GetLog(_root.Uri, args, out entries);

            if (entries != null && entries.Count > 0)
            {
                return(entries.Select(ToWorkItem));
            }

            return(null);
        }
Esempio n. 34
0
        private bool TryCredentials(string url, string username, string password)
        {
            var client = new SvnClient();
            client.Authentication.Clear();
            client.Authentication.DefaultCredentials = new NetworkCredential(username, password);
            client.Authentication.SslServerTrustHandlers += (o, e) =>
            {
                e.AcceptedFailures = e.Failures;
                e.Save = true;
            };

            try
            {
                Collection<SvnLogEventArgs> logs;
                client.GetLog(new Uri(url), new SvnLogArgs() { Limit = 1 }, out logs);
                return true;
            }
            catch (SvnAuthorizationException ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }
        }
Esempio n. 35
0
        private IEnumerable<Commit> GetCommits(SvnClient client, string repoUrl, long endRevision, int count, Func<SvnLogEventArgs, bool> filter)
        {
            var repoDiscoveryStep = RepoDiscoveryStepCoef * count;

            var commits = new List<Commit>();
            long discoveredDepth = 0;

            while (commits.Count < count && discoveredDepth <= MaxRepositoryDiscoverDepth && endRevision > 1)
            {
                var startRevision = endRevision > repoDiscoveryStep ? endRevision - repoDiscoveryStep : 1;

                var logArguments = new SvnLogArgs { Start = startRevision, End = endRevision };

                Collection<SvnLogEventArgs> logEvents;
                client.GetLog(new Uri(repoUrl), logArguments, out logEvents);

                commits.AddRange(_mapper.Map<SvnLogEventArgs, Commit>(logEvents.Where(filter)));

                discoveredDepth += endRevision - startRevision;
                endRevision = endRevision - 1 > repoDiscoveryStep ? endRevision - repoDiscoveryStep - 1 : 1;
            }

            return commits;
        }
Esempio n. 36
0
        /*****************************************************************************
         * @author Alex Wulff
         *
         * @par Description:
         * This method handles executions every 50 minutes, and finds logs and reports
         * breaks in builds.
         *
         *****************************************************************************/
        public void Run()
        {
            _File = string.Format("{0}\\{1}", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Commits.txt");
            _CommitLog = new Collection<string>();

            Collection<SvnLogEventArgs> slea = new Collection<SvnLogEventArgs>();

            using (SvnClient client = new SvnClient())
            {
                client.Authentication.DefaultCredentials = new NetworkCredential("7088881", "080419877088881");

                Uri svnrepo = new Uri("http://dev.mcs.sdsmt.edu/repos/srdesign1415/robots/trunk/landingpad/");

                client.GetLog(svnrepo, out slea);
            }

            //client.GetLog("http://dev.mcs.sdsmt.edu/repos/srdesign1415/robots/trunk/landingpad/", out slea);

            foreach (SvnLogEventArgs s in slea)
            {
                int id;
                bool success = int.TryParse(s.Author, out id);
                string name = "";
                if (success && _ID.ContainsValue(id))
                {
                    foreach (string peeps in _ID.Keys)
                    {
                        if (_ID[peeps] == id)
                        {
                            name = peeps;
                            break;
                        }
                    }

                    _CommitLog.Add(string.Format("=== {0} : {1} : {2} : {3} ====", s.Revision, name, s.Time, s.LogMessage).ToString());
                }
                else
                {
                    _CommitLog.Add(string.Format("=== {0} : {1} : {2} : {3} ====", s.Revision, s.Author, s.Time, s.LogMessage).ToString());
                }
            }

            if (IsLatest())
            {
                return;
            }
            else
            {
                // write to file.
                WriteLocal();

                // do mailing and checking of builds / unit tests.
                MailNewCommits();

                if (!BuildSuccess())
                {
                    MailSomeoneIsGonnaGetIt();
                }
            }
        }
Esempio n. 37
0
        public void RepositoryOperation_SetupRepository()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri uri = sbox.CreateRepository(SandBoxRepository.Empty);
            SvnCommitResult cr;

            SvnRepositoryOperationArgs oa = new SvnRepositoryOperationArgs();
            oa.LogMessage = "Everything in one revision";

            using (SvnMultiCommandClient mucc = new SvnMultiCommandClient(uri, oa))
            {
                mucc.CreateDirectory("trunk");
                mucc.CreateDirectory("branches");
                mucc.CreateDirectory("tags");
                mucc.CreateDirectory("trunk/src");
                mucc.SetProperty("", "svn:auto-props", "*.cs = svn:eol-style=native");
                mucc.SetProperty("", "svn:global-ignores", "bin obj");

                mucc.CreateFile("trunk/README", new MemoryStream(Encoding.UTF8.GetBytes("Welcome to this project")));
                mucc.SetProperty("trunk/README", "svn:eol-style", "native");

                Assert.That(mucc.Commit(out cr)); // Commit r1
                Assert.That(cr, Is.Not.Null);
            }

            using (SvnClient svn = new SvnClient())
            {
                Collection<SvnListEventArgs> members;
                svn.GetList(uri, out members);

                Assert.That(members, Is.Not.Empty);

                MemoryStream ms = new MemoryStream();
                SvnPropertyCollection props;
                svn.Write(new Uri(uri, "trunk/README"), ms, out props);

                Assert.That(props, Is.Not.Empty);
                Assert.That(Encoding.UTF8.GetString(ms.ToArray()), Is.EqualTo("Welcome to this project"));
                Assert.That(props.Contains("svn:eol-style"));

                Collection<SvnLogEventArgs> la;
                SvnLogArgs ll = new SvnLogArgs();
                ll.Start = 1;
                svn.GetLog(uri, ll, out la);
                Assert.That(la, Is.Not.Empty);
                Assert.That(la[0].LogMessage, Is.EqualTo("Everything in one revision"));
            }
        }
        private void fetchExec()
        {
            using (SvnClient client = new SvnClient())
            {
                Collection<SvnLogEventArgs> logItems = new Collection<SvnLogEventArgs>();

                client.GetLog(new Uri("http://192.168.1.193/svndata/fivestar/ecommerce/branches/dev2.1"), out logItems);
                svn.SvnLogs = logItems;

                Console.WriteLine(logItems[0].Author);

                SvnChangeItemCollection svnChange = logItems[0].ChangedPaths;

                Console.WriteLine(svnChange[0].Path);

                SvnTarget tgt = SvnTarget.FromString(svnChange[0].Path);

            }
        }
Esempio n. 39
0
        void LoadRevisions()
        {
            int limit;

            Int32.TryParse(textBoxLoadBunch.Text, out limit);

            var cts = new CancellationTokenSource();

            Task.Factory
                .StartNew(() => {
                    using (var client = new SvnClient())
                    {
                        client.Authentication.SslServerTrustHandlers += (sender, e) => { e.AcceptedFailures = SvnCertificateTrustFailures.MaskAllFailures; };
                        client.Authentication.DefaultCredentials = CredentialCache.DefaultNetworkCredentials;

                        SvnInfoEventArgs info;
                        client.GetInfo(_url != null ? (SvnTarget)new SvnUriTarget(_url) : new SvnPathTarget(_path), out info);
                        _repoUri = info.RepositoryRoot;

                        var args = new SvnLogArgs { Limit = limit };

                        var url = _url;

                        if (_lastLoaded != null)
                        {
                            args.OperationalRevision = _lastLoaded.Revision - 1;
                        }

                        Collection<SvnLogEventArgs> entries;
                        if (url != null)
                            client.GetLog(url, args, out entries);
                        else
                            client.GetLog(_path, args, out entries);

                        return entries;
                    }
                }, cts.Token)
                .TrackProgress(loadingOperation, cts)
                .LockControls(textBoxUrl, buttonLoad, buttonLoadNext, textBoxLoadBunch)
                .ContinueWith(t => {

                    if (t.IsFaulted || t.IsCanceled)
                    {
                        // if error occured - strat from scratch: can be load first N entries, can't continue
                        _lastLoaded = null;
                        buttonLoad.Enabled = true;
                        buttonLoadNext.Enabled = false;
                    }

                    cts.Token.ThrowIfCancellationRequested();

                    var entries = t.Result;

                    if (entries.Count < limit)
                    {
                        // nothing to load next - all revisions loaded
                        buttonLoadNext.Enabled = false;
                        _lastLoaded = null;
                    }
                    else
                    {
                        _lastLoaded = entries.Last();
                    }

                    try
                    {
                        listViewLog.BeginUpdate();

                        foreach (var entry in entries)
                        {
                            var lvi = new ListViewItem(new[] { entry.Revision.ToString(CultureInfo.InvariantCulture), entry.Author, entry.LogMessage })
                            {
                                Tag = entry
                            };
                            listViewLog.Items.Add(lvi);
                        }
                    }
                    finally
                    {
                        listViewLog.EndUpdate();
                    }

                }, TaskScheduler.FromCurrentSynchronizationContext())
                //.TrackProgress(loadingOperation)
                .WithDisposeWeak(cts)
            ;
        }
Esempio n. 40
0
    public static ICollection<SvnLogEventArgs> GetLogSince(string repositoryUri,
                                                           string target,
                                                           long revision)
    {
      var svnLogArgs = new SvnLogArgs
                       {
                         StrictNodeHistory = true,
                         End = revision,
                         BaseUri = new Uri(repositoryUri)
                       };

      Collection<SvnLogEventArgs> logItems;
      using (var svnClient = new SvnClient())
      {
        if (!svnClient.GetLog(new Uri(svnLogArgs.BaseUri,
                                      target),
                              svnLogArgs,
                              out logItems))
        {
          logItems = new Collection<SvnLogEventArgs>();
        }
      }

      return logItems;
    }
Esempio n. 41
0
        public void ChangeInfo_GetInfoCompare()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri reposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario);
            string reposPath = reposUri.LocalPath;

            using (SvnClient cl = new SvnClient())
            {
                SvnSetPropertyArgs sa = new SvnSetPropertyArgs();
                sa.BaseRevision = 17;
                sa.LogMessage = "Message";
                cl.RemoteSetProperty(reposUri, "MyProp", "Value", sa);
            }

            for (long ii = 1; ii < 19; ii++)
            {
                using (SvnLookClient lcl = new SvnLookClient())
                using (SvnClient cl = new SvnClient())
                {
                    SvnChangeInfoEventArgs r;
                    SvnChangeInfoArgs ia = new SvnChangeInfoArgs();
                    SvnLookOrigin origin = new SvnLookOrigin(reposPath, ii);

                    SvnLogArgs la = new SvnLogArgs();
                    la.Start = la.End = ii;

                    Collection<SvnLogEventArgs> lrc;
                    //ia.RetrieveChangedPaths = false; // Will fail if true
                    Assert.That(lcl.GetChangeInfo(origin, ia, out r));
                    Assert.That(cl.GetLog(reposUri, la, out lrc));

                    Assert.That(r, Is.Not.Null);
                    Assert.That(lrc.Count, Is.EqualTo(1));

                    SvnLogEventArgs lr = lrc[0];

                    Assert.That(r.Author, Is.EqualTo(lr.Author));
                    Assert.That(r.Revision, Is.EqualTo(lr.Revision));
                    Assert.That(r.BaseRevision, Is.EqualTo(lr.Revision - 1));
                    Assert.That(r.LogMessage, Is.EqualTo(lr.LogMessage));
                    Assert.That(r.Time, Is.EqualTo(lr.Time));

                    Assert.That(r.ChangedPaths, Is.Not.Null, "r.ChangedPaths({0})", ii);
                    Assert.That(lr.ChangedPaths, Is.Not.Null, "lr.ChangedPaths({0})", ii);

                    Assert.That(r.ChangedPaths.Count, Is.EqualTo(lr.ChangedPaths.Count));

                    for (int i = 0; i < r.ChangedPaths.Count; i++)
                    {
                        SvnChangeItem c = r.ChangedPaths[i];
                        SvnChangeItem lc = lr.ChangedPaths[c.Path];

                        Assert.That(c.Path, Is.EqualTo(lc.Path));
                        Assert.That(c.Action, Is.EqualTo(lc.Action));
                        Assert.That(c.CopyFromPath, Is.EqualTo(lc.CopyFromPath));
                        Assert.That(c.CopyFromRevision, Is.EqualTo(lc.CopyFromRevision));
                    }
                }
            }
        }
Esempio n. 42
0
    public static SvnLogEventArgs GetInitialLogItem(string repositoryUri,
                                                    string target)
    {
      var svnLogArgs = new SvnLogArgs
                       {
                         StrictNodeHistory = true,
                         BaseUri = new Uri(repositoryUri),
                         Start = SvnRevision.Zero,
                         End = SvnRevision.Head,
                         Limit = 1
                       };

      Collection<SvnLogEventArgs> logItems;
      using (var svnClient = new SvnClient())
      {
        if (!svnClient.GetLog(new Uri(svnLogArgs.BaseUri,
                                      target),
                              svnLogArgs,
                              out logItems))
        {
          logItems = new Collection<SvnLogEventArgs>();
        }
      }

      var logItem = logItems.SingleOrDefault();

      return logItem;
    }
Esempio n. 43
0
 private bool GetLogs(string path, string changelog)
 {
     SvnClient client = new SvnClient();
     Collection<SvnLogEventArgs> logItems = null;
     if (client.GetLog(path, out logItems))
     {
         DataTable table = new DataTable("log");
         table.Columns.Add("time", typeof(DateTime));
         table.Columns.Add("message", typeof(string));
         table.Columns.Add("author", typeof(string));
         foreach (SvnLogEventArgs args in logItems)
         {
             if (!string.IsNullOrEmpty(args.LogMessage))
             {
                 table.Rows.Add(new object[] { args.Time, args.LogMessage, args.Author });
             }
         }
         if (table.Rows.Count > 0)
         {
             DataSet set = new DataSet("logs");
             set.Tables.Add(table);
             set.WriteXml(changelog);
             return true;
         }
     }
     return false;
 }
Esempio n. 44
0
        private static void GetLogs(bool console_mode, string application_path, string repository_location, long last_revision, Output_Type output_type)
        {
            SvnTarget repository;

            SvnClient client = new SvnClient();

            long current_revision = -1;

            if (SvnTarget.TryParse(repository_location, out repository) == true)
            {
                try
                {
                    SvnInfoEventArgs info;
                    client.GetInfo(new Uri(repository_location), out info);
                    current_revision = info.Revision;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);

                    if (console_mode == true)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                if (last_revision < current_revision)
                {
                    DataTable datatable = new DataTable("log");
                    datatable.Columns.Add("Revision", typeof(long));
                    datatable.Columns.Add("Author", typeof(string));
                    datatable.Columns.Add("Time", typeof(DateTime));
                    datatable.Columns.Add("ChangedPaths", typeof(string));
                    datatable.Columns.Add("LogMessage", typeof(string));

                    try
                    {
                        System.Collections.ObjectModel.Collection<SvnLogEventArgs> logitems = new System.Collections.ObjectModel.Collection<SvnLogEventArgs>();

                        SvnLogArgs logargs = new SvnLogArgs(new SvnRevisionRange(current_revision, last_revision + 1));

                        client.GetLog(new Uri(repository_location), logargs, out logitems);

                        datatable.BeginLoadData();

                        foreach (SvnLogEventArgs logitem in logitems)
                        {
                            StringBuilder ChangedPaths = new StringBuilder();

                            if (logitem.ChangedPaths != null)
                            {
                                foreach (SvnChangeItem path in logitem.ChangedPaths)
                                {
                                    ChangedPaths.AppendFormat("{1} {2}{0}", Environment.NewLine, path.Action, path.Path);

                                    if (path.CopyFromRevision != -1)
                                    {
                                        ChangedPaths.AppendFormat("{1} -> {2}{0}", Environment.NewLine, path.CopyFromPath, path.CopyFromRevision);
                                    }
                                }
                            }

                            DataRow datarow = datatable.NewRow();
                            datarow["Revision"] = logitem.Revision;
                            datarow["Author"] = logitem.Author;
                            datarow["Time"] = logitem.Time.ToLocalTime();
                            datarow["ChangedPaths"] = ChangedPaths.ToString();
                            datarow["LogMessage"] = logitem.LogMessage;

                            datatable.Rows.Add(datarow);
                        }

                        datatable.EndLoadData();

                        datatable.AcceptChanges();

                        switch (output_type)
                        {
                            case Output_Type.Console:
                                OutputToConsole(console_mode, application_path, datatable);

                                break;
                            case Output_Type.Txt:
                                OutputToTxt(console_mode, application_path, datatable);

                                break;
                            case Output_Type.XML:
                                OutputToXML(console_mode, application_path, datatable);

                                break;
                            case Output_Type.XMLTransform:
                                OutputToXMLTransform(console_mode, application_path, datatable);

                                break;
                            case Output_Type.RSS:
                                OutputToRSS(console_mode, application_path, datatable);

                                break;
                            default:
                                break;
                        }

                        last_revision = Convert.ToInt32(datatable.Compute("max(Revision)", string.Empty));

                        System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                        config.AppSettings.Settings.Remove("last_revision");
                        config.AppSettings.Settings.Add("last_revision", last_revision.ToString());
                        config.Save();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);

                        if (console_mode == true)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }

                client.Dispose();
            }
            else
            {
                Debug.WriteLine("Unable to connect to repository");

                if (console_mode == true)
                {
                    Console.WriteLine("Unable to connect to repository");
                }
            }
        }
Esempio n. 45
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lbInfo.Content = "一切正常";

            String curDir = Directory.GetCurrentDirectory();
            String curExe = System.Reflection.Assembly.GetExecutingAssembly().Location;


            SvnClient = new SvnClient();

            SvnTarget svnTargetCurDir = SvnTarget.FromString(curDir);
            SvnTarget snvTargetCurExe = SvnTarget.FromString(curExe);

            // 未使用 - 获取目录下的文件状态
            Collection<SvnStatusEventArgs> svnStatusEventArgsCollection;
            SvnClient.GetStatus(Directory.GetCurrentDirectory(), out svnStatusEventArgsCollection);

            // 未使用 - 空的
            Collection<SvnPropertyListEventArgs> svnPropertyListEventArgsCollection;
            SvnClient.GetPropertyList(Directory.GetCurrentDirectory(), out svnPropertyListEventArgsCollection);

            // 未使用 - 获取一个文件的状态
            Collection<SvnFileVersionEventArgs> svnFileVersionEventArgsCollection;
            try
            {
                SvnClient.GetFileVersions(snvTargetCurExe, out svnFileVersionEventArgsCollection);
            }
            catch(SvnWorkingCopyPathNotFoundException ex)
            {
                // 如果查询的文件未加入Repo,会抛此异常
            }

            // 未使用 - 一个好像没什么用的信息列表,目录是第一个项,没有版本号
            Collection<SvnListEventArgs> svnListEventArgsCollection;
            SvnClient.GetList(svnTargetCurDir, out svnListEventArgsCollection);

            // 未使用 - 工作目录全路径
            String workingCopyRoot = SvnClient.GetWorkingCopyRoot(Directory.GetCurrentDirectory());
            
            // 未使用 - 整个仓库的最新版本
            long revision = 0;
            SvnClient.Youngest(Directory.GetCurrentDirectory(), out revision);

            // 此目录的相关变更 和 GUI中的ShowLog一样 是此目录的相关变更           
            Collection<SvnLogEventArgs> logList;
            try
            {
                SvnClient.GetLog(Directory.GetCurrentDirectory(), out logList);
            }
            catch(SvnInvalidNodeKindException ex)
            {
                lbInfo.Content = "当前目录不是SVN目录,停用更新检查功能";
                btnUpdateAndLaunch.Visibility = Visibility.Hidden;
                return;
            }

            // 获取本地目录信息,当前版本和修改版本都是本地的
            SvnInfoEventArgs svnInfoEventArgs;
            SvnClient.GetInfo(svnTargetCurDir, out svnInfoEventArgs);

            long curRevision = svnInfoEventArgs.Revision;       // 当前的SVN版本
            long changeRevision = logList[0].Revision;          // 当前目录的最新远程变更版本

            lbVersionChange.Content = changeRevision;
            lbVersionCur.Content = svnInfoEventArgs.Revision;

            if (curRevision < changeRevision)
            {
                btnUpdateAndLaunch.Visibility = Visibility.Visible;
                lbInfo.Content = "发现新版本";
            }
            else
            {
                btnUpdateAndLaunch.Visibility = Visibility.Hidden;
                lbInfo.Content = "已经是最新版";
            }

            // --------------------------------------------------------
            // SvnWorkingCopyClient
            // --------------------------------------------------------
            SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient();

            // 未使用 只有一个值IsText 没看出有什么用处
            SvnWorkingCopyState svnWorkingCopyState;
            svnWorkingCopyClient.GetState(Directory.GetCurrentDirectory(), out svnWorkingCopyState);

            // 未使用 返回仅本地存在的所有修改版本 
            SvnWorkingCopyVersion svnWorkingCopyVersion;
            svnWorkingCopyClient.GetVersion(curDir, out svnWorkingCopyVersion);

            // --------------------------------------------------------
            // SvnTools
            // --------------------------------------------------------
            // 未使用 传入正确的目录却返回false????
            bool isCurDirInWorkingCopy = SvnTools.IsManagedPath(curDir);

        }
Esempio n. 46
0
        public void Commit_WithAlternateUser()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Empty);
            string user = Guid.NewGuid().ToString();

            string dir = sbox.Wc;
            using (SvnClient client = new SvnClient())
            {
                client.Authentication.Clear();
                client.Configuration.LogMessageRequired = false;

                client.Authentication.UserNameHandlers +=
                    delegate(object sender, SvnUserNameEventArgs e)
                    {
                        e.UserName = user;
                    };

                client.SetProperty(dir, "a", "b");

                SvnCommitResult cr;
                client.Commit(dir, out cr);

                Collection<SvnLogEventArgs> la;
                client.GetLog(dir, out la);

                Assert.That(la.Count, Is.EqualTo(2));
                Assert.That(la[0].Revision, Is.EqualTo(cr.Revision));
                Assert.That(la[0].Author, Is.EqualTo(user));
                Assert.That(la[0].LogMessage, Is.EqualTo(""));
            }
        }