public async Task<ActionResult> Create(string projectId) { if (!string.IsNullOrEmpty(projectId)) { var projectRepo = new ProjectRepository(); var project = await projectRepo.Get(projectId); if (project == null) { project = new Project(); } return View(project); } return View(new Project()); }
public async Task<ActionResult> BuildAndroid(Project project) { var projectRepo = new ProjectRepository(); var isNewProject = false; if (project.Id.ToString().Trim() == "000000000000000000000000") { isNewProject = true; project.DateCreated = Helper.SetDateForMongo(DateTime.Now); project.User = User.Identity.Name; await projectRepo.CreateSync(project); } var output = ProcessBuild(project, "android", User.Identity.Name); return Json(new { success = true, projectId = project.Id.ToString(), isNew = isNewProject }, JsonRequestBehavior.AllowGet); }
private async Task<Task> ProcessBuild(Project project, string buildType, string user) { var buildRepo = new BuildRepository(); var ticks = DateTime.Now.Ticks.ToString(); var build = new Build { ProjectId = project.Id, BuildType = buildType, Status = "Pulling source files", BuildDateTime = Helper.SetDateForMongo(DateTime.Now), BuildFileLog = string.Format("{0}{1}_{2}Build.txt", user, ticks, buildType), GitFileLog = string.Format("{0}{1}_{2}GitPull.txt", user, ticks, buildType), OutputZipFile = string.Format("{0}{1}_{2}Build.zip", user, ticks, buildType), }; await buildRepo.CreateSync(build); return Task.Factory.StartNew(() => { var startDateTime = DateTime.Now; var baseWorkingDirectory = ConfigurationManager.AppSettings["WorkingDirectory"].ToString(); var baseOutputDirectory = ConfigurationManager.AppSettings["OutputDirectory"].ToString(); var workingDirectory = Path.Combine(baseWorkingDirectory, DateTime.Now.Ticks.ToString()); if (!Directory.Exists(workingDirectory)) { Directory.CreateDirectory(workingDirectory); } var outputDirectory = Path.Combine(baseOutputDirectory, string.Format("{0}\\{1}\\{2}", user, project.Id.ToString(), buildType)); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } var gitCommand = string.Format("git clone https://{0}:{1}@{2}", project.GitUsername, project.GitPassword, project.GitUrl.Replace("https://", "")); ExecuteCommand(gitCommand, workingDirectory, outputDirectory, build.GitFileLog); var workingDirectoryInfo = new DirectoryInfo(workingDirectory); var projectFolderName = (workingDirectoryInfo.GetDirectories()).FirstOrDefault().ToString(); if (!string.IsNullOrEmpty(projectFolderName)) { var projectFolder = Path.Combine(workingDirectory, projectFolderName); var cordovaAddPlatformCommand = string.Format("cordova platform add {0}", buildType); ExecuteCommand(cordovaAddPlatformCommand, projectFolder, outputDirectory, build.BuildFileLog); var cordovaBuildCommand = string.Format("cordova build {0}", buildType); Task.Run(async () => { var timeDifference = DateTime.Now - startDateTime; buildRepo.UpdateStatus("Building project", build.Id.ToString(), (int)timeDifference.TotalSeconds); }); ExecuteCommand(cordovaBuildCommand, projectFolder, outputDirectory, build.BuildFileLog); var buildDirectory = Path.Combine(workingDirectory, projectFolder, string.Format("platforms\\{0}", buildType)); var zipFullPath = Path.Combine(outputDirectory, build.OutputZipFile); Task.Run(async () => { var timeDifference = DateTime.Now - startDateTime; buildRepo.UpdateStatus("Completed", build.Id.ToString(), (int)timeDifference.TotalSeconds); }); ZipFile.CreateFromDirectory(buildDirectory, zipFullPath, CompressionLevel.Fastest, true); } }); }