Exemplo n.º 1
0
        private void SaveDownloadedFileInfo(IPostToDownload post, DownloadedFile downloadedFile)
        {
            //if (_downloadDirectory == null || downloadedFile.File == null)
            //    return;
            //string file = zPath.Combine(_downloadDirectory, zPath.GetDirectoryName(downloadedFile.File), _infoDirectory, zPath.GetFileName(downloadedFile.File)) + _infoSuffixFile;

            if (_downloadDirectory == null || downloadedFile.DownloadedFiles.Length == 0)
            {
                return;
            }
            // save info file to sub-directory .i, file = .i\filename.i
            string file = downloadedFile.DownloadedFiles[0];

            //file = zPath.Combine(_downloadDirectory, zPath.GetDirectoryName(file), _infoDirectory, zPath.GetFileName(file)) + _infoSuffixFile;
            file = zPath.Combine(_downloadDirectory, InfoFile.GetInfoFile(file));

            zfile.CreateFileDirectory(file);
            BsonDocument postDocument;

            if (post != null)
            {
                postDocument = post.ToBsonDocument();
            }
            else
            {
                postDocument = new BsonDocument();
            }
            new BsonDocument {
                { "Post", postDocument }, { "DownloadedFile", downloadedFile.ToBsonDocument() }
            }.zSave(file);
        }
Exemplo n.º 2
0
        private static string GetPostMessage(IPostToDownload post, string message, string file = null, string downloadLink = null, bool formated = true)
        {
            int messageLength   = 50;
            int printTypeLength = 25;

            if (!formated)
            {
                messageLength   = 0;
                printTypeLength = 0;
            }

            //string formatMessage;
            //if (formated)
            //    formatMessage = "{0,-50}";
            //else
            //    formatMessage = "{0}";
            //string formatPrintType;
            //if (formated)
            //    formatPrintType = "{0,-25}";
            //else
            //    formatPrintType = "{0}";

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0:dd-MM-yyyy HH:mm:ss}", DateTime.Now);
            sb.Append(" - ");
            //sb.AppendFormat("{0,-50}", message);
            sb.Append(message.PadRight(messageLength));
            sb.Append(" - ");
            if (post != null)
            {
                //sb.AppendFormat("{0,-25} - ", post.GetPrintType());
                sb.Append(post.GetPrintType().ToString().PadRight(printTypeLength));
                sb.Append(" - ");
                sb.AppendFormat("\"{0}\"", post.GetTitle());
            }
            else
            {
                sb.Append("(post is null)");
            }
            if (file != null)
            {
                sb.AppendFormat(" - \"{0}\"", file);
            }
            if (post != null)
            {
                sb.AppendFormat(" - \"{0}\"", post.GetDataHttpRequest().Url);
            }
            if (downloadLink != null)
            {
                sb.AppendFormat(" - link \"{0}\"", downloadLink);
            }
            return(sb.ToString());
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private void Downloaded(DownloadedFile downloadedFile)
        {
            string          message = GetDownloadStateText2(downloadedFile.State);
            IPostToDownload post    = null;

            if (downloadedFile.Key != null)
            {
                post = LoadPost(downloadedFile.Key);
            }
            //Trace.WriteLine("Downloaded : downloadedFile.Key {0}", downloadedFile.Key != null ? downloadedFile.Key.ToString() : "(null)");
            //Trace.WriteLine("Downloaded : post {0}", post != null ? post.ToString() : "(null)");

            SaveDownloadedFileInfo(post, downloadedFile);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(GetPostMessage(post, message));
            if (downloadedFile.DownloadedFiles != null)
            {
                foreach (string file in downloadedFile.DownloadedFiles)
                {
                    sb.AppendLine(string.Format("  file : \"{0}\"", file));
                }
            }
            if (downloadedFile.UncompressFiles != null)
            {
                foreach (string file in downloadedFile.UncompressFiles)
                {
                    sb.AppendLine(string.Format("  uncompress file : \"{0}\"", file));
                }
            }
            Trace.Write(sb.ToString());

            MailAddLine(GetPostMessage(post, message, formated: false));
            if (downloadedFile.DownloadedFiles != null)
            {
                foreach (string file in downloadedFile.DownloadedFiles)
                {
                    MailAddLine(string.Format("  file : \"{0}\"", file));
                }
            }
            if (downloadedFile.UncompressFiles != null)
            {
                foreach (string file in downloadedFile.UncompressFiles)
                {
                    MailAddLine(string.Format("  uncompress file : \"{0}\"", file));
                }
            }
        }
