Ejemplo n.º 1
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="testResultImage">The image to send.</param>
        public static bool SendImage(TestResultImage testResultImage)
        {
            if (!Connect())
            {
                throw new InvalidOperationException("Could not connect to image comparer server");
            }

            try
            {
                if (testResultImage.TestName == null && NUnit.Framework.TestContext.CurrentContext != null)
                {
                    testResultImage.TestName = NUnit.Framework.TestContext.CurrentContext.Test.FullName;
                }

                var binaryWriter = new BinaryWriter(ImageComparisonServer.WriteStream);
                var binaryReader = new BinaryReader(ImageComparisonServer.ReadStream);

                // Header
                binaryWriter.Write((int)ImageServerMessageType.SendImage);

                GameTestBase.TestGameLogger.Info(@"Sending image information...");
                testResultImage.Write(binaryWriter);

                return(binaryReader.ReadBoolean());
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="testResultImage">The image to send.</param>
        public static bool SendImage(TestResultImage testResultImage)
        {
            var task = SendImageAsync(testResultImage);

            task.Wait();
            return(task.Result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="testResultImage">The image to send.</param>
        public static async Task <bool> SendImageAsync(TestResultImage testResultImage)
        {
            if (!Connect())
            {
                throw new InvalidOperationException("Could not connect to image comparer server");
            }

            try
            {
                if (testResultImage.TestName == null && NUnit.Framework.TestContext.CurrentContext != null)
                {
                    testResultImage.TestName = NUnit.Framework.TestContext.CurrentContext.Test.FullName;
                }

                // Send initial parameters
                using (var memoryStream = new MemoryStream())
                {
                    var binaryWriter = new BinaryWriter(memoryStream);

                    // Header
                    binaryWriter.Write((int)ImageServerMessageType.SendImage);
                    GameTestBase.TestGameLogger.Info(@"Sending image information...");
                    testResultImage.Write(binaryWriter);

                    var dataWriter = new DataWriter(imageComparisonServer.OutputStream);
                    dataWriter.WriteBytes(memoryStream.ToArray());
                    await dataWriter.StoreAsync();

                    await dataWriter.FlushAsync();

                    dataWriter.DetachStream();
                }

                var dataReader = new DataReader(imageComparisonServer.InputStream);
                await dataReader.LoadAsync(1);

                var result = dataReader.ReadBoolean();
                dataReader.DetachStream();

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="testResultImage">The image to send.</param>
        public static bool SendImage(TestResultImage testResultImage)
        {
            if (!Connect())
                throw new InvalidOperationException("Could not connect to image comparer server");

            try
            {
                if (testResultImage.TestName == null && NUnit.Framework.TestContext.CurrentContext != null)
                {
                    testResultImage.TestName = NUnit.Framework.TestContext.CurrentContext.Test.FullName;
                }


                var networkStream = ImageComparisonServer.GetStream();
                var binaryWriter = new BinaryWriter(networkStream);
                var binaryReader = new BinaryReader(networkStream);

                // Header
                binaryWriter.Write((int)ImageServerMessageType.SendImage);

                GameTestBase.TestGameLogger.Info(@"Sending image information...");
                testResultImage.Write(binaryWriter);

                return binaryReader.ReadBoolean();
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="testResultImage">The image to send.</param>
        public static bool SendImage(TestResultImage testResultImage)
        {
            if (!Connect())
                throw new InvalidOperationException("Could not connect to image comparer server");

            try
            {
                if (testResultImage.TestName == null && NUnit.Framework.TestContext.CurrentContext != null)
                {
                    testResultImage.TestName = NUnit.Framework.TestContext.CurrentContext.Test.FullName;
                }

                var binaryWriter = new BinaryWriter(ImageComparisonServer.WriteStream);
                var binaryReader = new BinaryReader(ImageComparisonServer.ReadStream);

                // Header
                binaryWriter.Write((int)ImageServerMessageType.SendImage);

                GameTestBase.TestGameLogger.Info(@"Sending image information...");

                var sw = new Stopwatch();
                sw.Start();

                testResultImage.Write(binaryWriter);

                sw.Stop();
                GameTestBase.TestGameLogger.Info("Total calculation time: {0}", sw.Elapsed);

                return binaryReader.ReadBoolean();
            }
            catch (Exception)
            {
                return false;
            }
        }
Ejemplo n.º 6
0
 public TestResultServerImage(ImageComparerClient client)
 {
     Client = client;
     ClientImage = new TestResultImage();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Send the data of the test to the server.
 /// </summary>
 /// <param name="testResultImage">The image to send.</param>
 public static bool SendImage(TestResultImage testResultImage)
 {
     var task = SendImageAsync(testResultImage);
     task.Wait();
     return task.Result;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="testResultImage">The image to send.</param>
        public static async Task<bool> SendImageAsync(TestResultImage testResultImage)
        {
            if (!Connect())
                throw new InvalidOperationException("Could not connect to image comparer server");
			
            try
            {
                if (testResultImage.TestName == null && NUnit.Framework.TestContext.CurrentContext != null)
                {
                    testResultImage.TestName = NUnit.Framework.TestContext.CurrentContext.Test.FullName;
                }

                // Send initial parameters
                using (var memoryStream = new MemoryStream())
                {
                    var binaryWriter = new BinaryWriter(memoryStream);

                    // Header
                    binaryWriter.Write((int)ImageServerMessageType.SendImage);
                    GameTestBase.TestGameLogger.Info(@"Sending image information...");
                    testResultImage.Write(binaryWriter);

                    var dataWriter = new DataWriter(imageComparisonServer.OutputStream);
                    dataWriter.WriteBytes(memoryStream.ToArray());
                    await dataWriter.StoreAsync();
                    await dataWriter.FlushAsync();
                    dataWriter.DetachStream();
                }

                var dataReader = new DataReader(imageComparisonServer.InputStream);
                await dataReader.LoadAsync(1);
                var result = dataReader.ReadBoolean();
                dataReader.DetachStream();

                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }