本文整理汇总了C#中System.Uri.Split方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.Split方法的具体用法?C# Uri.Split怎么用?C# Uri.Split使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.Split方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseQueryString
/// <summary>
/// Get a Url's parameters leaving them url encoded
/// </summary>
/// <param name="urlString">The query string</param>
/// <returns></returns>
public static Dictionary<string, string> ParseQueryString(string urlString)
{
string queryString = new Uri(urlString).Query;
Dictionary<string, string> kVParms = new Dictionary<string, string>();
queryString.Replace("?", "");
string[] keyValPairing = queryString.Split('&', '=');
if ((keyValPairing.Length == 0) || (keyValPairing.Length % 2 != 0))
{
throw new Exception("Invalid input Url");
}
keyValPairing[0] = keyValPairing[0].TrimStart('?');
for (int i = 0; i < keyValPairing.Length - 1; i++)
{
kVParms.Add(keyValPairing[i], keyValPairing[i + 1]);
}
return kVParms;
}
示例2: FindButton_Click
/// <summary>
/// Called when the user looks for their League of Legends installation
/// </summary>
private void FindButton_Click(object sender, RoutedEventArgs e)
{
//Disable patching if the user selects another league installation.
PatchButton.IsEnabled = false;
RemoveButton.IsEnabled = false;
//Create a file dialog for the user to locate their league of legends installation.
OpenFileDialog findLeagueDialog = new OpenFileDialog();
findLeagueDialog.DefaultExt = ".exe";
findLeagueDialog.Filter = "League of Legends Launcher|lol.launcher*.exe|Garena Launcher|lol.exe"; //Only show the league of legends executables
string RiotPath = Path.Combine(Path.GetPathRoot(Environment.SystemDirectory), "Riot Games", "League of Legends");
string GarenaPath = Path.Combine(Path.GetPathRoot(Environment.SystemDirectory), "Program Files (x86)", "GarenaLoL", "GameData", "Apps", "LoL");
//If they don't have League of Legends in the default path, look for Garena.
if (!Directory.Exists(RiotPath))
findLeagueDialog.InitialDirectory = Path.GetFullPath(GarenaPath);
else
findLeagueDialog.InitialDirectory = Path.GetFullPath(RiotPath);
bool? selectedExectuable = findLeagueDialog.ShowDialog();
if (selectedExectuable == false || selectedExectuable == null)
return;
//Remove the executable from the location
Uri Location = new Uri(findLeagueDialog.FileName);
string SelectedLocation = Location.LocalPath.Replace(Location.Segments.Last(), string.Empty);
//Get the executable name to check for Garena
string LastSegment = Location.Segments.Last();
//If the file name is lol.exe, then it's garena
if (!LastSegment.StartsWith("lol.launcher"))
{
type = ServerType.GARENA;
RemoveButton.IsEnabled = true;
PatchButton.IsEnabled = true;
LocationTextbox.Text = Path.Combine(SelectedLocation, "Air");
}
else
{
//Check each RADS installation to find the latest installation
string radsLocation = Path.Combine(SelectedLocation, "RADS", "projects", "lol_air_client", "releases");
//Compare the version text with format x.x.x.x to get the largest directory
var versionDirectories = Directory.GetDirectories(radsLocation);
string finalDirectory = "";
int BiggestVersion = 0;
//Get the biggest version in the directory
foreach (string x in versionDirectories)
{
string CurrentVersion = new Uri(x).Segments.Last();
string[] VersionNumbers = CurrentVersion.Split('.');
for (int i = 0; i < VersionNumbers.Length; i++)
{
//Ensure that numbers like 0.0.2.1 are larger than 0.0.1.999
VersionNumbers[i] = VersionNumbers[i].PadLeft(3, '0');
}
int Version = Convert.ToInt32(string.Join("", VersionNumbers));
if (Version > BiggestVersion)
{
BiggestVersion = Version;
finalDirectory = x;
}
}
BackupVersion = BiggestVersion.ToString();
//If the version isn't the intended version, show a message to the user. This is just a warning and probably can be ignored
if (!_supportedVersions.Contains(BiggestVersion) && !Debugger.IsAttached)
{
string Message = "This version of LESs may not support your version of League of Legends. Continue? This could harm your installation.";
MessageBoxResult versionMismatchResult = MessageBox.Show(Message, "Invalid Version", MessageBoxButton.YesNo);
if (versionMismatchResult == MessageBoxResult.No)
return;
}
type = ServerType.NORMAL;
PatchButton.IsEnabled = true;
RemoveButton.IsEnabled = true;
LocationTextbox.Text = Path.Combine(finalDirectory, "deploy");
}
//Create the LESsBackup directory to allow the user to uninstall if they wish to later on.
Directory.CreateDirectory(Path.Combine(LocationTextbox.Text, "LESsBackup"));
Directory.CreateDirectory(Path.Combine(LocationTextbox.Text, "LESsBackup", BackupVersion));
}
示例3: generate_rule
public static AmbiguousRule generate_rule(string url)
{
/*
to solve issue #13
there are a lot of second level domains, e.g. domain.info.au, domain.vic.au, ...
so we check these rules:
if url has only two parts (e.g. x.tld or www.x.tld) choose *.x.tld
else if url has 3 parts or more(e.g. y.x.tld) and y!=www:
check the following rules: (x = second part after tld)
1.(x is part of domain)
if len(x) > 4: assume that x is not part of extension, and choose *.x.tld
2.(x is part of extension)
if len(x) <=2 (e.g. y.id.au) than choose *.y.x.tld
if x is in exceptions (com,net,org,edu,gov,asn.sch) choose *.y.x.tld
because many TLD's have second level domains on these, e.g. chap.sch.ir
if count(parts)==4 and first part is www: e.g. www.news.com.au, choose *.y.x.tld
if none of the rules apply, the case is ambiguous, display both options in a context menu.
e.g. sealake.vic.au or something.fun.ir
*/
// needed variables
var domain = new Uri(url).Host;
var parts = domain.Split('.');
var count = parts.Length;
var tld = parts.Last();
var x = "";
var y = "";
try
{
x = parts[count - 2]; //second-level
y = parts[count - 3]; //third-level
}
catch (IndexOutOfRangeException) { } // in case domain did not have 3 parts.. (e.g. localhost, google.com)
// creating the patterns
var rule_tld = String.Format("*.{0}.{1}", x, tld);
var rule_second = String.Format("*.{0}.{1}.{2}", y, x, tld);
var mode = 0; // 0 = error, 1=use rule_tld (*.x.tld), 2=use rule_second (*.y.x.tld), 3=ambiguous
// this conditions are based on the long comment above
if (count == 2 || (count == 3 && y == "www"))
mode = 1;
else if (count >= 3)
{
if (x.Length > 4)
mode = 1;
else if (
(x.Length <= 2) ||
((new[] { "com", "net", "org", "edu", "gov", "asn", "sch" }).Contains(x)) ||
(count == 4 && parts[0] == "www")
)
mode = 2;
else
mode = 3;
}
return new AmbiguousRule()
{
tld_rule = rule_tld,
second_rule = rule_second,
mode = mode
};
}
示例4: AppsList_SetContent
private void AppsList_SetContent(IEnumerable<string> sections)
{
Image defIcon = Resources.PortableAppsBox;
var index = 0;
var icoDbPath = Path.Combine(HomeDir, "Assets\\icon.db");
byte[] icoDb = null;
byte[] swIcoDb = null;
try
{
icoDb = File.ReadAllBytes(icoDbPath);
if (!string.IsNullOrEmpty(_swSrv) && !string.IsNullOrEmpty(_swUsr) && !string.IsNullOrEmpty(_swPwd))
swIcoDb = NetEx.Transfer.DownloadData($"{_swSrv}/AppIcon.db", _swUsr, _swPwd);
}
catch (Exception ex)
{
Log.Write(ex);
}
foreach (var section in sections)
{
var nam = Ini.Read(section, "Name", AppsDbPath);
var des = Ini.Read(section, "Description", AppsDbPath);
var cat = Ini.Read(section, "Category", AppsDbPath);
var ver = Ini.Read(section, "Version", AppsDbPath);
var pat = Ini.Read(section, "ArchivePath", AppsDbPath);
var siz = Ini.ReadLong(section, "InstallSize", 1, AppsDbPath) * 1024 * 1024;
var adv = Ini.ReadBoolean(section, "Advanced", AppsDbPath);
var src = "si13n7.com";
if (pat.StartsWithEx("http"))
try
{
var tmpHost = new Uri(pat).Host;
var tmpSplit = tmpHost.Split('.');
src = tmpSplit.Length >= 3 ? string.Join(".", tmpSplit[tmpSplit.Length - 2], tmpSplit[tmpSplit.Length - 1]) : tmpHost;
}
catch (Exception ex)
{
Log.Write(ex);
continue;
}
// Description filter
switch (section)
{
case "LibreCADPortable":
des = des.LowerText("tool");
break;
case "Mp3spltPortable":
des = des.UpperText("mp3", "ogg");
break;
case "SumatraPDFPortable":
des = des.LowerText("comic", "book", "e-", "reader");
break;
case "WinCDEmuPortable":
des = des.UpperText("cd/dvd/bd");
break;
case "WinDjViewPortable":
des = des.UpperText("djvu");
break;
}
des = $"{des.Substring(0, 1).ToUpper()}{des.Substring(1)}";
var item = new ListViewItem(nam) { Name = section };
item.SubItems.Add(des);
item.SubItems.Add(ver);
item.SubItems.Add(siz.FormatDataSize(true, true, true));
item.SubItems.Add(src);
item.ImageIndex = index;
if (section.EndsWith("###") && (string.IsNullOrEmpty(_swSrv) || string.IsNullOrEmpty(_swUsr) || string.IsNullOrEmpty(_swPwd)))
continue;
if (!string.IsNullOrWhiteSpace(cat))
{
try
{
var nameHash = (section.EndsWith("###") ? section.Substring(0, section.Length - 3) : section).EncryptToMd5();
if (icoDb == null)
throw new ArgumentNullException(nameof(icoDb));
foreach (var db in new[] { icoDb, swIcoDb })
{
if (db == null)
continue;
using (var stream = new MemoryStream(db))
try
{
using (var archive = new ZipArchive(stream))
foreach (var entry in archive.Entries)
{
if (entry.Name != nameHash)
continue;
imgList.Images.Add(nameHash, Image.FromStream(entry.Open()));
break;
}
}
catch (Exception ex)
{
Log.Write(ex);
}
}
if (!imgList.Images.ContainsKey(nameHash))
throw new PathNotFoundException(icoDbPath + ":" + nameHash + ">>" + section);
}
//.........这里部分代码省略.........
示例5: ParseQueryString
static NameValueCollection ParseQueryString(string url)
{
url = url.Replace("?", "");
var parameters = new NameValueCollection();
foreach (var parameter in url.Split('&').Where(p => p.Contains('=')).Select(p => p.Split('=')))
{
parameters.Add(parameter[0], parameter[1]);
}
return parameters;
}