-
-
Notifications
You must be signed in to change notification settings - Fork 363
refactor(ITcpSocketFactory): add GetOrCreate extension method #6277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/BootstrapBlazor/Extensions/ITcpSocketFactoryExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| using System.Runtime.Versioning; | ||
|
|
||
| namespace BootstrapBlazor.Components; | ||
|
|
||
| /// <summary> | ||
| /// <see cref="ITcpSocketFactory"/> 扩展方法类 | ||
| /// </summary> | ||
| [UnsupportedOSPlatform("browser")] | ||
| public static class ITcpSocketFactoryExtensions | ||
| { | ||
| /// <summary> | ||
| /// Retrieves an existing TCP socket client by name or creates a new one using the specified IP address and port. | ||
| /// </summary> | ||
| /// <param name="factory">The <see cref="ITcpSocketFactory"/> instance used to manage TCP socket clients.</param> | ||
| /// <param name="name">The unique name identifying the TCP socket client. Cannot be null or empty.</param> | ||
| /// <param name="ipAddress">The IP address of the endpoint to connect to. Must be a valid IPv4 or IPv6 address.</param> | ||
| /// <param name="port">The port number of the endpoint to connect to. Must be within the range 0 to 65535.</param> | ||
| /// <returns>An <see cref="ITcpSocketClient"/> instance representing the TCP socket client associated with the specified | ||
| /// name. If no client exists with the given name, a new client is created and returned.</returns> | ||
| public static ITcpSocketClient GetOrCreate(this ITcpSocketFactory factory, string name, string ipAddress, int port) | ||
| { | ||
| var endPoint = Utility.ConvertToIpEndPoint(ipAddress, port); | ||
| return factory.GetOrCreate(name, endPoint); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| using System.Net; | ||
|
|
||
| namespace BootstrapBlazor.Components; | ||
|
|
||
| /// <summary> | ||
|
|
@@ -11,21 +13,21 @@ namespace BootstrapBlazor.Components; | |
| public interface ITcpSocketFactory : IDisposable | ||
| { | ||
| /// <summary> | ||
| /// Retrieves an existing TCP socket associated with the specified host and port, or creates a new one if none | ||
| /// exists. | ||
| /// Retrieves an existing TCP socket client by name or creates a new one if it does not exist. | ||
| /// </summary> | ||
| /// <param name="host">The hostname or IP address of the remote endpoint. Cannot be null or empty.</param> | ||
| /// <param name="port">The port number of the remote endpoint. Must be a valid port number between 0 and 65535.</param> | ||
| /// <returns>An <see cref="ITcpSocketClient"/> instance representing the TCP socket for the specified host and port.</returns> | ||
| ITcpSocketClient GetOrCreate(string host, int port); | ||
| /// <param name="name">The unique name used to identify the TCP socket client. Cannot be null or empty.</param> | ||
| /// <param name="endPoint">The network endpoint to associate with the TCP socket client. Must be a valid <see | ||
| /// cref="System.Net.IPEndPoint"/> instance.</param> | ||
| /// <returns>An instance of <see cref="ITcpSocketClient"/> representing the TCP socket client associated with the specified | ||
| /// name and endpoint. If a client with the given name already exists, the existing instance is returned; otherwise, | ||
| /// a new client is created.</returns> | ||
| ITcpSocketClient GetOrCreate(string name, IPEndPoint endPoint); | ||
|
|
||
| /// <summary> | ||
| /// Removes the specified host and port combination from the collection. | ||
| /// Removes the TCP socket client associated with the specified name. | ||
| /// </summary> | ||
| /// <remarks>If the specified host and port combination does not exist in the collection, the method has | ||
| /// no effect.</remarks> | ||
| /// <param name="host">The hostname to remove. Cannot be null or empty.</param> | ||
| /// <param name="port">The port number associated with the host to remove. Must be a valid port number (0-65535).</param> | ||
| /// <returns>An <see cref="ITcpSocketClient"/> instance representing the TCP socket for the specified host and port.</returns> | ||
| ITcpSocketClient? Remove(string host, int port); | ||
| /// <param name="name">The name of the TCP socket client to remove. Cannot be <see langword="null"/> or empty.</param> | ||
| /// <returns>The removed <see cref="ITcpSocketClient"/> instance if a client with the specified name exists; otherwise, <see | ||
| /// langword="null"/>.</returns> | ||
| ITcpSocketClient? Remove(string name); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.