public string ProbeDevice(IPAddress address, int attempts)
            {
                Discovery discovery = new Discovery(_address);

                discovery.Discovered        += discovery_Discovered;
                discovery.DiscoveryFinished += discovery_DiscoveryFinished;

                for (int i = 1; i <= attempts; i++)
                {
                    bool stop;
                    lock (this)
                    {
                        stop = _stop;
                    }

                    if (stop)
                    {
                        return(string.Empty);
                    }

                    NotifyProgress(string.Format("Sending Probe Request {0}", i));

                    discovery.Probe(true, address, null, null);

                    System.Diagnostics.Debug.WriteLine(string.Format("{0}  Probe {1}",
                                                                     DateTime.Now.ToString("HH:mm:ss ffffff"), i));

                    DateTime startTime = DateTime.Now;
                    int      handle    = WaitHandle.WaitAny(new WaitHandle[] { _discoveredEvent, _timeoutEvent, _stopEvent }, Discovery.WS_DISCOVER_TIMEOUT + 3000);
                    DateTime endTime   = DateTime.Now;
                    discovery.Close();

                    if (handle >= 0)
                    {
                        if (handle == 0)
                        {
                            System.Diagnostics.Debug.WriteLine(string.Format("{0} Discovered",
                                                                             DateTime.Now.ToString("HH:mm:ss ffffff")));
                            break;
                        }
                        else if (handle == 1)
                        {
                            System.Diagnostics.Debug.WriteLine(string.Format("{0} Timeout",
                                                                             DateTime.Now.ToString("HH:mm:ss ffffff")));
                            NotifyProgress("No response");
                        }
                        else if (handle == 2)
                        {
                            System.Diagnostics.Debug.WriteLine("Device finder - stop");
                            throw new StopEventException();
                        }
                    }

                    System.Diagnostics.Debug.WriteLine(string.Format("{0}  continue...", DateTime.Now.ToString("HH:mm:ss ffffff")));
                }

                return(_probeMessage);
            }
