//Misc
        private void ShowBrowseFolderDialog()
        {
            System.Windows.Forms.FolderBrowserDialog dlgWRFolder = new System.Windows.Forms.FolderBrowserDialog()
            {
                Description         = "Select the folder containing the potential Web Resource files",
                ShowNewFolderButton = false
            };
            if (dlgWRFolder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IsActivePackageDirty = false;

                //Because Web Resources are relative to the root path,
                //all the current Web ResourceInfos should be cleared
                WebResourceInfos.Clear();
                WebResourceInfosSelected.Clear();

                //Change the rootpath and notify all bindings
                ActivePackage.Attribute("rootPath").Value = dlgWRFolder.SelectedPath;
                OnPropertyChanged("ActivePackage");

                //Auto-save
                SavePackages();

                //Display new files
                SearchAndPopulateFiles();
            }
        }
        private void SavePackages()
        {
            //The user is influenced to believe a Save event will only
            //save the ActivePackage but really it will save all of them.
            //Code is in place to prevent the user from editing one package then
            //trying to load another without saving the first.

            //At this point the XmlRootData object is stale and needs to be
            //repopulated with the Packages collection.
            XmlPackageData.Descendants("Package").Remove();

            //But the ActivePackage may have its Web Resources modified and they
            //need to be added back to the ActivePackage.
            if (ActivePackage != null)
            {
                ActivePackage.Elements("WebResourceInfo").Remove();
                ActivePackage.Add(WebResourceInfos.ToArray());
            }

            XmlPackageData.Element("Packages").Add(Packages.ToArray());

            XmlPackageData.Save(PACKAGES_FILENAME);

            IsActivePackageDirty = false;
        }
        private void LoadWebResourceInfos()
        {
            if (ActivePackage == null)
            {
                return;
            }

            //As always, clear the collection first.
            WebResourceInfos.Clear();
            WebResourceInfosSelected.Clear();

            var webResourceInfos = ActivePackage.Elements("WebResourceInfo");

            if (webResourceInfos != null)
            {
                foreach (var wr in webResourceInfos)
                {
                    WebResourceInfos.Add(wr);
                }
            }
        }
        private void DeleteSelectedPackage()
        {
            if (SelectedPackage != null)
            {
                var toBeDeleted = Packages.Where(x => x == SelectedPackage).FirstOrDefault();

                if (toBeDeleted != null)
                {
                    if (ActivePackage == SelectedPackage)
                    {
                        ActivePackage = null;
                        //Also, clear out any dependencies
                        CurrentFiles.Clear();
                        CurrentFilesSelected.Clear();
                        WebResourceInfos.Clear();
                        WebResourceInfosSelected.Clear();
                    }
                    Packages.Remove(toBeDeleted);
                    SelectedPackage = null;
                }
                SavePackages();
            }
        }
        private void DeleteSelectedWebResources(object parameter)
        {
            //Set the ActivePackage as Dirty.
            IsActivePackageDirty = true;

            WebResourceInfosSelected.Clear();

            if (parameter != null && parameter is IEnumerable)
            {
                //Lists allow the ForEach extension method good for
                //removing items of a collection. Looping through an
                //enumerable caused indexing errors after the first
                //iteration.
                List <XElement> infosToDelete = new List <XElement>();

                foreach (var wr in (IEnumerable)parameter)
                {
                    infosToDelete.Add((XElement)wr);
                }

                infosToDelete.ForEach(info => WebResourceInfos.Remove(info));
            }
        }
        private void AddFilesToWebResources(object parameter)
        {
            //Set the ActivePackage as Dirty.
            IsActivePackageDirty = true;

            //Clear the collection of selected files
            CurrentFilesSelected.Clear();

            //List<FileInfo> selectedFiles = new List<FileInfo>();
            if (parameter != null && parameter is IEnumerable)
            {
                foreach (var fileInfo in (IEnumerable)parameter)
                {
                    CurrentFilesSelected.Add((FileInfo)fileInfo);
                }
            }

            if (CurrentFilesSelected.Count > 0)
            {
                foreach (FileInfo fi in CurrentFilesSelected)
                {
                    //Add it to the list of web resource info, if not already there.
                    //The matching criteria will be the ?

                    XElement newInfo = ConvertFileInfoToWebResourceInfo(fi);

                    if (WebResourceInfos.Where(w => w.Attribute("filePath").Value == newInfo.Attribute("filePath").Value).Count() == 0)
                    {
                        WebResourceInfos.Add(newInfo);
                    }
                    else
                    {
                        //it's already in the list! do nothing.
                    }
                }
            }
        }