public static bool IsSupportedMatchingRule(Uri matchBy) { Fx.Assert(matchBy != null, "The matchBy must be non null."); return (matchBy.Equals(FindCriteria.ScopeMatchByPrefix) || matchBy.Equals(FindCriteria.ScopeMatchByUuid) || matchBy.Equals(FindCriteria.ScopeMatchByLdap) || matchBy.Equals(FindCriteria.ScopeMatchByExact) || matchBy.Equals(FindCriteria.ScopeMatchByNone)); }
internal static bool UriEquals(System.Uri u1, System.Uri u2, bool ignoreCase, bool includeHostInComparison, bool includePortInComparison) { if (u1.Equals(u2)) { return(true); } if (u1.Scheme != u2.Scheme) { return(false); } if (includePortInComparison && (u1.Port != u2.Port)) { return(false); } if (includeHostInComparison && (string.Compare(u1.Host, u2.Host, StringComparison.OrdinalIgnoreCase) != 0)) { return(false); } if (string.Compare(u1.AbsolutePath, u2.AbsolutePath, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0) { return(true); } string components = u1.GetComponents(UriComponents.Path, UriFormat.Unescaped); string strB = u2.GetComponents(UriComponents.Path, UriFormat.Unescaped); int length = ((components.Length > 0) && (components[components.Length - 1] == '/')) ? (components.Length - 1) : components.Length; int num2 = ((strB.Length > 0) && (strB[strB.Length - 1] == '/')) ? (strB.Length - 1) : strB.Length; if (num2 != length) { return(false); } return(string.Compare(components, 0, strB, 0, length, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0); }
/// <include file='doc\AssemblyCache.uex' path='docs/doc[@for="GlobalAssemblyCache.Contains"]/*' /> /// <param name="codeBaseUri">Uri pointing to the assembly</param> public static bool Contains(Uri codeBaseUri) { lock (GlobalAssemblyCache.Lock) { if (!GlobalAssemblyCache.FusionLoaded) { GlobalAssemblyCache.FusionLoaded = true; GlobalAssemblyCache.LoadLibrary(Path.Combine(Path.GetDirectoryName(typeof(object).Module.Assembly.Location), "fusion.dll")); } IAssemblyEnum assemblyEnum; int rc = GlobalAssemblyCache.CreateAssemblyEnum(out assemblyEnum, null, null, ASM_CACHE.GAC, 0); if (rc < 0 || assemblyEnum == null) return false; IApplicationContext applicationContext; IAssemblyName currentName; while (assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0) { AssemblyName assemblyName = new AssemblyName(currentName); if (assemblyName.CodeBase.StartsWith(codeBaseUri.Scheme)) { try { Uri foundUri = new Uri(assemblyName.CodeBase); if (codeBaseUri.Equals(foundUri)) return true; } catch (Exception) { } } } return false; } }
/// <param name="codeBaseUri">Uri pointing to the assembly</param> public static bool Contains(Uri codeBaseUri){ if (codeBaseUri == null) { Debug.Fail("codeBaseUri == null"); return false; } lock(GlobalAssemblyCache.Lock){ if (!GlobalAssemblyCache.FusionLoaded){ GlobalAssemblyCache.FusionLoaded = true; System.Reflection.Assembly systemAssembly = typeof(object).Assembly; //^ assume systemAssembly != null && systemAssembly.Location != null; string dir = Path.GetDirectoryName(systemAssembly.Location); //^ assume dir != null; GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll")); } IAssemblyEnum assemblyEnum; int rc = GlobalAssemblyCache.CreateAssemblyEnum(out assemblyEnum, null, null, ASM_CACHE.GAC, 0); if (rc < 0 || assemblyEnum == null) return false; IApplicationContext applicationContext; IAssemblyName currentName; while (assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0){ //^ assume currentName != null; AssemblyName assemblyName = new AssemblyName(currentName); string scheme = codeBaseUri.Scheme; if (scheme != null && assemblyName.CodeBase.StartsWith(scheme)){ try{ Uri foundUri = new Uri(assemblyName.CodeBase); if (codeBaseUri.Equals(foundUri)) return true; #if !FxCop }catch(Exception){ #else }finally{ #endif } } } return false; } }
/// <summary> /// Initializes a new instance of the <see cref="Saml2AuthorizationDecisionStatement"/> class from /// a resource and decision. /// </summary> /// <param name="resource">The <see cref="Uri"/> of the resource to be authorized.</param> /// <param name="decision">The <see cref="SamlAccessDecision"/> in use.</param> /// <param name="actions">Collection of <see cref="Saml2Action"/> specifications.</param> public Saml2AuthorizationDecisionStatement(Uri resource, SamlAccessDecision decision, IEnumerable<Saml2Action> actions) { if (null == resource) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("resource"); } // This check is making sure the resource is either a well-formed absolute uri or // an empty relative uri before passing through to the rest of the constructor. if (!(resource.IsAbsoluteUri || resource.Equals(EmptyResource))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("resource", SR.GetString(SR.ID4121)); } if (decision < SamlAccessDecision.Permit || decision > SamlAccessDecision.Indeterminate) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("decision")); } this.resource = resource; this.decision = decision; if (null != actions) { foreach (Saml2Action action in actions) { this.actions.Add(action); } } }
public object Deserialize(string value, JsonConverter converter) { //Integration.Implementation.LogAudit("TinCanActor Deserialize called", null); IDictionary objMap = converter.DeserializeJSONToMap(value); string typeField = null; if (objMap.Contains("type")) { typeField = (string)objMap["type"]; } //Avoid infinite loop here, if type is this base class Type targetType = typeof(ActivityDefinition_JsonTarget); if (typeField != null) { Uri activityType = new Uri((string)objMap["type"]); if (activityType.Equals("http://adlnet.gov/expapi/activities/cmi.interaction")) { targetType = typeof(InteractionDefinition); } } return converter.DeserializeJSON(value, targetType); }
internal static AtomLinkMetadata MergeLinkMetadata(AtomLinkMetadata metadata, string relation, Uri href, string title, string mediaType) { AtomLinkMetadata metadata2 = new AtomLinkMetadata(metadata); string strB = metadata2.Relation; if (strB != null) { if (string.CompareOrdinal(relation, strB) != 0) { throw new ODataException(Strings.ODataAtomWriterMetadataUtils_LinkRelationsMustMatch(relation, strB)); } } else { metadata2.Relation = relation; } if (href != null) { Uri uri = metadata2.Href; if (uri != null) { if (!href.Equals(uri)) { throw new ODataException(Strings.ODataAtomWriterMetadataUtils_LinkHrefsMustMatch(href, uri)); } } else { metadata2.Href = href; } } if (title != null) { string str2 = metadata2.Title; if (str2 != null) { if (string.CompareOrdinal(title, str2) != 0) { throw new ODataException(Strings.ODataAtomWriterMetadataUtils_LinkTitlesMustMatch(title, str2)); } } else { metadata2.Title = title; } } if (mediaType != null) { string str3 = metadata2.MediaType; if (str3 == null) { metadata2.MediaType = mediaType; return metadata2; } if (!HttpUtils.CompareMediaTypeNames(mediaType, str3)) { throw new ODataException(Strings.ODataAtomWriterMetadataUtils_LinkMediaTypesMustMatch(mediaType, str3)); } } return metadata2; }
public void ProcessRequest(HttpContext context, Uri serviceBaseUri) { var sparqlGenerator = new SparqlGenerator(_config.Map, _config.DefaultLanguageCode, _config.MaxPageSize); var messageWriterSettings = new ODataMessageWriterSettings(_config.BaseODataWriterSettings) { BaseUri = serviceBaseUri }; if (context.Request.AcceptTypes != null) { messageWriterSettings.SetContentType(String.Join(",", context.Request.AcceptTypes), context.Request.Headers["Accept-Charset"]); } var requestMessage = new HttpDataRequestMessage(context.Request); ODataVersion effectiveVersion = GetEffectiveODataVersion(requestMessage); messageWriterSettings.Version = effectiveVersion; var metadataUri = new Uri(serviceBaseUri, "./$metadata"); if (serviceBaseUri.Equals(context.Request.Url)) { // We need to respond with the service document var responseMessage = new HttpDataResponseMessage(context.Response); context.Response.ContentType = "application/xml"; context.Response.ContentEncoding = System.Text.Encoding.UTF8; var feedGenerator = new ODataFeedGenerator(requestMessage, responseMessage, _config.Map, serviceBaseUri.ToString(), messageWriterSettings); feedGenerator.WriteServiceDocument(); } else if (serviceBaseUri.ToString().TrimEnd('/').Equals(context.Request.Url.ToString().TrimEnd('/'))) { // Trimming of trailing slash to normalize - the serviceBaseUri should always have a trailing slash, // but we will redirect requests that do not to the proper service document url context.Response.RedirectPermanent(serviceBaseUri.ToString(), true); } else if (metadataUri.Equals(context.Request.Url)) { context.Response.ContentType = "application/xml"; context.Response.WriteFile(_config.MetadataPath); } else { var parsedQuery = QueryDescriptorQueryNode.ParseUri( context.Request.Url, serviceBaseUri, _config.Model); sparqlGenerator.ProcessQuery(parsedQuery); var responseMessage = new HttpDataResponseMessage(context.Response); var feedGenerator = new ODataFeedGenerator( requestMessage, responseMessage, _config.Map, serviceBaseUri.ToString(), messageWriterSettings); sparqlGenerator.SparqlQueryModel.Execute(_config.SparqlEndpoint, feedGenerator); context.Response.ContentType = "application/atom+xml"; } }
// Remove the 'CredentialInfo' object from the list that matches to the given 'Uri' and 'AuthenticationType' public void Remove(Uri uriObj, String authenticationType) { for (int index = 0; index < arrayListObj.Count; index++) { CredentialInfo credentialInfo = (CredentialInfo)arrayListObj[index]; if (uriObj.Equals(credentialInfo.uriObj) && authenticationType.Equals(credentialInfo.authenticationType)) arrayListObj.RemoveAt(index); } }
/// <summary> /// Applys the rule instance to the public or system identifier in an /// attempt to locate the URI of a resource with can provide the required /// information. /// </summary> /// <param name="publicId">The public identifier of the external entity /// being referenced, or null if none was supplied.</param> /// <param name="systemId">The system identifier of the external entity /// being referenced.</param> /// <param name="catalogs">The stack of catalogs being processed.</param> /// <returns>A new URI if the rule was successfully applied, otherwise /// <b>null</b>.</returns> public String ApplyTo(String publicId, String systemId, Stack<GroupEntry> catalogs) { Uri targetUri = new Uri (systemId); Uri systemUri = new Uri (BaseAsUri (), this.systemId); if (targetUri.Equals (systemUri)) return (new Uri (BaseAsUri (), new Uri (uri)).ToString ()); return (null); }
public NetworkCredential GetCredential(Uri uriObj, String authenticationType) { for (int index = 0; index < arrayListObj.Count; index++) { CredentialInfo credentialInfoObj = (CredentialInfo)arrayListObj[index]; if (uriObj.Equals(credentialInfoObj.uriObj) && authenticationType.Equals(credentialInfoObj.authenticationType)) return credentialInfoObj.networkCredentialObj; } return null; }
private static byte[] GetBytesFromWeb(Uri imageURL) { if (imageURL.Equals(Resources.MissingPictureUrl)) return ConvertImageToBytes(Resources.missingPicture); try { var webClient = new WebClient(); return webClient.DownloadData(imageURL); } catch { return ConvertImageToBytes(Resources.missingPicture); } }
public static void fEquals() { Uri uri1 = new Uri("http://www.yahoo.com/tw"); Uri uri2 = new Uri("http://www.yahoo.com"); if (uri1.Equals(uri2)) { MessageBox.Show("相同"); } else { MessageBox.Show("不相同"); } }
public void StorageUriWithTwoUris() { Uri primaryClientUri = new Uri("http://" + AccountName + BlobService + EndpointSuffix); Uri primaryContainerUri = new Uri(primaryClientUri, "container"); Uri secondaryClientUri = new Uri("http://" + AccountName + SecondarySuffix + BlobService + EndpointSuffix); Uri dummyClientUri = new Uri("http://" + AccountName + "-dummy" + BlobService + EndpointSuffix); StorageUri singleUri = new StorageUri(primaryClientUri); Assert.IsTrue(primaryClientUri.Equals(singleUri.PrimaryUri)); Assert.IsNull(singleUri.SecondaryUri); StorageUri singleUri2 = new StorageUri(primaryClientUri); Assert.IsTrue(singleUri.Equals(singleUri2)); StorageUri singleUri3 = new StorageUri(secondaryClientUri); Assert.IsFalse(singleUri.Equals(singleUri3)); StorageUri multiUri = new StorageUri(primaryClientUri, secondaryClientUri); Assert.IsTrue(primaryClientUri.Equals(multiUri.PrimaryUri)); Assert.IsTrue(secondaryClientUri.Equals(multiUri.SecondaryUri)); Assert.IsFalse(multiUri.Equals(singleUri)); StorageUri multiUri2 = new StorageUri(primaryClientUri, secondaryClientUri); Assert.IsTrue(multiUri.Equals(multiUri2)); TestHelper.ExpectedException<ArgumentException>( () => new StorageUri(primaryClientUri, primaryContainerUri), "StorageUri constructor should fail if both URIs do not point to the same resource"); StorageUri multiUri3 = new StorageUri(primaryClientUri, dummyClientUri); Assert.IsFalse(multiUri.Equals(multiUri3)); StorageUri multiUri4 = new StorageUri(dummyClientUri, secondaryClientUri); Assert.IsFalse(multiUri.Equals(multiUri4)); StorageUri multiUri5 = new StorageUri(secondaryClientUri, primaryClientUri); Assert.IsFalse(multiUri.Equals(multiUri5)); }
internal DynamicVirtualDiscoSearcher(string startDir, string[] excludedUrls, string rootUrl) : base(excludedUrls) { this.webApps = new Hashtable(); this.Adsi = new Hashtable(); base.origUrl = rootUrl; this.entryPathPrefix = this.GetWebServerForUrl(rootUrl) + "/ROOT"; this.startDir = startDir; string localPath = new Uri(rootUrl).LocalPath; if (localPath.Equals("/")) { localPath = ""; } this.rootPathAsdi = this.entryPathPrefix + localPath; }
/// <summary> /// Determines whether the GAC contains the specified code base URI. /// </summary> /// <param name="codeBaseUri">The code base URI.</param> public static bool Contains(Uri codeBaseUri) { Contract.Requires(codeBaseUri != null); lock (GlobalLock.LockingObject) { #if COMPACTFX var gacKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"\Software\Microsoft\.NETCompactFramework\Installer\Assemblies\Global"); if (gacKey == null) return false; var codeBase = codeBaseUri.AbsoluteUri; foreach (var gacName in gacKey.GetValueNames()) { var values = gacKey.GetValue(gacName) as string[]; if (values == null || values.Length == 0) continue; if (string.Equals(values[0], codeBase, StringComparison.OrdinalIgnoreCase)) return true; if (values.Length > 1 && string.Equals(values[1], codeBase, StringComparison.OrdinalIgnoreCase)) return true; } return false; #else #if __MonoCS__ IAssemblyEnum assemblyEnum = new MonoAssemblyEnum(); #else if (!GlobalAssemblyCache.FusionLoaded) { GlobalAssemblyCache.FusionLoaded = true; var systemAssembly = typeof(object).Assembly; var systemAssemblyLocation = systemAssembly.Location; string dir = Path.GetDirectoryName(systemAssemblyLocation)??""; GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll")); } IAssemblyEnum assemblyEnum; int rc = GlobalAssemblyCache.CreateAssemblyEnum(out assemblyEnum, null, null, ASM_CACHE.GAC, 0); if (rc < 0 || assemblyEnum == null) return false; #endif IApplicationContext applicationContext; IAssemblyName currentName; while (assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0) { //^ assume currentName != null; AssemblyName assemblyName = new AssemblyName(currentName); string/*?*/ scheme = codeBaseUri.Scheme; if (scheme != null && assemblyName.CodeBase.StartsWith(scheme, StringComparison.OrdinalIgnoreCase)) { try { Uri foundUri = new Uri(assemblyName.CodeBase); if (codeBaseUri.Equals(foundUri)) return true; } catch (System.ArgumentNullException) { } catch (System.UriFormatException) { } } } return false; #endif } }
static int Equals(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); System.Uri obj = (System.Uri)ToLua.CheckObject <System.Uri>(L, 1); object arg0 = ToLua.ToVarObject(L, 2); bool o = obj != null?obj.Equals(arg0) : arg0 == null; LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
internal void FetchRequest(System.Uri uri, WebRequest request) { this._Request = request; this._Policy = request.CachePolicy; this._Response = null; this._ResponseCount = 0; this._ValidationStatus = CacheValidationStatus.DoNotUseCache; this._CacheFreshnessStatus = System.Net.Cache.CacheFreshnessStatus.Undefined; this._CacheStream = null; this._CacheStreamOffset = 0L; this._CacheStreamLength = 0L; if (!uri.Equals(this._Uri)) { this._CacheKey = uri.GetParts(UriComponents.AbsoluteUri, UriFormat.Unescaped); } this._Uri = uri; }
private void OnSourceChanged(Uri oldValue, Uri newValue, Object parameter) { // if resetting source or old source equals new, don't do anything if (this.IsResetSource || newValue != null && newValue.Equals(oldValue)) { return; } // handle fragment navigation string newFragment = null; var oldValueNoFragment = NavigationManager.RemoveFragment(oldValue); var newValueNoFragment = NavigationManager.RemoveFragment(newValue, out newFragment); if (newValueNoFragment != null && newValueNoFragment.Equals(oldValueNoFragment)) { // fragment navigation FragmentNavigationEventArgs args = new FragmentNavigationEventArgs { Fragment = newFragment, Parameter = parameter, }; OnFragmentNavigation(this.Content as IContent, args); } else { var navType = this.IsNavigatingHistory ? NavigationType.Back : NavigationType.New; // only invoke CanNavigate for new navigation if (!this.IsNavigatingHistory && !CanNavigate(oldValue, newValue, navType)) { return; } Navigate(oldValue, newValue, navType, parameter); } }
public void Equals3 () { Uri uri1 = new Uri ("svn+ssh://[email protected]"); Uri uri2 = new Uri ("svn+ssh://[email protected]"); Assert.IsTrue (uri1.Equals (uri2)); }
public void Equals2 () { Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main"); Uri uri2 = new Uri ("http://www.contoso.com/index.htm?x=1"); Assert.IsTrue (!uri1.Equals (uri2), "#2 known to fail with ms.net 1.x"); }
// 检查数组中的哪个url和strOneBinding端口、地址冲突 // return: // -2 不冲突 // -1 出错 // >=0 发生冲突的url在数组中的下标 static int IsBindingDup(string strOneBinding, string[] bindings, out string strError) { strError = ""; if (String.IsNullOrEmpty(strOneBinding) == true) { strError = "strOneBinding参数值不能为空"; return -1; } Uri one_uri = new Uri(strOneBinding); for (int i = 0; i < bindings.Length; i++) { string strCurrentBinding = bindings[i]; if (String.IsNullOrEmpty(strCurrentBinding) == true) continue; Uri current_uri = new Uri(strCurrentBinding); if (one_uri.Scheme.ToLower() == "net.tcp") { if (current_uri.Scheme.ToLower() == "net.tcp") { // 端口不能冲突 if (one_uri.Port == current_uri.Port) { strError = "'"+strOneBinding+"' 和 '"+strCurrentBinding+"' 之间端口号冲突了"; return i; } } else if (current_uri.Scheme.ToLower() == "net.pipe") { // 不存在冲突的可能 } else if (current_uri.Scheme.ToLower() == "http") { // 端口号不能冲突 if (one_uri.Port == current_uri.Port) { strError = "'" + strOneBinding + "' 和 '" + strCurrentBinding + "' 之间端口号冲突了"; return i; } } } else if (one_uri.Scheme.ToLower() == "net.pipe") { if (current_uri.Scheme.ToLower() == "net.pipe") { // 不能全部相同 if (one_uri.Equals(current_uri) == true) { strError = "net.pipe类型的URL '" + strOneBinding + "' 有两项完全相同"; return i; } if (IsUrlEqual(one_uri.ToString(), current_uri.ToString()) == true) { strError = "net.pipe类型的URL '" + strOneBinding + "' 有两项实质上相同(末尾仅仅差异一个'/'字符)"; return i; } } } else if (one_uri.Scheme.ToLower() == "http") { if (current_uri.Scheme.ToLower() == "net.tcp") { // 端口不能冲突 if (one_uri.Port == current_uri.Port) { strError = "'" + strOneBinding + "' 和 '" + strCurrentBinding + "' 之间端口号冲突了"; return i; } } else if (current_uri.Scheme.ToLower() == "net.pipe") { // 不可能冲突 } else if (current_uri.Scheme.ToLower() == "http") { // 端口号可以相同,但是不能全部相同 if (one_uri.Equals(current_uri) == true) { strError = "http类型的URL '"+strOneBinding+"' 有两项完全相同"; return i; } if (IsUrlEqual(one_uri.ToString(), current_uri.ToString()) == true) { strError = "http类型的URL '" + strOneBinding + "' 有两项实质上相同(末尾仅仅差异一个'/'字符)"; return i; } } } } return -2; }
// 对两个URL字符串进行忽略最后一个'/'字符的比较 static bool IsUrlEqual(string url1, string url2) { if (url1.Length > 0 && url1[url1.Length - 1] != '/') url1 += "/"; if (url2.Length > 0 && url2[url2.Length - 1] != '/') url2 += "/"; if (url1 == url2) return true; // 更严格地比较 try { Uri uri1 = new Uri(url1); Uri uri2 = new Uri(url2); if (uri1.Equals(uri2) == true) return true; return false; } catch { return false; } }
bool UriEqual( Uri uri1, string uri1Str, string uri2Str, XmlResolver resolver ) { if (resolver == null) { return uri1Str == uri2Str; } if (uri1 == null){ uri1 = resolver.ResolveUri( null, uri1Str ); } Uri uri2 = resolver.ResolveUri( null, uri2Str ); return uri1.Equals(uri2); }
public static string UriWrtDocumentUri(string uri, string documentUri) { var result = uri; try { var uriParsed = new Uri(uri); var documentUriParsed = new Uri(documentUri); if (uriParsed.Equals(documentUriParsed)) { result = "'self'"; } else if (uriParsed.Scheme == documentUriParsed.Scheme) { result = uriParsed.Host; if (!(uriParsed.Port == 0 || uriParsed.IsDefaultPort)) { result += ":" + uriParsed.Port; } } } catch (Exception) { // Again we can get exceptions if the URI can't parse as a .NET URI. // Pass through if we can't do anything better. } return result; }
public void RelativeEqualsTest() { Uri uri1 = new Uri ("foo/bar", UriKind.Relative); Uri uri2 = new Uri ("foo/bar", UriKind.Relative); Uri uri3 = new Uri ("bar/man", UriKind.Relative); Uri uri4 = new Uri ("BAR/MAN", UriKind.Relative); Assert.IsTrue (uri1 == uri2, "#1a"); Assert.IsTrue (uri1.Equals(uri2), "#1b"); Assert.IsTrue (uri1 != uri3, "#2a"); Assert.IsTrue (!uri1.Equals(uri3), "#2b"); Assert.IsTrue (uri1 == uri2, "#3a"); Assert.IsTrue (uri1.Equals(uri2), "#3b"); Assert.IsTrue (uri1 != uri3, "#4a"); Assert.IsTrue (!uri1.Equals(uri3), "#4b"); Assert.IsTrue (uri3 != uri4, "#5a"); Assert.IsTrue (!uri3.Equals(uri4), "#5b"); }
public void Equals4 () { var uri = new Uri ("http://w3.org"); Assert.IsFalse (uri.Equals ("-")); }
public void TestEquals2 () { Uri a = new Uri ("http://www.go-mono.com"); Uri b = new Uri ("http://www.go-mono.com"); Assert.AreEqual (a, b, "#1"); a = new Uri ("mailto:user:[email protected]?subject=uri"); b = new Uri ("MAILTO:USER:[email protected]?SUBJECT=URI"); Assert.IsTrue (a != b, "#2"); Assert.AreEqual ("mailto:user:[email protected]?subject=uri", a.ToString (), "#2a"); Assert.AreEqual ("mailto:USER:[email protected]?SUBJECT=URI", b.ToString (), "#2b"); a = new Uri ("http://www.go-mono.com/ports/"); b = new Uri ("http://www.go-mono.com/PORTS/"); Assert.IsTrue (!a.Equals (b), "#3"); }
static List<string> getListing(string url) { string name = new Uri(url).AbsolutePath; name = Path.GetFileName(name.TrimEnd('/')); List<string> list = new List<string>(); if (File.Exists(datadirectory + Path.DirectorySeparatorChar + name)) { if (new FileInfo(datadirectory + Path.DirectorySeparatorChar + name).Length > 0) { using (StreamReader sr = new StreamReader(datadirectory + Path.DirectorySeparatorChar + name)) { while (!sr.EndOfStream) { list.Add(sr.ReadLine()); } sr.Close(); } return list; } } try { log.Info("srtm req " + url); WebRequest req = HttpWebRequest.Create(url); using (WebResponse res = req.GetResponse()) using (StreamReader resstream = new StreamReader(res.GetResponseStream())) { string data = resstream.ReadToEnd(); Regex regex = new Regex("href=\"([^\"]+)\"", RegexOptions.IgnoreCase); if (regex.IsMatch(data)) { MatchCollection matchs = regex.Matches(data); for (int i = 0; i < matchs.Count; i++) { if (matchs[i].Groups[1].Value.ToString().Contains("..")) continue; if (matchs[i].Groups[1].Value.ToString().Contains("http")) continue; if (matchs[i].Groups[1].Value.ToString().EndsWith("/srtm/version2_1/")) continue; list.Add(url.TrimEnd(new char[] {'/', '\\'}) + "/" + matchs[i].Groups[1].Value.ToString()); } } } using (StreamWriter sw = new StreamWriter(datadirectory + Path.DirectorySeparatorChar + name)) { list.ForEach(x => { sw.WriteLine((string)x); }); if (name.Equals("README.txt") || name.Equals("Region_definition.jpg")) sw.Write(" "); sw.Close(); } } catch (WebException ex) { log.Error(ex); throw; } return list; }
public void Equals1 () { Uri uri1 = new Uri ("http://www.contoso.com/index.htm#main"); Uri uri2 = new Uri ("http://www.contoso.com/index.htm#fragment"); Assert.IsTrue (uri1.Equals (uri2), "#1"); Assert.IsTrue (!uri2.Equals ("http://www.contoso.com/index.html?x=1"), "#3"); Assert.IsTrue (!uri1.Equals ("http://www.contoso.com:8080/index.htm?x=1"), "#4"); }
private void OnSourceChanged(Uri oldValue, Uri newValue) { // if resetting source or old source equals new, don’t do anything if (_isResetSource || newValue != null && newValue.Equals(oldValue)) { return; } // handle fragment navigation string newFragment; var oldValueNoFragment = NavigationHelper.RemoveFragment(oldValue); var newValueNoFragment = NavigationHelper.RemoveFragment(newValue, out newFragment); if (newValueNoFragment != null && newValueNoFragment.Equals(oldValueNoFragment)) { // fragment navigation var args = new FragmentNavigationEventArgs { Fragment = newFragment }; OnFragmentNavigation(Content as IContent, args); } else { var navType = _isNavigatingHistory ? NavigationType.Back : _isNavigatingFuture ? NavigationType.Forward : NavigationType.New; // only invoke CanNavigate for new navigation if (!_isNavigatingHistory && !_isNavigatingFuture && !CanNavigate(oldValue, newValue, navType)) { return; } Navigate(oldValue, newValue, navType); } }
private void OnSelectedSourceChanged(Uri oldValue, Uri newValue) { if (!_isSelecting) { // if old and new are equal, don't do anything if (newValue != null && newValue.Equals(oldValue)) { return; } UpdateSelection(); } // raise SelectedSourceChanged event var handler = SelectedSourceChanged; handler?.Invoke(this, new SourceEventArgs(newValue)); }
/*-------------- internal members -------------*/ // internal void FetchRequest(Uri uri, WebRequest request) { _Request = request; _Policy = request.CachePolicy; _Response = null; _ResponseCount = 0; _ValidationStatus = CacheValidationStatus.DoNotUseCache; _CacheFreshnessStatus = CacheFreshnessStatus.Undefined; _CacheStream = null; _CacheStreamOffset = 0L; _CacheStreamLength = 0L; if (!uri.Equals(_Uri)) { // it's changed from previous call _CacheKey = uri.GetParts(UriComponents.AbsoluteUri, UriFormat.Unescaped); } _Uri = uri; }