Example #1
0
 public IActionResult Build(Guid id, Guid pid)
 {
     var project = DB.Projects
         .Where(x => x.CISetId == id && x.Id == pid)
         .SingleOrDefault();
     if (project == null)
         return Prompt(x =>
         {
             x.Title = "资源没有找到";
             x.Details = "您请求的资源没有找到,请返回重试!";
             x.StatusCode = 404;
         });
     project.CurrentVersion++;
     var ciset = DB.CISets
         .Where(x => x.Id == id)
         .SingleOrDefault();
     ciset.LastBuildingTime = DateTime.Now;
     var status = new Status
     {
         ProjectId = project.Id,
         Type = StatusType.Project,
         UserId = User.Current.Id,
         Result = StatusResult.Queued,
         Time = DateTime.Now
     };
     DB.Statuses.Add(status);
     DB.SaveChanges();
     if (project.RunWithLinux)
     {
         status.RunWithLinux = true;
         status.LinuxResult = StatusResult.Queued;
         var node = NodeProvider.GetFreeNode(Package.OSType.Linux);
         if (node != null)
             node.SendCIBuildTask(status.Id, project.ZipUrl, string.Format(project.VersionRule, project.CurrentVersion), project.AdditionalEnvironmentVariables);
         else
             status.LinuxResult = StatusResult.Ignored;
     }
     if (project.RunWithOsx)
     {
         status.RunWithLinux = true;
         status.OsxResult = StatusResult.Queued;
         var node = NodeProvider.GetFreeNode(Package.OSType.OSX);
         if (node != null)
             node.SendCIBuildTask(status.Id, project.ZipUrl, string.Format(project.VersionRule, project.CurrentVersion), project.AdditionalEnvironmentVariables);
         else
             status.OsxResult = StatusResult.Ignored;
     }
     if (project.RunWithWindows)
     {
         status.RunWithWindows = true;
         status.WindowsResult = StatusResult.Queued;
         var node = NodeProvider.GetFreeNode(Package.OSType.Windows);
         if (node != null)
             node.SendCIBuildTask(status.Id, project.ZipUrl, string.Format(project.VersionRule, project.CurrentVersion), project.AdditionalEnvironmentVariables);
         else
             status.WindowsResult = StatusResult.Ignored;
     }
     status.Result = status.GenerateResult();
     DB.SaveChanges();
     vNextChinaHub.Clients.Group("StatusList").OnStatusChanged(status.Id);
     return RedirectToAction("Show", "CI", new { id = id });
 }
        public async Task<IActionResult> Submit(long id, IFormFile file, string nuget)
        {
            var exp = DB.Experiments
                .Where(x => x.Id == id)
                .SingleOrDefault();
            if (exp == null)
                return Prompt(x => 
                {
                    x.Title = "资源没有找到";
                    x.Details = "您请求的资源没有找到,请返回重试!";
                    x.StatusCode = 404;
                });
            if (!User.AnyRoles("Root, Master") && exp.CheckPassed == false)
                return Prompt(x => 
                {
                    x.Title = "资源没有找到";
                    x.Details = "您请求的资源没有找到,请返回重试!";
                    x.StatusCode = 404;
                });
            if (!User.AnyRoles("Root, Master") && exp.Contests.Count > 0 && exp.Contests.Max(y => y.Contest.End) > DateTime.Now)
                return Prompt(x =>
                {
                    x.Title = "资源没有找到";
                    x.Details = "您请求的资源没有找到,请返回重试!";
                    x.StatusCode = 404;
                });
            var Status = new Status
            {
                UserId = User.Current.Id,
                Time = DateTime.Now,
                Result = StatusResult.Queued,
                ExperimentId = id,
                Archive = await file.ReadAllBytesAsync(),
                MemoryUsage = file.Length / 1024
            };

            switch(exp.OS)
            {
                case OSType.CrossPlatform:
                    Status.RunWithLinux = true;
                    Status.RunWithOsx = true;
                    Status.RunWithWindows = true;
                    Status.LinuxResult = StatusResult.Queued;
                    Status.OsxResult = StatusResult.Queued;
                    Status.WindowsResult = StatusResult.Queued;
                    break;
                case OSType.Random:
                    switch (NodeProvider.GetFreeNode().OS)
                    {
                        case Package.OSType.Linux:
                            Status.RunWithLinux = true;
                            Status.LinuxResult = StatusResult.Queued;
                            break;
                        case Package.OSType.OSX:
                            Status.RunWithOsx = true;
                            Status.OsxResult = StatusResult.Queued;
                            break;
                        case Package.OSType.Windows:
                            Status.RunWithWindows = true;
                            Status.WindowsResult = StatusResult.Queued;
                            break;
                    }
                    break;
                case OSType.Linux:
                    Status.RunWithLinux = true;
                    Status.LinuxResult = StatusResult.Queued;
                    break;
                case OSType.OSX:
                    Status.RunWithOsx = true;
                    Status.OsxResult = StatusResult.Queued;
                    break;
                case OSType.Windows:
                    Status.RunWithWindows = true;
                    Status.WindowsResult = StatusResult.Queued;
                    break;
            }

            DB.Statuses.Add(Status);
            DB.SaveChanges();

            if (Status.RunWithLinux)
            {
                var node = NodeProvider.GetFreeNode(Package.OSType.Linux);
                if (node == null)
                    Status.LinuxResult = Models.StatusResult.Ignored;
                else
                    await node.SendJudgeTask(Status.Id, Status.Archive, Status.Experiment.TestArchive, Status.NuGet + "\r\n" + Status.Experiment.NuGet);
            }
            if (Status.RunWithWindows)
            {
                var node = NodeProvider.GetFreeNode(Package.OSType.Windows);
                if (node == null)
                    Status.WindowsResult = Models.StatusResult.Ignored;
                else
                    await node.SendJudgeTask(Status.Id, Status.Archive, Status.Experiment.TestArchive, Status.NuGet + "\r\n" + Status.Experiment.NuGet);
            }
            if (Status.RunWithOsx)
            {
                var node = NodeProvider.GetFreeNode(Package.OSType.OSX);
                if (node == null)
                    Status.OsxResult = Models.StatusResult.Ignored;
                else
                    await node.SendJudgeTask(Status.Id, Status.Archive, Status.Experiment.TestArchive, Status.NuGet + "\r\n" + Status.Experiment.NuGet);
            }
            Status.Result = Status.GenerateResult();
            exp.Submitted++;
            DB.SaveChanges();
            vNextChinaHub.Clients.Group("StatusList").OnStatusChanged(Status.Id);
            return RedirectToAction("Show", "Status", new { id = Status.Id });
        }