private void GetPictureUri() { string origin = OriginalString; if (origin.EndsWith(".jpg") || origin.EndsWith(".png") || origin.EndsWith(".png") || origin.EndsWith(".gif") || origin.EndsWith(".bmp") || origin.EndsWith(".tiff") || origin.EndsWith(".ico")) { PictureUri = this; } else if (Host == "imgur.com") { if (OriginalString.IndexOf("imgur.com/a/") == -1) { Match match = new Regex("imgur.com/").Match(OriginalString); if (match.Success) { string ID = OriginalString.Substring(match.Index + match.Length); if (ID != "") { PictureUri = new Uri("http://i.imgur.com/" + ID + ".png"); } } } } else if (Host == "i.imgur.com") { string str = OriginalString; if (str.IndexOf("i.imgur.com/a/") == -1) { Match match = new Regex("i.imgur.com/").Match(str); if (match.Success) { string ID = OriginalString.Substring(match.Index + match.Length); if (ID != "") { PictureUri = new Uri("http://i.imgur.com/" + ID + ".png"); } } } } }
private void parseComponents(string url) { if (isRelativeRestUrl(url) || isAbsoluteRestUrl(url)) { var uri = new Uri(url, UriKind.RelativeOrAbsolute); string localPath = uri.IsAbsoluteUri ? uri.LocalPath : url; var components = localPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int count = components.Length; if (count < 2) { return; // unparseable } var history = -1; for (var index = 0; index < count; index++) { if (components[index] == TransactionBuilder.HISTORY) { history = index; } } if (history > -1 && history == count - 1) { return; // illegal use, there's just a _history component, but no version id } int resourceTypePos = (history > -1) ? history - 2 : count - 2; ResourceType = components[resourceTypePos]; Id = components[resourceTypePos + 1]; if (uri.IsAbsoluteUri) { var baseUri = url.Substring(0, url.IndexOf(ResourceType + "/" + Id)); if (!baseUri.EndsWith("/")) { baseUri += "/"; } BaseUri = new Uri(baseUri, UriKind.Absolute); } if (history != -1 && count >= 4 && history < count - 1) { VersionId = components[history + 1]; } Form = uri.IsAbsoluteUri ? ResourceIdentityForm.AbsoluteRestUrl : ResourceIdentityForm.RelativeRestUrl; } else if (isUrn(url)) { int lastSep = 8; if (url.StartsWith("urn:uuid:")) { lastSep = 8; } if (url.StartsWith("urn:oid:")) { lastSep = 7; } BaseUri = new Uri(url.Substring(0, lastSep + 1), UriKind.Absolute); Id = OriginalString.Substring(lastSep + 1); Form = ResourceIdentityForm.Urn; } else if (isLocal(url)) { Id = OriginalString.Substring(1); // strip '#' Form = ResourceIdentityForm.Local; } }
public override string ToString() { if (IsAbsoluteUri) { return(base.ToString()); } int index = OriginalString.IndexOfAny(_qf); if (index < 0) { return(((ParentPath == null) ? BaseName : ParentPath + "/" + BaseName) + Extension); } return(((ParentPath == null) ? BaseName : ParentPath + "/" + BaseName) + Extension + OriginalString.Substring(index)); }