/// <summary>
        /// Open a new window for users to add new image to the collection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addImage_Click(object sender, RoutedEventArgs e)
        {
            AddImageWindow newWindow = new AddImageWindow();
            newWindow.mainWindow = this;
            newWindow.big_window1.setCatalogNumber(EntryListBox.Items.Count);
            newWindow.big_window1.mainWindow = this;
            newWindow.big_window1.setImageProperty(false);
            MetaDataEntry newSmall = new MetaDataEntry();
            newWindow.big_window1.MetaDataList.Items.Add(newSmall);
            newSmall.setBigWindow(newWindow.big_window1);
            //Initially set the two buttons disabled, after the user save to the catalog then will these two be abled
            newWindow.big_window1.mapButton.IsEnabled = false;
            newWindow.big_window1.hotspot.IsEnabled = false;

            Canvas.SetLeft(newWindow.big_window1.save, 349);
            Canvas.SetLeft(newWindow.big_window1.mapButton, 513);
            Canvas.SetLeft(newWindow.big_window1.hotspot, 713);
            newWindow.WindowState = System.Windows.WindowState.Normal;
            newWindow.ShowDialog();
        }
        /// <summary>
        /// Loads and opens the addImageWindow
        /// </summary>
        private void edit_Click(object sender, EventArgs e)
        {
            AddImageWindow newBigWindow = new AddImageWindow();
            newBigWindow.mainWindow = _newWindow;
            newBigWindow.WindowState = System.Windows.WindowState.Normal;
            newBigWindow.big_window1.setCatalogNumber(catalogNumber);
            newBigWindow.big_window1.browse.Visibility = Visibility.Hidden;
            newBigWindow.big_window1.createDZ.Visibility = Visibility.Hidden;
            newBigWindow.big_window1.setMainWindow(_newWindow); //pass the main window to the addImage Control

            Image wpfImage = new Image();
            FileStream stream = new FileStream(imagePath, FileMode.Open);
            System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream);
            wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage);
            stream.Close();

            //The image of the window is set according to its ratio of length and width
            Utils.setAspectRatio(newBigWindow.big_window1.imageCanvas, newBigWindow.big_window1.imageRec, newBigWindow.big_window1.image1, wpfImage, 7);

            //set image source
            newBigWindow.big_window1.image1.Source = wpfImage.Source;
            String dataDir = "Data/";
            String dataUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\";
            // String dataDir = "C:\\Users\\MISATRAN\\Desktop\\LADS-new\\GCNav\\bin\\Debug\\Data\\";
            XmlDocument doc = new XmlDocument();
            doc.Load(dataDir + "NewCollection.xml");
            if (doc.HasChildNodes)
            {
                foreach (XmlNode docNode in doc.ChildNodes)
                {
                    if (docNode.Name == "Collection")
                    {

                        foreach (XmlNode node in docNode.ChildNodes)
                        {
                            if (node.Name == "Image")
                            {
                                String title = node.Attributes.GetNamedItem("title").InnerText;
                                String path = node.Attributes.GetNamedItem("path").InnerText;
                                if (imageName == path)
                                {
                                    String artist = node.Attributes.GetNamedItem("artist").InnerText;
                                    String year = node.Attributes.GetNamedItem("year").InnerText;

                                    String medium = node.Attributes.GetNamedItem("medium").InnerText;

                                    //Loads the information about the imgae
                                    newBigWindow.big_window1.year_tag.Text = year;
                                    newBigWindow.big_window1.artist_tag.Text = artist;
                                    newBigWindow.big_window1.title_tag.Text = title;
                                    newBigWindow.big_window1.medium_tag.Text = medium;
                                    newBigWindow.big_window1.setImageName(path);
                                    newBigWindow.big_window1.setImagePath(dataUri + "Images\\" + "Thumbnail\\" + path);
                                    newBigWindow.big_window1.setImageProperty(true);

                                    if(node.Attributes.GetNamedItem("description")!=null){
                                        String summary = node.Attributes.GetNamedItem("description").InnerText;
                                        newBigWindow.big_window1.summary.Text = summary;
                                    }
                                    //Loads the keywords
                                    String keyword = "";
                                    foreach (XmlNode imgnode in node.ChildNodes)
                                    {
                                        if (imgnode.Name == "Keywords")
                                        {
                                            foreach (XmlNode keywd in imgnode.ChildNodes)
                                            {
                                                if (keywd.Name == "Keyword")
                                                {
                                                    if (keyword == "")
                                                    {
                                                        keyword = keyword + keywd.Attributes.GetNamedItem("Value").InnerText;
                                                    }
                                                    else
                                                    {
                                                        keyword = keyword + "," + keywd.Attributes.GetNamedItem("Value").InnerText;
                                                    }
                                                }
                                            }
                                        }
                                        //Load metadatas if there is any
                                        if (imgnode.Name == "Metadata")
                                        {

                                            foreach (XmlNode meta in imgnode.ChildNodes)
                                            {
                                                if (meta.Name == "Group")
                                                { //This needs to specify group A,B,C or D. Groups are not specified in this release
                                                    foreach (XmlNode file in meta)
                                                    {
                                                        String fileName = file.Attributes.GetNamedItem("Filename").InnerText; //this is to save the imageName

                                                        //need to special case this for videos images and audio files
                                                        System.Windows.Controls.Image wpfImage2 = new System.Windows.Controls.Image();
                                                        _helpers = new Helpers();
                                                        if (_helpers.IsImageFile(fileName))
                                                        {
                                                            String fullPath = dataUri + "Images/" + "Metadata/" + fileName;
                                                            FileStream stream2 = new FileStream(fullPath, FileMode.Open);
                                                            System.Drawing.Image dImage2 = System.Drawing.Image.FromStream(stream2);
                                                            wpfImage2 = _helpers.ConvertDrawingImageToWPFImage(dImage2);
                                                            stream2.Close();

                                                            //set image source
                                                            MetaDataEntry newSmallwindow = new MetaDataEntry();
                                                            //Utils.setAspectRatio(newSmallwindow.imageCanvas, newSmallwindow.imageRec, newSmallwindow.image1, metaBitmapImage, 4);
                                                            newSmallwindow.image1.Source = wpfImage2.Source;
                                                            newSmallwindow.title_tag.Text = fileName;

                                                            if (file.Attributes.GetNamedItem("Name") != null)
                                                            {
                                                                String name = file.Attributes.GetNamedItem("Name").InnerText;
                                                                newSmallwindow.name_tag.Text = name;
                                                            }
                                                            if (file.Attributes.GetNamedItem("Description") != null)
                                                            {
                                                                String description = file.Attributes.GetNamedItem("Description").InnerText;
                                                                newSmallwindow.summary.Text = description;
                                                            }
                                                            newSmallwindow.tags.Text = keyword;
                                                            newBigWindow.big_window1.MetaDataList.Items.Add(newSmallwindow);
                                                            newSmallwindow.setBigWindow(newBigWindow.big_window1);
                                                        }
                                                        //loads videos
                                                        else if (_helpers.IsVideoFile(fileName))
                                                        {
                                                            String fullPath = dataUri + "Videos/" + "Metadata/" + fileName;
                                                            BitmapImage metaBitmapImage = new BitmapImage();
                                                            metaBitmapImage.BeginInit();
                                                            String thumbPath = fullPath;
                                                            int decrement = System.IO.Path.GetExtension(thumbPath).Length;
                                                            thumbPath = thumbPath.Remove(thumbPath.Length - decrement, decrement);
                                                            thumbPath += ".bmp";
                                                            metaBitmapImage.UriSource = new Uri(thumbPath);
                                                            metaBitmapImage.EndInit();

                                                            //set image source
                                                            MetaDataEntry newSmallwindow = new MetaDataEntry();

                                                            newSmallwindow.image1.Source = metaBitmapImage;
                                                            newSmallwindow.title_tag.Text = fileName;

                                                            if (file.Attributes.GetNamedItem("Name") != null)
                                                            {
                                                                String name = file.Attributes.GetNamedItem("Name").InnerText;
                                                                newSmallwindow.name_tag.Text = name;
                                                            }
                                                            if (file.Attributes.GetNamedItem("description") != null)
                                                            {
                                                                String description = file.Attributes.GetNamedItem("description").InnerText;
                                                                newSmallwindow.summary.Text = description;
                                                            }
                                                            newSmallwindow.tags.Text = keyword;
                                                            newBigWindow.big_window1.MetaDataList.Items.Add(newSmallwindow);
                                                            newSmallwindow.setBigWindow(newBigWindow.big_window1);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    newBigWindow.big_window1.tags.Text = keyword;
                                    }
                                }
                             }
                        }
                    }
                }
            if (newBigWindow.big_window1.MetaDataList.Items.Count == 0) {
                MetaDataEntry newSmallwindow = new MetaDataEntry();
                newBigWindow.big_window1.MetaDataList.Items.Add(newSmallwindow);
                newSmallwindow.setBigWindow(newBigWindow.big_window1);
            }
            newBigWindow.Show();
        }
 public AddWebImage(MetaDataEntry metaEntry)
 {
     InitializeComponent();
     _metaEntry = metaEntry;
 }
        /// <summary>
        /// When 'Browse' button for Main Artwork is clicked, open a 'file open' dialog for user to open an image file.
        /// </summary>
        private void Browse_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
            ofd.Multiselect = false;

            ofd.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.TIFF;*.TIF;*.JPEG;*.PNG)|*.BMP;*.JPG;*.GIF;*.TIFF;*.TIF;*.JPEG;*.PNG|All files(*.*)|*.*";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {

                string[] filePath = ofd.FileNames;
                string[] safeFilePath = ofd.SafeFileNames;

                for (int i = 0; i < safeFilePath.Length; i++)
                {
                    // FileInfo info = new FileInfo(safeFilePath[i]);
                    //Check what type of the metedata
                    image1.Width = 186;
                    image1.Height = 136;
                    imageRec.Width = 200;
                    imageRec.Height = 150;
                    Canvas.SetTop(image1, 7);
                    Canvas.SetTop(imageRec, 0);
                    Canvas.SetLeft(image1, 7);
                    Canvas.SetLeft(imageRec, 0);
                    //BitmapImage myBitmapImage = new BitmapImage();
                    System.Windows.Controls.Image wpfImage = new System.Windows.Controls.Image();

                    try
                    {

                        System.Drawing.Image img = Helpers.getThumbnail(@filePath[i],400);
                        String tempname = System.IO.Path.GetTempFileName();
                        img.Save(tempname);
                        img.Dispose();

                        FileStream fstream = new FileStream(tempname, FileMode.Open);
                        System.Drawing.Image dImage = System.Drawing.Image.FromStream(fstream);
                        wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage);
                        dImage.Dispose();
                        fstream.Close();
                        File.Delete(tempname);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show("The image file is broken or not valid");
                        return;
                    }

                    Utils.setAspectRatio(imageCanvas, imageRec, image1, wpfImage, 7);

                    //set image source
                    image1.Source = wpfImage.Source;
                    string filename = safeFilePath[i];
                    string extension = System.IO.Path.GetExtension(safeFilePath[i]);
                    string tempFileName = System.IO.Path.GetFileNameWithoutExtension(safeFilePath[i]);
                    Random random = new Random();
                    int randomNumber = random.Next(0, 100000000);
                    filename = tempFileName + randomNumber + extension;
                    while (File.Exists("Data/Images/Metadata/" + filename))
                    {
                        randomNumber = random.Next(0, 100000000);
                        filename = tempFileName + randomNumber + extension;
                    }
                    this.setImageName(filename);
                    this.setImagePath(filePath[i]);

                    title_tag.Text = "";
                    year_tag.Text = "";
                    medium_tag.Text = "";
                    artist_tag.Text = "";
                    tags.Text = "";
                    summary.Text = "";
                    MetaDataList.Items.Clear();
                    MetaDataEntry newSmall = new MetaDataEntry();
                    newSmall.setBigWindow(this);
                    MetaDataList.Items.Add(newSmall);
                }
            }
        }
 /// <summary>
 /// Open a control to handle metadata processing.
 /// </summary>
 private void addMetadata_Click(object sender, RoutedEventArgs e)
 {
     MetaDataEntry newSmallWindow = new MetaDataEntry();
     MetaDataList.Items.Add(newSmallWindow);
     newSmallWindow.setBigWindow(this);
 }
        //for image assets
        //used when an item is added to the dock at the bottom.
        public void createMetaThumbnail(MetaDataEntry mde)
        {
            string filename = mde.title_tag.Text;
            string path = mde.metaImagePath;

            //uses the thumbnail image of the video
            if (_helpers.IsVideoFile(path))
            {
                string newPath = "data/Videos/Metadata/";
                string fBitmapName = path;

                int decrement = System.IO.Path.GetExtension(fBitmapName).Length;
                fBitmapName = fBitmapName.Remove(fBitmapName.Length - decrement, decrement);
                fBitmapName += ".bmp";

                System.Drawing.Image img = System.Drawing.Image.FromFile(fBitmapName);
                int decrement2 = System.IO.Path.GetExtension(filename).Length;
                filename = filename.Remove(filename.Length - decrement2, decrement2);

                filename += ".bmp";
                img.Save(newPath + filename);
                img.Dispose();

            }
            else if (_helpers.IsImageFile(path))
            {
                string newPath = "data/Images/Metadata/";

                System.Drawing.Image img = System.Drawing.Image.FromFile(path);
                img = img.GetThumbnailImage(128, 128, null, new IntPtr());
                img.Save(newPath + "Thumbnail/" + filename);
                img.Dispose();

            }
        }