private void JobStatusChanged(Job job_, Job.StatusEnum status) { try { JobImpl job = (JobImpl)job_; Trace.TraceInformation("Form JobStatusChanged was called for: {0}, which changed status to {1}", job.Title, status.ToString()); if (Server.IsRemote) { if (status == Job.StatusEnum.StartedOnServer) { RemoteJobInfo remoteJobInfo; if (JobMap.TryGetValue(job, out remoteJobInfo) == false) { Trace.TraceError("Could not find jenkins job for {0}. Persistence will not work", job.Title); } else { SavedJob saved = SavedJob.CreateSavedJob( job.Title, job.WorkingDirectory, job.RunCommand, job.Status.ToString(), remoteJobInfo.JenkinsJobName); saved.VFUrl = Server.JenkinsUrl; Entities.SavedJobs.AddObject(saved); Entities.SaveChanges(); Entities.SavedJobs.Detach(saved); } } else if (Job.IsFailedStatus(status) || status == Job.StatusEnum.Succeeded) { RemoteJobInfo remoteJobInfo; if (JobMap.TryGetValue(job, out remoteJobInfo) == false) { Trace.TraceError("Could not find jenkins job for {0}. It may remain in the database", job.Title); } else { foreach (var entity in Entities.SavedJobs.Where(x => x.JobName == remoteJobInfo.JenkinsJobName)) { Entities.SavedJobs.DeleteObject(entity); } Entities.SaveChanges(); } } } if (status == Job.StatusEnum.Ready) { JobsToBeStarted.Add(delegate() { StartJob(job); }); } } catch (Exception ex) { //TODO: Propagate error back to UI? Trace.TraceError(ex.ToString()); } }
/// <summary> /// Create a new SavedJob object. /// </summary> /// <param name="title">Initial value of the Title property.</param> /// <param name="workingDirectory">Initial value of the WorkingDirectory property.</param> /// <param name="runCommand">Initial value of the RunCommand property.</param> /// <param name="status">Initial value of the Status property.</param> /// <param name="jobName">Initial value of the JobName property.</param> public static SavedJob CreateSavedJob(global::System.String title, global::System.String workingDirectory, global::System.String runCommand, global::System.String status, global::System.String jobName) { SavedJob savedJob = new SavedJob(); savedJob.Title = title; savedJob.WorkingDirectory = workingDirectory; savedJob.RunCommand = runCommand; savedJob.Status = status; savedJob.JobName = jobName; return(savedJob); }
/// <summary> /// Deprecated Method for adding a new object to the SavedJobs EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSavedJobs(SavedJob savedJob) { base.AddObject("SavedJobs", savedJob); }