示例#1
0
        /// <summary>
        /// Calls SlpFindSrvs and executes cb for every result found.
        /// </summary>
        /// <param name="serviceType">
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="scopes">
        /// A <see cref="System.String[]"/>
        /// </param>
        /// <param name="cb">
        /// A <see cref="ServerFoundCallback"/>
        /// </param>
        public void Find(string serviceType, string[] scopes, ServerFoundCallback cb)
        {
            var scopelist        = String.Empty;
            var collatedServices = new HashSet <string>();

            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }
            if (serviceType.Equals(string.Empty))
            {
                throw new SlpException(SlpError.TYPE_ERROR);
            }

            if (scopes != null)
            {
                scopelist = String.Join(",", scopes);
            }

            if (wait != null)
            {
                throw new SlpException(SlpError.HANDLE_IN_USE);
            }
            wait = new AutoResetEvent(false);

            var err = SlpNativeMethods.FindSrvs(hSlp, serviceType, scopelist, String.Empty,
                                                delegate(SlpHandle h, string url, UInt16 lifetime, SlpError errcode, IntPtr cookie) {
                if (errcode == SlpError.OK)
                {
                    if (!collatedServices.Contains(url))
                    {
                        collatedServices.Add(url);
                        if (cb != null)
                        {
                            cb(url, lifetime);
                        }
                    }
                }
                if (errcode == SlpError.LAST_CALL)
                {
                    wait.Set();
                    return(SlpBoolean.False);
                }
                return(SlpBoolean.True);
            }, IntPtr.Zero);

            if (err != SlpError.OK)
            {
                throw new SlpException(err);
            }

            wait.WaitOne();
            wait = null;
        }
示例#2
0
        /// <summary>
        /// Calls SlpFindSrvs and executes cb for every result found.
        /// </summary>
        /// <param name="serviceType">
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="scopes">
        /// A <see cref="System.String[]"/>
        /// </param>
        /// <param name="cb">
        /// A <see cref="ServerFoundCallback"/>
        /// </param>
        public void Find(string serviceType, string[] scopes, ServerFoundCallback cb)
        {
            var scopelist = String.Empty;
              var collatedServices = new HashSet<string>();
              if (serviceType == null)
            throw new ArgumentNullException ("serviceType");
              if (serviceType.Equals (string.Empty))
            throw new SlpException ( SlpError.TYPE_ERROR );

              if (scopes != null)
            scopelist = String.Join (",", scopes);

              if (wait != null) throw new SlpException(SlpError.HANDLE_IN_USE);
              wait = new AutoResetEvent(false);

              var err = SlpNativeMethods.FindSrvs (hSlp, serviceType, scopelist, String.Empty,
            delegate ( SlpHandle h, string url, UInt16 lifetime, SlpError errcode, IntPtr cookie ) {
              if ( errcode == SlpError.OK ){
            if ( !collatedServices.Contains(url) ){
              collatedServices.Add(url);
              if (cb != null) cb(url, lifetime);
            }
              }
              if (errcode == SlpError.LAST_CALL)
              {
              wait.Set();
              return SlpBoolean.False;
              }
              return SlpBoolean.True;
            }, IntPtr.Zero);
              if (err != SlpError.OK)
            throw new SlpException ( err );

              wait.WaitOne();
              wait = null;
        }