#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using HeuristicLab.Common; namespace HeuristicLab.Services.Hive.Common.DataTransfer { [DataContract] [Serializable] public class LightweightJob : HiveItem { [DataMember] public TimeSpan? ExecutionTime { get; set; } [DataMember] public Guid? ParentJobId { get; set; } [DataMember] public List StateLog { get; set; } [DataMember] public JobState State { get; set; } public StateLog CurrentStateLog { get { return StateLog.Last(); } } public DateTime DateCreated { get { return StateLog.First().DateTime; } } public DateTime? DateFinished { get { return CurrentStateLog.State == JobState.Finished ? new DateTime?(CurrentStateLog.DateTime) : null; } } public LightweightJob() { StateLog = new List(); } public LightweightJob(Job job) { this.Id = job.Id; this.ExecutionTime = job.ExecutionTime; this.ParentJobId = job.ParentJobId; this.StateLog = new List(job.StateLog); this.State = job.State; } protected LightweightJob(LightweightJob original, Cloner cloner) : base(original, cloner) { this.ExecutionTime = original.ExecutionTime; this.ParentJobId = original.ParentJobId; this.StateLog = new List(original.StateLog); this.State = original.State; } public override IDeepCloneable Clone(Cloner cloner) { return new LightweightJob(this, cloner); } public void SetState(JobState state) { this.State = state; this.StateLog.Add(new StateLog() { State = state, DateTime = DateTime.Now }); } public void SetState(JobState state, Guid userId) { this.State = state; this.StateLog.Add(new StateLog() { State = state, DateTime = DateTime.Now, UserId = userId }); } public void SetState(JobState state, Guid slaveId, string exception) { this.State = state; this.StateLog.Add(new StateLog() { State = state, DateTime = DateTime.Now, SlaveId = slaveId, Exception = exception }); } } }