Esempio n. 1
0
 /// <summary>
 /// Set host name or address and port number in URL.
 /// </summary>
 /// <param name="url"></param>
 /// <param name="host"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public static string SetHostAndPort(string url, string host, string port)
 {
     Energy.Base.Url x = url;
     x.Host = host;
     x.Port = port;
     return(x.ToString());
 }
Esempio n. 2
0
 /// <summary>
 /// Set host name or address and port number in URL.
 /// When port number is not in range 1 .. 65535 it will be considered undefined and will be removed.
 /// </summary>
 /// <param name="url"></param>
 /// <param name="host"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public static string SetHostAndPort(string url, string host, int port)
 {
     Energy.Base.Url x = url;
     x.Host = host;
     x.Port = port > 0 && port <= 65535 ? port.ToString() : "";
     return(x.ToString());
 }
Esempio n. 3
0
        /// <summary>
        /// Create URL object from string.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static Url Explode(string url)
        {
            if (null == url)
            {
                return(null);
            }
            else if (0 == url.Length)
            {
                return(new Energy.Base.Url());
            }
            string pattern = Energy.Base.Expression.Url;
            Regex  r       = new Regex(pattern);
            Match  m       = r.Match(url);

            if (!m.Success)
            {
                return(null);
            }
            Energy.Base.Url result = new Energy.Base.Url();
            result.Scheme   = m.Groups["scheme"].Value;
            result.Slash    = m.Groups["slash"].Value;
            result.Host     = m.Groups["host"].Value;
            result.Port     = m.Groups["port"].Value;
            result.Path     = m.Groups["path"].Value;
            result.Query    = m.Groups["query"].Value;
            result.Fragment = m.Groups["fragment"].Value;
            result.User     = m.Groups["user"].Value;
            result.Password = m.Groups["password"].Value;
            return(result);
        }
Esempio n. 4
0
 /// <summary>
 /// Make URL address overriding parts of it.
 /// Pass null as parameter to skip it or empty value to remove specified part from URL.
 /// </summary>
 /// <param name="url"></param>
 /// <param name="scheme"></param>
 /// <param name="host"></param>
 /// <param name="port"></param>
 /// <param name="path"></param>
 /// <param name="query"></param>
 /// <param name="fragment"></param>
 /// <param name="user"></param>
 /// <param name="password"></param>
 /// <param name="value">Optionally replace placeholder {0} as value</param>
 /// <returns></returns>
 public static string Make(string url, string scheme, string host, string port
                           , string path, string query, string fragment, string user, string password
                           , string value)
 {
     Energy.Base.Url x = url;
     if (scheme != null)
     {
         string pattern = @":([^\s]*)";
         Match  match   = Regex.Match(scheme, pattern);
         if (match.Success)
         {
             x.Slash  = match.Groups[1].Value;
             x.Scheme = scheme.Substring(0, match.Index);
         }
         else
         {
             x.Slash  = "//";
             x.Scheme = scheme;
         }
     }
     if (host != null)
     {
         x.Host = host;
     }
     if (port != null)
     {
         x.Port = port;
     }
     if (path != null)
     {
         x.Path = path;
     }
     if (query != null)
     {
         x.Query = query;
     }
     if (fragment != null)
     {
         x.Fragment = fragment;
     }
     if (user != null)
     {
         x.User = user;
     }
     if (password != null)
     {
         x.Password = password;
     }
     url = x.ToString();
     if (value != null && Energy.Base.Text.Contains(url, "{0}"))
     {
         url = url.Replace("{0}", value);
     }
     return(url);
 }
Esempio n. 5
0
 /// <summary>
 /// Set port number in URL.
 /// When port number is not in range 1 .. 65535 it will be considered undefined and will be removed.
 /// </summary>
 /// <param name="url"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public static string SetPort(string url, int port)
 {
     Energy.Base.Url x = url;
     x.Port = port > 0 && port <= 65535 ? port.ToString() : "";
     return(x.ToString());
 }
Esempio n. 6
0
 /// <summary>
 /// Set port number in URL.
 /// </summary>
 /// <param name="url"></param>
 /// <param name="port"></param>
 /// <returns></returns>
 public static string SetPort(string url, string port)
 {
     Energy.Base.Url x = url;
     x.Port = port;
     return(x.ToString());
 }
Esempio n. 7
0
 /// <summary>
 /// Set host name or address in URL.
 /// </summary>
 /// <param name="url"></param>
 /// <param name="host"></param>
 /// <returns></returns>
 public static string SetHost(string url, string host)
 {
     Energy.Base.Url x = url;
     x.Host = host;
     return(x.ToString());
 }