コード例 #1
0
        private static AlertResult GetSingleAlert(AlertApiRequest request)
        {
            try
            {
                var symbol = request.StickerSymbol.ToUpper();
                var task   = Task.Run(() =>
                {
                    var mgr = new AlertMgr(symbol);
                    return(mgr);
                });
                task.Wait();
                var myMgr = task.Result;

                var task2 = Task.Run(() =>
                {
                    return(myMgr.GetAlertResult());
                });
                task2.Wait();
                var result = task2.Result;
                return(result);
            }
            catch (Exception ex)
            {
                return(new AlertResult
                {
                    Success = false,
                    Symbol = request.StickerSymbol,
                    ErrorMessage = ex.Message
                });
            }
        }
コード例 #2
0
        public AlertResultActionResult GetAlertResult([FromBody] AlertApiRequest request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new AlertResultActionResult(
                               new AlertApiResonse {
                        Exception = new Exception("InValid Input")
                    }));
                }

                AlertResult result   = GetSingleAlert(request);
                var         response = new AlertApiResonse
                {
                    AlertResult = result,
                    Exception   = result.Success ? null : new Exception(result.ErrorMessage)
                };
                return(new AlertResultActionResult(response));
            }
            catch (Exception ex)
            {
                return(new AlertResultActionResult(new AlertApiResonse
                {
                    Exception = ex,
                    AlertResult = new AlertResult
                    {
                        Success = false,
                        ErrorMessage = "Errors in execute your request, please retry later."
                    }
                }));
            }
        }