Esempio n. 1
0
        /// <summary>
        /// Stops the current asynchronous search.
        /// </summary>
        public void Stop()
        {
            if (Logging.Enabled)
            {
                Logging.Log(
                    this,
                    string.Format(
                        "Async discovery stopping with - SearchURI:'{0}', ResolveNetworkInterface:'{1}', AddressFamily:'{2}'",
                        msSearchURI, mbResolveNetworkInterface, mafAddressFamily.ToString()), 1);
            }

            try
            {
                // If we are searching
                if (miFindHandle != 0)
                {
                    // Cancel the search
                    if (Logging.Enabled)
                    {
                        Logging.Log(this, "Cancelling async find");
                    }
                    mfFinder.CancelAsyncFind(miFindHandle);

                    // Ignore the callback
                    if (Logging.Enabled)
                    {
                        Logging.Log(this, "Notifying callback to ignore");
                    }
                    mdfcCallback.Ignore();

                    // Clear the callback
                    mdfcCallback = null;

                    // Reset the find handle
                    miFindHandle = 0;
                }
            }
            finally
            {
                if (Logging.Enabled)
                {
                    Logging.Log(this, "Finished async discovery stop", -1);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Stops the current asynchronous search.
        /// </summary>
        public void Stop()
        {
            if (Logging.Enabled)
                Logging.Log(
                    this,
                    string.Format(
                        "Async discovery stopping with - SearchURI:'{0}', ResolveNetworkInterface:'{1}', AddressFamily:'{2}'",
                        msSearchURI, mbResolveNetworkInterface, mafAddressFamily.ToString()), 1);

            try
            {
                // If we are searching
                if (miFindHandle != 0)
                {
                    // Cancel the search
                    if (Logging.Enabled)
                        Logging.Log(this, "Cancelling async find");
                    mfFinder.CancelAsyncFind(miFindHandle);

                    // Ignore the callback
                    if (Logging.Enabled)
                        Logging.Log(this, "Notifying callback to ignore");
                    mdfcCallback.Ignore();

                    // Clear the callback
                    mdfcCallback = null;

                    // Reset the find handle
                    miFindHandle = 0;
                }
            }
            finally
            {
                if (Logging.Enabled)
                    Logging.Log(this, "Finished async discovery stop", -1);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Starts an asynchronous search using current parameters if one isnt already in progress.
        /// </summary>
        /// <returns>True if a new asynchronous search was started, false otherwise.</returns>
        public bool Start()
        {
            if (Logging.Enabled)
                Logging.Log(
                    this,
                    string.Format(
                        "Async discovery starting with - SearchURI:'{0}', ResolveNetworkInterface:'{1}', AddressFamily:'{2}'",
                        msSearchURI, mbResolveNetworkInterface, mafAddressFamily.ToString()), 1);

            try
            {
                if (miFindHandle == 0)
                {
                    // Set the address family if its available
                    if (mfFinder is IUPnPAddressFamilyControl)
                    {
                        if (Logging.Enabled)
                            Logging.Log(this, "Setting address family");
                        ((IUPnPAddressFamilyControl)mfFinder).SetAddressFamily((int)mafAddressFamily);
                    }

                    // If we want to resolve the network interface
                    if (Logging.Enabled)
                        Logging.Log(this, "Creating callback");
                    if (mbResolveNetworkInterface)
                        // Then use the with interface device finder callback
                        mdfcCallback = new DeviceFinderCallbackWithInterface(this);
                    else
                        // Otherwise use the standard device finder callback
                        mdfcCallback = new DeviceFinderCallback(this);

                    string lsSearchURI;

                    // If search uri isnt specified
                    if (string.IsNullOrEmpty(msSearchURI))
                    {
                        // Search for all devices
                        if (Logging.Enabled)
                            Logging.Log(this, "Search URI not specified using all devices");
                        lsSearchURI = csAllDevices;
                    }
                    else
                        // Otherwise use search uri
                        lsSearchURI = msSearchURI;

                    // Create the find handle
                    if (Logging.Enabled)
                        Logging.Log(this, "Creating find handle");
                    miFindHandle = mfFinder.CreateAsyncFind(lsSearchURI, 0, mdfcCallback);

                    // Start the search
                    if (miFindHandle != 0)
                    {
                        if (Logging.Enabled)
                            Logging.Log(this, "Starting async find");
                        mfFinder.StartAsyncFind(miFindHandle);
                    }
                    else
                        if (Logging.Enabled)
                            Logging.Log(this, "Creation of find handle failed");

                    // Return true if the search was started
                    return miFindHandle != 0;
                }
                else
                {
                    // Already searching, return false
                    if (Logging.Enabled)
                        Logging.Log(this, "Discovery already in progress");
                    return false;
                }
            }
            finally
            {
                if (Logging.Enabled)
                    Logging.Log(this, "Finished async discovery start", -1);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Starts an asynchronous search using current parameters if one isnt already in progress.
        /// </summary>
        /// <returns>True if a new asynchronous search was started, false otherwise.</returns>
        public bool Start()
        {
            if (Logging.Enabled)
            {
                Logging.Log(
                    this,
                    string.Format(
                        "Async discovery starting with - SearchURI:'{0}', ResolveNetworkInterface:'{1}', AddressFamily:'{2}'",
                        msSearchURI, mbResolveNetworkInterface, mafAddressFamily.ToString()), 1);
            }

            try
            {
                if (miFindHandle == 0)
                {
                    // Set the address family if its available
                    if (mfFinder is IUPnPAddressFamilyControl)
                    {
                        if (Logging.Enabled)
                        {
                            Logging.Log(this, "Setting address family");
                        }
                        ((IUPnPAddressFamilyControl)mfFinder).SetAddressFamily((int)mafAddressFamily);
                    }

                    // If we want to resolve the network interface
                    if (Logging.Enabled)
                    {
                        Logging.Log(this, "Creating callback");
                    }
                    if (mbResolveNetworkInterface)
                    {
                        // Then use the with interface device finder callback
                        mdfcCallback = new DeviceFinderCallbackWithInterface(this);
                    }
                    else
                    {
                        // Otherwise use the standard device finder callback
                        mdfcCallback = new DeviceFinderCallback(this);
                    }

                    string lsSearchURI;

                    // If search uri isnt specified
                    if (string.IsNullOrEmpty(msSearchURI))
                    {
                        // Search for all devices
                        if (Logging.Enabled)
                        {
                            Logging.Log(this, "Search URI not specified using all devices");
                        }
                        lsSearchURI = csAllDevices;
                    }
                    else
                    {
                        // Otherwise use search uri
                        lsSearchURI = msSearchURI;
                    }

                    // Create the find handle
                    if (Logging.Enabled)
                    {
                        Logging.Log(this, "Creating find handle");
                    }
                    miFindHandle = mfFinder.CreateAsyncFind(lsSearchURI, 0, mdfcCallback);

                    // Start the search
                    if (miFindHandle != 0)
                    {
                        if (Logging.Enabled)
                        {
                            Logging.Log(this, "Starting async find");
                        }
                        mfFinder.StartAsyncFind(miFindHandle);
                    }
                    else
                    if (Logging.Enabled)
                    {
                        Logging.Log(this, "Creation of find handle failed");
                    }

                    // Return true if the search was started
                    return(miFindHandle != 0);
                }
                else
                {
                    // Already searching, return false
                    if (Logging.Enabled)
                    {
                        Logging.Log(this, "Discovery already in progress");
                    }
                    return(false);
                }
            }
            finally
            {
                if (Logging.Enabled)
                {
                    Logging.Log(this, "Finished async discovery start", -1);
                }
            }
        }