Exemple #1
0
        public async Task <IActionResult> Index()
        {
            try
            {
                var path      = _sendingModel.Url.ToLower();
                var qSettings = _appSetting.Get <List <QSettingModel> >("QueueSettings");
                var mItems    = qSettings?.FindAll(s => s.Active && path.StartsWith(s.Prefix.ToLower()));
                var queue     = mItems?.OrderByDescending(s => s.Prefix.Length).FirstOrDefault();

                if (queue == null)
                {
                    return(StatusCode((int)GlobalStatusCode.NotFound, GlobalStatusCode.NotFound.GetEnumName() + ", 001"));
                }

                if (queue.MustAuthorize)
                {
                    if (!_sendingModel.IsAuthenticated)
                    {
                        return(StatusCode((int)GlobalStatusCode.AccessDenied,
                                          GlobalStatusCode.AccessDenied.GetEnumName()));
                    }

                    /*var user = await _cacheMemory.Get<BaseUserInfo>(_sendingModel.TokenInfo.TokenId, Provider.Globals);
                     * if (user == null)
                     * {
                     *  var uInfo = await _authenticateService.Get(_sendingModel.TokenInfo.TokenId);
                     *  user = uInfo?.UserInfo;
                     * }
                     *
                     * if (user == null)
                     * {
                     *  return StatusCode((int) GlobalStatusCode.AccessDenied,
                     *      GlobalStatusCode.AccessDenied.GetEnumName());
                     * }*/
                }

                var res = await _transmitter.Request(queue, _sendingModel);

                if (res == null)
                {
                    return(StatusCode((int)GlobalStatusCode.InternalServerError,
                                      GlobalStatusCode.InternalServerError.GetEnumName()));
                }

                if (!(res is QWebResponse response))
                {
                    return(StatusCode((int)GlobalStatusCode.InternalServerError,
                                      GlobalStatusCode.InternalServerError.GetEnumName()));
                }

                if (response.Headers == null)
                {
                    response.Headers = new Dictionary <string, string>();
                }

                if (!response.Headers.ContainsKey("Content-Type"))
                {
                    response.Headers.Add("Content-Type", "application/json");
                }

                foreach (var header in response.Headers)
                {
                    Response.Headers.Add(header.Key, header.Value);
                }

                return(StatusCode(response.Status, JsonConvert.DeserializeObject(response.Response)));
            }
            catch (Exception e)
            {
                return(StatusCode((int)GlobalStatusCode.InternalServerError, e));
            }
        }