Esempio n. 1
0
        /// <summary>
        /// Queries for all instances of a particular service on the local network.
        /// </summary>
        /// <param name="name">The instance to query, for example "My WebServer._http._tcp"</param>
        /// <param name="fields">The details to query</param>
        /// <returns>The service instance</returns>
        /// <remarks>Excluding some fields (for example the IP address) may reduce the time taken</remarks>
        public ServiceInstance LookupInstance(string name, ServiceInstanceFields fields)
        {
            ServiceInstance instance = new ServiceInstance(name);

            if ((fields & ServiceInstanceFields.DisplayName) != 0)
            {
                instance.DisplayName = DecodeDisplayName(name);
            }

            if ((fields & ServiceInstanceFields.Parameters) != 0)
            {
                instance.Parameters = LookupInstanceDetails(name);
            }

            if ((fields & ServiceInstanceFields.DnsAddresses) != 0 ||
                (fields & ServiceInstanceFields.IPAddresses) != 0)
            {
                instance.EndPoints = LookupInstanceEndpoints(name, fields);
            }

            return(instance);
        }
        /// <summary>
        /// Queries for all instances of a particular service on the local network.
        /// </summary>
        /// <param name="name">The instance to query, for example "My WebServer._http._tcp"</param>
        /// <param name="fields">The details to query</param>
        /// <returns>The service instance</returns>
        /// <remarks>Excluding some fields (for example the IP address) may reduce the time taken</remarks>
        public ServiceInstance LookupInstance(string name, ServiceInstanceFields fields)
        {
            ServiceInstance instance = new ServiceInstance(name);

            if ((fields & ServiceInstanceFields.DisplayName) != 0)
            {
                instance.DisplayName = DecodeDisplayName(name);
            }

            if ((fields & ServiceInstanceFields.Parameters) != 0)
            {
                instance.Parameters = LookupInstanceDetails(name);
            }

            if ((fields & ServiceInstanceFields.DnsAddresses) != 0
                || (fields & ServiceInstanceFields.IPAddresses) != 0)
            {
                instance.EndPoints = LookupInstanceEndpoints(name, fields);
            }

            return instance;
        }
        /// <summary>
        /// Connects to the service.
        /// </summary>
        /// <param name="userName">The username to use, if the owner of the Mac / PC is prompted.</param>
        /// <param name="computerName">The computer name to use, if the owner of the Mac / PC is prompted.</param>
        /// <param name="maxWaitSecs">The maximum number of seconds to wait to be granted access.</param>
        public void Connect(string userName, string computerName, int maxWaitSecs)
        {
            var sysParams = GetParams("sys");

            int volFlags = 0;
            string volFlagsStr;
            if (sysParams.TryGetValue("adVF", out volFlagsStr))
            {
                volFlags = ParseInt(volFlagsStr);
            }

            if ((volFlags & 0x200) != 0)
            {
                _userName = userName;
                AskForAccess(userName, computerName, maxWaitSecs);

                // Flush any stale mDNS data - the server advertises extra info (such as the discs available)
                // after a client is granted permission to access a disc.
                _sdClient.FlushCache();

                _instance = _sdClient.LookupInstance(_instance.Name, ServiceInstanceFields.All);
            }
        }
 internal OpticalDiscService(ServiceInstance instance, ServiceDiscoveryClient sdClient)
 {
     _sdClient = sdClient;
     _instance = instance;
 }