public static bool TryParse(string uri, out CmUri cmUri)
        {
            cmUri = null;
            if (string.IsNullOrEmpty(uri))
            {
                return(false);
            }
            string   ns = null;
            ItemType itemType;
            int      itemId        = -1;
            int      publicationId = -1;
            int      version       = -1;

            try
            {
                Match match = UriRegEx.Match(uri);
                if (!match.Success)
                {
                    return(false);
                }
                ns            = match.Groups["namespace"].Value;
                publicationId = int.Parse(match.Groups["pubId"].Value);
                itemId        = int.Parse(match.Groups["itemId"].Value);
                if (match.Groups["itemType"].Captures.Count > 0)
                {
                    itemType = (ItemType)int.Parse(match.Groups["itemType"].Value);
                }
                else
                {
                    itemType = Sdl.Tridion.Api.Client.ItemType.Component;
                }
                if (match.Groups["version"].Captures.Count > 0)
                {
                    version = int.Parse(match.Groups["version"].Value);
                }

                cmUri = new CmUri(NamespaceIdentiferToId(ns), publicationId, itemId, itemType, version);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        private static string ResolveLink(Tridion.ContentManager.TcmUri tcmUri, string pageContextId, bool resolveToBinary, Localization localization)
        {
            switch (tcmUri.ItemType)
            {
            case ItemType.Page:
                return(ResolvePageLink(tcmUri, localization));

            case ItemType.Component:
                // If requested (resolveToBinary = true), try to resolve Binary Link first.
                string binaryLink = null;
                if (resolveToBinary)
                {
                    binaryLink = ResolveBinaryLink(tcmUri, localization);
                }
                if (binaryLink != null)
                {
                    return(binaryLink);
                }

                int   pageId;
                CmUri cmUri;
                if (CmUri.TryParse(pageContextId, out cmUri))
                {
                    pageId = cmUri.ItemId;
                }
                else if (!int.TryParse(pageContextId, out pageId))
                {
                    pageId = -1;
                }

                return(ResolveComponentLink(tcmUri, localization, pageId));

            default:
                throw new DxaException("Unexpected item type in TCM URI: " + tcmUri);
            }
        }
Example #3
0
 public static bool IsCmUri(this string str) => CmUri.IsCmUri(str);
 public CmUri(CmUri uri)
     : this(uri.Namespace, uri.PublicationId, uri.ItemId, uri.ItemType, uri.Version)
 {
 }