本文整理汇总了C#中System.Uri.MakeRelativeUri方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.MakeRelativeUri方法的具体用法?C# Uri.MakeRelativeUri怎么用?C# Uri.MakeRelativeUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.MakeRelativeUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateRelativePath
public static string GenerateRelativePath(string from, string to)
{
if(String.IsNullOrWhiteSpace(from) || String.IsNullOrWhiteSpace(to))
{
throw new ArgumentNullException("Requires paths");
}
Uri fromUri = new Uri(from);
Uri toUri = new Uri(to);
//The URI schemes have to match in order for the path to be made relative
if(fromUri.Scheme != toUri.Scheme)
{
return to;
}
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
string relative = Uri.UnescapeDataString(relativeUri.ToString());
//If neccessary to do so, normalise the use of slashes to always be the default for this platform
if(toUri.Scheme.ToUpperInvariant() == "FILE")
{
relative = relative.Replace(Path.AltDirectorySeparatorChar,
Path.DirectorySeparatorChar);
}
return relative;
}
示例2: Format
public XDocument Format(IDirectoryTreeNode featureNode, GeneralTree<IDirectoryTreeNode> features, DirectoryInfo rootFolder)
{
var xmlns = HtmlNamespace.Xhtml;
var featureNodeOutputPath = Path.Combine(this.configuration.OutputFolder.FullName, featureNode.RelativePathFromRoot);
var featureNodeOutputUri = new Uri(featureNodeOutputPath);
var container = new XElement(xmlns + "div", new XAttribute("id", "container"));
container.Add(this.htmlHeaderFormatter.Format());
container.Add(this.htmlTableOfContentsFormatter.Format(featureNode.OriginalLocationUrl, features, rootFolder));
container.Add(this.htmlContentFormatter.Format(featureNode, features));
container.Add(this.htmlFooterFormatter.Format());
var body = new XElement(xmlns + "body");
body.Add(container);
var head = new XElement(xmlns + "head");
head.Add(new XElement(xmlns + "title", string.Format("{0}", featureNode.Name)));
head.Add(new XElement(xmlns + "link",
new XAttribute("rel", "stylesheet"),
new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.MasterStylesheet)),
new XAttribute("type", "text/css")));
head.Add(new XElement(xmlns + "link",
new XAttribute("rel", "stylesheet"),
new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.PrintStylesheet)),
new XAttribute("type", "text/css"),
new XAttribute("media", "print")));
head.Add(new XElement(xmlns + "script",
new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.jQueryScript)),
new XAttribute("type", "text/javascript"),
new XText(string.Empty)));
head.Add(new XElement(xmlns + "script",
new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.jQueryDataTablesScript)),
new XAttribute("type", "text/javascript"),
new XText(string.Empty)));
head.Add(new XElement(xmlns + "script",
new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.AdditionalScripts)),
new XAttribute("type", "text/javascript"),
new XText(string.Empty)));
head.Add(new XElement(xmlns + "script",
new XAttribute("type", "text/javascript"),
documentReady));
var html = new XElement(xmlns + "html",
new XAttribute(XNamespace.Xml + "lang", "en"),
head,
body);
var document = new XDocument(
new XDeclaration("1.0", "UTF-8", null),
new XDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty),
html);
return document;
}
示例3: Visit
public override void Visit(Document document)
{
var directoryAttribute = document.Attributes.FirstOrDefault(a => a.Name == "docdir");
if (directoryAttribute != null)
{
document.Attributes.Remove(directoryAttribute);
}
// check if this document has generated includes to other files
var includeAttribute = document.Attributes.FirstOrDefault(a => a.Name == "includes-from-dirs");
if (includeAttribute != null)
{
var thisFileUri = new Uri(_destination.FullName);
var directories = includeAttribute.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var directory in directories)
{
foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.OutputDirPath, directory), "*.asciidoc", SearchOption.AllDirectories))
{
var fileInfo = new FileInfo(file);
var referencedFileUri = new Uri(fileInfo.FullName);
var relativePath = thisFileUri.MakeRelativeUri(referencedFileUri);
var include = new Include(relativePath.OriginalString);
document.Add(include);
}
}
}
base.Visit(document);
}
示例4: MakeRelative
private string MakeRelative(string filePath, string referencePath)
{
var fileUri = new Uri(filePath);
var referenceUri = new Uri(referencePath);
return referenceUri.MakeRelativeUri(fileUri).ToString();
}
示例5: ResolveUri
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual Uri ResolveUri(Uri baseUri, string relativeUri)
{
if (baseUri == null || (!baseUri.IsAbsoluteUri && baseUri.OriginalString.Length == 0))
{
return new Uri(relativeUri, UriKind.RelativeOrAbsolute);
}
else
{
if (relativeUri == null || relativeUri.Length == 0)
{
return baseUri;
}
// relative base Uri
if (!baseUri.IsAbsoluteUri)
{
// create temporary base for the relative URIs
Uri tmpBaseUri = new Uri("tmp:///");
// create absolute base URI with the temporary base
Uri absBaseUri = new Uri(tmpBaseUri, baseUri.OriginalString);
// resolve the relative Uri into a new absolute URI
Uri resolvedAbsUri = new Uri(absBaseUri, relativeUri);
// make it relative by removing temporary base
Uri resolvedRelUri = tmpBaseUri.MakeRelativeUri(resolvedAbsUri);
return resolvedRelUri;
}
return new Uri(baseUri, relativeUri);
}
}
示例6: MakeRelative
public static string MakeRelative(string filePath, string referencePath)
{
var fileUri = new Uri(filePath);
var referenceUri = new Uri(referencePath);
return Uri.UnescapeDataString(referenceUri.MakeRelativeUri(fileUri).ToString());
}
示例7: MakeRelativePath
internal static DirectoryPath MakeRelativePath(this DirectoryPath directoryPath, ICakeEnvironment environment, DirectoryPath rootDirectoryPath)
{
if (directoryPath == null)
{
throw new ArgumentNullException(nameof(directoryPath));
}
if (environment == null)
{
throw new ArgumentNullException(nameof(environment));
}
if (rootDirectoryPath == null)
{
throw new ArgumentNullException(nameof(rootDirectoryPath));
}
var dirUri = new Uri(directoryPath.MakeAbsolute(environment).FullPath);
var rootUri = new Uri($"{rootDirectoryPath.MakeAbsolute(environment).FullPath}/");
var relativeUri = rootUri.MakeRelativeUri(dirUri);
var relativePath = Uri.UnescapeDataString(relativeUri.ToString());
var relativeDirectoryPath = new DirectoryPath(relativePath);
return relativeDirectoryPath;
}
示例8: GetPathRelativeTo
string GetPathRelativeTo(string BasePath, string ToPath)
{
Uri path1 = new Uri(BasePath);
Uri path2 = new Uri(ToPath);
Uri diff = path1.MakeRelativeUri(path2);
return diff.ToString();
}
示例9: MakeRelative
public static string MakeRelative(string basePath, string absolutePath)
{
Uri baseUri = new Uri(basePath);
Uri absoluteUri = new Uri(absolutePath);
var result = absoluteUri.MakeRelativeUri(baseUri);
return result.OriginalString;
}
示例10: ObterPastaRelativa
private string ObterPastaRelativa(string projectFileName, string basePath)
{
Uri uriProjectPath = new Uri(Path.GetFullPath(projectFileName));
Uri uriBasePath = new Uri(basePath);
Uri uriRelativa = uriProjectPath.MakeRelativeUri(uriBasePath);
return uriRelativa.ToString();
}
示例11: MakeRelativePath
public static string MakeRelativePath(string relativeDirectory,string filename)
{
try
{
if( filename.Length == 0 || IsUNC(filename) || IsRelative(filename) )
return filename;
Uri fileUri = new Uri(filename);
Uri referenceUri = new Uri(relativeDirectory + "/");
string relativePath = referenceUri.MakeRelativeUri(fileUri).ToString();
relativePath = Uri.UnescapeDataString(relativePath);
relativePath = relativePath.Replace('/','\\');
if( relativePath.IndexOf(':') < 0 && relativePath[0] != '.' ) // add a .\ (as CSPro does)
relativePath = ".\\" + relativePath;
return relativePath;
}
catch( Exception )
{
}
return filename;
}
示例12: FindFiles
public IEnumerable<string> FindFiles(string baseDir, IEnumerable<string> ignores)
{
List<string> filesToParse = new List<string>();
List<string> files = new List<string>();
files.AddRange(Directory.GetFiles(baseDir, "*.lua", SearchOption.AllDirectories));
files.AddRange(Directory.GetFiles(baseDir, "*.ns2doc", SearchOption.AllDirectories));
foreach (string path in files)
{
Uri fileNameUri = new Uri("file://" + path);
Uri baseDirUri = new Uri("file://" + baseDir);
string fileName = Uri.UnescapeDataString(baseDirUri.MakeRelativeUri(fileNameUri).ToString());
bool skip = false;
foreach (string ignore in ignores)
{
if (ignore.StartsWith("~"))
{
skip = !fileName.StartsWith(ignore.Substring(1));
}
else if (fileName.StartsWith(ignore))
{
skip = true;
break;
}
}
if (!skip)
{
filesToParse.Add(path);
}
}
return filesToParse;
}
示例13: GetRelativePath
public static string GetRelativePath(string currentDirectory, string filePath)
{
var uriFile = new Uri(filePath);
var uriCurrentDir = new Uri(currentDirectory + (!currentDirectory.EndsWith("\\") ? "\\" : ""));
return uriCurrentDir.MakeRelativeUri(uriFile).ToString();
}
示例14: FormSaveSettings
public FormSaveSettings(string saveLocation, FormWorld world)
{
InitializeComponent();
this.saveLocation = saveLocation;
this.world = world;
var saveUri = new Uri(saveLocation);
foreach (var tileset in world.Tilesets)
{
string relative = saveUri.MakeRelativeUri(new Uri(tileset.Filename)).ToString();
Node node = new Node(Path.GetFileName(tileset.Filename))
{
CheckBoxVisible = true,
Checked = tileset.ShouldBuild
};
Cell cell = new Cell()
{
Text = tileset.BuildLocation != null ? tileset.BuildLocation :
Path.Combine(Path.GetDirectoryName(relative), Path.GetFileNameWithoutExtension(relative)),
Editable = true
};
node.Cells[0].Editable = false;
node.Cells.Add(cell);
tilesetFilesList.Nodes.Add(node);
}
}
示例15: MakeRelative
private static string MakeRelative(string baseFile, string file)
{
Uri baseUri = new Uri(baseFile, UriKind.RelativeOrAbsolute);
Uri fileUri = new Uri(file, UriKind.RelativeOrAbsolute);
return baseUri.MakeRelativeUri(fileUri).ToString();
}