private IEnumerable<string> ConvertMusic(IEventListener iel, CancellationToken iCancellationToken)
        {
            int Current = 0;

            if (iCancellationToken.IsCancellationRequested)
                yield break;

            foreach (string Music in _ListMusic)
            {
                iel.Report(new ConvertProgessEventArgs(_ClueName.DisplayName, ++Current, _ListMusic.Count));

                string OutDirectory = Context.ConvertManager.PathFromOutput(Music, _ClueName);
                string TempDir = Context.Folders.Temp;

                using (IMusicFileConverter imf = _IMusicConverter.GetMusicConverter(Music, OutDirectory, TempDir))
                {

                    if (iCancellationToken.IsCancellationRequested)
                        yield break;

                    bool res = imf.ConvertTomp3();

                    if (res)
                    {
                        AddConvertedFiles(Music, imf.ConvertName);

                        yield return imf.ConvertName;
                    }
                    else
                    {
                        Trace.WriteLine("Unable to convert file"+Music);
                        iel.OnFactorisableError<UnableToConvertFile>(Music);
                    }
                }
            }
        }
        protected override ImporterConverterAbstract GetNext(IEventListener iel, CancellationToken iCancellationToken)
        {
            int CDnumber = _IMusicConverter.GetDriverNumber(_Driver);

            if (!CDHelper.CanOpenCDDoor(CDnumber))
            {
                //ca pue un lecteur de cd qu'on ne peut pas ouvrir
                //je ne fair rien dans ce cas (cle 3G?)
                Trace.WriteLine("Problem due to device detected as CD driver");
                return null;
            }

            using (CDLocker cdl = CDLocker.GetLocker(CDnumber))
            {
                if (!cdl.IsOK)
                {
                    iel.Report(new NoCDInsertedArgs());
                    Trace.WriteLine("CD driver not ready");
                    return null;
                }

                if (!CDHelper.IsCDAudio(CDnumber))
                {
                    iel.Report(new NoCDAudioInsertedArgs());
                    System.Diagnostics.Trace.WriteLine("CD not audio");
                    return null;
                }

                iel.Report(new CDIndentifyingProgessEventArgs());

                CDInfoHandler cih = new CDInfoHandler(CDnumber);

                IEnumerable<MatchAlbum> albums = Context.FindFromHashes(cih.IDs.RawHash);
                if (albums.Any())
                {
                    OtherAlbumsConfirmationNeededEventArgs error = new OtherAlbumsConfirmationNeededEventArgs(albums);
                    iel.Report(error);

                    System.Diagnostics.Trace.WriteLine("CD potentially aleady imported");

                    if (!error.Continue)
                    {
                        System.Diagnostics.Trace.WriteLine("stopping import");
                        return null;
                    }
                }

                IWebQuery webq = Context.Session.WebQueryFactory.FromCDInfo(cih);
                webq.NeedCoverArt = false;
                IInternetFinder ifn = Context.Session.GetInternetFinder(webq);
                ifn.Compute(iCancellationToken,null);

                AmbigueousCDInformationArgs acfi = new AmbigueousCDInformationArgs(ifn.Result.Found, AlbumDescriptor.CreateBasicFromCD(cih, Context));

                iel.Report(acfi);

                if (!acfi.Continue)
                    return null;

                AlbumDescriptor ifad = acfi.SelectedInfo as AlbumDescriptor;

                iel.Report(new CDImportingProgessEventArgs(ifad.Name));

                ifad.MergeIDsFromCDInfos(cih);

                IMusicfilesConverter IMC = _IMusicConverter.GetCDMusicConverter(ifad, Context.Folders.File, false, CDnumber);

                if (IMC == null)
                {
                    TimeSpan ts = TimeSpan.FromSeconds(7);
                    int repeat = 0;
                    int Maxtent = 3;
                    while ((IMC == null) && (repeat < Maxtent))
                    {
                        bool Forcebute = repeat == (Maxtent - 1);
                        Thread.Sleep(ts);
                        IMC = _IMusicConverter.GetCDMusicConverter(ifad, Context.Folders.File, Forcebute, CDnumber);
                        repeat++;
                        Trace.WriteLine(string.Format("Trial {0} to get CDMusicConverter, Forcebute {1} success {2}", repeat, Forcebute, (IMC == null)));
                        ts = TimeSpan.FromSeconds(ts.TotalSeconds * 3);
                    }

                    if (IMC == null)
                    {
                        System.Diagnostics.Trace.WriteLine("no importer returned");
                        iel.Report(new CDInUse());
                        return null;
                    }
                }

                Action ParrallelCoverLoading = null;

                IList<WebMatch<IFullAlbumDescriptor>> resultwithimage = null;

                if (acfi.PreprocessedWebInfo != null)
                {
                    resultwithimage = acfi.PreprocessedWebInfo;
                    ParrallelCoverLoading = () => acfi.PreprocessedWebInfo.Apply(wr => wr.FindItem.LoadImages());
                }
                else
                {
                    IWebQuery webqim = new WebQueryFactory(Context.Session).FromAlbumDescriptor(ifad);
                    webqim.NeedCoverArt = true;

                    IInternetFinder ifni = Context.Session.GetInternetFinder(webqim);

                    resultwithimage = new List<WebMatch<IFullAlbumDescriptor>>();

                    if (ifad.HasImage())
                    {
                        resultwithimage.Add(new WebMatch<IFullAlbumDescriptor>(ifad, MatchPrecision.Suspition, acfi.Provider));
                    }

                    ParrallelCoverLoading = () => { ifad.LoadImages(); ifni.Compute(iCancellationToken,null); resultwithimage.AddCollection(ifni.Result.Found); };
                }

                int TN = ifad.TrackDescriptors.Count;

                IAsyncResult ias = ParrallelCoverLoading.BeginInvoke(null, null);

                bool feedbacknegative = false;

                IProgress<TrackConverted> progress = new SimpleProgress<TrackConverted>
                ( (e) =>
                    {
                        iel.Report(new ConvertProgessEventArgs(ifad.Name, (int)e.Track.TrackNumber, TN));
                        if (e.OK)
                        {
                            _TDs.Add(e.Track);
                        }
                        else
                        {
                            feedbacknegative = true;
                            iel.OnFactorisableError<UnableToConvertFile>(e.Track.Name);
                        }
                    }
                );

                bool convres = IMC.ConvertTomp3(progress, iCancellationToken);

                if ((convres == false) && (_TDs.Count == 0) && (feedbacknegative == false))
                {
                    iel.Report(new CDUnknownErrorArgs());
                    return null;
                }

                if (iCancellationToken.IsCancellationRequested)
                {
                    return null;
                }

                if (!ias.IsCompleted)
                {
                    iel.Report(new CDImportingProgessAdditionalCoverInfoEventArgs(ifad));
                }

                if (_OpenCDDoorOnComplete)
                    CDHelper.OpenCDDoor();

                bool okfound = ias.AsyncWaitHandle.WaitOne(TimeSpan.FromMinutes(3), false);
                //j'attends pas plus de 1 minute apres avoir grave le cd pour trouver
                //les pochettes sur internet
 
                Trace.WriteLine(string.Format("CD import cover from internet time out result (false:timedout): {0}!", okfound));

                if (resultwithimage != null)
                {             
                    int tracknumber = ifad.RawTrackDescriptors.Count;           
                    var images = resultwithimage.Where(wr => ((wr.FindItem.MatchTrackNumberOnDisk(tracknumber)) && (wr.FindItem.Images != null) && (wr.FindItem.Images.Count > 0))).ToList();

                    if (images.Count > 0)
                    {
                        Trace.WriteLine(string.Format("{0} Image(s) found!!", images.Count));

                        CDCoverInformationArgs cdfi = new CDCoverInformationArgs(images, ifad);
                        iel.Report(cdfi);
                    }
                    else
                    {
                        Trace.WriteLine(string.Format("Information found but no matching image found for CD:{0} !",ifad));
                    }
                }
                else
                {
                    Trace.WriteLine("No image found for CD!");
                }

                Trace.WriteLine("Import CD OK");

                return new MusicWithMetadaImporter(_TDs.ToArray(), new List<string>(), new ICDInfosHelperAdpt(ifad));
            }
        }
        protected override ImporterConverterAbstract GetNext(IEventListener iel, CancellationToken iCancellationToken)
        {
            if (_Done)
                throw new InvalidOperationException("reentrance");

            _Done = true;

            if (!Analyse())
            {
                //Cue does not match..let's do the easy way.
                return new MusicConverterImporter(_IMusicConverter, _MusicandCueFile.Select(i => i.Item1).ToList(), _ListImage, _ClueName);
            }

            foreach (Tuple<string, AlbumDescriptor> MAC in _MusicandCueFile)
            {
                _MusicConverted.Add(MAC.Item1);
                _MusicConverted.Add(MAC.Item2.CUESheetFileName);
            }

            List<TrackConverted> tracks = new List<TrackConverted>();

            SpaceChecker sc = new SpaceChecker(Context.ConvertManager.PathFromOutput(_MusicandCueFile[0].Item1, _ClueName),
                from mac in _MusicandCueFile select mac.Item1);

            if (!sc.OK)
            {
                iel.Report(new NotEnougthSpace(sc.ToString()));
                return null;
            }

            if (iCancellationToken.IsCancellationRequested)
            {
                return null;
            }

            foreach (Tuple<string, AlbumDescriptor> MAC in _MusicandCueFile)
            {
                string MusicPath = MAC.Item1;
                AlbumDescriptor Cs = MAC.Item2;

                int Current = 1;
                iel.Report(new ConvertProgessEventArgs(_ClueName.DisplayName, Current, Cs.RawTrackDescriptors.Count));

                bool OK = false;

                using (IMusicfilesConverter imcc = _IMusicConverter.GetMusicConverter(MusicPath, Cs.RawTrackDescriptors, Context.ConvertManager.PathFromOutput(MusicPath, _ClueName), Context.Folders.Temp))
                {

                    IProgress<TrackConverted> progress = new SimpleProgress<TrackConverted>
                    ( (e) =>
                    {
                        iel.Report(new ConvertProgessEventArgs(_ClueName.DisplayName, ++Current, Cs.RawTrackDescriptors.Count));
                        if (e.OK)
                        {
                            tracks.Add(e);
                            AddConvertedFiles(MusicPath, e.Track.Path);
                        }
                        else
                            iel.OnFactorisableError<UnableToConvertFile>(e.Track.Name);
                    });

                    OK = imcc.ConvertTomp3(progress, iCancellationToken);
                }
            }

            if (iCancellationToken.IsCancellationRequested)
            {
                return null;
            }

            return new MusicWithMetadaImporter((from t in tracks select t.Track).ToArray<ITrackDescriptor>(), _ListImage, _ClueName); ;
        }
        private void ExtractCallBack(ExtractFileCallbackArgs efc, IEventListener iel, CancellationToken iCancellationToken)
        {
            switch (efc.Reason)
            {
                case ExtractFileCallbackReason.Start:

                    string nd = null;
                    bool root = false;

                    if (efc.ArchiveFileInfo.FileName == MusicExporter.XMLName)
                    {
                        nd = _ICC.Folders.Temp;
                        root = true;
                    }
                    else
                    {
                        nd = _ICC.Folders.File;
                    }

                    efc.ExtractToFile = FileInternalToolBox.CreateNewAvailableName(Path.Combine(nd, efc.ArchiveFileInfo.FileName));
                    if (root)
                        _RX = efc.ExtractToFile;
                    else
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(efc.ExtractToFile));
                    }

                    if ((!efc.ArchiveFileInfo.IsDirectory) && !(root))
                    {
                        iel.Report(new ExtractProgessEventArgs(string.Format("{0} from {1}", Path.GetFileName(efc.ArchiveFileInfo.SafePath()), _Sex.FileName)));
                        AddAssociationIfNeeded(efc.ArchiveFileInfo.FileName, efc.ExtractToFile);
                    }

                    DescompactedFiles.Add(efc.ExtractToFile);
                    break;

                case ExtractFileCallbackReason.Failure:
                    iel.OnFactorisableError<UnableToExtractFileFromRar>(string.Format("{0} from {1} : {2}", Path.GetFileName(efc.ArchiveFileInfo.FileName), _Sex.FileName, efc.Exception));
                    efc.Exception = null;
                    efc.ExtractToFile = null;
                    _Success = false;
                    break;
            }

            if (iCancellationToken.IsCancellationRequested)
            {
                _Success = false;
                efc.CancelExtraction = true;
            }
        }
            private void ExtractCallBack(ExtractFileCallbackArgs efc, IEventListener iel, CancellationToken iCancellationToken)
            {
                switch (efc.Reason)
                {
                    case ExtractFileCallbackReason.Start:

                        string Dest = GetFileName(efc.ArchiveFileInfo);

                        if (Dest == null)
                        {
                            efc.ExtractToFile = null;
                            break;
                        }

                        efc.ExtractToFile = Dest;

                        if (!efc.ArchiveFileInfo.IsDirectory)
                            iel.Report(new ExtractProgessEventArgs(string.Format("{0} from {1}", Path.GetFileName(efc.ArchiveFileInfo.SafePath()), RarContext.DisplayName)));

                        Files.Add(Dest);
                        break;

                    case ExtractFileCallbackReason.Failure:
                        iel.OnFactorisableError<UnableToExtractFileFromRar>(string.Format("{0} from {1} : {2}", Path.GetFileName(efc.ArchiveFileInfo.SafePath()), RarContext.DisplayName, efc.Exception));
                        efc.Exception = null;
                        efc.ExtractToFile = null;
                        _DOK = false;
                        break;
                }

                if (iCancellationToken.IsCancellationRequested)
                    efc.CancelExtraction = true;
            }