Example #1
0
        public static void ValidateLogFile(List <BitmapContainer_Accessor> inputImages, string assembleFileName, SpritePackingType_Accessor packingType)
        {
            Assert.IsTrue(File.Exists("ReplaceLog.xml"));
            var doc = new XmlDocument();

            doc.Load("ReplaceLog.xml");
            Assert.IsNotNull(doc);

            foreach (var entry in inputImages)
            {
                InputImage_Accessor file  = entry.InputImage;
                XmlNodeList         nodes = doc.SelectNodes("//images/output/input/originalfile[.='" + file.AbsoluteImagePath.ToLowerInvariant() + "']");
                Assert.IsNotNull(nodes);
                Assert.AreEqual(1, nodes.Count, "There should be exactly one row exist for an image file in map Xml log file.");
                XmlNode node = nodes[0];
                Assert.IsNotNull(node);
                XmlNode inputNode = node.ParentNode;
                Assert.IsNotNull(inputNode);
                XmlNode outputNode = inputNode.ParentNode;
                Assert.IsNotNull(outputNode);
                if (outputNode.Attributes != null)
                {
                    string outputFile = outputNode.Attributes["file"].Value;

                    // A blank output file name means the input file was not assembled
                    if (string.IsNullOrEmpty(outputFile))
                    {
                        XmlNode genNode = inputNode.SelectSingleNode("comment");
                        Assert.IsNotNull(genNode);
                        Assert.IsNull(inputNode.SelectSingleNode("width"));
                        Assert.IsNull(inputNode.SelectSingleNode("height"));
                        Assert.IsNull(inputNode.SelectSingleNode("xposition"));
                        Assert.IsNull(inputNode.SelectSingleNode("yposition"));
                    }
                    else
                    {
                        Assert.IsTrue(outputNode.Attributes["file"].Value.Length > 0);
                        using (var bitmap = (Bitmap)Image.FromFile(file.AbsoluteImagePath))
                        {
                            Assert.AreEqual(inputNode.SelectSingleNode("width").InnerText, bitmap.Width.ToString());
                            Assert.AreEqual(inputNode.SelectSingleNode("height").InnerText, bitmap.Height.ToString());
                            Assert.IsTrue(inputNode.SelectSingleNode("xposition").InnerText != string.Empty);
                            Assert.IsTrue(inputNode.SelectSingleNode("yposition").InnerText != string.Empty);

                            if (packingType == SpritePackingType_Accessor.Vertical)
                            {
                                Assert.IsTrue(inputNode.SelectSingleNode(PositionInSprite).InnerText.Equals(file.Position.ToString(), StringComparison.OrdinalIgnoreCase));
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 private static void LoadData(List <BitmapContainer_Accessor> data, IEnumerable <string> files)
 {
     foreach (var path in files)
     {
         var inputImage = new InputImage_Accessor(path);
         var bitmap     = (Bitmap)Image.FromFile(path);
         data.Add(new BitmapContainer_Accessor(inputImage)
         {
             bitmap = bitmap
         });
     }
 }
Example #3
0
        /// <summary>Converts string array to List of InputImage. The conversion sets Image position for
        /// Individual Images to Left.</summary>
        /// <param name="imagePaths">String array of Image paths.</param>
        /// <returns>List of InputImage objects.</returns>
        internal static List <InputImage_Accessor> ConvertToInputImageList(string[] imagePaths)
        {
            if (imagePaths == null)
            {
                throw new ArgumentNullException("imagePaths");
            }

            var inputImages = new List <InputImage_Accessor>();

            foreach (var imagePath in imagePaths)
            {
                if (!string.IsNullOrEmpty(imagePath))
                {
                    var inputImage = new InputImage_Accessor(imagePath);
                    inputImages.Add(inputImage);
                }
            }

            return(inputImages);
        }
Example #4
0
        /// <summary>Parses image file paths.</summary>
        /// <param name="filePaths">Semi-colon separated list of file paths.</param>
        private static void ParseInputFilePaths(string filePaths)
        {
            if (string.IsNullOrEmpty(filePaths) || filePaths.Trim().Length == 0)
            {
                throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, ImageAssembleStrings.ValueMissingForInputParameterMessage, Paths));
            }

            const string Left  = "L";
            const string Right = "R";

            // The code below generates InputImageList from the filepath and position
            // pair values provided as input.
            var imageList = new List <InputImage_Accessor>();
            var fileNames = filePaths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var pathValue in fileNames)
            {
                var path = pathValue.Trim();
                if (!string.IsNullOrEmpty(path))
                {
                    if (path.Contains("|"))
                    {
                        var pairValue = path.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                        // Check filepath and position are not empty
                        if (pairValue.Length == 2 && pairValue[0].Trim().Length > 0 && pairValue[1].Trim().Length > 0)
                        {
                            // Throw an exception if invalid value is provided for Image Position
                            if (!pairValue[1].Trim().Equals(Right, StringComparison.OrdinalIgnoreCase) && !pairValue[1].Trim().Equals(Left, StringComparison.OrdinalIgnoreCase))
                            {
                                throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, ImageAssembleStrings.InvalidImagePositionMessage, pairValue[1], pairValue[0], string.Format(CultureInfo.CurrentUICulture, ImageAssembleStrings.ImagePositionValues, Left, Right)));
                            }

                            var inputImage = new InputImage_Accessor(pairValue[0].Trim());
                            inputImage.Position = pairValue[1].Trim().Equals(Right, StringComparison.OrdinalIgnoreCase) ? ImagePosition.Right : ImagePosition.Left;

                            // Verify bug# 956706 (Image Assemble Tool: When specifiying individual input file paths, duplicates are not detected and are drawn to the assembled image)
                            var result = imageList.Where(il => il.AbsoluteImagePath.Equals(inputImage.AbsoluteImagePath, StringComparison.OrdinalIgnoreCase) && il.Position == inputImage.Position);
                            if (result != null && result.Count() > 0)
                            {
                                // If Image already exists then throw exception for duplicate input files
                                throw new ImageAssembleException(string.Format(CultureInfo.CurrentCulture, ImageAssembleStrings.DuplicateInputFilePathsMessage, Paths, inputImage.AbsoluteImagePath));
                            }
                            else
                            {
                                imageList.Add(inputImage);
                            }
                        }
                        else
                        {
                            throw new ImageAssembleException(string.Format(CultureInfo.CurrentCulture, ImageAssembleStrings.InputFilesPathAndPositionMessage, pathValue));
                        }
                    }
                    else
                    {
                        throw new ImageAssembleException(string.Format(CultureInfo.CurrentCulture, ImageAssembleStrings.InputFilesMissingPositionMessage, pathValue));
                    }
                }
            }

            // If there are not InputImage in the list then throw an exception
            if (imageList.Count == 0)
            {
                throw new ImageAssembleException(ImageAssembleStrings.NoInputFileToProcessMessage);
            }

            // Thrown an exception if there are image file paths provides that do not exist.
            var notExist = imageList.Where(il => !File.Exists(il.AbsoluteImagePath)).ToList();

            if (notExist != null && notExist.Count > 0)
            {
                var sb = new StringBuilder(string.Format(CultureInfo.CurrentCulture, ImageAssembleStrings.IgnoredFilesMessage));
                sb.Append("\n");

                foreach (var ne in notExist)
                {
                    sb.Append(ne.AbsoluteImagePath + "\n");
                }

                throw new ImageAssembleException(sb.ToString());
            }

            // Set InputImageList for the class
            inputImageList = imageList;
        }