示例#1
0
        /// <summary>
        /// Creates a URI for the given project/solution item.
        /// </summary>
        /// <remarks>
        /// For Project Items: solution://PROJECTGUID/ITEMGUID or solution://PROJECTIDGUID/ProjectItemPath
        /// For Solution Items: solution://root/SolutionItemPath
        /// </remarks>
        private Uri CreateSolutionOrProjectItemUri(IItem solutionOrProjectItem)
        {
            Guard.NotNull(() => solutionOrProjectItem, solutionOrProjectItem);

            //Check if projectitem or solutionitem
            var project = solutionOrProjectItem.GetContainingProject();

            if (project != null)
            {
                // Check if projectitem has <ItemGuid>.
                var itemGuid = (string)solutionOrProjectItem.Data.ItemGuid;
                if (string.IsNullOrEmpty(itemGuid))
                {
                    // Try creating unique id
                    solutionOrProjectItem.AddItemIdentifier();
                }

                // Check if projectitem has <ItemGuid>.
                itemGuid = (string)solutionOrProjectItem.Data.ItemGuid;
                if (!string.IsNullOrEmpty(itemGuid))
                {
                    // Use GUID Format
                    UriBuilder builder = new UriBuilder();
                    builder.Scheme = this.UriScheme;
                    builder.Host   = project.Id;
                    builder.Path   = TrimUriPath(itemGuid);
                    return(builder.Uri);
                }
                else
                {
                    // Use full project path Format
                    UriBuilder builder = new UriBuilder();
                    builder.Scheme = this.UriScheme;
                    builder.Host   = project.Id;
                    builder.Path   = MakeUriPath(solutionOrProjectItem.GetLogicalPath(project));
                    return(builder.Uri);
                }
            }
            else
            {
                // Use full solution path format
                var builder = new StringBuilder()
                              .Append(this.UriScheme)
                              .Append(Uri.SchemeDelimiter)
                              .Append(RootPrefix)
                              .Append(MakeUriPath(solutionOrProjectItem.GetLogicalPath()));

                return(new Uri(builder.ToString()));
            }
        }