Ejemplo n.º 1
0
        private int GetCurrentSvnRevision(string directory)
        {
            switch (_revisionGetMethod)
            {
            case RevisionGetMethod.UseSvnInfo:
                return(SvnHelper.GetCurrentRevision(directory));

            case RevisionGetMethod.Incremental:
                return(GetPreviousSvnRevision() + 1);

            default:
                throw new Exception();
            }
        }
Ejemplo n.º 2
0
        public void GetFileContent(string userName, string password, string fileUrl, int reversion)
        {
            var svn = new SvnHelper()
            {
                UserName = userName, Password = password
            };
            var result = new Result()
            {
                Content = svn.GetFileContent(fileUrl, reversion)
            };
            JavaScriptSerializer js = new JavaScriptSerializer();

            Context.Response.Clear();
            Context.Response.Write(JsonConvert.SerializeObject(result));
        }
Ejemplo n.º 3
0
        public void GetChangedFileList(int startReversion, int endReversion, string userName, string password, string url)
        {
            var svn = new SvnHelper()
            {
                UserName = userName, Password = password
            };
            var list = svn.GetChangedFileList(url, startReversion, endReversion);
            JavaScriptSerializer js = new JavaScriptSerializer();

            Context.Response.Clear();
            Context.Response.ContentType = "application/json";
            IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();

            timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            Context.Response.Write(JsonConvert.SerializeObject(list, Newtonsoft.Json.Formatting.Indented, timeFormat));
        }
Ejemplo n.º 4
0
        public void GetLogs(int startReversion = 170, int endReversion = 172, string userName = "******", string password = "******", string url = "https://tjs-svn.centaline.com.cn:8443/svn/cchr/cchrwebapi/trunk/sourcecode")
        {
            var svn = new SvnHelper()
            {
                UserName = userName, Password = password
            };
            var list = svn.GetLogs(url, startReversion, endReversion);
            JavaScriptSerializer js = new JavaScriptSerializer();

            Context.Response.Clear();
            Context.Response.ContentType = "application/json";
            IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();

            timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            Context.Response.Write(JsonConvert.SerializeObject(list, Newtonsoft.Json.Formatting.Indented, timeFormat));
        }
