Esempio n. 1
0
        private bool SendDTO(ResultDTO dto)
        {
            if (m_LostConnection)
            {
                return(false);
            }
#if UTT_SOCKETS_SUPPORTED
            try
            {
                using (var tcpClient = new TcpClient())
                {
                    var result  = tcpClient.BeginConnect(m_Ip, m_Port, null, null);
                    var success = result.AsyncWaitHandle.WaitOne(m_ConnectionTimeout);
                    if (!success)
                    {
                        return(false);
                    }
                    try
                    {
                        tcpClient.EndConnect(result);
                    }
                    catch (SocketException)
                    {
                        m_LostConnection = true;
                        return(false);
                    }

                    var bf = new DTOFormatter();
                    bf.Serialize(tcpClient.GetStream(), dto);
                    tcpClient.GetStream().Close();
                    tcpClient.Close();
                    Debug.Log("Sent " + dto.messageType);
                }
            }
            catch (SocketException e)
            {
                Debug.LogException(e);
                m_LostConnection = true;
                return(false);
            }
#endif  // if UTT_SOCKETS_SUPPORTED
            return(true);
        }
Esempio n. 2
0
        private bool SendDTO(ResultDTO dto)
        {
            if (m_LostConnection) return false;
#if UTT_SOCKETS_SUPPORTED 
            try
            {
                using (var tcpClient = new TcpClient())
                {
                    var result = tcpClient.BeginConnect(m_Ip, m_Port, null, null);
                    var success = result.AsyncWaitHandle.WaitOne(m_ConnectionTimeout);
                    if (!success)
                    {
                        return false;
                    }
                    try
                    {
                        tcpClient.EndConnect(result);
                    }
                    catch (SocketException)
                    {
                        m_LostConnection = true;
                        return false;
                    }

                    var bf = new DTOFormatter();
                    bf.Serialize(tcpClient.GetStream(), dto);
                    tcpClient.GetStream().Close();
                    tcpClient.Close();
                    Debug.Log("Sent " + dto.messageType);
                }
            }
            catch (SocketException e)
            {
                Debug.LogException(e);
                m_LostConnection = true;
                return false;
            }
#endif  // if UTT_SOCKETS_SUPPORTED
            return true;
        }
 private bool SendDTO(ResultDTO dto)
 {
     if (m_LostConnection)
     {
         return(false);
     }
     try
     {
         using (TcpClient tcpClient = new TcpClient())
         {
             IAsyncResult asyncResult = tcpClient.BeginConnect(m_Ip, m_Port, null, null);
             if (!asyncResult.AsyncWaitHandle.WaitOne(m_ConnectionTimeout))
             {
                 return(false);
             }
             try
             {
                 tcpClient.EndConnect(asyncResult);
             }
             catch (SocketException)
             {
                 m_LostConnection = true;
                 return(false);
             }
             DTOFormatter dTOFormatter = new DTOFormatter();
             dTOFormatter.Serialize(tcpClient.GetStream(), dto);
             tcpClient.GetStream().Close();
             tcpClient.Close();
             Debug.Log("Sent " + dto.messageType);
         }
     }
     catch (SocketException exception)
     {
         Debug.LogException(exception);
         m_LostConnection = true;
         return(false);
     }
     return(true);
 }
        private void AcceptCallback(TcpClient client)
        {
            m_Repaint = true;
            ResultDTO dto;

            try
            {
                m_LastMessageReceived = DateTime.Now;
                using (var stream = client.GetStream())
                {
                    var bf = new DTOFormatter();
                    dto = (ResultDTO)bf.Deserialize(stream);
                    stream.Close();
                }
                client.Close();
            }
            catch (ObjectDisposedException e)
            {
                Debug.LogException(e);
                m_StatusLabel = "Got disconnected";
                return;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return;
            }

            switch (dto.messageType)
            {
            case ResultDTO.MessageType.TestStarted:
                m_StatusLabel = dto.testName;
                m_TestTimeout = TimeSpan.FromSeconds(dto.testTimeout);
                break;

            case ResultDTO.MessageType.TestFinished:
                m_TestResults.Add(dto.testResult);
                m_TestTimeout = TimeSpan.Zero;
                if (dto.testResult.Executed && dto.testResult.ResultState != TestResultState.Ignored && !dto.testResult.IsSuccess)
                {
                    m_TestFailed = true;
                }
                break;

            case ResultDTO.MessageType.RunStarted:
                m_TestResults = new List <ITestResult>();
                m_StatusLabel = "Run started: " + dto.loadedLevelName;
                break;

            case ResultDTO.MessageType.RunFinished:
                WriteResultsToLog(dto, m_TestResults);
                if (!string.IsNullOrEmpty(m_Configuration.resultsDir))
                {
                    var platform     = m_Configuration.runInEditor ? "Editor" : m_Configuration.buildTarget.ToString();
                    var resultWriter = new XmlResultWriter(dto.loadedLevelName, platform, m_TestResults.ToArray());
                    try
                    {
                        if (!Directory.Exists(m_Configuration.resultsDir))
                        {
                            Directory.CreateDirectory(m_Configuration.resultsDir);
                        }
                        var filePath = Path.Combine(m_Configuration.resultsDir, dto.loadedLevelName + ".xml");
                        File.WriteAllText(filePath, resultWriter.GetTestResult());
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
                break;

            case ResultDTO.MessageType.AllScenesFinished:
                m_Running     = false;
                m_RunFinished = true;
                break;

            case ResultDTO.MessageType.Ping:
                break;
            }
        }
Esempio n. 5
0
        private void AcceptCallback(TcpClient client)
        {
            m_Repaint = true;
            ResultDTO dto;
            try
            {
                m_LastMessageReceived = DateTime.Now;
                using (var stream = client.GetStream())
                {
                    var bf = new DTOFormatter();
                    dto = (ResultDTO)bf.Deserialize(stream);
                    stream.Close();
                }
                client.Close();
            }
            catch (ObjectDisposedException e)
            {
                Debug.LogException(e);
                m_StatusLabel = "Got disconnected";
                return;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return;
            }

            switch (dto.messageType)
            {
                case ResultDTO.MessageType.TestStarted:
                    m_StatusLabel = dto.testName;
                    m_TestTimeout = TimeSpan.FromSeconds(dto.testTimeout);
                    break;
                case ResultDTO.MessageType.TestFinished:
                    m_TestResults.Add(dto.testResult);
                    m_TestTimeout = TimeSpan.Zero;
                    if (dto.testResult.Executed && dto.testResult.ResultState != TestResultState.Ignored && !dto.testResult.IsSuccess)
                        m_TestFailed = true;
                    break;
                case ResultDTO.MessageType.RunStarted:
                    m_TestResults = new List<ITestResult>();
                    m_StatusLabel = "Run started: " + dto.loadedLevelName;
                    break;
                case ResultDTO.MessageType.RunFinished:
                    WriteResultsToLog(dto, m_TestResults);
                    if (!string.IsNullOrEmpty(m_Configuration.resultsDir))
                    {
                        var platform = m_Configuration.runInEditor ? "Editor" : m_Configuration.buildTarget.ToString();
                        var resultWriter = new XmlResultWriter(dto.loadedLevelName, platform, m_TestResults.ToArray());
                        try
                        {
                            if (!Directory.Exists(m_Configuration.resultsDir))
                            {
                                Directory.CreateDirectory(m_Configuration.resultsDir);
                            }
                            var filePath = Path.Combine(m_Configuration.resultsDir, dto.loadedLevelName + ".xml");
                            File.WriteAllText(filePath, resultWriter.GetTestResult());
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                        }
                    }
                    break;
            case ResultDTO.MessageType.AllScenesFinished:
                m_Running = false;
                m_RunFinished = true;
                break;
            case ResultDTO.MessageType.Ping:
                    break;
            }
        }