/// <summary> /// Update status for the specified runId, taskname combination. /// </summary> /// <remarks>Overloaded convenience method.</remarks> /// <param name="statusExpression">"RUN001:Delta:Started"</param> public static void Update(string taskName, string status, string comment, DateTime started, DateTime ended) { // To uniquely identify a status. string filter = string.Format(" BatchId = {0} and BatchName = '{1}' and Task = '{2}' ", Service.BatchId, Service.BatchName, taskName); IList <StatusUpdate> items = GetByFilter(filter).Item; bool isCreating = false; if (items == null || items.Count == 0) { isCreating = true; } StatusUpdate entry = isCreating ? new StatusUpdate() : items[0]; entry.Task = taskName; entry.Status = status.ToLower().Trim(); entry.Comment = comment; if (isCreating) { entry.StartTime = started; entry.EndTime = ended; Create(entry); } else { entry.EndTime = ended; Update(entry); } }
/// <summary> /// Populate the username, computer and comment. /// </summary> /// <param name="entity"></param> /// <param name="action"></param> public override void Massage(object entity, EntityAction action) { StatusUpdate update = entity as StatusUpdate; update.Computer = Environment.MachineName; update.ExecutionUser = Environment.UserName; // Set times. if (update.StartTime == DateTime.MinValue) { update.StartTime = DateTime.Now; } if (update.EndTime == DateTime.MinValue) { update.EndTime = DateTime.Now; } if (update.BatchTime == DateTime.MinValue) { update.BatchTime = StatusUpdates.Service.BatchTime; } if (update.BusinessDate == DateTime.MinValue) { update.BusinessDate = StatusUpdates.Service.BusinessDate; } if (update.BatchId <= 0) { update.BatchId = StatusUpdates.Service.BatchId; } if (string.IsNullOrEmpty(update.BatchName)) { update.BatchName = StatusUpdates.Service.BatchName; } // Add comment. if (string.IsNullOrEmpty(update.Comment)) { // Batch , Task, Status at Time. string comment = string.Format("[{0}] : [{1}] : [{2}]", update.BatchName, update.Task, update.Status); update.Comment = comment; } }
/// <summary> /// Validation method for the entity. /// </summary> /// <param name="target">The target.</param> /// <param name="useTarget">if set to <c>true</c> [use target].</param> /// <param name="results">The results.</param> /// <returns></returns> protected override bool ValidateInternal(ValidationEvent validationEvent) { object target = validationEvent.Target; IValidationResults results = validationEvent.Results; int initialErrorCount = results.Count; StatusUpdate entity = (StatusUpdate)target; Validation.IsStringLengthMatch(entity.Computer, false, false, true, -1, 30, results, "Computer"); Validation.IsStringLengthMatch(entity.ExecutionUser, false, true, true, 1, 30, results, "ExecutionUser"); Validation.IsDateWithinRange(entity.BusinessDate, false, false, DateTime.MinValue, DateTime.MaxValue, results, "BusinessDate"); Validation.IsStringLengthMatch(entity.BatchName, false, true, true, 1, 30, results, "BatchName"); Validation.IsNumericWithinRange(entity.BatchId, false, false, -1, -1, results, "BatchId"); Validation.IsDateWithinRange(entity.BatchTime, false, false, DateTime.MinValue, DateTime.MaxValue, results, "BatchTime"); Validation.IsStringLengthMatch(entity.Task, false, true, true, 1, 50, results, "Task"); Validation.IsStringLengthMatch(entity.Status, false, true, true, 1, 30, results, "Status"); Validation.IsDateWithinRange(entity.StartTime, false, false, DateTime.MinValue, DateTime.MaxValue, results, "StartTime"); Validation.IsDateWithinRange(entity.EndTime, false, false, DateTime.MinValue, DateTime.MaxValue, results, "EndTime"); Validation.IsStringLengthMatch(entity.Ref, true, false, true, -1, 30, results, "Ref"); Validation.IsStringLengthMatch(entity.Comment, true, false, true, -1, 150, results, "Comment"); return(initialErrorCount == results.Count); }