Ejemplo n.º 5
0
        public void UpdateSvnLogToDatabase()
        {
            GetProjectRevision();
            MessageAdd(string.Format("开始同步"));
            #region 遍历项目
            foreach (var svnProject in _svnProjectList)
            {
                MessageAdd(string.Format("项目:{0},数据库当前版本:{1}", svnProject.Name, svnProject.Revision));
                var svn = new SvnHelper()
                {
                    UserName = svnProject.DomainAccount, Password = svnProject.Password
                };
                var logList = new List <SvnReversionModel>();
                try
                {
                    logList = svn.GetLogs(svnProject.Url, svnProject.Revision, 0);
                }
                catch (Exception e)
                {
                    MessageAdd(string.Format("出错了:{0},{1}", svnProject.Name, e.Message));
                    continue;
                }

                if (logList == null || logList.Count == 0)
                {
                    MessageAdd(string.Format("svn当前版本:{0},无最新日志", svnProject.Revision));
                    continue;
                }
                //待插入的用户列表
                List <SvnUser> insertSvnUserList = new List <SvnUser>();
                //待插入的日志列表
                List <SvnLog> insertSvnLogList = new List <SvnLog>();
                //待插入的日志文件列表
                List <SvnLogFile> insertSvnLogFileList = new List <SvnLogFile>();

                #region 遍历日志 保存数据到insertSvnUserList、insertSvnLogList和insertSvnLogFileList
                foreach (var log in logList)
                {
                    SvnLog svnLog = new SvnLog();
                    svnLog.ID        = Guid.NewGuid().ToString().ToUpper();
                    svnLog.ProjectID = svnProject.ID;
                    int revision = 0;
                    int.TryParse(log.Reversion.ToString(), out revision);
                    if (revision == 0)
                    {
                        continue;
                    }
                    svnLog.Revision   = revision;
                    svnLog.CreateTime = log.Time;
                    svnLog.Message    = log.LogMessage;
                    if (string.IsNullOrEmpty(log.Author))
                    {
                        continue;
                    }
                    var domainAccount = Regex.Replace(log.Author, "@CENTALINE", "", RegexOptions.IgnoreCase);
                    #region 用户是否存在,不存在,需要插入insertSvnUserList
                    if (_svnUserList.Any(p => p.DomainAccount == domainAccount))
                    {
                        svnLog.UserID = _svnUserList.FirstOrDefault(p => p.DomainAccount == domainAccount).ID;
                    }
                    else
                    {
                        var svnUser = new SvnUser()
                        {
                            ID            = Guid.NewGuid().ToString().ToUpper(),
                            DomainAccount = domainAccount,
                            RealName      = "导入用户" + new Random().Next(100, 999),
                            Description   = "svn日志导入的用户,请修改真实姓名"
                        };
                        svnLog.UserID = svnUser.ID;
                        insertSvnUserList.Add(svnUser);
                        //插入用户缓存
                        _svnUserList.Add(svnUser);
                    }
                    #endregion
                    #region 插入日志insertSvnLogList和文件insertSvnLogFileList
                    insertSvnLogList.Add(svnLog);
                    foreach (var file in log.PathList)
                    {
                        SvnLogFile svnLogFile = new SvnLogFile();
                        svnLogFile.ID     = Guid.NewGuid().ToString().ToUpper();
                        svnLogFile.LogID  = svnLog.ID;
                        svnLogFile.Path   = file.Path;
                        svnLogFile.Action = file.Action;
                        insertSvnLogFileList.Add(svnLogFile);
                    }
                    #endregion
                }
                #endregion

                #region 插入数据到表SVN_User、SVN_Log和SVN_LogFile
                //每次插入100条数据
                int           insertCount = 800;
                StringBuilder sql         = new StringBuilder();
                List <string> valueList   = new List <string>();
                if (insertSvnUserList.Count > 0)
                {
                    for (int i = 0; i <= Math.Floor(insertSvnUserList.Count * 1.0 / insertCount); i++)
                    {
                        sql.Append(@"insert into SVN_User(ID,DomainAccount,RealName,Description) values");
                        insertSvnUserList.OrderBy(p => p.ID).Skip(i * insertCount).Take(insertCount).ToList().ForEach(p =>
                        {
                            valueList.Add(string.Format("('{0}','{1}','{2}','{3}')", p.ID, p.DomainAccount, p.RealName, p.Description));
                        });
                        sql.Append(String.Join(",", valueList) + ";");
                        ExcuteTransaction(sql.ToString());
                        sql.Clear();
                        valueList.Clear();
                    }
                }
                if (insertSvnLogList.Count > 0)
                {
                    for (int i = 0; i <= Math.Floor(insertSvnLogList.Count * 1.0 / insertCount); i++)
                    {
                        sql.Append(@"insert into SVN_Log(ID,ProjectID,UserID,CreateTime,Revision,Message) values");
                        insertSvnLogList.OrderBy(p => p.ID).Skip(i * insertCount).Take(insertCount).ToList().ForEach(p =>
                        {
                            valueList.Add(string.Format("('{0}','{1}','{2}','{3}',{4},'{5}')", p.ID, p.ProjectID, p.UserID, p.CreateTime, p.Revision, p.Message.Replace("//", "").Replace("'", "")));
                        });
                        sql.Append(String.Join(",", valueList) + ";");
                        ExcuteTransaction(sql.ToString());
                        sql.Clear();
                        valueList.Clear();
                    }
                }
                if (insertSvnLogFileList.Count > 0)
                {
                    for (int i = 0; i <= Math.Floor(insertSvnLogFileList.Count * 1.0 / insertCount); i++)
                    {
                        sql.Append(@"insert into SVN_LogFile(LogID,Path,Action) values");
                        insertSvnLogFileList.OrderBy(p => p.LogID).Skip(i * insertCount).Take(insertCount).ToList().ForEach(p =>
                        {
                            valueList.Add(string.Format("('{0}','{1}','{2}')", p.LogID, p.Path, p.Action));
                        });
                        sql.Append(String.Join(",", valueList) + ";");
                        ExcuteTransaction(sql.ToString());
                        sql.Clear();
                        valueList.Clear();
                    }
                }

                //var sqlString = sql.ToString();
                //if (!string.IsNullOrEmpty(sqlString))
                //{
                //    ExcuteTransaction(sqlString);
                //}
                if (insertSvnLogList.Count > 0)
                {
                    MessageAdd(string.Format("更新了:{0}个版本:分别是:{1}", insertSvnLogList.Count, String.Join(",", insertSvnLogList.Select(p => p.Revision).ToList())));
                }
                #endregion
            }
            #endregion
            MessageAdd(string.Format("结束同步\r\n\r\n"));
        }