Пример #1
0
        public async Task <ActionResult <BaseParameters> > Master([FromServices] ModuleManager moduleManager, [FromServices] ResetSiteCacheCommand resetSiteCacheCommand, [FromServices] IRouteManager routeManager, [FromServices] IOptions <ApplicationConfig> options, [FromQuery] string url, [FromQuery] string port = "")
        {
            var fullRequestUrl = HttpUtility.UrlDecode(url);
            var fullUrl        = fullRequestUrl.Split('?')[0];

            if (fullUrl.Contains(":"))
            {
                fullUrl = fullUrl.Replace($":{port}", "");
            }

            var parameters     = new BaseParameters();
            var simpleUrl      = fullUrl.Replace("https://", "").Replace("http://", "");
            var findRouteInput = new FindRouteInput();

            findRouteInput.Url      = simpleUrl;
            findRouteInput.FullUrl  = fullRequestUrl;
            findRouteInput.IsSecure = true;
            findRouteInput.Port     = Request.Host.Port.ToString();

            var findRouteResult = await routeManager.FindRouteAsync(findRouteInput);

            if (!findRouteResult.IsSuccess)
            {
                return(NotFound());
            }

            var currentRequest = new CurrentRequest();

            var siteId = findRouteResult.SiteId;

            currentRequest.SiteId      = siteId;
            currentRequest.DomainId    = findRouteResult.DomainId;
            currentRequest.DomainDatas = new Dictionary <string, string>();
            currentRequest.IsSecure    = true;
            currentRequest.Port        = findRouteInput.Port;
            if (findRouteResult.DomainDatas != null)
            {
                foreach (var domainData in findRouteResult.DomainDatas)
                {
                    currentRequest.DomainDatas.Add(domainData);
                }
            }

            dynamic master;

            try
            {
                master = await moduleManager.GetMasterAsync(currentRequest);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "This catch should be remove");
                master =
                    await
                    Business.InvokeAsync <ResetSiteCacheCommand, ResetSiteCacheInput, CommandResult <dynamic> >(
                        resetSiteCacheCommand,
                        new ResetSiteCacheInput { Site = currentRequest });
            }

            var value     = options.Value;
            var baseUrlJs = value.MainDomainUrl;

            parameters.Master = JsonConvert.SerializeObject(master, new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });
            parameters.Version       = value.Version;
            parameters.MainDomainUrl = @UrlHelper.Concat(baseUrlJs);
            parameters.IsDebug       = value.IsDebug;
            parameters.BaseUrlJs     = baseUrlJs;
            parameters.Header        = HomeController.GetHeader(findRouteResult, master, Request, fullRequestUrl);
            parameters.BaseUrlSite   = parameters.Header.BaseUrlSite;
            return(parameters);
        }
Пример #2
0
        public async Task <ActionResult <BaseParameters> > Master([FromServices] ModuleManager moduleManager, [FromServices] ResetSiteCacheCommand resetSiteCacheCommand, [FromServices] IRouteManager routeManager, [FromServices] IOptions <ApplicationConfig> options, [FromQuery] string url, [FromQuery] string port = "")
        {
            /*var requestedDomain = $"{Request.Scheme}://{Request.Host.Host}";
             *          string applicationPath = Request.PathBase;
             *          string requestedPath = path;
             *          var fullRequestUrl = @UrlHelper.Concat(requestedDomain, Request.PathBase, requestedPath);
             *
             *          var fullUrl = UrlHelper.Concat(requestedDomain, applicationPath, requestedPath);*/

            var fullRequestUrl = url;
            var fullUrl        = fullRequestUrl.Split('?')[0];

            if (fullUrl.Contains(":"))
            {
                fullUrl = fullUrl.Replace($":{port}", "");
            }



            var parameters     = new BaseParameters();
            var simpleUrl      = fullUrl.Replace("https://", "").Replace("http://", "");
            var findRouteInput = new FindRouteInput();

            findRouteInput.Url      = simpleUrl;
            findRouteInput.FullUrl  = fullRequestUrl;
            findRouteInput.IsSecure = true;
            findRouteInput.Port     = Request.Host.Port.ToString();

            var findRouteResult = await routeManager.FindRouteAsync(findRouteInput);

            if (!findRouteResult.IsSuccess)
            {
                return(NotFound());
            }

            var currentRequest = new CurrentRequest();

            var siteId = findRouteResult.SiteId;

            currentRequest.SiteId      = siteId;
            currentRequest.DomainId    = findRouteResult.DomainId;
            currentRequest.DomainDatas = new Dictionary <string, string>();
            currentRequest.IsSecure    = true;
            currentRequest.Port        = findRouteInput.Port;
            if (findRouteResult.DomainDatas != null)
            {
                foreach (var domainData in findRouteResult.DomainDatas)
                {
                    currentRequest.DomainDatas.Add(domainData);
                }
            }


            dynamic master;

            try
            {
                master = await moduleManager.GetMasterAsync(currentRequest);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "This catch should be remove");
                master =
                    await
                    Business.InvokeAsync <ResetSiteCacheCommand, ResetSiteCacheInput, CommandResult <dynamic> >(
                        resetSiteCacheCommand,
                        new ResetSiteCacheInput { Site = currentRequest });
            }


            var value = options.Value;

            parameters.Master        = master;
            parameters.Version       = value.Version;
            parameters.MainDomainUrl = @UrlHelper.Concat(value.MainDomainUrl);
            parameters.IsDebug       = value.IsDebug;
            //var baseUrl = UriHelper.BuildAbsolute(Request.Scheme, Request.Host).TrimEnd('/');
            // parameters.BaseUrl = baseUrl;

            var baseUrlJs = "";

            baseUrlJs = value.MainDomainUrl;

            parameters.BaseUrlJs = baseUrlJs;


            // var masterJson = JsonConvert.SerializeObject(master);

            parameters.Header = HomeController.GetHeader(findRouteResult, master, Request, fullRequestUrl);

            parameters.BaseUrlSite = parameters.Header.BaseUrlSite;

            return(parameters);
        }