Ejemplo n.º 1
0
        /// <summary>
        /// Create directory browser to browse remote directories.  Catch BrowseException
        /// and check code to understand e.g. permission issues, etc.
        /// </summary>
        /// <param name="folder">Folder name</param>
        /// <param name="cacheOnly">Only deliver from cache</param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public static async Task <IDirectoryBrowser> CreateDirectoryBrowserAsync(
            SocketAddress proxy, string folder, bool cacheOnly, CancellationToken ct)
        {
            var socket = new BrowseSocket(Socket.Provider, BrowseRequest.Dirpath);
            await socket.ConnectAsync(proxy, ct);

            await socket.BrowseBeginAsync(new ProxySocketAddress(folder ?? ""), ct);

            return(new DirectoryBrowser()
            {
                Socket = socket, CacheOnly = cacheOnly, Throw = true
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create service browser - returns service records, which identifiy either
        /// - domains (if both domain and type are null)
        /// - service types (if only domain are given)
        /// - Service names - with type and domain (if both type and domain are provded)
        /// </summary>
        /// <param name="proxy">Proxy endpoint(s) to use for resolve</param>
        /// <param name="type">service type to browse or null</param>
        /// <param name="domain">domain to browse or null</param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public static async Task <IDnsServiceBrowser> CreateServiceRecordBrowserAsync(
            SocketAddress proxy, string type, string domain, bool cacheOnly, CancellationToken ct)
        {
            var socket = new BrowseSocket(Socket.Provider, BrowseRequest.Service);
            await socket.ConnectAsync(proxy, ct);

            await socket.BrowseBeginAsync(new DnsServiceRecord {
                Type   = string.IsNullOrEmpty(type) ? null : type,
                Domain = string.IsNullOrEmpty(domain) ? null : domain
            }.ToSocketAddress(), ct);

            return(new ServiceRecordBrowser()
            {
                Socket = socket, CacheOnly = cacheOnly
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create host resolving enumerator (enumerates all addresses for a particular host address).
        /// Performs gethostbyaddr and gethostbyname type functionality (i.e. getaddrinfo).
        /// </summary>
        /// <param name="proxy">Proxy endpoint(s) to use for resolve</param>
        /// <param name="host">Address to resolve</param>
        /// <param name="cacheOnly">Only deliver from cache</param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public static async Task <IDnsHostEntryResolver> CreateHostEntryResolverAsync(
            SocketAddress proxy, SocketAddress host, bool cacheOnly, CancellationToken ct)
        {
            var address = host.AsProxySocketAddress();

            if (address == null)
            {
                throw new ArgumentException(nameof(host));
            }
            var socket = new BrowseSocket(Socket.Provider, BrowseRequest.Resolve);
            await socket.ConnectAsync(proxy, ct);

            await socket.BrowseBeginAsync(address, ct);

            return(new HostEntryResolver(address)
            {
                Socket = socket, CacheOnly = cacheOnly
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create service record resolving enumerator
        /// </summary>
        /// <param name="proxy">The proxy endpoint(s) to use</param>
        /// <param name="record">The service record to resolve</param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public static async Task <IDnsServiceResolver> CreateServiceRecordResolverAsync(
            SocketAddress proxy, DnsServiceRecord record, bool cacheOnly, CancellationToken ct)
        {
            if (string.IsNullOrEmpty(record.Name) || string.IsNullOrEmpty(record.Type) ||
                record.Removed)
            {
                throw new ArgumentException("Invalid service, no name, not type or been removed",
                                            nameof(record));
            }
            var socket = new BrowseSocket(Socket.Provider, BrowseRequest.Service);
            await socket.ConnectAsync(proxy ?? record.Interface, ct);

            await socket.BrowseBeginAsync(record.ToSocketAddress(), ct);

            return(new ServiceRecordResolver(record)
            {
                Socket = socket, CacheOnly = cacheOnly
            });
        }