Ejemplo n.º 1
0
        public void FindTypes(string namingAuthority, string[] scopes, ServerTypeFoundCallback cb)
        {
            String scopelist = null;

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

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

            wait = new AutoResetEvent(false);

            var collatedTypes = new HashSet <string>();

            var err = SlpNativeMethods.FindSrvTypes(hSlp, namingAuthority, scopelist,
                                                    delegate(SlpHandle h, string serviceType, SlpError errcode, IntPtr cookie) {
                if (errcode == SlpError.OK)
                {
                    foreach (var st in serviceType.Split(','))
                    {
                        if (!collatedTypes.Contains(st))
                        {
                            collatedTypes.Add(st);
                            if (cb != null)
                            {
                                cb(st);
                            }
                        }
                    }
                }
                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;
        }
Ejemplo n.º 2
0
        public void FindTypes( string namingAuthority, string[] scopes, ServerTypeFoundCallback cb )
        {
            String scopelist = null;
              if (scopes != null)
            scopelist = String.Join (",", scopes);

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

              wait = new AutoResetEvent(false);

              var collatedTypes = new HashSet<string>();

              var err = SlpNativeMethods.FindSrvTypes( hSlp, namingAuthority, scopelist,
            delegate ( SlpHandle h, string serviceType, SlpError errcode, IntPtr cookie ) {
              if ( errcode == SlpError.OK ){
            foreach ( var st in serviceType.Split(',') ){
              if ( !collatedTypes.Contains( st ) ){
                collatedTypes.Add( st );
                if ( cb != null ) cb( st );
              }
            }
              }
              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;
        }