public async Task <FindPathResult> GetUrlAsync(ICurrentRequest currentRequest, string action, string controller, object additionalValues) { if (currentRequest == null) { throw new ArgumentException("currentRequest is null"); } var input = new FindPathInput(); input.DomainDatas = currentRequest.DomainDatas; input.DomainId = currentRequest.DomainId.ToString(CultureInfo.InvariantCulture); input.IsSecure = currentRequest.IsSecure; input.Port = currentRequest.Port; input.Datas = new Dictionary <string, string>(); input.Datas.Add("action", action); input.Datas.Add("controller", controller); var values = UrlHelper.GetValues(additionalValues); if (values != null) { foreach (var value in values) { input.Datas.Add(value.Key, value.Value); } } return(await _routeManager.FindDomainPathAsync(input)); }
public static async Task <GetSiteMapResult> SitemapUrlAsync(ItemDataModel itemDataModel, IDataFactory dataFactory, IRouteManager routeManager) { var isSecure = true; var siteBusinessModel = (SiteBusinessModel)itemDataModel.Data; var input = new FindPathInput(); input.DomainDatas = new Dictionary <string, string>(); input.DomainDatas.Add("site", UrlHelper.NormalizeTextForUrl(siteBusinessModel.Name)); input.MasterDomainId = siteBusinessModel.MasterDomainId; input.IsSecure = null; input.Datas = new Dictionary <string, string>(); input.Datas.Add("controller", "Seo"); input.Datas.Add("action", "Sitemap"); var result = await routeManager.FindDomainPathAsync(input); var getSiteMapResult = new GetSiteMapResult(); getSiteMapResult.BaseUrl = UrlHelper.Concat(result.BaseUrl, result.PreUrl); getSiteMapResult.Url = result.FullUrl; return(getSiteMapResult); }
/// <summary> /// Récupère la première route qui match avec les parmètres /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <FindRouteResult> FindRouteAsync(FindRouteInput input) { var result = new FindRouteResult(); result.IsSuccess = true; if (_routeProvider.Domains == null) { result.IsSuccess = false; result.HttpCode = "404"; return(result); } var url = input.Url; if (string.IsNullOrEmpty(url)) { result.IsSuccess = false; result.HttpCode = "404"; return(result); } var datas = new Dictionary <string, string>(); var domainDatas = new Dictionary <string, string>(); var cacheResult = await _cacheRepository.GetValueAsync <FindRouteResult>(input, CacheRepository.CacheUrlRoutageKey); if (cacheResult != null) { return(cacheResult); } #region 1: on récupère le domaine et la culture var loadDomainResult = await LoadDomainAsync(url, domainDatas, _routeProvider, _logger); // On récupère le nom de domaine var domain = loadDomainResult.Domain; var siteId = loadDomainResult.SiteId; // On éjecte les domaines non sécurisé if (domain == null) { result.IsSuccess = false; result.HttpCode = "404"; return(result); } if (domain.SecureMode == SecureMode.Secure && !input.IsSecure) { ComputeRedirection(input, result); return(result); } #endregion #region 3: Route // On récupère la route associé var routePath = GetRoutePath(url, domain, domainDatas); var route = await LoadRouteAsync(routePath, datas, _routeProvider, domainDatas, siteId, _logger); if (route == null) { result.IsSuccess = false; result.HttpCode = "404"; return(result); } // on ajoute les valeurs par défaut de la route if (route.DefaultValues != null) { foreach (var defaultValue in route.DefaultValues) { if (!datas.ContainsKey(defaultValue.Key)) { datas.Add(defaultValue.Key, defaultValue.Value); } } } #endregion if (!string.IsNullOrEmpty(route.Controller)) { SetValue(datas, "controller", route.Controller); } if (!string.IsNullOrEmpty(route.Action)) { SetValue(datas, "action", route.Action); } if (!string.IsNullOrEmpty(route.Namespace)) { SetValue(datas, "namespace", route.Namespace); } // Gestion de la redirection de domain à domain if (!string.IsNullOrEmpty(domain.RedirecToDomainId)) { if (!route.CancelRedirect) { var findPathInput = new FindPathInput(); findPathInput.DomainDatas = domainDatas; findPathInput.DomainId = domain.RedirecToDomainId; findPathInput.IsSecure = null; findPathInput.Port = input.Port; findPathInput.Datas = datas; var resultFindDomainPath = await FindDomainPathAsync(findPathInput); result.IsSuccess = false; result.HttpCode = "301"; if (input.FullUrl.StartsWith(_routeProvider.ProtocolDefault)) { result.RedirectionUrl = resultFindDomainPath.FullUrl; } } } if (!string.IsNullOrEmpty(route.RedirectPath)) { result.IsSuccess = false; result.HttpCode = "301"; if (input.FullUrl.StartsWith(_routeProvider.ProtocolDefault)) { result.RedirectionUrl = route.RedirectPath; //UrlHelper.Concat(domain.Path, route.RedirectPath); } } result.Datas = datas; result.DomainDatas = domainDatas; result.RouteId = route.Identity; result.SiteId = siteId; result.DomainId = domain.Id; result.Path = routePath; result.RewritePath = (new Rewriter()).Map(routePath, route, datas); result.Domain = domain.Path; await _cacheRepository.SaveAsync(new Data.Model.Cache.CacheItem() { Key = JsonConvert.SerializeObject(input), Type = CacheRepository.CacheUrlRoutageKey, SiteId = siteId, Value = JsonConvert.SerializeObject(result), CreateDate = DateTime.Now }); return(result); }
/// <summary> /// Retourne le chemin complet de la route et domaine qui match /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <FindPathResult> FindDomainPathAsync(FindPathInput input) { var findPathResult = new FindPathResult(); findPathResult.IsSuccess = false; if (_routeProvider.Domains == null) { return(findPathResult); } var datas = new Dictionary <string, string>(); var datasDomain = new Dictionary <string, string>(); foreach (var data in input.Datas) { var key = data.Key; datas.Add(key, data.Value); } //Pour les données de nom de domaine, on persite les valeurs s'il nont pas été redéfinie if (input.DomainDatas != null) { foreach (var domainData in input.DomainDatas) { var key = domainData.Key; if (!datasDomain.ContainsKey(key)) { datasDomain.Add(key, domainData.Value.ToString(CultureInfo.InvariantCulture)); } } } var domainMasterId = input.MasterDomainId; if (string.IsNullOrEmpty(domainMasterId)) { domainMasterId = (from d in _routeProvider.Domains where input.DomainId == d.Id select d.DomainMasterId).FirstOrDefault(); } if (string.IsNullOrEmpty(domainMasterId)) { return(findPathResult); } Route route; var routePath = GetRoutePath(_routeProvider, datas, input.DomainDatas, _logger, out route); Domain domain; var isSecure = false; if (!string.IsNullOrEmpty(input.DomainId)) { domain = (from d in _routeProvider.Domains where d.Id == input.DomainId select d).FirstOrDefault(); isSecure = domain.SecureMode == SecureMode.Secure; if (domain == null) { return(findPathResult); } } else { if (input.IsSecure.HasValue) { var secureMode = input.IsSecure.Value ? SecureMode.Secure : SecureMode.NoSecure; isSecure = input.IsSecure.Value; domain = (from d in _routeProvider.Domains where d.DomainMasterId == domainMasterId && d.SecureMode == secureMode && IsSameDomainType(datasDomain, d) select d).FirstOrDefault(); if (domain == null) { return(findPathResult); } } else { domain = (from d in _routeProvider.Domains where d.DomainMasterId == domainMasterId && IsSameDomainType(datasDomain, d) select d).FirstOrDefault(); if (domain == null) { return(findPathResult); } isSecure = domain.SecureMode == SecureMode.Secure; } } var domainPath = GetPath(domain.Path, datasDomain, null); var domainSplitted = domainPath.Split('/'); var domainLenght = domainSplitted.Length; if (domainLenght <= 0) { return(findPathResult); } var requestDomain = domainSplitted[0]; var preUrl = domainPath.ReplaceIgnoreCase(requestDomain, string.Empty); var applicationPath = string.Empty; if (datasDomain.ContainsKey("application_path")) { applicationPath = UrlHelper.RemoveSeparator(datasDomain["application_path"]); preUrl = UrlHelper.RemoveSeparator(preUrl.ReplaceFirstIgnoreCase(applicationPath, string.Empty)); } findPathResult.RoutePathWithoutHomePage = routePath; // Gestion de la page d'accueil var isHomePage = await IsHomePage(domain, datasDomain, datas); if (isHomePage) { routePath = string.Empty; } var path = GetPath(isSecure, requestDomain, applicationPath, preUrl, input.Port, routePath, _routeProvider.ProtocolSecure); findPathResult.PreUrl = preUrl; findPathResult.RequestDomain = requestDomain; findPathResult.Path = path; findPathResult.Route = route; findPathResult.IsSuccess = true; findPathResult.RoutePath = routePath; var protocole = isSecure ? _routeProvider.ProtocolSecure : _routeProvider.ProtocolDefault; findPathResult.FullUrl = string.Concat(protocole, "://", UrlHelper.Concat(requestDomain, path)); findPathResult.BaseUrl = string.Concat(protocole, "://", requestDomain); findPathResult.IsSecure = isSecure; return(findPathResult); }
/// <summary> /// Returns a path in reverse order (final target first) /// </summary> public static List <Vector2> FindPath(FindPathInput input) { var agentHalfSize = input.agentSize * 0.5f; var tree = new List <Node>(); var result = new List <Vector2>(); // TODO PERF: Don't need allocations per call if not running in parallel RaycastHit2D[] lHits = new RaycastHit2D[2]; RaycastHit2D[] rHits = new RaycastHit2D[2]; var first = new Node { position = input.from, parentIndex = -1 }; tree.Add(first); for (int i = 0; i < tree.Count && i < PATH_NODES_MAX; i++) { // TODO PERF: direction is recalculated in edge raycast var node = tree[i]; var direction = (input.target - node.position); direction.Normalize(); var raycast = EdgeRaycast(input.target, node.position, agentHalfSize, ref lHits, ref rHits, input.layerMask); if (raycast.Valid) { // hit something var center = raycast.Item.transform.position.ToVector2(); var leftDir = Rotate90Left(direction); // get obstacle size from input or circle collider var obstacleRadius = input.obstacleSize; var col = raycast.Item.collider as CircleCollider2D; if (col != null) { var wScale = col.transform.lossyScale; Assert.AreEqual(wScale.x, wScale.y, "Scale is not uniform"); obstacleRadius = col.radius * wScale.x; } var marginAbs = input.margin * obstacleRadius; var distanceFromCenter = obstacleRadius + marginAbs; var lOffsetVec = leftDir * distanceFromCenter; bool canReachSide; { // find potential positions // try sides of obstacle var newPosLeft = center + lOffsetVec; var newPosRight = center - lOffsetVec; canReachSide = FindCloserAndAdd(newPosLeft, newPosRight); } if (!canReachSide) { // try sides of current node var offsetVec = lOffsetVec * 0.5f; var newPosLeft = center - direction * distanceFromCenter + offsetVec; var newPosRight = center - direction * distanceFromCenter - offsetVec; FindCloserAndAdd(newPosLeft, newPosRight); } bool FindCloserAndAdd(Vector2 lhs, Vector2 rhs) { // pick closer first // TODO PERF: no need for two branches, done for readability // TODO PERF: redundant check, also in CheckAndAdd var leftDist = (lhs - node.position).sqrMagnitude; var rightDist = (rhs - node.position).sqrMagnitude; bool leftCloser = leftDist < rightDist; Vector2 closerPos = leftCloser ? lhs : rhs; Vector2 furtherPos = !leftCloser ? lhs : rhs; // Add New Nodes bool added = false; added |= CheckAndAdd(closerPos); added |= CheckAndAdd(furtherPos); return(added); } // If way between currnet node and the new position is clear, add the node to tree // return true if added bool CheckAndAdd(Vector2 newPos) { // TODO PERF: Don't need the hit info, just to see if hit anything, but for convenience sake var raycastIn = EdgeRaycast(newPos, node.position, agentHalfSize, ref lHits, ref rHits, input.layerMask); if (!raycastIn.Valid) { tree.Add(new Node { position = newPos, parentIndex = i }); return(true); } return(false); } } else // found valid path { // add last node to resulting path var final = input.target - (direction * input.targetDistance); result.Add(final); // traverse the tree in reverse order and add to result for (int j = i; j > 0; j = tree[j].parentIndex) { result.Add(tree[j].position); } return(result); } } // could not find a valid path return(result); }
protected override async Task ActionAsync() { if (string.IsNullOrEmpty(Input.Data.SiteName)) { throw new ArgumentException("SiteName is empty"); } if (string.IsNullOrEmpty(Input.Data.ModuleId)) { throw new ArgumentException("ModuleId is empty"); } if (string.IsNullOrEmpty(Input.Data.CategoryId)) { throw new ArgumentException("CategoryId is empty"); } var checkAddSiteInput = new CheckAddSiteInput { CategoryId = Input.Data.CategoryId, ModuleId = Input.Data.ModuleId, SiteId = Input.Data.SiteId, SiteName = Input.Data.SiteName }; if (await CheckAddSiteCommand.IsSiteAlreadyExistAsync(_dataFactorySource, _dataFactoryDestination, checkAddSiteInput)) { Result.ValidationResult.AddError("SITE_ADRESS_ALREADY_EXIST", "L'adresse demandé existe déjà"); } var addSiteItemBusinessModel = (AddSiteBusinessModel) (await _dataFactorySource.ItemRepository.GetItemAsync(Input.Data.Site.SiteId, Input.Data.ModuleId)).Data; var template = addSiteItemBusinessModel.Templates.First(t => t.CategoryId == Input.Data.CategoryId); var newSiteName = template.Title + " " + Input.Data.SiteName; var itemDataModelCurrentSite = await TransfertSiteCommand.GetSiteAsync(template.SiteId, _dataFactorySource); var currentSiteBusinessModel = (SiteBusinessModel)itemDataModelCurrentSite.Data; #region duplication du site var createFromSiteModel = new CreateFromSiteModel(); createFromSiteModel.CategoryId = template.CategoryId; createFromSiteModel.SiteName = newSiteName; createFromSiteModel.Title = Input.Data.SiteName; createFromSiteModel.UserId = Input.UserId; var moduleSite = _businessModuleFactory.GetModuleCreate(itemDataModelCurrentSite.Module); var siteItemDataModel = await moduleSite.CreateFromAsync(_dataFactorySource, _dataFactoryDestination, itemDataModelCurrentSite, null, false, createFromSiteModel); #endregion await _dataFactoryDestination.SaveChangeAsync(); await _cacheProvider.UpdateCacheAsync(siteItemDataModel.Id); #region Association Site/User await SaveSiteUserCommand.CreateNewSiteUserAsync(_siteUserService, _userService, siteItemDataModel.Id, Input.UserId); #endregion #region Generation Url nouveaux site var siteBusinessModel = (SiteBusinessModel)siteItemDataModel.Data; var input = new FindPathInput(); input.DomainDatas = new Dictionary <string, string>(); input.DomainDatas.Add("site", UrlHelper.NormalizeTextForUrl(newSiteName)); if (Input.Data.Port.HasValue) { input.Port = Input.Data.Port.ToString(); } //TODO règle temporaire pour le développement var isLocalhost = Input.Data.Site.DomainDatas.ContainsKey("domain") && Input.Data.Site.DomainDatas["domain"] == "localhost"; if (isLocalhost) { input.DomainDatas.Add("domain", Input.Data.Site.DomainDatas["domain"]); } input.MasterDomainId = siteBusinessModel.MasterDomainId; input.IsSecure = null; input.Datas = await _routeProvider.GetRootMetadataAsync(siteItemDataModel.Id); var result = await _routeManager.FindDomainPathAsync(input); #endregion // On reconstitue l'Url var protocole = Input.Data.IsSecure ? _routeProvider.ProtocolSecure : _routeProvider.ProtocolDefault; var port = string.Empty; if (Input.Data.Port.HasValue && Input.Data.Port.Value != 80 && Input.Data.Port.Value != 443) { port = string.Concat(":", Input.Data.Port.Value.ToString(CultureInfo.InvariantCulture)); } var siteUrl = string.Concat(protocole, "://", UrlHelper.Concat(string.Concat(result.RequestDomain, port), result.Path)); await SendEmailAsync(newSiteName, siteUrl, Input.UserId); Result.Data = UrlHelper.Concat(siteUrl, "/site/creation/confirmation?dm=false"); }