Beispiel #1
0
        public UrlParameter AddUrlParameter(string name, string value)
        {
            if (_parameters == null)
            {
                _parameters = new ArrayList();
            }
            UrlParameter parameter = new UrlParameter(name, value);

            _parameters.Add(parameter);
            return(parameter);
        }
Beispiel #2
0
		public UrlParameter AddUrlParameter(string name, string value)
		{
			if( _parameters == null )
				_parameters = new ArrayList();
			UrlParameter parameter = new UrlParameter(name, value);
			_parameters.Add( parameter );
			return parameter;
		}
Beispiel #3
0
        private void InternalParseUrl(string url)
        {
            string    tempUrl;
            Regex     regex;
            Match     match;
            string    user;
            string    password;
            string    database;
            string    host;
            string    protocol;
            int       port;
            string    parameters;
            ArrayList parametersCollection;
            string    parameterPart;

            string[]    parameter;
            char[]      separator;
            IEnumerator enumerator;

            try
            {
                tempUrl = url;
                if (tempUrl.Length == 0)
                {
                    tempUrl = ":///";
                }

                regex = new Regex(@"^(?<protocol>[\w\%]*)://((?'username'[\w\%]*)(:(?'password'[\w\%]*))?@)?(?'host'[\w\.\(\)\-\%\\\$]*)(:?(?'port'\d+))?/(?'database'[^?]*)?(\?(?'params'.*))?");
                match = regex.Match(tempUrl);
                if (!match.Success)
                {
                    throw new ArgumentOutOfRangeException();
                }

                user     = HttpUtility.UrlDecode(match.Result("${username}"));
                password = HttpUtility.UrlDecode(match.Result("${password}"));
                database = HttpUtility.UrlDecode(match.Result("${database}"));
                host     = HttpUtility.UrlDecode(match.Result("${host}"));
                protocol = HttpUtility.UrlDecode(match.Result("${protocol}"));
                port     = 0;
                if (match.Result("${port}").Length != 0)
                {
                    port = int.Parse(match.Result("${port}"));
                }
                if (port < 0 || port > 65535)
                {
                    throw new ArgumentOutOfRangeException("url", "This URL cannot be parsed. Invalid Port number.");
                }

                parameters           = match.Result("${params}");
                parametersCollection = new ArrayList();
                if (parameters != null && parameters != string.Empty)
                {
                    separator = new char[1] {
                        '&'
                    };
                    string[] splittedParameters = parameters.Split(separator);
                    enumerator = splittedParameters.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        parameterPart = ((string)enumerator.Current);
                        separator     = new char[1] {
                            '='
                        };
                        parameter = parameterPart.Split(separator, 2);
                        if (parameter.Length != 2)
                        {
                            throw new ArgumentOutOfRangeException("url", "This URL cannot be parsed. Invalid parameter.");
                        }
                        UrlParameter urlParameter = new UrlParameter(HttpUtility.UrlDecode(parameter[0]), HttpUtility.UrlDecode(parameter[1]));
                        parametersCollection.Add(urlParameter);
                    }
                }
                this._url        = url;
                this._user       = user;
                this._password   = password;
                this._database   = database;
                this._host       = host;
                this._protocol   = protocol;
                this._port       = port;
                this._parameters = parametersCollection;
            }
            catch (Exception ex)
            {
                if (ex is ArgumentOutOfRangeException)
                {
                    throw;
                }
                throw new ArgumentOutOfRangeException("url", "This URL cannot be parsed.");
            }
        }
Beispiel #4
0
		private void InternalParseUrl(string url)
		{
			string tempUrl;
			Regex regex;
			Match match;
			string user;
			string password;
			string database;
			string host;
			string protocol;
			int port;
			string parameters;
			ArrayList parametersCollection;
			string parameterPart;
			string[] parameter;
			char[] separator;
			IEnumerator enumerator;
			try
			{
				tempUrl = url;
				if (tempUrl.Length == 0)
					tempUrl = ":///";
 
				regex = new Regex(@"^(?<protocol>[\w\%]*)://((?'username'[\w\%]*)(:(?'password'[\w\%]*))?@)?(?'host'[\w\.\(\)\-\%\\\$]*)(:?(?'port'\d+))?/(?'database'[^?]*)?(\?(?'params'.*))?");
				match = regex.Match(tempUrl);
				if (!match.Success)
					throw new ArgumentOutOfRangeException();

				user = HttpUtility.UrlDecode(match.Result("${username}"));
				password = HttpUtility.UrlDecode(match.Result("${password}"));
				database = HttpUtility.UrlDecode(match.Result("${database}"));
				host = HttpUtility.UrlDecode(match.Result("${host}"));
				protocol = HttpUtility.UrlDecode(match.Result("${protocol}"));
				port = 0;
				if (match.Result("${port}").Length != 0)
				{
					port = int.Parse(match.Result("${port}"));
 
				}
				if (port < 0 || port > 65535)
					throw new ArgumentOutOfRangeException("url", "This URL cannot be parsed. Invalid Port number.");
 
				parameters = match.Result("${params}");
				parametersCollection = new ArrayList();
				if( parameters != null && parameters != string.Empty )
				{
					separator = new char[1]{ '&' };
					string[] splittedParameters = parameters.Split(separator);
					enumerator = splittedParameters.GetEnumerator();
					while (enumerator.MoveNext())
					{
						parameterPart = ((string)enumerator.Current);
						separator = new char[1]{ '=' };
						parameter = parameterPart.Split(separator, 2);
						if (parameter.Length != 2)
						{
							throw new ArgumentOutOfRangeException("url", "This URL cannot be parsed. Invalid parameter.");

						}
						UrlParameter urlParameter = new UrlParameter(HttpUtility.UrlDecode(parameter[0]), HttpUtility.UrlDecode(parameter[1]));
						parametersCollection.Add(urlParameter); 
					}
				}
				this._url = url;
				this._user = user;
				this._password = password;
				this._database = database;
				this._host = host;
				this._protocol = protocol;
				this._port = port;
				this._parameters = parametersCollection; 
			}
			catch (Exception ex)
			{
				if(ex is ArgumentOutOfRangeException)
					throw;
				throw new ArgumentOutOfRangeException("url", "This URL cannot be parsed.");
			}
		}