MaskImagesImport - Copy.cs 15.5 KB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Xml;

namespace AIAWindowsUtility
{
    public partial class MaskImagesImport : Form
    {
        public MaskImagesImport()
        {
            InitializeComponent();
        }

        private void btnImportFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog1.Filter = "Extensible Markup Language (*.xml)|*.xml|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;

            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                if (!String.Equals(Path.GetExtension(openFileDialog1.FileName),
                       ".xml",
                       StringComparison.OrdinalIgnoreCase))
                {
                    // Invalid file type selected; display an error.
                    MessageBox.Show("The type of the selected file is not supported by this application. You must select an XML file.",
                                    "Invalid File Type",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else
                {
                    if (openFileDialog1.FileName.Length > 0) //If a file is open
                    {

                        string path = openFileDialog1.FileName; // The Path to the .Xml file //

                        FileStream READER = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Set up the filestream (READER) //

                        System.Xml.XmlDocument CompSpecs = new System.Xml.XmlDocument();// Set up the XmlDocument (CompSpecs) //

                        CompSpecs.Load(READER); //Load the data from the file into the XmlDocument (CompSpecs) //

                        XmlNodeList dlNodeList = CompSpecs.SelectNodes("/response/dl");
                        foreach (XmlNode dlNode in dlNodeList)
                        {

                            int folderNameValue = Convert.ToInt32(dlNode.Attributes["ln"].Value);
                            string folderName = (folderNameValue - 1).ToString();

                            string layersFolder = @"I:\100-PROJECTS\100-REQUIREMENTS\400AIA\Module\DA\images\Gender\Female\DissectibleBodyView\FemaleAnterior(voId=5)\Layers\" + folderName;
                            if (Directory.Exists(layersFolder))
                            {
                                Console.WriteLine("Layer: " + folderName + " is already created");

                                 XmlNodeList mapNodeList = dlNode.SelectNodes("map");

                                string imageFileSourcePath = @"I:\100-PROJECTS\400-DEVELOPMENT\ADAMEduAIA\Flex\v107\content\en_US\da_dat_img\75\5\";

                                foreach (XmlNode mapNode in mapNodeList)
                                {
                                    string bodyRegionFolder = mapNode.Attributes["brId"].Value.ToString();
                                    string bodyRegionFolderPath = layersFolder + @"\" + bodyRegionFolder + @"\";

                                    if (Directory.Exists(bodyRegionFolderPath))
                                    {
                                        if (folderName == "0")
                                        {
                                            DirectoryInfo bodyRegionDr = Directory.CreateDirectory(bodyRegionFolderPath);
                                            XmlNode artNode = mapNode.SelectSingleNode("art");
                                            string skinToneName = artNode.Attributes["sktn"].Value.ToString();
                                            DirectoryInfo skinToneDr = Directory.CreateDirectory(bodyRegionFolderPath + skinToneName);
                                            string imageFileName = artNode.Attributes["compId"].Value.ToString();
                                            string[] imagenameSplit = imageFileName.Split('.');
                                            string maskImageName = imagenameSplit[0] + "_mci.png";

                                            imageFileSourcePath = imageFileSourcePath + maskImageName;

                                            string skinToneDirectoryPath = bodyRegionFolderPath + skinToneName + @"\" + maskImageName;
                                            if (File.Exists(imageFileSourcePath))
                                            {
                                                File.Copy(imageFileSourcePath, skinToneDirectoryPath);
                                            }
                                            else
                                            {
                                                System.IO.File.WriteAllText("~/logs/imageNotFound_" + System.DateTime.Now.ToString("MMddyyyy") + ".txt", "not found at :" + imageFileSourcePath + " for l;ayer no: " + folderName + " Body Region Id: " + bodyRegionFolder);
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("BodyRegion: " + bodyRegionFolder + " is already created");


                                        }


                                    }
                                    else
                                    {
                                        if (folderName == "0")
                                        {
                                            DirectoryInfo bodyRegionDr = Directory.CreateDirectory(bodyRegionFolderPath);
                                            XmlNode artNode = mapNode.SelectSingleNode("art");
                                            string skinToneName = artNode.Attributes["sktn"].Value.ToString();
                                            DirectoryInfo skinToneDr = Directory.CreateDirectory(bodyRegionFolderPath + skinToneName);
                                            string imageFileName = artNode.Attributes["compId"].Value.ToString();
                                            string[] imagenameSplit = imageFileName.Split('.');
                                            string maskImageName = imagenameSplit[0] + "_mci.png";

                                            imageFileSourcePath = imageFileSourcePath + maskImageName;

                                            string skinToneDirectoryPath = bodyRegionFolderPath + skinToneName + @"\" + maskImageName;
                                            if (File.Exists(imageFileSourcePath))
                                            {
                                                File.Copy(imageFileSourcePath, skinToneDirectoryPath);
                                            }
                                            else
                                            {
                                                System.IO.File.WriteAllText("~/logs/imageNotFound_" + System.DateTime.Now.ToString("MMddyyyy") + ".txt", "not found at :" + imageFileSourcePath + " for l;ayer no: " + folderName + " Body Region Id: " + bodyRegionFolder);
                                            }
                                        }
                                        else
                                        {
                                            DirectoryInfo bodyRegionDr = Directory.CreateDirectory(bodyRegionFolderPath);

                                            XmlNode artNode = mapNode.SelectSingleNode("art");
                                            string imageFileName = artNode.Attributes["compId"].Value.ToString();


                                            string[] imagenameSplit = imageFileName.Split('.');
                                            string maskImageName = imagenameSplit[0] + "_mci." + imagenameSplit[1];

                                            

                                            if (File.Exists(imageFileSourcePath))
                                            {
                                                File.Copy(imageFileSourcePath, bodyRegionFolderPath + maskImageName);
                                            }
                                            else
                                            {
                                                System.IO.File.WriteAllText("~/logs/imageNotFound_" + System.DateTime.Now.ToString("MMddyyyy") + ".txt", "not found at :" + imageFileSourcePath + " for l;ayer no: " + folderName + " Body Region Id: " + bodyRegionFolder);
                                            }


                                        }
                                    }
                                }

                            }
                            else
                            {

                                DirectoryInfo di = Directory.CreateDirectory(layersFolder);

                                XmlNodeList mapNodeList = dlNode.SelectNodes("map");

                                string imageFileSourcePath = @"I:\100-PROJECTS\400-DEVELOPMENT\ADAMEduAIA\Flex\v107\content\en_US\da_dat_img\75\5\";

                                foreach (XmlNode mapNode in mapNodeList)
                                {
                                    string bodyRegionFolder = mapNode.Attributes["brId"].Value.ToString();
                                    string bodyRegionFolderPath = layersFolder + @"\" + bodyRegionFolder + @"\";

                                    if (Directory.Exists(bodyRegionFolderPath))
                                    {
                                        if (folderName == "0")
                                        {
                                            DirectoryInfo bodyRegionDr = Directory.CreateDirectory(bodyRegionFolderPath);
                                            XmlNode artNode = mapNode.SelectSingleNode("art");
                                            string skinToneName = artNode.Attributes["sktn"].Value.ToString();
                                            DirectoryInfo skinToneDr = Directory.CreateDirectory(bodyRegionFolderPath + skinToneName);
                                            string imageFileName = artNode.Attributes["compId"].Value.ToString();
                                            string[] imagenameSplit = imageFileName.Split('.');
                                            string maskImageName = imagenameSplit[0] + "_mci.png";

                                            imageFileSourcePath = imageFileSourcePath + maskImageName;

                                            string skinToneDirectoryPath = bodyRegionFolderPath + skinToneName + @"\" + maskImageName;
                                            if (File.Exists(imageFileSourcePath))
                                            {
                                                File.Copy(imageFileSourcePath, skinToneDirectoryPath);
                                            }
                                            else
                                            {
                                                System.IO.File.WriteAllText("~/logs/imageNotFound_" + System.DateTime.Now.ToString("MMddyyyy") + ".txt", "not found at :" + imageFileSourcePath + " for l;ayer no: " + folderName + " Body Region Id: " + bodyRegionFolder);
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("BodyRegion: " + bodyRegionFolder + " is already created");


                                        }


                                    }
                                    else
                                    {
                                        if (folderName == "0")
                                        {
                                            DirectoryInfo bodyRegionDr = Directory.CreateDirectory(bodyRegionFolderPath);
                                            XmlNode artNode = mapNode.SelectSingleNode("art");
                                            string skinToneName = artNode.Attributes["sktn"].Value.ToString();
                                            DirectoryInfo skinToneDr = Directory.CreateDirectory(bodyRegionFolderPath + skinToneName);
                                            string imageFileName = artNode.Attributes["compId"].Value.ToString();
                                            string[] imagenameSplit = imageFileName.Split('.');
                                            string maskImageName = imagenameSplit[0] + "_mci.png";

                                            imageFileSourcePath = imageFileSourcePath + maskImageName;

                                            string skinToneDirectoryPath = bodyRegionFolderPath + skinToneName + @"\" + maskImageName;
                                            if (File.Exists(imageFileSourcePath))
                                            {
                                                File.Copy(imageFileSourcePath, skinToneDirectoryPath);
                                            }
                                            else
                                            {
                                                System.IO.File.WriteAllText("~/logs/imageNotFound_" + System.DateTime.Now.ToString("MMddyyyy") + ".txt", "not found at :" + imageFileSourcePath + " for l;ayer no: " + folderName + " Body Region Id: " + bodyRegionFolder);
                                            }
                                        }
                                        else
                                        {
                                            DirectoryInfo bodyRegionDr = Directory.CreateDirectory(bodyRegionFolderPath);

                                            XmlNode artNode = mapNode.SelectSingleNode("art");
                                            string imageFileName = artNode.Attributes["compId"].Value.ToString();


                                            string[] imagenameSplit = imageFileName.Split('.');
                                            string maskImageName = imagenameSplit[0] + "_mci." + imagenameSplit[1];

                                            

                                            if (File.Exists(imageFileSourcePath))
                                            {
                                                File.Copy(imageFileSourcePath, bodyRegionFolderPath + maskImageName);
                                            }
                                            else
                                            {
                                                System.IO.File.WriteAllText("~/logs/imageNotFound_" + System.DateTime.Now.ToString("MMddyyyy") + ".txt", "not found at :" + imageFileSourcePath + " for l;ayer no: " + folderName + " Body Region Id: " + bodyRegionFolder);
                                            }


                                        }
                                    }
                                }
                                //MessageBox.Show("Congratulations !! you have successfully imported all images for xml : " + path);
                            }
                            // }
                        }
                      
                    }
                }
            }
        }
    }
}