public static PageUrlOptions ParsePublicUrl(string url, out NameValueCollection notUsedQueryParameters) { var urlString = new UrlString(url); notUsedQueryParameters = null; if (!IsPublicUrl(urlString.FilePath)) { return(null); } string requestPath; Uri uri; if (Uri.TryCreate(urlString.FilePath, UriKind.Absolute, out uri)) { requestPath = HttpUtility.UrlDecode(uri.AbsolutePath).ToLower(); } else { requestPath = urlString.FilePath.ToLower(); } string requestPathWithoutUrlMappingName; CultureInfo locale = PageUrl.GetCultureInfo(requestPath, out requestPathWithoutUrlMappingName); if (locale == null) { return(null); } string dataScopeName = urlString["dataScope"]; if (dataScopeName.IsNullOrEmpty()) { dataScopeName = DataScopeIdentifier.GetDefault().Name; } Guid pageId = Guid.Empty; using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), locale)) { if (PageStructureInfo.GetLowerCaseUrlToIdLookup().TryGetValue(requestPath.ToLower(), out pageId) == false) { return(null); } } urlString["dataScope"] = null; notUsedQueryParameters = urlString.GetQueryParameters(); return(new PageUrlOptions(dataScopeName, locale, pageId, UrlType.Public)); }
public static bool TryParseFriendlyUrl(string relativeUrl, out PageUrlOptions urlOptions) { if (IsAdminPath(relativeUrl)) { urlOptions = null; return(false); } string path; CultureInfo cultureInfo = PageUrl.GetCultureInfo(relativeUrl, out path); if (cultureInfo == null) { urlOptions = null; return(false); } string loweredRelativeUrl = relativeUrl.ToLower(CultureInfo.InvariantCulture); // Getting the site map IEnumerable <XElement> siteMap; DataScopeIdentifier dataScope = DataScopeIdentifier.GetDefault(); using (new DataScope(dataScope, cultureInfo)) { siteMap = PageStructureInfo.GetSiteMap(); } XAttribute matchingAttributeNode = siteMap.DescendantsAndSelf() .Attributes("FriendlyUrl") .FirstOrDefault(f => string.Equals(f.Value, loweredRelativeUrl, StringComparison.OrdinalIgnoreCase)); if (matchingAttributeNode == null) { urlOptions = null; return(false); } XElement pageNode = matchingAttributeNode.Parent; XAttribute pageIdAttr = pageNode.Attributes("Id").FirstOrDefault(); Verify.IsNotNull(pageIdAttr, "Failed to get 'Id' attribute from the site map"); Guid pageId = new Guid(pageIdAttr.Value); urlOptions = new PageUrlOptions(dataScope.Name, cultureInfo, pageId, UrlType.Friendly); return(true); }
public static UrlString BuildUrl(UrlType urlType, PageUrlOptions options) { Verify.ArgumentNotNull(options, "options"); Verify.ArgumentCondition(urlType != UrlType.Undefined, "urlType", "Url type is undefined"); if (urlType == UrlType.Public) { var lookupTable = PageStructureInfo.GetIdToUrlLookup(options.DataScopeIdentifierName, options.Locale); if (!lookupTable.ContainsKey(options.PageId)) { return(null); } var publicUrl = new UrlString(lookupTable[options.PageId]); if (options.DataScopeIdentifierName != DataScopeIdentifier.GetDefault().Name) { publicUrl["dataScope"] = options.DataScopeIdentifierName; } return(publicUrl); } if (urlType == UrlType.Internal) { string basePath = UrlUtils.ResolvePublicUrl("Renderers/Page.aspx"); var result = new UrlString(basePath); result["pageId"] = options.PageId.ToString(); result["cultureInfo"] = options.Locale.ToString(); result["dataScope"] = options.DataScopeIdentifierName; return(result); } throw new NotImplementedException("BuildUrl function supports only 'Public' and 'Unternal' urls."); }
private static void AddInterfaceAttributes(CodeAttributeDeclarationCollection attributes, DataTypeDescriptor dataTypeDescriptor) { attributes.Add( new CodeAttributeDeclaration( typeof(AutoUpdatebleAttribute).FullName, new CodeAttributeArgument[] { } )); attributes.Add( new CodeAttributeDeclaration( typeof(DataScopeAttribute).FullName, new [] { new CodeAttributeArgument( new CodePrimitiveExpression(DataScopeIdentifier.GetDefault().Name)) } )); attributes.Add( new CodeAttributeDeclaration( typeof(RelevantToUserTypeAttribute).FullName, new [] { new CodeAttributeArgument( new CodePrimitiveExpression(nameof(UserType.Developer))) } )); attributes.Add( new CodeAttributeDeclaration( typeof(CodeGeneratedAttribute).FullName, new CodeAttributeArgument[] { } )); attributes.Add( new CodeAttributeDeclaration( typeof(DataAncestorProviderAttribute).FullName, new [] { new CodeAttributeArgument( new CodeTypeOfExpression(typeof(NoAncestorDataAncestorProvider)) ) } )); attributes.Add( new CodeAttributeDeclaration( typeof(ImmutableTypeIdAttribute).FullName, new [] { new CodeAttributeArgument(new CodePrimitiveExpression(dataTypeDescriptor.DataTypeId.ToString())) } )); var xhtmlEmbedableEnumRef = new CodeFieldReferenceExpression( new CodeTypeReferenceExpression( typeof(XhtmlRenderingType) ), XhtmlRenderingType.Embedable.ToString()); attributes.Add( new CodeAttributeDeclaration( typeof(KeyTemplatedXhtmlRendererAttribute).FullName, new [] { new CodeAttributeArgument(xhtmlEmbedableEnumRef), new CodeAttributeArgument(new CodePrimitiveExpression("<span>{label}</span>")) } )); foreach (string keyFieldName in dataTypeDescriptor.KeyPropertyNames) { bool isDefinedOnSuperInterface = dataTypeDescriptor.SuperInterfaces.Any(f => f.GetProperty(keyFieldName) != null); if (!isDefinedOnSuperInterface) { attributes.Add( new CodeAttributeDeclaration( typeof(KeyPropertyNameAttribute).FullName, new [] { new CodeAttributeArgument(new CodePrimitiveExpression(keyFieldName)) } )); } } if (dataTypeDescriptor.StoreSortOrderFieldNames.Count > 0) { attributes.Add( new CodeAttributeDeclaration( typeof(StoreSortOrderAttribute).FullName, dataTypeDescriptor.StoreSortOrderFieldNames.Select(name => new CodeAttributeArgument(new CodePrimitiveExpression(name))).ToArray() )); } if (!string.IsNullOrEmpty(dataTypeDescriptor.Title)) { attributes.Add( new CodeAttributeDeclaration( typeof(TitleAttribute).FullName, new CodeAttributeArgument( new CodePrimitiveExpression(dataTypeDescriptor.Title) ) )); } if (!string.IsNullOrEmpty(dataTypeDescriptor.LabelFieldName)) { attributes.Add( new CodeAttributeDeclaration( typeof(LabelPropertyNameAttribute).FullName, new CodeAttributeArgument( new CodePrimitiveExpression(dataTypeDescriptor.LabelFieldName) ) )); } if (!string.IsNullOrEmpty(dataTypeDescriptor.InternalUrlPrefix)) { attributes.Add( new CodeAttributeDeclaration( typeof(InternalUrlAttribute).FullName, new CodeAttributeArgument( new CodePrimitiveExpression(dataTypeDescriptor.InternalUrlPrefix) ) )); } foreach (var dataTypeAssociationDescriptor in dataTypeDescriptor.DataAssociations) { attributes.Add( new CodeAttributeDeclaration( typeof(DataAssociationAttribute).FullName, new CodeAttributeArgument(new CodeTypeOfExpression(dataTypeAssociationDescriptor.AssociatedInterfaceType)), new CodeAttributeArgument(new CodePrimitiveExpression(dataTypeAssociationDescriptor.ForeignKeyPropertyName)), new CodeAttributeArgument(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(DataAssociationType)), dataTypeAssociationDescriptor.AssociationType.ToString())) )); } if (!dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPageMetaData))) { if (dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled))) { attributes.Add( new CodeAttributeDeclaration( typeof(PublishProcessControllerTypeAttribute).FullName, new CodeAttributeArgument(new CodeTypeOfExpression(typeof(GenericPublishProcessController))))); } } if (dataTypeDescriptor.Cachable) { // [CachingAttribute(CachingType.Full)] attributes.Add( new CodeAttributeDeclaration( typeof(CachingAttribute).FullName, new CodeAttributeArgument( new CodeFieldReferenceExpression( new CodeTypeReferenceExpression(typeof(CachingType)), nameof(CachingType.Full) ) ))); } if (dataTypeDescriptor.Searchable) { // [SearchableTypeAttribute] attributes.Add( new CodeAttributeDeclaration( typeof(SearchableTypeAttribute).FullName )); } }