Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the calculation by identifier.
        /// </summary>
        /// <param name="calculationId">The calculation identifier.</param>
        private void Delete(int calculationId)
        {
            try
            {
                using (var transaction = database.GetTransaction())
                {
                    int minId      = sealingSlabDepot.GetMinId(calculationId) ?? 0;
                    int maxId      = sealingSlabDepot.GetMaxId(calculationId) ?? 0;
                    int difference = maxId - minId;

                    // This operation can take a lot of time so we set the time out to 4 minutes.
                    database.OneTimeCommandTimeout = deleteTimeout;

                    if (difference > deleteMaxDataSets)
                    {
                        // Only delete the max defined amount of datasets.
                        // The remaining datasets will be deleted in the next task.
                        sealingSlabDepot.DeleteByCalculationId(calculationId, minId, minId + deleteMaxDataSets);
                    }
                    else
                    {
                        sealingSlabDepot.DeleteByCalculationId(calculationId);
                        calculationDepot.Delete(calculationId);
                    }

                    transaction.Complete();
                }
            }
            catch (Exception ex)
            {
                App.Logger.Error(ex);

                var stateError  = stateDepot.GetByName(State.NameError);
                var calculation = calculationDepot.GetById(calculationId);
                calculation.StateId = stateError.Id;

                calculationDepot.Save(calculation);
            }
        }
 /// <summary>
 /// Gets the calculation by identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns></returns>
 public Calculation GetById(int id)
 {
     return(calculationDepot.GetById(id));
 }