Beispiel #1
0
        private IPostToDownload LoadPost(ServerKey key)
        {
            if (!_servers.ContainsKey(key.Server))
            {
                Trace.WriteLine("error unknow server \"{0}\"", key.Server);

                return(null);
            }
            return(_servers[key.Server].Load(key.Id));
        }
Beispiel #2
0
        public bool TryDownloadPost(IPostToDownload 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);
            }

            ServerKey key = new ServerKey {
                Server = post.GetServer(), Id = post.GetKey()
            };
            // state : NotDownloaded, WaitToDownload, DownloadStarted, DownloadCompleted, DownloadFailed
            DownloadState state = GetDownloadFileState(key);

            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);
            }

            // file : "print\.02_hebdo\Challenges\Challenges - 2016-03-31 - no 481"
            if (_downloadManager != null)
            {
                Try(() => _downloadManager.AddFileToDownload(key, post.GetDownloadLinks(), file));
            }

            return(true);
        }
Beispiel #3
0
 private DownloadState GetDownloadFileState(ServerKey key)
 {
     //if (_downloadManager_v1 != null)
     //    return _downloadManager_v1.GetDownloadFileState(key);
     if (_downloadManager != null)
     {
         return(_downloadManager.GetDownloadFileState(key));
     }
     else
     {
         return(DownloadState.NotDownloaded);
     }
 }
Beispiel #4
0
        public DownloadState GetDownloadFileState(ServerKey key)
        {
            DownloadedFile downloadedFile = GetDownloadedFile(key);

            if (downloadedFile != null)
            {
                return(downloadedFile.State);
            }
            QueueDownloadFile queueDownloadFile = GetQueueDownloadFile(key);

            if (queueDownloadFile != null)
            {
                return(DownloadState.WaitToDownload);
            }
            return(DownloadState.NotDownloaded);
        }
Beispiel #5
0
        public void AddFileToDownload(ServerKey key, IRequestDownloadLinks downloadLinks, string file = null)
        {
            DownloadItemLink[] downloadItemLinks = DownloadItemLink.CreateDownloadItemLinkArray(downloadLinks);

            QueueDownloadFile downloadFile = new QueueDownloadFile
            {
                Key = key,
                DownloadItemLinks                       = downloadItemLinks,
                RequestTime                             = DateTime.Now,
                Directory                               = file != null?zPath.GetDirectoryName(file) : null,
                                               Filename = file != null?zPath.GetFileName(file) : null
            };

            downloadFile.Id       = _mongoQueueDownloadFileManager.GetNewId();
            downloadFile.Modified = true;
            SaveQueueDownloadFile(downloadFile);
        }
 private IPostToDownload LoadPost(ServerKey key)
 {
     if (!_servers.ContainsKey(key.Server))
     {
         Trace.WriteLine("error unknow server \"{0}\"", key.Server);
         return null;
     }
     return _servers[key.Server].Load(key.Id);
 }
 private DownloadState GetDownloadFileState(ServerKey key)
 {
     //if (_downloadManager_v1 != null)
     //    return _downloadManager_v1.GetDownloadFileState(key);
     if (_downloadManager != null)
         return _downloadManager.GetDownloadFileState(key);
     else
         return DownloadState.NotDownloaded;
 }
        public bool TryDownloadPost(IPostToDownload 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;
            }

            ServerKey key = new ServerKey { Server = post.GetServer(), Id = post.GetKey() };
            // state : NotDownloaded, WaitToDownload, DownloadStarted, DownloadCompleted, DownloadFailed
            DownloadState state = GetDownloadFileState(key);
            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);

            // file : "print\.02_hebdo\Challenges\Challenges - 2016-03-31 - no 481"
            if (_downloadManager != null)
                Try(() => _downloadManager.AddFileToDownload(key, post.GetDownloadLinks(), file));

            return true;
        }
Beispiel #9
0
 public DownloadState GetDownloadFileState(ServerKey key)
 {
     DownloadedFile downloadedFile = GetDownloadedFile(key);
     if (downloadedFile != null)
         return downloadedFile.State;
     QueueDownloadFile queueDownloadFile = GetQueueDownloadFile(key);
     if (queueDownloadFile != null)
         return DownloadState.WaitToDownload;
     return DownloadState.NotDownloaded;
 }
Beispiel #10
0
        public void AddFileToDownload(ServerKey key, IRequestDownloadLinks downloadLinks, string file = null)
        {
            DownloadItemLink[] downloadItemLinks = DownloadItemLink.CreateDownloadItemLinkArray(downloadLinks);

            QueueDownloadFile downloadFile = new QueueDownloadFile
            {
                Key = key,
                DownloadItemLinks = downloadItemLinks,
                RequestTime = DateTime.Now,
                Directory = file != null ? zPath.GetDirectoryName(file) : null,
                Filename = file != null ? zPath.GetFileName(file) : null
            };
            downloadFile.Id = _mongoQueueDownloadFileManager.GetNewId();
            downloadFile.Modified = true;
            SaveQueueDownloadFile(downloadFile);
        }