Exemplo n.º 5
0
 private static void TracePost(IPostToDownload post, string message, string file = null, string downloadLink = null)
 {
     Trace.WriteLine(GetPostMessage(post, message, file, downloadLink));
 }
Exemplo n.º 6
0
 private static void TracePost(IPostToDownload post, string message, string file = null, string downloadLink = null)
 {
     Trace.WriteLine(GetPostMessage(post, message, file, downloadLink));
 }
Exemplo n.º 7
0
        private static string GetPostMessage(IPostToDownload post, string message, string file = null, string downloadLink = null, bool formated = true)
        {
            int messageLength = 50;
            int printTypeLength = 25;
            if (!formated)
            {
                messageLength = 0;
                printTypeLength = 0;
            }

            //string formatMessage;
            //if (formated)
            //    formatMessage = "{0,-50}";
            //else
            //    formatMessage = "{0}";
            //string formatPrintType;
            //if (formated)
            //    formatPrintType = "{0,-25}";
            //else
            //    formatPrintType = "{0}";

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("{0:dd-MM-yyyy HH:mm:ss}", DateTime.Now);
            sb.Append(" - ");
            //sb.AppendFormat("{0,-50}", message);
            sb.Append(message.PadRight(messageLength));
            sb.Append(" - ");
            if (post != null)
            {
                //sb.AppendFormat("{0,-25} - ", post.GetPrintType());
                sb.Append(post.GetPrintType().ToString().PadRight(printTypeLength));
                sb.Append(" - ");
                sb.AppendFormat("\"{0}\"", post.GetTitle());
            }
            else
                sb.Append("(post is null)");
            if (file != null)
                sb.AppendFormat(" - \"{0}\"", file);
            if (post != null)
                sb.AppendFormat(" - \"{0}\"", post.GetDataHttpRequest().Url);
            if (downloadLink != null)
                sb.AppendFormat(" - link \"{0}\"", downloadLink);
            return sb.ToString();
        }
Exemplo n.º 8
0
        private void SaveDownloadedFileInfo(IPostToDownload post, DownloadedFile downloadedFile)
        {
            //if (_downloadDirectory == null || downloadedFile.File == null)
            //    return;
            //string file = zPath.Combine(_downloadDirectory, zPath.GetDirectoryName(downloadedFile.File), _infoDirectory, zPath.GetFileName(downloadedFile.File)) + _infoSuffixFile;

            if (_downloadDirectory == null || downloadedFile.DownloadedFiles.Length == 0)
                return;
            // save info file to sub-directory .i, file = .i\filename.i
            string file = downloadedFile.DownloadedFiles[0];
            //file = zPath.Combine(_downloadDirectory, zPath.GetDirectoryName(file), _infoDirectory, zPath.GetFileName(file)) + _infoSuffixFile;
            file = zPath.Combine(_downloadDirectory, InfoFile.GetInfoFile(file));

            zfile.CreateFileDirectory(file);
            BsonDocument postDocument;
            if (post != null)
                postDocument = post.ToBsonDocument();
            else
                postDocument = new BsonDocument();
            new BsonDocument { { "Post", postDocument }, { "DownloadedFile", downloadedFile.ToBsonDocument() } }.zSave(file);
        }
Exemplo n.º 9
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;
        }