Exemple #1
0
 protected void MakeSureRequestedCalculationIsValid(TargetingCalculationInfo calculationInfo)
 {
     if (calculationInfo.StatusCode > 0)
     {
         var issue = new ErrorIssue(
             "Your calculation (ID: " + calculationInfo.Id + ") has already been run on " + calculationInfo.StartedOn + ", it doesn't make sense to run the same calcualtion multiple times."
             );
         throw new ValidationException(issue);
     }
 }
Exemple #2
0
        protected void MakeSureRequestedCalculationIsStillValid(TargetingCalculationInfo calculationInfo, IEnumerable <TargetingCalculationInfo> latestCalculationInfos)
        {
            try
            {
                var latestCalculation = latestCalculationInfos.GetEnumerator();
                if (!latestCalculation.MoveNext())
                {
                    throw new ApplicationException();
                }
                var first = latestCalculation.Current;
                if (latestCalculation.MoveNext())
                {
                    var second = latestCalculation.Current;

                    if (first.Id == calculationInfo.Id)
                    {
                        // our calculation is on top which is good, however we need to check if the previous calculation was finished
                        if (second.StatusCode < 1)
                        {
                            throw new ApplicationException("There is a calculation (ID: " + second.Id + ") already in the queue. This calculation is either running or failed and somebody needs to clean it up. Try again if a few minutes. If you get the same issue, contact your administrator.");
                        }
                    }
                    else if (second.Id == calculationInfo.Id)
                    {
                        // our calculation is second in the list meaning it must be finished
                        if (second.StatusCode < 1)
                        {
                            throw new ApplicationException("Your calculation (ID: " + second.Id + ") has already been run on " + calculationInfo.StartedOn + ", it doesn't make sense to run the same calcualtion multiple times.");
                        }
                        else
                        {
                            throw new ApplicationException("Your calculation is just weird.");
                        }
                    }
                    else
                    {
                        throw new ApplicationException("Your calculation (ID: " + calculationInfo.Id + ") is neither the last one nor the one right before the last one. I am not sure how this can be possible. Anyway, it is a bad situation and there will be no calculations at this time. Sorry.");
                    }
                }
                else
                {
                    // there is only one calculation which is...
                    if (first.Id != calculationInfo.Id)
                    {
                        throw new ApplicationException("There is only one calculation in the queue and it is not yours. Weird...");
                    }
                }
            }
            catch (Exception exception)
            {
                throw new ValidationException(new ErrorIssue(exception.Message));
            }
        }
Exemple #3
0
        public CalculationInfo RequestCalculation(IDataManager manager)
        {
            var targetingCOmputationIdRange = manager.ReserveTargetingComputationIds(1);

            if (!targetingCOmputationIdRange.MoveNext())
            {
                throw new ApplicationException("Unable to reserve a targeting computation ID.");
            }
            var computationId = targetingCOmputationIdRange.Current;

            var targetingComputationInfo = new TargetingCalculationInfo(
                computationId,
                0,
                DateTime.Now, // <---- doesn't matter, isn't going to be used anyways
                null,
                null,
                null
                );

            manager.InsertTargetingComputation(targetingComputationInfo);
            return(new CalculationInfo {
                Id = computationId
            });
        }