Ejemplo n.º 1
0
        void AddBookToUpdateQueue(BookElementEx bex, Book.ScrapeSet scrapedSet)
        {
            StreamWriter sw = new StreamWriter(m_config.SqlFile, true /*fAppend*/, System.Text.Encoding.Default);

            sw.WriteLine(BuildSetString(bex, null, scrapedSet));
            sw.Close();
        }
Ejemplo n.º 2
0
        void LogBookUpdateError(BookElementEx bex, Book.ScrapeSet scrapedSet, string sReason)
        {
            StreamWriter swSql = new StreamWriter(m_config.SqlFile, true /*fAppend*/, System.Text.Encoding.Default);
            StreamWriter swLog = new StreamWriter(m_config.LogFile, true /*fAppend*/, System.Text.Encoding.Default);

            swLog.WriteLine($"{bex.ScanCode}: {bex.Title}: FAILED: {sReason}");
            swLog.Close();

            swSql.WriteLine(BuildSetString(bex, " -- FAILED QUERY!", scrapedSet));

            swSql.Close();
        }
Ejemplo n.º 3
0
        private bool DownloadCoverForBook(BookElementEx bex, string sLocalRoot, string sLocalPath, out string sError)
        {
            sError = null;
            try
            {
                string sFullPath = Path.Combine(sLocalRoot, sLocalPath);

                if (!Directory.Exists(sFullPath))
                {
                    Directory.CreateDirectory(sFullPath);
                }

                Uri        uri = new Uri($"http://{bex.RawCoverUrl}");
                WebRequest req = WebRequest.Create(uri);

                string sPathname    = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);
                string sFilename    = Path.GetFileName(sPathname);
                string sFullOutPath = Path.Combine(sFullPath, sFilename);
                string sOutPath     = $"{sLocalPath}\\{sFilename}";

                WebResponse response = req.GetResponse();

                Stream stream = response.GetResponseStream();
                Stream stmOut = new FileStream(sFullOutPath, FileMode.Create);

                stream.CopyTo(stmOut);
                stmOut.Close();
                stmOut.Dispose();
                stream.Close();
                stream.Dispose();
                response.Close();
                response.Dispose();

                bex.RawCoverUrl = sOutPath;
                return(true);
            }
            catch (Exception exc)
            {
                bex.RawCoverUrl = null;
                sError          = $"failed to download cover art: {bex.RawCoverUrl}: {exc.Message}";
                return(false);
            }
        }
Ejemplo n.º 4
0
        string BuildSetString(BookElementEx bex, string sComment, Book.ScrapeSet set)
        {
            List <string> plsSet = new List <string>();

            UpdateStatus status = (UpdateStatus)bex.UpdateStatus;

            plsSet.Add(String.Format(" LastUpdate='{0}' ", DateTime.Now.ToString("d")));

            if (!String.IsNullOrEmpty(bex.ReleaseDate) && set.HasFlag(Book.ScrapeSet.ReleaseDate))
            {
                DateTime dttm = DateTime.Parse(bex.ReleaseDate);

                plsSet.Add(String.Format(" ReleaseDate='{0}' ", dttm.ToString("yyyy/MM/dd")));
                status |= UpdateStatus.ReleaseDate;
            }

            if (!String.IsNullOrEmpty(bex.Author) && set.HasFlag(Book.ScrapeSet.Author))
            {
                plsSet.Add($" Author='{Sql.Sqlify(bex.Author)}' ");
                status |= UpdateStatus.Author;
            }

            if (!String.IsNullOrEmpty(bex.RawCoverUrl) && set.HasFlag(Book.ScrapeSet.CoverSrc))
            {
                plsSet.Add($" CoverSrc='{Sql.Sqlify(bex.RawCoverUrl)}' ");
                status |= UpdateStatus.CoverSrc;
            }

            if (!String.IsNullOrEmpty(bex.Series) && set.HasFlag(Book.ScrapeSet.Series))
            {
                plsSet.Add($" Series='{Sql.Sqlify(bex.Series)}' ");
                status |= UpdateStatus.Series;
            }

            if (!String.IsNullOrEmpty(bex.Summary) && set.HasFlag(Book.ScrapeSet.Summary))
            {
                string s = Sql.Sqlify(bex.Summary);

                s = s.Replace("\n", "' + CHAR(13) + CHAR(10) + '");
                plsSet.Add($" Summary='{s}' ");
                status |= UpdateStatus.Summary;
            }

            StringBuilder sb = new StringBuilder(256);

            sb.Append($"UPDATE upc_Books SET UpdateStatus={(int)status} ");

            foreach (string s in plsSet)
            {
                sb.Append(", ");
                sb.Append(s);
            }

            sb.Append($"WHERE ID='{bex.BookID}'");
            if (!String.IsNullOrEmpty(sComment))
            {
                sb.Append(sComment);
            }

            return(sb.ToString());
        }