当前位置: 首页>>代码示例>>C#>>正文


C# Url.MakeRelative方法代码示例

本文整理汇总了C#中Url.MakeRelative方法的典型用法代码示例。如果您正苦于以下问题:C# Url.MakeRelative方法的具体用法?C# Url.MakeRelative怎么用?C# Url.MakeRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Url的用法示例。


在下文中一共展示了Url.MakeRelative方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenameAllChildren

        /// <summary>
        /// Renames all child nodes for a given ProjectNode.
        /// This function is called by SaveProjectToLocation() to rename all documents
        /// in the project recursively.
        /// </summary>
        /// <param name="node">ProjectNode</param>
        private void RenameAllChildren(HierarchyNode node)
        {
            if (node is FileNode)
            {
                FileNode n = node as FileNode;
                if (n.IsLink)
                {
                    Url baseUrl = new Url(this.ProjectFolder + Path.DirectorySeparatorChar);
                    string linkPath = baseUrl.MakeRelative(new Url(n.Url));
                    n.ItemNode.Rename(linkPath);
                }
                else
                {
                    string subfolder = this.GetBaseDirectoryForAddingFiles(n);
                    string source = n.Url;
                    string target = Path.Combine(subfolder, n.Caption);

                    // note that source and target is never same since IDE uses source location
                    // in volatile path and IDE will prevent saving the project into the volatile location.
                    // volatile path ex: c:\Documents and Settings\<user>\Local Settings\Application Data\Temporary Projects.
                    Debug.Assert(!NativeMethods.IsSamePath(source, target));

                    n.RenameDocument(source, target);

                    // now make the target relative
                    Url url = new Url(target);
                    Url baseUrl = new Url(this.ProjectFolder + Path.DirectorySeparatorChar);
                    string relPath = baseUrl.MakeRelative(url);
                    n.ItemNode.Rename(relPath);
                }
            }
            else if (node is FolderNode || node is ProjectNode || node is ReferenceContainerNode)
            {
                if (node is FolderNode)
                {
                    string subfolder = this.GetBaseDirectoryForAddingFiles(node);
                    Directory.CreateDirectory(subfolder);
                }

                for (HierarchyNode n = node.FirstChild; n != null; n = n.NextSibling)
                {
                    this.RenameAllChildren(n);
                }
            }
            else if (node is ReferenceNode)
            {
                // fix 'HintPath' to point to location relative to new project location
                string relPath = node.ItemNode.GetMetadata(ProjectFileConstants.HintPath);
                if (String.IsNullOrEmpty(relPath))
                {
                    relPath = node.ItemNode.GetMetadata(ProjectFileConstants.Include);
                }

                if (String.IsNullOrEmpty(relPath))
                {
                    return;
                }

                // do not process if variables are used
                int startIndex, endIndex;
                if ((startIndex = relPath.IndexOf("$(", StringComparison.Ordinal)) >= 0 && (endIndex = relPath.IndexOf(Convert.ToString(')', CultureInfo.InvariantCulture), startIndex + 2, StringComparison.Ordinal)) >= 0)
                {
                    return;
                }

                // get correct url to the reference
                // this.ProjectMgr.BaseURI points to the old project location
                Url url = new Url(this.ProjectMgr.BaseURI, relPath);

                // now make path relative to the new project location
                Url baseUrl = new Url(this.ProjectFolder + Path.DirectorySeparatorChar);
                relPath = baseUrl.MakeRelative(url);
                node.ItemNode.SetMetadata(ProjectFileConstants.HintPath, relPath);
            }
        }
开发者ID:bullshock29,项目名称:Wix3.6Toolset,代码行数:81,代码来源:projectnode.cs

示例2: AddItemWithSpecific


//.........这里部分代码省略.........
                        }
                    }

                    // Copy the file to the correct location.
                    // We will suppress the file change events to be triggered to this item, since we are going to copy over the existing file and thus we will trigger a file change event. 
                    // We do not want the filechange event to ocur in this case, similar that we do not want a file change event to occur when saving a file.
                    IVsFileChangeEx fileChange = this.site.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx;
                    if (fileChange == null)
                    {
                        throw new InvalidOperationException();
                    }

                    try
                    {
                        fileChange.IgnoreFile(VSConstants.VSCOOKIE_NIL, newFileName, 1);
                        if (op == VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE)
                        {
                            this.AddFileFromTemplate(file, newFileName);
                        }
                        else
                        {
                            PackageUtilities.CopyUrlToLocal(new Uri(file), newFileName);
                        }
                    }
                    finally
                    {
                        fileChange.IgnoreFile(VSConstants.VSCOOKIE_NIL, newFileName, 0);
                    }
                }

                if (op == VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE)
                {
                    Url baseUrl = new Url(this.ProjectFolder + Path.DirectorySeparatorChar);
                    string relativePath = baseUrl.MakeRelative(new Url(file));
                    string linkPath = baseUrl.MakeRelative(new Url(newFileName));

                    HierarchyNode existingLink = this.FindChild(file);
                    if (!this.AllowDuplicateLinks && existingLink != null)
                    {
                        string message = String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.LinkAlreadyExistsInProject, CultureInfo.CurrentUICulture), newFileName);
                        string title = string.Empty;
                        OLEMSGICON icon = OLEMSGICON.OLEMSGICON_CRITICAL;
                        OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                        VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);
                        result[0] = VSADDRESULT.ADDRESULT_Cancel;
                        return (int)OleConstants.OLECMDERR_E_CANCELED;
                    }

                    if (overwrite)
                    {
                        child.Remove(false);
                    }

                    this.AddNewFileNodeToHierarchy(n, relativePath, linkPath);
                }
                else
                {
                    HierarchyNode existingLink = this.FindChild(newFileName);
                    bool bExistingIsExcluded = false;
                    HierarchyNode newFileNode = existingLink;
                    if (existingLink != null)
                    {
                        object isNonMemberItem = existingLink.GetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem);
                        bExistingIsExcluded = (isNonMemberItem != null) && ((bool)isNonMemberItem);
                        existingLink.Remove(false);
开发者ID:bullshock29,项目名称:Wix3.6Toolset,代码行数:67,代码来源:projectnode.cs


注:本文中的Url.MakeRelative方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。