public Chisler Calculate(int threadId, int newPart, CalcRequestEnum сalcRequest, Func <int, int, int> calculator) { var container = ChislerContainer.GetInstance(); var currentChisler = container.GetCalcValue(threadId, сalcRequest); //Расчёт var currentValue = currentChisler.Value == 0 ? 1 : currentChisler.Value; var newValue = calculator(currentValue, newPart); //Обновление контейнера результатов return(container.UpdateCalcValue(threadId, newValue, сalcRequest)); }
public Chisler GetCalcValue(int threadId, CalcRequestEnum сalcRequest) { Chisler result; lock (SyncRoot) { result = GetСalcValues(сalcRequest).SingleOrDefault(ch => ch.ThreadId == threadId); if (result == null) { result = new Chisler { ThreadId = threadId, Value = 1 }; GetСalcValues(сalcRequest).Add(result); } } return(result); }
public Chisler Calculate(Chisler chisler, CalcRequestEnum сalcRequest, Func <int, int, int> calculator) { return(Calculate(chisler.ThreadId, chisler.Value, сalcRequest, calculator)); }
public IEnumerable <Chisler> GetCurrentValues(CalcRequestEnum сalcRequest) { var container = ChislerContainer.GetInstance(); return(container.GetCurentCalcValues(сalcRequest)); }
public IEnumerable <Chisler> GetCurentCalcValues(CalcRequestEnum сalcRequest) { return(GetСalcValues(сalcRequest)); }
private List <Chisler> GetСalcValues(CalcRequestEnum сalcRequest) { return(сalcRequest == CalcRequestEnum.Starter ? _starterValues : _continuerValues); }