Beispiel #1
0
 public FibonacciNumberResponse FibonacciNumber(FibonacciNumberRequest request)
 {
     if (request == null)
     {
         throw new FaultException <ArgumentNullException>(new ArgumentNullException("request"), "null arguments are invalid");
     }
     try
     {
         var result = new FibonacciNumberResponse(FibonacciManager.Calculate(request.n));
         return(result);
     }
     catch (ArgumentOutOfRangeException exp)
     {
         throw new FaultException <ArgumentOutOfRangeException>(exp, exp.Message);
     }
     catch (Exception ex)
     {
         throw new FaultException(ex.Message);
     }
 }
Beispiel #2
0
        public async Task <FibonacciNumberResponse> FibonacciNumberAsync(FibonacciNumberRequest request)
        {
            if (request == null)
            {
                throw new FaultException <ArgumentNullException>(new ArgumentNullException("request"), "null arguments are invalid");
            }

            return(await Task.Run <FibonacciNumberResponse>(() =>
            {
                try
                {
                    var result = new FibonacciNumberResponse(FibonacciManager.Calculate(request.n));
                    return result;
                }
                catch (ArgumentOutOfRangeException exp)
                {
                    throw new FaultException <ArgumentOutOfRangeException>(exp, exp.Message);
                }
                catch (Exception ex)
                {
                    throw new FaultException(ex.Message);
                }
            }));
        }