// used to download one post
        public bool TryDownloadPost(IPostToDownload_v1 post, string downloadDirectory = null, bool forceDownloadAgain = false, bool forceSelect = false, bool simulateDownload = false)
        {
            if (_downloadAllPrintType != null)
            {
                forceSelect = forceSelect || _downloadAllPrintType(post.GetPrintType());
            }
            FindPrintInfo findPrint = FindPrint(post.GetTitle(), post.GetPrintType(), forceSelect);

            if (!findPrint.found)
            {
                TracePost(post, "post not selected");
                return(false);
            }

            // corrigé le 20/11/2014
            //DownloadPostKey key = new DownloadPostKey { server = post.server, id = post.id };
            DownloadPostKey_v1 key = new DownloadPostKey_v1 {
                server = post.GetServer(), id = post.GetKey()
            };
            // state : NotDownloaded, WaitToDownload, DownloadStarted, DownloadCompleted, DownloadFailed
            DownloadState state = GetDownloadFileState(key);

            //if (state != DownloadState.NotDownloaded && !forceDownloadAgain)
            if ((state == DownloadState.WaitToDownload || state == DownloadState.DownloadStarted || state == DownloadState.DownloadCompleted) && !forceDownloadAgain)
            {
                if (FilterTracePost(state))
                {
                    TracePost(post, "post " + GetDownloadStateText1(state), findPrint.file);
                }
                return(false);
            }

            string file = findPrint.file;

            if (downloadDirectory != null)
            {
                file = downloadDirectory + "\\" + file;
            }

            if (simulateDownload)
            {
                TracePost(post, "simulate start download", file);
                return(false);
            }
            else
            {
                TracePost(post, "start download", file);
            }

            if (_downloadManager_v1 != null)
            {
                Try(() => _downloadManager_v1.DownloadFile(key, post.GetDownloadLinks(), file));
            }
            if (_downloadManager != null)
            {
                Try(() => _downloadManager.AddFileToDownload(key, post.GetDownloadLinks_new(), file));
            }

            return(true);
        }
        private IPostToDownload_v1 LoadPost(DownloadPostKey_v1 key)
        {
            if (!_servers_v1.ContainsKey(key.server))
            {
                Trace.WriteLine("error unknow server \"{0}\"", key.server);

                return(null);
            }
            return(_servers_v1[key.server].LoadPost(key.id));
        }
 private DownloadState GetDownloadFileState(DownloadPostKey_v1 key)
 {
     if (_downloadManager_v1 != null)
     {
         return(_downloadManager_v1.GetDownloadFileState(key));
     }
     else if (_downloadManager != null)
     {
         return(_downloadManager.GetDownloadFileState(key));
     }
     else
     {
         return(DownloadState.NotDownloaded);
     }
 }