Beispiel #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);
            }
        }
Beispiel #2
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;
            }
        }
        /// <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;
            }
        }
        /// <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;
            }
        }
        /// <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;
            }
        }