Ejemplo n.º 1
0
        /// <summary>
        /// Process a request for image comparison (client uses it to know if test succeeded or failed).
        /// </summary>
        /// <param name="binaryReader">The binary reader.</param>
        /// <param name="binaryWriter">The binary writer.</param>
        private void ProcessRequestImageComparisonStatus(ImageComparerClient imageComparerClient, BinaryReader binaryReader, BinaryWriter binaryWriter)
        {
            var testName = binaryReader.ReadString();

            var receivedImages = imageComparerClient.Images;
            List <TestResultServerImage> receivedImageForThisTest;

            lock (receivedImages)
            {
                if (!receivedImages.TryGetValue(testName, out receivedImageForThisTest))
                {
                    // No image, return false?!
                    binaryWriter.Write(true);
                    return;
                }
            }

            // perform comparisons
            var testSucceeded = true;

            foreach (var receivedImage in receivedImageForThisTest)
            {
                testSucceeded &= receivedImage.MeanSquareError == 0.0f;
            }

            binaryWriter.Write(testSucceeded);
            binaryWriter.Flush();
        }
Ejemplo n.º 2
0
        private void ClientThread(object res)
        {
            var client = (TcpClient)res;

            var imageComparerClient = new ImageComparerClient();

            lock (clients)
            {
                clients[client] = Thread.CurrentThread;
            }

            try
            {
                using (var networkStream = client.GetStream())
                {
                    var binaryReader = new BinaryReader(networkStream);
                    var binaryWriter = new BinaryWriter(networkStream);

                    // Read common information to all tests (device, branch, etc...)
                    imageComparerClient.Connection.Read(binaryReader);

                    // Process requests
                    while (true)
                    {
                        var messageType = (ImageServerMessageType)binaryReader.ReadInt32();
                        if (messageType == ImageServerMessageType.ConnectionFinished)
                        {
                            break;
                        }

                        switch (messageType)
                        {
                        case ImageServerMessageType.SendImage:
                            // Receives an image
                            ProcessSendImage(imageComparerClient, binaryReader, binaryWriter);
                            break;

                        case ImageServerMessageType.RequestImageComparisonStatus:
                            // Returns comparison status
                            ProcessRequestImageComparisonStatus(imageComparerClient, binaryReader, binaryWriter);
                            break;
                        }
                    }
                }

                client.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Client thread exception: {0}", e);
            }

            lock (clients)
            {
                clients.Remove(client);
            }
        }
Ejemplo n.º 3
0
        private void ProcessSendImage(ImageComparerClient imageComparerClient, BinaryReader reader, BinaryWriter binaryWriter)
        {
            var receivedImage = new TestResultServerImage(imageComparerClient);

            // Read image header
            receivedImage.ClientImage.Read(reader);

            Console.WriteLine(@"Receiving {0} from {1}", receivedImage.ClientImage.TestName, imageComparerClient.Connection.Serial);

            // Compute paths
            var goldPath = Path.Combine(baseOutputPath, receivedImage.GetGoldDirectory());
            var outputPath = Path.Combine(baseOutputPath, receivedImage.GetOutputDirectory());

            receivedImage.GoldPath = goldPath;
            receivedImage.OutputPath = outputPath;
            receivedImage.JsonPath = Path.Combine(baseOutputPath, "json");

            Directory.CreateDirectory(receivedImage.GoldPath);
            Directory.CreateDirectory(receivedImage.OutputPath);
            Directory.CreateDirectory(receivedImage.JsonPath);

            receivedImage.GoldFileName = Path.Combine(goldPath, receivedImage.GetFileName());
            receivedImage.ResultFileName = Path.Combine(outputPath, receivedImage.GetFileName());
            receivedImage.DiffFileName = Path.Combine(outputPath, receivedImage.GetDiffFileName());
            receivedImage.DiffNormFileName = Path.Combine(outputPath, receivedImage.GetNormDiffFileName());

            // Seems like image magick doesn't like to read from UNC path (size is OK but not data?)
            // Let's use temp path to do most of the work before copying
            var resultTempFileName = Path.GetTempPath() + Guid.NewGuid() + ".png";
            try
            {
                // Read image data
                using (var image = receivedImage.ClientImage.Image)
                using (var resultFileStream = File.OpenWrite(resultTempFileName))
                {
                    image.Save(resultFileStream, ImageFileType.Png);
                }

                CompareImage(receivedImage, resultTempFileName);
            }
            finally
            {
                File.Delete(resultTempFileName);
            }

            var receivedImages = imageComparerClient.Images;
            List<TestResultServerImage> receivedImageForThisTest;
            lock (receivedImages)
            {
                if (!receivedImages.TryGetValue(receivedImage.ClientImage.TestName, out receivedImageForThisTest))
                {
                    receivedImageForThisTest = new List<TestResultServerImage>();
                    receivedImage.FrameIndex = receivedImageForThisTest.Count;
                    receivedImages.Add(receivedImage.ClientImage.TestName, receivedImageForThisTest);
                }
            }

            receivedImageForThisTest.Add(receivedImage);

            // Send ack
            binaryWriter.Write(true);
        }
