当前位置: 首页>>代码示例>>C#>>正文


C# Uri.IsWellFormedOriginalString方法代码示例

本文整理汇总了C#中System.Uri.IsWellFormedOriginalString方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.IsWellFormedOriginalString方法的具体用法?C# Uri.IsWellFormedOriginalString怎么用?C# Uri.IsWellFormedOriginalString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Uri的用法示例。


在下文中一共展示了Uri.IsWellFormedOriginalString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EncodeUri

        public static string EncodeUri(Uri uri)
        {

            if (!uri.IsAbsoluteUri)
            {
                var uriString = uri.IsWellFormedOriginalString() ? uri.ToString() : Uri.EscapeUriString(uri.ToString());
                return EscapeReservedCspChars(uriString);
            }

            var host = uri.Host;
            var encodedHost = EncodeHostname(host);

            var needsReplacement = !host.Equals(encodedHost);

            var authority = uri.GetLeftPart(UriPartial.Authority);

            if (needsReplacement)
            {
                authority = authority.Replace(host, encodedHost);
            }

            if (uri.PathAndQuery.Equals("/"))
            {
                return authority;
            }

            return authority + EscapeReservedCspChars(uri.PathAndQuery);
        }
开发者ID:modulexcite,项目名称:NWebsec,代码行数:28,代码来源:CspUriSource.cs

示例2: GetDomain

        public static void GetDomain(string fromUrl, out string domain, out string subDomain)
        {
            domain = "";
            subDomain = "";
            try
            {
                if (fromUrl.IndexOf("的名片") > -1)
                {
                    subDomain = fromUrl;
                    domain = "名片";
                    return;
                }

                UriBuilder builder = new UriBuilder(fromUrl);
                fromUrl = builder.ToString();

                Uri u = new Uri(fromUrl);

                if (u.IsWellFormedOriginalString())
                {
                    if (u.IsFile)
                    {
                        subDomain = domain = "客户端本地文件路径";

                    }
                    else
                    {
                        string Authority = u.Authority;
                        string[] ss = u.Authority.Split('.');
                        if (ss.Length == 2)
                        {
                            Authority = "www." + Authority;
                        }
                        int index = Authority.IndexOf('.', 0);
                        domain = Authority.Substring(index + 1, Authority.Length - index - 1).Replace("comhttp","com");
                        subDomain = Authority.Replace("comhttp", "com");
                        if (ss.Length < 2)
                        {
                            domain = "不明路径";
                            subDomain = "不明路径";
                        }
                    }
                }
                else
                {
                    if (u.IsFile)
                    {
                        subDomain = domain = "客户端本地文件路径";
                    }
                    else
                    {
                        subDomain = domain = "不明路径";
                    }
                }
            }
            catch
            {
                subDomain = domain = "不明路径";
            }
        }
开发者ID:Rainyhhh,项目名称:International-Website,代码行数:60,代码来源:UrlOper.cs

示例3: OnMessage

        public async void OnMessage(IMessage message)
        {
            try
            {
                if (!message.IsFromMyself && !message.IsHistorical)
                {
                    var match = regex.Match(message.FullBody);
                    if (regex.IsMatch(message.FullBody))
                    {
                        var uri = new Uri(message.FullBody);
                        if (uri.IsWellFormedOriginalString())
                        {
                            var reply = this.MakeReply(await this.QueryAsync(uri));

                            if (!String.IsNullOrWhiteSpace(reply))
                            {
                                // TODO: gotta get new lines sorted out
                                await this.backend.SendMessageAsync(message.ReplyTo, reply);
                            }
                        }
                    }
                }
            }
            catch(Exception e)
            {
                Console.Error.WriteLine(e); // TODO: handle better
            }
        }
开发者ID:kfritz,项目名称:bentbot,代码行数:28,代码来源:WebPreview.cs

示例4: checkConfig

        public bool checkConfig()
        {
            try
            {
                Uri uri = new Uri(Attr.EMDRServer);

                if (!uri.IsWellFormedOriginalString())
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }

            try
            {
                var conn = new SqlConnectionStringBuilder(Attr.DataSource);
            }
            catch (Exception)
            {
                return false;
            }

            if ( Attr.TrimHistDays < 0 || Attr.TrimHistDays > 1000000 ||
                    Attr.TrimOrdersDays < 0 || Attr.TrimOrdersDays > 1000000)
            {
                return false;
            }

            return true;
        }
