Exemplo n.º 1
0
 /// <summary>
 ///     Creates a clone of this instance with the specified substitutions.
 /// </summary>
 /// <param name="enableListener">A value indicating whether to listen for incoming connections.</param>
 /// <param name="listenPort">The port on which to listen for incoming connections.</param>
 /// <param name="enableDistributedNetwork">A value indicating whether to establish distributed network connections.</param>
 /// <param name="acceptDistributedChildren">A value indicating whether to accept distributed child connections.</param>
 /// <param name="distributedChildLimit">The number of allowed distributed children.</param>
 /// <param name="maximumUploadSpeed">The total maximum allowable upload speed, in kibibytes per second.</param>
 /// <param name="maximumDownloadSpeed">The total maximum allowable download speed, in kibibytes per second.</param>
 /// <param name="deduplicateSearchRequests">
 ///     A value indicating whether duplicated distributed search requests should be discarded.
 /// </param>
 /// <param name="autoAcknowledgePrivateMessages">
 ///     A value indicating whether to automatically send a private message acknowledgement upon receipt.
 /// </param>
 /// <param name="autoAcknowledgePrivilegeNotifications">
 ///     A value indicating whether to automatically send a privilege notification acknowledgement upon receipt.
 /// </param>
 /// <param name="acceptPrivateRoomInvitations">A value indicating whether to accept private room invitations.</param>
 /// <param name="serverConnectionOptions">The options for the server message connection.</param>
 /// <param name="peerConnectionOptions">The options for peer message connections.</param>
 /// <param name="transferConnectionOptions">The options for peer transfer connections.</param>
 /// <param name="incomingConnectionOptions">The options for incoming connections.</param>
 /// <param name="distributedConnectionOptions">The options for distributed message connections.</param>
 /// <param name="userEndPointCache">The user endpoint cache to use when resolving user endpoints.</param>
 /// <param name="searchResponseResolver">
 ///     The delegate used to resolve the <see cref="SearchResponse"/> for an incoming <see cref="SearchRequest"/>.
 /// </param>
 /// <param name="searchResponseCache">
 ///     The search response cache to use when a response is not able to be delivered immediately.
 /// </param>
 /// <param name="browseResponseResolver">
 ///     The delegate used to resolve the <see cref="BrowseResponse"/> for an incoming <see cref="BrowseRequest"/>.
 /// </param>
 /// <param name="directoryContentsResolver">
 ///     The delegate used to resolve the <see cref="Directory"/> for an incoming <see cref="FolderContentsRequest"/>.
 /// </param>
 /// <param name="userInfoResolver">The delegate used to resolve the <see cref="UserInfo"/> for an incoming <see cref="UserInfoRequest"/>.</param>
 /// <param name="enqueueDownload">The delegate invoked upon an receipt of an incoming <see cref="QueueDownloadRequest"/>.</param>
 /// <param name="placeInQueueResolver">
 ///     The delegate used to resolve the <see cref="int"/> response for an incoming request.
 /// </param>
 /// <returns>The cloned instance.</returns>
 internal SoulseekClientOptions With(
     bool?enableListener                            = null,
     int?listenPort                                 = null,
     bool?enableDistributedNetwork                  = null,
     bool?acceptDistributedChildren                 = null,
     int?distributedChildLimit                      = null,
     int?maximumUploadSpeed                         = null,
     int?maximumDownloadSpeed                       = null,
     bool?deduplicateSearchRequests                 = null,
     bool?autoAcknowledgePrivateMessages            = null,
     bool?autoAcknowledgePrivilegeNotifications     = null,
     bool?acceptPrivateRoomInvitations              = null,
     ConnectionOptions serverConnectionOptions      = null,
     ConnectionOptions peerConnectionOptions        = null,
     ConnectionOptions transferConnectionOptions    = null,
     ConnectionOptions incomingConnectionOptions    = null,
     ConnectionOptions distributedConnectionOptions = null,
     IUserEndPointCache userEndPointCache           = null,
     Func <string, int, SearchQuery, Task <SearchResponse> > searchResponseResolver = null,
     ISearchResponseCache searchResponseCache = null,
     Func <string, IPEndPoint, Task <BrowseResponse> > browseResponseResolver            = null,
     Func <string, IPEndPoint, int, string, Task <Directory> > directoryContentsResolver = null,
     Func <string, IPEndPoint, Task <UserInfo> > userInfoResolver         = null,
     Func <string, IPEndPoint, string, Task> enqueueDownload              = null,
     Func <string, IPEndPoint, string, Task <int?> > placeInQueueResolver = null)
 {
     return(new SoulseekClientOptions(
                enableListener: enableListener ?? EnableListener,
                listenPort: listenPort ?? ListenPort,
                enableDistributedNetwork: enableDistributedNetwork ?? EnableDistributedNetwork,
                acceptDistributedChildren: acceptDistributedChildren ?? AcceptDistributedChildren,
                distributedChildLimit: distributedChildLimit ?? DistributedChildLimit,
                maximumConcurrentUploads: MaximumConcurrentUploads,
                maximumUploadSpeed: maximumUploadSpeed ?? MaximumUploadSpeed,
                maximumConcurrentDownloads: MaximumConcurrentDownloads,
                maximumDownloadSpeed: maximumDownloadSpeed ?? MaximumDownloadSpeed,
                deduplicateSearchRequests: deduplicateSearchRequests ?? DeduplicateSearchRequests,
                messageTimeout: MessageTimeout,
                autoAcknowledgePrivateMessages: autoAcknowledgePrivateMessages ?? AutoAcknowledgePrivateMessages,
                autoAcknowledgePrivilegeNotifications: autoAcknowledgePrivilegeNotifications ?? AutoAcknowledgePrivilegeNotifications,
                acceptPrivateRoomInvitations: acceptPrivateRoomInvitations ?? AcceptPrivateRoomInvitations,
                minimumDiagnosticLevel: MinimumDiagnosticLevel,
                startingToken: StartingToken,
                serverConnectionOptions: (serverConnectionOptions ?? ServerConnectionOptions).WithoutInactivityTimeout(),
                peerConnectionOptions: peerConnectionOptions ?? PeerConnectionOptions,
                transferConnectionOptions: (transferConnectionOptions ?? TransferConnectionOptions).WithoutInactivityTimeout(),
                incomingConnectionOptions: incomingConnectionOptions ?? IncomingConnectionOptions,
                distributedConnectionOptions: distributedConnectionOptions ?? DistributedConnectionOptions,
                userEndPointCache: userEndPointCache ?? UserEndPointCache,
                searchResponseResolver: searchResponseResolver ?? SearchResponseResolver,
                searchResponseCache: searchResponseCache ?? SearchResponseCache,
                browseResponseResolver: browseResponseResolver ?? BrowseResponseResolver,
                directoryContentsResolver: directoryContentsResolver ?? DirectoryContentsResolver,
                userInfoResolver: userInfoResolver ?? UserInfoResolver,
                enqueueDownload: enqueueDownload ?? EnqueueDownload,
                placeInQueueResolver: placeInQueueResolver ?? PlaceInQueueResolver));
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="SoulseekClientOptions"/> class.
        /// </summary>
        /// <param name="enableListener">A value indicating whether to listen for incoming connections.</param>
        /// <param name="listenPort">The port on which to listen for incoming connections.</param>
        /// <param name="enableDistributedNetwork">A value indicating whether to establish distributed network connections.</param>
        /// <param name="acceptDistributedChildren">A value indicating whether to accept distributed child connections.</param>
        /// <param name="distributedChildLimit">The number of allowed distributed children.</param>
        /// <param name="deduplicateSearchRequests">
        ///     A value indicating whether duplicated distributed search requests should be discarded.
        /// </param>
        /// <param name="messageTimeout">
        ///     The message timeout, in milliseconds, used when waiting for a response from the server.
        /// </param>
        /// <param name="autoAcknowledgePrivateMessages">
        ///     A value indicating whether to automatically send a private message acknowledgement upon receipt.
        /// </param>
        /// <param name="autoAcknowledgePrivilegeNotifications">
        ///     A value indicating whether to automatically send a privilege notification acknowledgement upon receipt.
        /// </param>
        /// <param name="acceptPrivateRoomInvitations">A value indicating whether to accept private room invitations.</param>
        /// <param name="minimumDiagnosticLevel">The minimum level of diagnostic messages to be generated by the client.</param>
        /// <param name="startingToken">The starting value for download and search tokens.</param>
        /// <param name="serverConnectionOptions">The options for the server message connection.</param>
        /// <param name="peerConnectionOptions">The options for peer message connections.</param>
        /// <param name="transferConnectionOptions">The options for peer transfer connections.</param>
        /// <param name="incomingConnectionOptions">The options for incoming connections.</param>
        /// <param name="distributedConnectionOptions">The options for distributed message connections.</param>
        /// <param name="userEndPointCache">The user endpoint cache to use when resolving user endpoints.</param>
        /// <param name="searchResponseResolver">
        ///     The delegate used to resolve the <see cref="SearchResponse"/> for an incoming <see cref="SearchRequest"/>.
        /// </param>
        /// <param name="searchResponseCache">The search response cache to use when a response is not able to be delivered immediately.</param>
        /// <param name="browseResponseResolver">
        ///     The delegate used to resolve the <see cref="BrowseResponse"/> for an incoming <see cref="BrowseRequest"/>.
        /// </param>
        /// <param name="directoryContentsResponseResolver">
        ///     The delegate used to resolve the <see cref="FolderContentsResponse"/> for an incoming <see cref="FolderContentsRequest"/>.
        /// </param>
        /// <param name="userInfoResponseResolver">
        ///     The delegate used to resolve the <see cref="UserInfo"/> for an incoming <see cref="UserInfoRequest"/>.
        /// </param>
        /// <param name="enqueueDownloadAction">The delegate invoked upon an receipt of an incoming <see cref="QueueDownloadRequest"/>.</param>
        /// <param name="placeInQueueResponseResolver">
        ///     The delegate used to resolve the <see cref="PlaceInQueueResponse"/> for an incoming request.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown when the value supplied for <paramref name="listenPort"/> is not between 1024 and 65535.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown when the value supplied for <paramref name="distributedChildLimit"/> is less than zero.
        /// </exception>
        public SoulseekClientOptions(
            bool enableListener                            = true,
            int listenPort                                 = 50000,
            bool enableDistributedNetwork                  = true,
            bool acceptDistributedChildren                 = true,
            int distributedChildLimit                      = 25,
            bool deduplicateSearchRequests                 = true,
            int messageTimeout                             = 5000,
            bool autoAcknowledgePrivateMessages            = true,
            bool autoAcknowledgePrivilegeNotifications     = true,
            bool acceptPrivateRoomInvitations              = false,
            DiagnosticLevel minimumDiagnosticLevel         = DiagnosticLevel.Info,
            int startingToken                              = 0,
            ConnectionOptions serverConnectionOptions      = null,
            ConnectionOptions peerConnectionOptions        = null,
            ConnectionOptions transferConnectionOptions    = null,
            ConnectionOptions incomingConnectionOptions    = null,
            ConnectionOptions distributedConnectionOptions = null,
            IUserEndPointCache userEndPointCache           = null,
            Func <string, int, SearchQuery, Task <SearchResponse> > searchResponseResolver = null,
            ISearchResponseCache searchResponseCache = null,
            Func <string, IPEndPoint, Task <BrowseResponse> > browseResponseResolver = null,
            Func <string, IPEndPoint, int, string, Task <Directory> > directoryContentsResponseResolver = null,
            Func <string, IPEndPoint, Task <UserInfo> > userInfoResponseResolver         = null,
            Func <string, IPEndPoint, string, Task> enqueueDownloadAction                = null,
            Func <string, IPEndPoint, string, Task <int?> > placeInQueueResponseResolver = null)
        {
            EnableListener = enableListener;
            ListenPort     = listenPort;

            if (ListenPort < 1024 || ListenPort > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException(nameof(listenPort), $"Must be between 1024 and {IPEndPoint.MaxPort}");
            }

            EnableDistributedNetwork  = enableDistributedNetwork;
            AcceptDistributedChildren = acceptDistributedChildren;
            DistributedChildLimit     = distributedChildLimit;

            if (DistributedChildLimit < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(distributedChildLimit), "Must be greater than or equal to zero");
            }

            DeduplicateSearchRequests = deduplicateSearchRequests;

            MessageTimeout = messageTimeout;
            AutoAcknowledgePrivateMessages        = autoAcknowledgePrivateMessages;
            AutoAcknowledgePrivilegeNotifications = autoAcknowledgePrivilegeNotifications;
            AcceptPrivateRoomInvitations          = acceptPrivateRoomInvitations;
            MinimumDiagnosticLevel = minimumDiagnosticLevel;
            StartingToken          = startingToken;

            ServerConnectionOptions      = (serverConnectionOptions ?? new ConnectionOptions()).WithoutInactivityTimeout();
            PeerConnectionOptions        = peerConnectionOptions ?? new ConnectionOptions();
            TransferConnectionOptions    = (transferConnectionOptions ?? new ConnectionOptions()).WithoutInactivityTimeout();
            IncomingConnectionOptions    = incomingConnectionOptions ?? new ConnectionOptions();
            DistributedConnectionOptions = distributedConnectionOptions ?? new ConnectionOptions();

            UserEndPointCache = userEndPointCache;

            SearchResponseResolver = searchResponseResolver;
            SearchResponseCache    = searchResponseCache;

            BrowseResponseResolver            = browseResponseResolver ?? defaultBrowseResponse;
            DirectoryContentsResponseResolver = directoryContentsResponseResolver;

            UserInfoResponseResolver     = userInfoResponseResolver ?? defaultUserInfoResponse;
            EnqueueDownloadAction        = enqueueDownloadAction ?? defaultEnqueueDownloadAction;
            PlaceInQueueResponseResolver = placeInQueueResponseResolver ?? defaultPlaceInQueueResponse;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="SoulseekClientOptionsPatch"/> class.
        /// </summary>
        /// <param name="enableListener">A value indicating whether to listen for incoming connections.</param>
        /// <param name="listenPort">The port on which to listen for incoming connections.</param>
        /// <param name="enableDistributedNetwork">A value indicating whether to establish distributed network connections.</param>
        /// <param name="acceptDistributedChildren">A value indicating whether to accept distributed child connections.</param>
        /// <param name="distributedChildLimit">The number of allowed distributed children.</param>
        /// <param name="maximumUploadSpeed">The total maximum allowable upload speed, in kibibytes per second.</param>
        /// <param name="maximumDownloadSpeed">The total maximum allowable download speed, in kibibytes per second.</param>
        /// <param name="deduplicateSearchRequests">
        ///     A value indicating whether duplicated distributed search requests should be discarded.
        /// </param>
        /// <param name="autoAcknowledgePrivateMessages">
        ///     A value indicating whether to automatically send a private message acknowledgement upon receipt.
        /// </param>
        /// <param name="autoAcknowledgePrivilegeNotifications">
        ///     A value indicating whether to automatically send a privilege notification acknowledgement upon receipt.
        /// </param>
        /// <param name="acceptPrivateRoomInvitations">A value indicating whether to accept private room invitations.</param>
        /// <param name="serverConnectionOptions">The options for the server message connection.</param>
        /// <param name="peerConnectionOptions">The options for peer message connections.</param>
        /// <param name="transferConnectionOptions">The options for peer transfer connections.</param>
        /// <param name="incomingConnectionOptions">The options for incoming connections.</param>
        /// <param name="distributedConnectionOptions">The options for distributed message connections.</param>
        /// <param name="userEndPointCache">The user endpoint cache to use when resolving user endpoints.</param>
        /// <param name="searchResponseResolver">
        ///     The delegate used to resolve the <see cref="SearchResponse"/> for an incoming <see cref="SearchRequest"/>.
        /// </param>
        /// <param name="searchResponseCache">
        ///     The search response cache to use when a response is not able to be delivered immediately.
        /// </param>
        /// <param name="browseResponseResolver">
        ///     The delegate used to resolve the <see cref="BrowseResponse"/> for an incoming <see cref="BrowseRequest"/>.
        /// </param>
        /// <param name="directoryContentsResolver">
        ///     The delegate used to resolve the <see cref="Directory"/> for an incoming <see cref="FolderContentsRequest"/>.
        /// </param>
        /// <param name="userInfoResolver">The delegate used to resolve the <see cref="UserInfo"/> for an incoming <see cref="UserInfoRequest"/>.</param>
        /// <param name="enqueueDownload">The delegate invoked upon an receipt of an incoming <see cref="QueueDownloadRequest"/>.</param>
        /// <param name="placeInQueueResolver">
        ///     The delegate used to resolve the <see cref="int"/> response for an incoming request.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown when the value supplied for <paramref name="listenPort"/> is not between 1024 and 65535.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown when the value supplied for <paramref name="distributedChildLimit"/> is less than zero.
        /// </exception>
        public SoulseekClientOptionsPatch(
            bool?enableListener                            = null,
            int?listenPort                                 = null,
            bool?enableDistributedNetwork                  = null,
            bool?acceptDistributedChildren                 = null,
            int?distributedChildLimit                      = null,
            int?maximumUploadSpeed                         = null,
            int?maximumDownloadSpeed                       = null,
            bool?deduplicateSearchRequests                 = null,
            bool?autoAcknowledgePrivateMessages            = null,
            bool?autoAcknowledgePrivilegeNotifications     = null,
            bool?acceptPrivateRoomInvitations              = null,
            ConnectionOptions serverConnectionOptions      = null,
            ConnectionOptions peerConnectionOptions        = null,
            ConnectionOptions transferConnectionOptions    = null,
            ConnectionOptions incomingConnectionOptions    = null,
            ConnectionOptions distributedConnectionOptions = null,
            IUserEndPointCache userEndPointCache           = null,
            Func <string, int, SearchQuery, Task <SearchResponse> > searchResponseResolver = null,
            ISearchResponseCache searchResponseCache = null,
            Func <string, IPEndPoint, Task <BrowseResponse> > browseResponseResolver            = null,
            Func <string, IPEndPoint, int, string, Task <Directory> > directoryContentsResolver = null,
            Func <string, IPEndPoint, Task <UserInfo> > userInfoResolver         = null,
            Func <string, IPEndPoint, string, Task> enqueueDownload              = null,
            Func <string, IPEndPoint, string, Task <int?> > placeInQueueResolver = null)
        {
            EnableListener = enableListener;
            ListenPort     = listenPort;

            if (ListenPort < 1024 || ListenPort > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException(nameof(listenPort), "Must be between 1024 and 65535");
            }

            EnableDistributedNetwork  = enableDistributedNetwork;
            AcceptDistributedChildren = acceptDistributedChildren;
            DistributedChildLimit     = distributedChildLimit;

            if (DistributedChildLimit < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(distributedChildLimit), "Must be greater than or equal to zero");
            }

            MaximumUploadSpeed   = maximumUploadSpeed;
            MaximumDownloadSpeed = maximumDownloadSpeed;

            DeduplicateSearchRequests = deduplicateSearchRequests;

            AutoAcknowledgePrivateMessages        = autoAcknowledgePrivateMessages;
            AutoAcknowledgePrivilegeNotifications = autoAcknowledgePrivilegeNotifications;
            AcceptPrivateRoomInvitations          = acceptPrivateRoomInvitations;

            ServerConnectionOptions      = serverConnectionOptions?.WithoutInactivityTimeout();
            PeerConnectionOptions        = peerConnectionOptions;
            TransferConnectionOptions    = transferConnectionOptions?.WithoutInactivityTimeout();
            IncomingConnectionOptions    = incomingConnectionOptions;
            DistributedConnectionOptions = distributedConnectionOptions;

            UserEndPointCache = userEndPointCache;

            SearchResponseResolver = searchResponseResolver;
            SearchResponseCache    = searchResponseCache;

            BrowseResponseResolver    = browseResponseResolver;
            DirectoryContentsResolver = directoryContentsResolver;

            UserInfoResolver     = userInfoResolver;
            EnqueueDownload      = enqueueDownload;
            PlaceInQueueResolver = placeInQueueResolver;
        }