Ejemplo n.º 4
0
        private void ClientThread(object res)
        {
            var client = (TcpClient)res;

            var imageComparerClient = new ImageComparerClient();

            lock (clients)
            {
                clients[client] = Thread.CurrentThread;
            }

            try
            {
                using (var networkStream = client.GetStream())
                {
                    var binaryReader = new BinaryReader(networkStream);
                    var binaryWriter = new BinaryWriter(networkStream);

                    // Read common information to all tests (device, branch, etc...)
                    imageComparerClient.Connection.Read(binaryReader);

                    // Process requests
                    while (true)
                    {
                        var messageType = (ImageServerMessageType)binaryReader.ReadInt32();
                        if (messageType == ImageServerMessageType.ConnectionFinished)
                            break;

                        switch (messageType)
                        {
                            case ImageServerMessageType.SendImage:
                                // Receives an image
                                ProcessSendImage(imageComparerClient, binaryReader, binaryWriter);
                                break;
                            case ImageServerMessageType.RequestImageComparisonStatus:
                                // Returns comparison status
                                ProcessRequestImageComparisonStatus(imageComparerClient, binaryReader, binaryWriter);
                                break;
                        }
                    }
                }

                client.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Client thread exception: {0}", e);
            }

            lock (clients)
            {
                clients.Remove(client);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Process a request for image comparison (client uses it to know if test succeeded or failed).
        /// </summary>
        /// <param name="binaryReader">The binary reader.</param>
        /// <param name="binaryWriter">The binary writer.</param>
        private void ProcessRequestImageComparisonStatus(ImageComparerClient imageComparerClient, BinaryReader binaryReader, BinaryWriter binaryWriter)
        {
            var testName = binaryReader.ReadString();

            var receivedImages = imageComparerClient.Images;
            List<TestResultServerImage> receivedImageForThisTest;
            lock (receivedImages)
            {
                if (!receivedImages.TryGetValue(testName, out receivedImageForThisTest))
                {
                    // No image, return false?!
                    binaryWriter.Write(true);
                    return;
                }
            }

            // perform comparisons
            var testSucceeded = true;
            foreach (var receivedImage in receivedImageForThisTest)
            {
                testSucceeded &= receivedImage.MeanSquareError == 0.0f;
            }

            binaryWriter.Write(testSucceeded);
            binaryWriter.Flush();
        }
Ejemplo n.º 6
0
        private void ProcessSendImage(ImageComparerClient imageComparerClient, BinaryReader reader, BinaryWriter binaryWriter)
        {
            var receivedImage = new TestResultServerImage(imageComparerClient);

            // Read image header
            receivedImage.ClientImage.Read(reader);

            Console.WriteLine(@"Receiving {0} from {1}", receivedImage.ClientImage.TestName, imageComparerClient.Connection.Serial);

            // Compute paths
            var goldPath   = Path.Combine(baseOutputPath, receivedImage.GetGoldDirectory());
            var outputPath = Path.Combine(baseOutputPath, receivedImage.GetOutputDirectory());

            receivedImage.GoldPath   = goldPath;
            receivedImage.OutputPath = outputPath;
            receivedImage.JsonPath   = Path.Combine(baseOutputPath, "json");

            Directory.CreateDirectory(receivedImage.GoldPath);
            Directory.CreateDirectory(receivedImage.OutputPath);
            Directory.CreateDirectory(receivedImage.JsonPath);

            receivedImage.GoldFileName     = Path.Combine(goldPath, receivedImage.GetFileName());
            receivedImage.ResultFileName   = Path.Combine(outputPath, receivedImage.GetFileName());
            receivedImage.DiffFileName     = Path.Combine(outputPath, receivedImage.GetDiffFileName());
            receivedImage.DiffNormFileName = Path.Combine(outputPath, receivedImage.GetNormDiffFileName());

            // Seems like image magick doesn't like to read from UNC path (size is OK but not data?)
            // Let's use temp path to do most of the work before copying
            var resultTempFileName = Path.GetTempPath() + Guid.NewGuid() + ".png";

            try
            {
                // Read image data
                using (var image = receivedImage.ClientImage.Image)
                    using (var resultFileStream = File.OpenWrite(resultTempFileName))
                    {
                        image.Save(resultFileStream, ImageFileType.Png);
                    }

                CompareImage(receivedImage, resultTempFileName);
            }
            finally
            {
                File.Delete(resultTempFileName);
            }

            var receivedImages = imageComparerClient.Images;
            List <TestResultServerImage> receivedImageForThisTest;

            lock (receivedImages)
            {
                if (!receivedImages.TryGetValue(receivedImage.ClientImage.TestName, out receivedImageForThisTest))
                {
                    receivedImageForThisTest = new List <TestResultServerImage>();
                    receivedImage.FrameIndex = receivedImageForThisTest.Count;
                    receivedImages.Add(receivedImage.ClientImage.TestName, receivedImageForThisTest);
                }
            }

            receivedImageForThisTest.Add(receivedImage);

            // Send ack
            binaryWriter.Write(true);
        }
Ejemplo n.º 7
0
 public TestResultServerImage(ImageComparerClient client)
 {
     Client = client;
     ClientImage = new TestResultImage();
 }
Ejemplo n.º 8
0
 public TestResultServerImage(ImageComparerClient client)
 {
     Client      = client;
     ClientImage = new TestResultImage();
 }