开发者ID:Ralack,项目名称:EMDRGatherer,代码行数:33,代码来源:EmdrConfig.cs

示例5: AdvanceNext

        public bool AdvanceNext()
        {
            var page = new Uri(_domain, _currentLocation);
            var doc = _web.Load(page.ToString());

            string location = _ScrapeNextLink(doc);
            _currentLocation = new Uri(location, UriKind.Relative);

            return !String.IsNullOrEmpty(location) && _currentLocation.IsWellFormedOriginalString();
        }
开发者ID:karpinsn,项目名称:ZOMGComics,代码行数:10,代码来源:XPathScraper.cs

示例6: GetDomain

 public static void GetDomain(string fromUrl, out string domain, out string subDomain)
 {
     domain = "";
     subDomain = "";
     try
     {
         if (fromUrl.IndexOf("的名片") > -1)
         {
             subDomain = fromUrl;
             domain = "名片";
         }
         else
         {
             fromUrl = new UriBuilder(fromUrl).ToString();
             Uri uri = new Uri(fromUrl);
             if (uri.IsWellFormedOriginalString())
             {
                 if (uri.IsFile)
                 {
                     subDomain = domain = "客户端本地文件路径";
                 }
                 else
                 {
                     string authority = uri.Authority;
                     string[] strArray = uri.Authority.Split(new char[] { '.' });
                     if (strArray.Length == 2)
                     {
                         authority = "www." + authority;
                     }
                     int index = authority.IndexOf('.', 0);
                     domain = authority.Substring(index + 1, (authority.Length - index) - 1).Replace("comhttp", "com");
                     subDomain = authority.Replace("comhttp", "com");
                     if (strArray.Length < 2)
                     {
                         domain = "不明路径";
                         subDomain = "不明路径";
                     }
                 }
             }
             else if (uri.IsFile)
             {
                 subDomain = domain = "客户端本地文件路径";
             }
             else
             {
                 subDomain = domain = "不明路径";
             }
         }
     }
     catch
     {
         subDomain = domain = "不明路径";
     }
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:54,代码来源:UrlOper.cs

示例7: _GetCurrentDocument

        private HtmlDocument _GetCurrentDocument()
        {
            //  Form the page URI
            Uri page = new Uri(_domain, _currentLocation);
            HtmlDocument doc = null;

            //  If we have a well formed URI then load the page and return it
            if (page.IsWellFormedOriginalString())
            {
                doc = _web.Load(page.ToString());
            }

            return doc;
        }
开发者ID:karpinsn,项目名称:ZOMGComics,代码行数:14,代码来源:XPathScraper.cs

示例8: RenderLink

        /// <summary>
        /// Internal method for rendering links
        /// </summary>
        public static string RenderLink(BBCodeNode Node, bool ThrowOnError, object LookupTable)
        {
            if ((Node.Attribute ?? "").Trim() == "")
                if (Node.Children.Length != 0 && (Node.Children[0] as BBCodeTextNode) == null)
                    if (ThrowOnError)
                        throw new HtmlRenderException("[url] tag does not contain a URL attribute");
                    else
                        return Error(Node, LookupTable);
                else
                {
                    // support self-links such as [url]http://google.com[/url]
                    Node = ((BBCodeNode)Node.Clone()); // Nodes are mutable, and we don't want to mess with the original Node.
                    Node.Attribute = Node.Children[0].ToString();
                }

            Uri src = null;
            try
            {
                src = new Uri(Node.Attribute);
            }
            catch (UriFormatException)
            {
                if (ThrowOnError)
                    throw;
                return Error(Node, LookupTable);
            }

            if (!src.IsWellFormedOriginalString())
                if (ThrowOnError)
                    throw new HtmlRenderException("URL in [url] tag not well formed or relative");
                else
                    return Error(Node, LookupTable);

            if (!src.Scheme.Contains("http"))
                if (ThrowOnError)
                    throw new HtmlRenderException("URL scheme must be either HTTP or HTTPS");
                else
                    return Error(Node, LookupTable);

            return "<a href=\"" + HttpUtility.HtmlEncode(src.ToString()) + "\">"
                    + Node.Children.ToHtml()
                    + "</a>";
        }
开发者ID:philstrong,项目名称:BBsharp,代码行数:46,代码来源:Link.cs

示例9: RenderImage

        /// <summary>
        /// Internal method for rendering images
        /// </summary>
        public static string RenderImage(BBCodeNode Node, bool ThrowOnError, object LookupTable)
        {
            if (Node.Children.Length != 1)
                if (ThrowOnError)
                    throw new HtmlRenderException("[img] tag does not to contain image URL");
                else
                    return Error(Node, LookupTable);

            if ((Node.Children[0] as BBCodeTextNode) == null)
                if (ThrowOnError)
                    throw new HtmlRenderException("[img] tag does not to contain image URL");
                else
                    return Error(Node, LookupTable);

            Uri src = null;
            try
            {
                src = new Uri(Node.Children[0].ToString(), UriKind.Absolute);
            }
            catch (UriFormatException)
            {
                if (ThrowOnError)
                    throw;
                return Error(Node, LookupTable);
            }

            if (!src.IsWellFormedOriginalString())
                if (ThrowOnError)
                    throw new HtmlRenderException("Image URL in [img] tag not well formed or relative");
                else
                    return Error(Node, LookupTable);

            if (!src.Scheme.Contains("http"))
                if (ThrowOnError)
                    throw new HtmlRenderException("Image URL scheme must be either HTTP or HTTPS");
                else
                    return Error(Node, LookupTable);

            return "<img src=\"" + HttpUtility.HtmlEncode(src.ToString()) + "\" alt=\"" + HttpUtility.HtmlEncode(src.ToString()) + "\" />";
        }
开发者ID:philstrong,项目名称:BBsharp,代码行数:43,代码来源:Image.cs

示例10: StartService

        /// <summary>
        ///   Starts the actual service
        /// </summary>
        /// <param name="fallen8"> Fallen-8. </param>
        private void StartService(Fallen8 fallen8)
        {
            #region configuration
            var configs = new Dictionary<String, String>();
            foreach (String key in ConfigurationManager.AppSettings)
            {
                var value = ConfigurationManager.AppSettings[key];

                configs.Add(key, value);
            }

            String adminIpAddress;
            configs.TryGetValue("AdminIPAddress", out adminIpAddress);

            UInt16 adminPort = 2323;
            String adminPortString;
            if(configs.TryGetValue("AdminPort", out adminPortString))
            {
                adminPort = Convert.ToUInt16(adminPortString);
            }

            String adminUriPattern;
            configs.TryGetValue("AdminUriPattern", out adminUriPattern);

            String restServiceAddress;
            configs.TryGetValue("RESTServicePattern", out restServiceAddress);

            #endregion

            var address = String.IsNullOrWhiteSpace(adminIpAddress) ? IPAddress.Any.ToString() : adminIpAddress;
            var port = adminPort;
            var uriPattern = String.IsNullOrWhiteSpace(adminUriPattern) ? "Admin" : adminUriPattern;

            _uri = new Uri("http://" + address + ":" + port + "/" + uriPattern);

            if (!_uri.IsWellFormedOriginalString())
                throw new Exception("The URI pattern is not well formed!");

            Service = new AdminService(fallen8);

            _host = new ServiceHost(Service, _uri)
                        {
                            CloseTimeout = new TimeSpan(0, 0, 0, 0, 50)
                        };

            _restServiceAddress = String.IsNullOrWhiteSpace(restServiceAddress) ? "REST" : restServiceAddress;

            try
            {
                var binding = new WebHttpBinding
                                  {
                                      MaxBufferSize = 268435456,
                                      MaxReceivedMessageSize = 268435456,
                                      SendTimeout = new TimeSpan(1, 0, 0),
                                      ReceiveTimeout = new TimeSpan(1, 0, 0)
                                  };

                var readerQuotas = new XmlDictionaryReaderQuotas
                                       {
                                           MaxDepth = 2147483647,
                                           MaxStringContentLength = 2147483647,
                                           MaxBytesPerRead = 2147483647,
                                           MaxNameTableCharCount = 2147483647,
                                           MaxArrayLength = 2147483647
                                       };

                binding.ReaderQuotas = readerQuotas;

                var se = _host.AddServiceEndpoint(typeof (IAdminService), binding, _restServiceAddress);
                var webBehav = new WebHttpBehavior
                                   {
                                       HelpEnabled = true
                                   };
                se.Behaviors.Add(webBehav);

                ((ServiceBehaviorAttribute) _host.Description.Behaviors[typeof (ServiceBehaviorAttribute)]).
                    InstanceContextMode = InstanceContextMode.Single;

            }
            catch (Exception)
            {
                _host.Abort();
                throw;
            }
        }
开发者ID:kuba85,项目名称:fallen-8,代码行数:89,代码来源:AdminServicePlugin.cs

示例11: btnAddClicked

 private void btnAddClicked(object sender, RoutedEventArgs e)
 {
     try {
     Uri argUri = new Uri(this.txtURL.Text);
     if (argUri.IsWellFormedOriginalString()) {
       if (!this.theWatchManager.AddURL(argUri)) {
     this.winAddAdvanced = new windowAddAdvanced(argUri);
     this.winAddAdvanced.RegisterWatchThreadManager(ref this.theWatchManager);
     this.winAddAdvanced.Show();
       }
       if (Properties.Settings.Default.AutoSaveOnAdd) {
     this.wts.Serialize(this.theWatchManager, this.theDownloadManager);
       }
     } else {
       BrushConverter converter = new BrushConverter();
       this.txtURL.Background = converter.ConvertFromString("RED") as SolidColorBrush;
     }
       } catch (Exception) {
     BrushConverter converter2 = new BrushConverter();
     this.txtURL.Background = converter2.ConvertFromString("RED") as SolidColorBrush;
       }
 }
开发者ID:AdamCarrick,项目名称:inbefore404,代码行数:22,代码来源:windowMain.xaml.cs

示例12: StartService

        protected void StartService()
        {
            Dictionary<string, string> configs = ConfigHelper.GetPluginSpecificConfig (PluginName);

            // wenn ein zweiter Port vorhanden ist, kann eine zweite Instanz gestartet werden
            int instances = configs.ContainsKey ("2ndPort") ? 2 : 1;
            string[] prefixes = new string[] { "", "2nd" };
            // TODO: Dynamisch Anzahl und Art der Prefixes herausfinden; momentan sind die Werte fix (max 2 Prefixes/Instanzen, einmal "" und einmal "2nd")

            try {
                for (int instance = 1; instance <= instances; instance++) {
                    String authMethod = ConfigHelper.GetInstanceParam (configs, "AuthenticationMethod", prefixes, instance);

                    ServiceSecurity serviceSecurity = new ServiceSecurity (authMethod);
                    Uri uri = new Uri (serviceSecurity.HTTP_S + "://" + _address + ":" + _port + "/" + _uriPattern + "/REST");
                    if (!uri.IsWellFormedOriginalString ()) {
                        throw new Exception ("The URI Pattern is not well formed!");
                    }
                    _uris.Add (uri);

                    ServiceHost host = new ServiceHost (_service, uri) {
                        CloseTimeout = new TimeSpan (0, 0, 0, 0, 50)

                    };
                    _hosts.Add (host);

                    var binding = new WebHttpBinding {
                        MaxReceivedMessageSize = 268435456,
                        SendTimeout = new TimeSpan (1, 0, 0),
                        ReceiveTimeout = new TimeSpan (1, 0, 0),
                        // für Security: Anhand des Binding-Namens wird eruiert, welche ConfigSection & Prefix für diese ServiceBinding-Instanz genutzt werden soll
                        Name = PluginName + "." + prefixes [instance - 1]
                    };
                    binding.Security.Mode = serviceSecurity.BindingSecurityMode;
                    binding.Security.Transport.ClientCredentialType = serviceSecurity.BindingClientCredentialType;

                    var readerQuotas = new XmlDictionaryReaderQuotas {
                        MaxDepth = 2147483647,
                        MaxStringContentLength = 2147483647,
                        MaxBytesPerRead = 2147483647,
                        MaxNameTableCharCount = 2147483647,
                        MaxArrayLength = 2147483647
                    };
                    binding.ReaderQuotas = readerQuotas;

                    var se = host.AddServiceEndpoint (RESTServiceInterfaceType, binding, uri);
                    var webBehav = new WebHttpBehavior {
                        FaultExceptionEnabled = true,
                        HelpEnabled = true
                    };
                    se.Behaviors.Add (webBehav);

                    // this adds a additional instanceId header to every response
                    se.Behaviors.Add (new FaultTolerantServiceBehavior ());

                    ((ServiceBehaviorAttribute)host.Description.Behaviors [typeof(ServiceBehaviorAttribute)]).InstanceContextMode = InstanceContextMode.Single;
                }
            } catch (Exception) {
                _hosts.ForEach (h => h.Abort ());
                throw;
            }
        }
开发者ID:politician,项目名称:fallen-8,代码行数:62,代码来源:ARESTServicePlugin.cs

示例13: ConstructBNetConnectionString

        public static string ConstructBNetConnectionString(
            string user, string pwd, string host, string port, string db)
        {
            Uri uri;
            try
            {
                string uriString = string.Format("mysql://{0}:{1}", host, port);
                uri = new Uri(uriString);
            }
            catch (UriFormatException)
            {
                uri = null;
            }

            if (uri == null || !uri.IsWellFormedOriginalString() || string.IsNullOrWhiteSpace(user)
                || string.IsNullOrWhiteSpace(pwd) || string.IsNullOrWhiteSpace(db))
            {
                return null;
            }

            var connString =
                string.Format(
                    "server='{2}';port={3};database='{4}';User Id='{0}';Password='{1}';"
                    + "Check Parameters=false;Persist Security Info=False;Allow Zero Datetime=True;Convert Zero Datetime=True;",
                    user,
                    pwd,
                    host,
                    port,
                    db);

            return ConstructBNetEntityConnectionString(connString);
        }
开发者ID:st4l,项目名称:BEsharp,代码行数:32,代码来源:CommandExecutor.cs

示例14: NewsX_Methods

		public void NewsX_Methods ()
		{
			Uri uri = new Uri ("newsx://go-mono.com/");
			Assert.AreEqual ("//go-mono.com/", uri.GetComponents (UriComponents.Path, UriFormat.SafeUnescaped), "GetComponents");
			Assert.IsTrue (uri.IsBaseOf (uri), "IsBaseOf");
			Assert.IsTrue (uri.IsWellFormedOriginalString (), "IsWellFormedOriginalString");
			// ??? our parser doesn't seems to be called :(
		}
开发者ID:Profit0004,项目名称:mono,代码行数:8,代码来源:NewsStyleUriParserTest.cs

示例15: ParseServerUris

        private static IEnumerable<ServerInfo> ParseServerUris(IEnumerable<string> serverStrings)
        {
            var results = new List<ServerInfo>();
            int id = 0;
            foreach (string server in serverStrings)
            {
                id++;
                Uri uri;

                try
                {
                    uri = new Uri("bnet://" + server);
                }
                catch (UriFormatException)
                {
                    uri = null;
                }

                if (uri == null || !uri.IsWellFormedOriginalString()
                    || string.IsNullOrEmpty(uri.UserInfo) || uri.UserInfo.IndexOf(':') > -1)
                {
                    Console.WriteLine("Invalid server: " + server);
                    return null;
                }

                int port = uri.IsDefaultPort ? 2302 : uri.Port;

                results.Add(
                    new ServerInfo
                        {
                            ServerId = id,
                            ServerName = uri.DnsSafeHost + ":" + port,
                            LoginCredentials =
                                new BattlEyeLoginCredentials
                                    {
                                        Host = uri.DnsSafeHost,
                                        Port = port,
                                        Password = uri.UserInfo
                                    }
                        });
            }

            if (results.Count > 0)
            {
                return results;
            }

            return null;
        }
开发者ID:st4l,项目名称:BEsharp,代码行数:49,代码来源:Program.cs


注:本文中的System.Uri.IsWellFormedOriginalString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。