Beispiel #2
0
        private SoapMessage <object> ReceiveHelloMessage(
            string stepName,
            string noMessageText,
            int timeout)
        {
            Discovery discovery = new Discovery(_nic.IP);

            discovery.HelloReceived     += OnHelloReceived;
            discovery.ReceiveError      += OnDiscoveryError;
            discovery.DiscoveryFinished += OnDiscoveryFinished;
            _eventTimeout.Reset();
            _eventHelloReceived.Reset();
            _eventByeReceived.Reset();
            _eventDiscoveryError.Reset();

            SoapMessage <object> response = null;

            try
            {
                discovery.WaitHello(_cameraIp, _cameraId, timeout);
                RunStep(() =>
                {
                    int res = WaitForResponse(new WaitHandle[] {
                        _eventHelloReceived,
                        _eventByeReceived,
                        _eventDiscoveryError,
                        _eventTimeout
                    });
                    if (res == 0)
                    {
                        response = _message;
                        if (_message != null)
                        {
                            string dump = System.Text.Encoding.UTF8.GetString(_message.Raw);
                            LogResponse(dump);
                        }
                    }
                    else if (res == 2)
                    {
                        string message = _error.Message + _error.InnerException ?? " " + _error.InnerException.Message;
                        throw new AssertException(message);
                    }
                    else if (noMessageText != null)
                    {
                        throw new AssertException(noMessageText);
                    }
                }, stepName);
            }
            finally
            {
                discovery.Close();
            }
            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// Receives message of specified type from DUT
        /// </summary>
        /// <param name="timeout">Time to wait</param>
        /// <param name="checkIP">if true wait from current device IP</param>
        /// <param name="checkDeviceId">if true wait for current device uuid</param>
        /// <param name="action">additional action after begin waiting</param>
        /// <returns>Message</returns>
        private SoapMessage <object> ReceiveMessageInternal(
            WaitMessageType type,
            string stepName,
            string noMessageText,
            bool checkIP,
            bool checkDeviceId,
            Action action,
            Action <SoapMessage <object> > validation,
            int timeout)
        {
            Discovery discovery = new Discovery(_nic.IP);
            bool      waitHello = (type & WaitMessageType.Hello) != 0;
            bool      waitBye   = (type & WaitMessageType.Bye) != 0;

            if (waitHello)
            {
                discovery.HelloReceived += OnHelloReceived;
            }
            if (waitBye)
            {
                discovery.ByeReceived += OnByeReceived;
            }
            discovery.ReceiveError      += OnDiscoveryError;
            discovery.DiscoveryFinished += OnDiscoveryFinished;
            _eventTimeout.Reset();
            _eventHelloReceived.Reset();
            _eventByeReceived.Reset();
            _eventDiscoveryError.Reset();
            SoapMessage <object> response = null;

            try
            {
                if (waitBye && waitHello)
                {
                    discovery.WaitByeOrHello(checkIP ? _cameraIp : null, checkDeviceId ? _cameraId : null, timeout);
                }
                else if (waitBye)
                {
                    discovery.WaitBye(checkIP ? _cameraIp : null, checkDeviceId ? _cameraId : null, timeout);
                }
                else
                {
                    discovery.WaitHello(checkIP ? _cameraIp : null, checkDeviceId ? _cameraId : null, timeout);
                }
                if (action != null)
                {
                    action();
                }
                RunStep(() =>
                {
                    int res = WaitForResponse(new WaitHandle[] {
                        _eventHelloReceived,
                        _eventByeReceived,
                        _eventDiscoveryError,
                        _eventTimeout
                    });
                    if (((res == 0) && waitHello) ||
                        ((res == 1) && waitBye))
                    {
                        response = _message;
                    }
                    else if (res == 2)
                    {
                        string message = _error.Message + _error.InnerException ?? " " + _error.InnerException.Message;
                        throw new AssertException(message);
                    }
                    else if (noMessageText != null)
                    {
                        throw new AssertException(noMessageText);
                    }
                    if (validation != null)
                    {
                        validation(response);
                    }
                }, stepName);
            }
            finally
            {
                discovery.Close();
            }
            return(response);
        }
Beispiel #4
0
        /// <summary>
        /// Receives message of specified type from DUT
        /// </summary>
        /// <param name="timeout">Time to wait</param>
        /// <param name="checkIP">if true wait from current device IP</param>
        /// <param name="checkDeviceId">if true wait for current device uuid</param>
        /// <param name="afterStartAction">additional afterStartAction after begin waiting</param>
        /// <returns>Message</returns>
        private SoapMessage <object> ReceiveMessageInternal(WaitMessageType type,
                                                            string stepName,
                                                            string noMessageText,
                                                            bool checkIP,
                                                            bool checkDeviceId,
                                                            Action afterStartAction,
                                                            Discovery.MessageFilterFunction messageFilter,
                                                            Action <SoapMessage <object> > validationAction,
                                                            int timeout)
        {
            Discovery discovery = new Discovery(_nic.IP)
            {
                MessageFilter = messageFilter
            };
            bool waitHello = (type & WaitMessageType.Hello) != 0;
            bool waitBye   = (type & WaitMessageType.Bye) != 0;

            if (waitHello)
            {
                discovery.HelloReceived += OnHelloReceived;
            }
            if (waitBye)
            {
                discovery.ByeReceived += OnByeReceived;
            }
            discovery.ReceiveError      += OnDiscoveryError;
            discovery.DiscoveryFinished += OnDiscoveryFinished;

            _eventTimeout.Reset();
            _eventHelloReceived.Reset();
            _eventByeReceived.Reset();
            _eventDiscoveryError.Reset();
            SoapMessage <object> response = null;

            try
            {
                var title = string.Format("Waiting for {0} message...", waitBye ? "Bye" : "Hello");
                if (waitBye && waitHello)
                {
                    title = string.Format("Waiting for {0} message...", "Bye or Hello");
                }

                {
                    BeginStep(title);
                    if (waitBye && waitHello)
                    {
                        discovery.WaitByeOrHello(checkIP ? _cameraIp : null, checkDeviceId ? _cameraId : null, timeout);
                    }
                    else if (waitBye)
                    {
                        discovery.WaitBye(checkIP ? _cameraIp : null, checkDeviceId ? _cameraId : null, timeout);
                    }
                    else
                    {
                        discovery.WaitHello(checkIP ? _cameraIp : null, checkDeviceId ? _cameraId : null, timeout);
                    }
                    StepPassed();
                }

                if (afterStartAction != null)
                {
                    afterStartAction();
                }
                RunStep(() =>
                {
                    int res = WaitForResponse(new WaitHandle[] { _eventHelloReceived,
                                                                 _eventByeReceived,
                                                                 _eventDiscoveryError,
                                                                 _eventTimeout });

                    if (((res == 0) && waitHello) || ((res == 1) && waitBye))
                    {
                        response = _message;
                        if (_message != null)
                        {
                            string dump = System.Text.Encoding.UTF8.GetString(_message.Raw);
                            LogResponse(dump);
                        }
                    }
                    else if (res == 2)
                    {
                        string message = _error.Message + _error.InnerException ?? " " + _error.InnerException.Message;
                        throw new AssertException(message);
                    }
                    else if (noMessageText != null)
                    {
                        throw new AssertException(noMessageText);
                    }
                    if (validationAction != null)
                    {
                        validationAction(response);
                    }
                }, stepName);
            }
            finally
            {
                discovery.Close();
            }
            return(response);
        }