// Methods
		public bool Check (Evidence evidence)
		{
			if (evidence == null)
				return false;

			string codebase = Assembly.GetCallingAssembly ().CodeBase;
			Uri local = new Uri (codebase);
			Url ucode = new Url (codebase);

			// *both* ApplicationDirectory and Url must be in *Host* evidences
			bool adir = false;
			bool url = false;
			IEnumerator e = evidence.GetHostEnumerator ();
			while (e.MoveNext ()) {
				object o = e.Current;

				if (!adir && (o is ApplicationDirectory)) {
					ApplicationDirectory ad = (o as ApplicationDirectory);
					string s = ad.Directory;
					adir = (String.Compare (s, 0, local.ToString (), 0, s.Length, true, CultureInfo.InvariantCulture) == 0);
				}
				else if (!url && (o is Url)) {
					url = ucode.Equals (o);
				}

				// got both ?
				if (adir && url)
					return true;
			}
			return false;
		}
Пример #2
0
		private string Prepare (string url) 
		{
			if (url == null)
				throw new ArgumentNullException ("Url");
			if (url == String.Empty)
				throw new FormatException (Locale.GetText ("Invalid (empty) Url"));

			int protocolPos = url.IndexOf (Uri.SchemeDelimiter);	// '://'
			if (protocolPos > 0) {
				if (url.StartsWith ("file://")) {
					// convert file url into uppercase
					url = "file://" + url.Substring (7).ToUpperInvariant ();
				} else {
					// add a trailing slash if none (lonely one) is present
					if (url.LastIndexOf ("/") == protocolPos + 2)
						url += "/";
				}
			} else {
				// add file scheme (default) and convert url to uppercase
				url = "file://" + url.ToUpperInvariant ();
			}

			// don't escape and don't reduce (e.g. '.' and '..')
			Uri uri = new Uri (url, false, false);
			if ((uri.Host.IndexOf ('*') < 0) || (uri.Host.Length < 2)) // lone star case
				url = uri.ToString ();
			else {
				string msg = Locale.GetText ("Invalid * character in url");
				throw new ArgumentException (msg, "name");
			}

			return url;
		}
Пример #3
0
		// internal
#if NET_2_0
		private string Prepare (string url) 
		{
			if (url == null)
				throw new ArgumentNullException ("Url");
			if (url == String.Empty)
				throw new FormatException (Locale.GetText ("Invalid (empty) Url"));

			int protocolPos = url.IndexOf (Uri.SchemeDelimiter);	// '://'
			if (protocolPos > 0) {
				if (url.StartsWith ("file://")) {
					// convert file url into uppercase
					url = "file://" + url.Substring (7);
				}
				// don't escape and don't reduce (e.g. '.' and '..')
				Uri uri = new Uri (url, false, false);
				url = uri.ToString ();
			}

			int lastpos = url.Length - 1;
			if (url [lastpos] == '/')
				url = url.Substring (0, lastpos);

			return url;
		}