/// <summary>
 ///  Add To PLaylist
 /// </summary>
 public void                             CMD_AddToPlaylist_Executed(ListView Arg)
 {
     if (Arg != null && Arg.Name == "LibraryList")
     {
         foreach (var Item in Arg.SelectedItems)
         {
             Playlist.AddFilm(Library.GetIndex(Library.Films.IndexOf(Item as Model.Film)));
         }
     }
 }
 /// <summary>
 ///  Clear Playlist And Play
 /// </summary>
 public void                             CMD_ClearPlaylistAndPlay_Executed(ListView Arg)
 {
     if (Arg != null && Arg.Name == "LibraryList")
     {
         CMD_Stop_Executed(null);
         Playlist.Clean();
         foreach (var Item in Arg.SelectedItems)
         {
             Playlist.AddFilm(Library.GetIndex(Library.Films.IndexOf(Item as Model.Film)));
         }
         LoadMedia(Playlist.GetFirst().Path);
     }
 }
        /// <summary>
        ///  Opening A New Media File And Playing It
        /// </summary>
        public void                             CMD_Open_Executed(String Arg)
        {
            OpenFileDialog Dialog = new OpenFileDialog();

            Dialog.Multiselect     = true;
            Dialog.Title           = "Select One Or Several Media Files";
            Dialog.Filter         += "Video Files (*.avi, *.mpeg, *.mpg, *.mp4, *.wmv) | *.avi;*.mpeg;*.mpg;*.mp4;*.wmv;";
            Dialog.Filter         += " | Audio Files (*.mp3, *.wav, *.mid, *.midi) | *.mp3;*.wav;*.mid;*.midi;";
            Dialog.Filter         += " | Image Files (*.jpg, *.jpeg, *.png, *.gif, *.bmp) | *.jpg;*.jpeg;*.png;*.gif;*.bmp;";
            Dialog.CheckFileExists = true;
            Dialog.CheckPathExists = true;
            var Player = new WindowsMediaPlayer();

            if (Dialog.ShowDialog() == true)
            {
                Loading = true;
                Task T = new Task(() =>
                {
                    if (Arg == "OPEN")
                    {
                        App.Current.Dispatcher.BeginInvoke((Action) delegate() { Playlist.Clean(); });
                    }

                    foreach (String _File in Dialog.FileNames)
                    {
                        var Clip           = Player.newMedia(_File);
                        Model.Film NewFilm = new Model.Film(Path.GetFileNameWithoutExtension(_File), TimeSpan.FromSeconds((Clip.duration == 0 ? 4 : Clip.duration)), _File, false, MyGetType(Path.GetExtension(_File)));

                        if (Arg == "LIBRARY")
                        {
                            App.Current.Dispatcher.BeginInvoke((Action) delegate() { Library.AddFilm(NewFilm); });
                        }
                        else
                        {
                            App.Current.Dispatcher.BeginInvoke((Action) delegate() { Playlist.AddFilm(NewFilm); });
                        }
                        _NbFilesLoaded++;
                        NotifyPropertyChanged("NbFilesLoaded");
                    }

                    if (Arg == "OPEN")
                    {
                        App.Current.Dispatcher.BeginInvoke((Action) delegate() { LoadMedia(Playlist.GetFirst().Path); });
                    }
                    App.Current.Dispatcher.BeginInvoke((Action) delegate() { CMD_SavePlayList.RaiseCanExecuteChanged(); });
                });

                T.ContinueWith(antecedent => Loading = false, TaskScheduler.FromCurrentSynchronizationContext());
                T.Start();
            }
        }
        /// <summary>
        ///  Doble Click On A Elem Of A ListView
        /// </summary>
        public void                             EVNT_ListViewDoubleClick(object sender, MouseEventArgs e, MyWindowsMediaPlayer.MainWindow MW)
        {
            ListViewItem Item = sender as ListViewItem;

            if (Item != null)
            {
                if (Item.IsDescendantOf(MW.PlayList) && Playlist.GetIndex(MW.PlayList.SelectedIndex) != null)
                {
                    LoadMedia(Playlist.GetIndex(MW.PlayList.SelectedIndex).Path);
                }
                else if (Item.IsDescendantOf(MW.LibraryList) && Library.GetIndex(LibraryPos) != null && LibraryPos < Library.FilmsView.Count)
                {
                    Playlist.Clean();
                    Playlist.AddFilm(Library.FilmsView[LibraryPos]);
                    LoadMedia(Playlist.GetFirst().Path);
                }
            }
        }
        /// <summary>
        /// Handling Drag n Drop
        /// </summary>
        public void                             CMD_DragNDrop_Executed(DragEventArgs e)
        {
            var  Player = new WindowsMediaPlayer();
            bool Empty  = (Playlist.Films.Count == 0);

            String[] FileNames = (String[])e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop, true);

            foreach (String _Path in FileNames)
            {
                if (MyGetType(Path.GetExtension(_Path)) != Model.Film.MediaType.Unknown)
                {
                    var Clip = Player.newMedia(_Path);
                    Playlist.AddFilm(new Model.Film(Path.GetFileNameWithoutExtension(_Path), TimeSpan.FromSeconds((Clip.duration == 0 ? 4 : Clip.duration)), _Path));
                }
            }
            if (Empty && Playlist.Films.Count > 0)
            {
                LoadMedia(Playlist.GetFirst().Path);
            }
        }
        /// <summary>
        ///  Get Through The Folders Recursively
        /// </summary>
        public void                             ScanFolder(String _Folder, String Arg)
        {
            try
            {
                DirectoryInfo DirBase = new DirectoryInfo(_Folder);
                var           Dirs    = DirBase.EnumerateDirectories();

                foreach (DirectoryInfo Dir in Dirs)
                {
                    if (!((Dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
                    {
                        ScanFolder(Dir.FullName, Arg);
                    }
                }

                var _Files = Directory.GetFiles(_Folder);
                var Player = new WindowsMediaPlayer();

                foreach (string _File in _Files)
                {
                    if (MyGetType(Path.GetExtension(_File)) != Model.Film.MediaType.Unknown)
                    {
                        var        Clip    = Player.newMedia(_File);
                        Model.Film NewFilm = new Model.Film(Path.GetFileNameWithoutExtension(_File), TimeSpan.FromSeconds((Clip.duration == 0 ? 4 : Clip.duration)), _File, false, MyGetType(Path.GetExtension(_File)));

                        if (Arg == "LIBRARY")
                        {
                            App.Current.Dispatcher.BeginInvoke((Action) delegate() { Library.AddFilm(NewFilm); });
                        }
                        else
                        {
                            App.Current.Dispatcher.BeginInvoke((Action) delegate() { Playlist.AddFilm(NewFilm); });
                        }
                        _NbFilesLoaded++;
                        NotifyPropertyChanged("NbFilesLoaded");
                    }
                }
            }
            catch (Exception e) {}
        }