예제 #1
0
 /// <summary>
 /// Returns whether change is allowed while run is scheduled or active. Currently only Delete All is not allowed.
 /// </summary>
 /// <param name="changeAction"></param>
 /// <param name="changeTargets"></param>
 /// <param name="targets"></param>
 /// <returns></returns>
 private bool IsChangeAllowedWhileRunScheduledOrActive <T>(ChangeActions changeAction, ChangeTargets changeTargets, IEnumerable <T> targets)
 {
     if (changeAction == ChangeActions.Delete && changeTargets == ChangeTargets.AllItems)
     {
         // All of the types where repository supports Delete All
         return(Array.IndexOf(new Type[] { typeof(Break), typeof(Campaign), typeof(Clash), typeof(Demographic), typeof(Product), typeof(Programme), typeof(Rating),
                                           typeof(RatingsPredictionSchedule), typeof(Schedule), typeof(Spot), typeof(Universe) }, typeof(T)) == -1);
     }
     return(true);     // Allowed for anything else
 }
예제 #2
0
        /// <summary>
        /// Validates before changing the data.
        /// </summary>
        /// <param name="changeAction"></param>
        /// <param name="changeTargets"></param>
        /// <param name="targets">Items that will be modified (Empty is target=AllItems)</param>
        /// <returns></returns>
        public IEnumerable <ChangeValidationResult> ValidateChange <T>(ChangeActions changeAction, ChangeTargets changeTargets, IEnumerable <T> targets)
        {
            List <ChangeValidationResult> results = new List <ChangeValidationResult>();

            if (!IsChangeAllowedWhileRunScheduledOrActive <T>(changeAction, changeTargets, targets))
            {
                // Change to this data is not allowed while run scheduled or active, check if any runs
                var runs = _runRepository.GetAll().Where(r => r.Scenarios.Where(s => s.IsScheduledOrRunning).Any()).ToList();
                foreach (var run in runs)
                {
                    results.Add(new ChangeValidationResult(ChangeValidationResult.ResultTypes.Error, run, string.Format("Cannot delete data because run {0} is scheduled or active", run.Description)));
                }
            }
            return(results);
        }