コード例 #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 networkStream = ImageComparisonServer.GetStream();
                var binaryWriter  = new BinaryWriter(networkStream);
                var binaryReader  = new BinaryReader(networkStream);

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

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

                return(binaryReader.ReadBoolean());
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #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);
                    TestGameBase.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;
            }
        }
コード例 #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);
                    TestGameBase.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;
            }
        }
コード例 #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);

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

                return binaryReader.ReadBoolean();
            }
            catch (Exception)
            {
                throw;
            }
        }