private static List <ProjectVo> ToVoList(List <ProjectEntity> entityList)
        {
            var processList = new List <ProjectVo>();

            foreach (var entity in entityList)
            {
                ProjectVo process = ToVo(entity);

                processList.Add(process);
            }

            return(processList);
        }
        private ProjectEntity ToEntity(ProjectVo process)
        {
            ProjectEntity entity = new ProjectEntity();

            entity.Id           = process.Id;
            entity.Name         = process.Name;
            entity.Description  = process.Description;
            entity.Repository   = process.Repository;
            entity.TemplateName = process.TemplateName;
            if (process.ParamList != null && process.ParamList.Count > 0)
            {
                entity.Params = JsonConvert.SerializeObject(process.ParamList);
            }

            entity.DataStatus     = 1;
            entity.CreateBy       = "HarrisZhang";
            entity.CreateTime     = DateTime.Now;
            entity.LastUpdateBy   = "HarrisZhang";
            entity.LastUpdateTime = DateTime.Now;

            return(entity);
        }
        private static ProjectVo ToVo(ProjectEntity entity)
        {
            var project = new ProjectVo();

            project.Id           = entity.Id;
            project.Name         = entity.Name;
            project.Description  = entity.Description;
            project.Repository   = entity.Repository;
            project.DataStatus   = entity.DataStatus;
            project.TemplateName = entity.TemplateName;
            if (!string.IsNullOrEmpty(entity.Params))
            {
                project.ParamList = JsonConvert.DeserializeObject <List <ParamVo> >(entity.Params);
            }

            project.CreateBy       = entity.CreateBy;
            project.CreateTime     = entity.CreateTime;
            project.LastUpdateBy   = entity.LastUpdateBy;
            project.LastUpdateTime = entity.LastUpdateTime;

            return(project);
        }
Пример #4
0
 public DataResult <bool> Update(ProjectVo vo)
 {
     throw new NotImplementedException();
 }
        public BuildSetupResponse Setup(BuildSetupRequest request)
        {
            BuildSetupResponse response = new BuildSetupResponse();

            ProjectVo appVo = null;

            using (var sqliteConn = ConnectionProvider.GetSqliteConn())
            {
                appVo = sqliteConn.QueryFirstOrDefault <ProjectVo>("select * from project where Name = @Name", new { Name = request.Name });
                if (appVo == null)
                {
                    response.Message = "app not found";
                    return(response);
                }
            }

            ProcessEntity processEntity = null;

            using (var sqliteConn = ConnectionProvider.GetSqliteConn())
            {
                processEntity = sqliteConn.QueryFirstOrDefault <ProcessEntity>("select * from process where Name = @Name", new { Name = appVo.TemplateName });
                if (processEntity == null)
                {
                    response.Message = "template not found";
                    return(response);
                }
            }

            var process = new CSharpLibraryTemplate();

            var steps = JsonConvert.DeserializeObject <List <StepVo> >(processEntity.Steps);

            process.Cmds = steps.Select(v => v.Command).ToList();

            List <Param> paramList = new List <Param>();

            paramList.Add(new Param {
                Key = "Repository", Description = "git repository"
            });
            paramList.Add(new Param {
                Key = "Branch", Description = "git branch", DefaultValue = "master"
            });
            paramList.Add(new Param {
                Key = "BuildVersion", Description = "build version"
            });
            paramList.Add(new Param {
                Key = "OutputFolder", Description = "Output Folder"
            });
            if (!string.IsNullOrEmpty(processEntity.Params))
            {
                var items = JsonConvert.DeserializeObject <List <ParamVo> >(processEntity.Params);
                foreach (var item in items)
                {
                    paramList.Add(new Param {
                        Key = item.Key, DefaultValue = item.DefaultValue, Description = item.Description
                    });
                }
            }

            process.Params = paramList;

            string configXml = process.TransformText();

            SavoryWebClient client = new SavoryWebClient();

            client.Authorization = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(GlobalVariables.JenkinsUserId + ":" + GlobalVariables.JenkinsApiToken));
            client.HttpMethod    = Utility.WebClient.HttpMethod.Post;
            client.Content       = configXml;

            client.ContentType = "application/xml";

            if (IsJobExists(appVo.Name))
            {
                client.Host = $"{GlobalVariables.JenkinsHost}/job/{appVo.Name}/config.xml";
            }
            else
            {
                client.Host = $"{GlobalVariables.JenkinsHost}/createItem?name={appVo.Name}";
            }

            response.Message = client.RequestForString();

            response.Status = 1;
            return(response);
        }