/* * public http() * { * statusCode = 0; * errorString = String.Empty; * contentType = String.Empty; * } */ public string binaryStream2MD5File(page p, BinaryReader binStream, string contentType, string contentLength) { string appPath = System.AppDomain.CurrentDomain.BaseDirectory.ToString(); md5 MD5 = new md5(); string fullPath = appPath + MD5.compute(p._page); nsGlobalOutput.output.write("\n + Downloading " + p.GenerateURL() + " ... "); nsGlobalOutput.output.write(" - Content-Type: " + contentType); nsGlobalOutput.output.write(" - Content-Length: " + contentLength + " bytes \n"); try { int BUFFER_SIZE = 4096; byte[] buf = new byte[BUFFER_SIZE]; System.IO.FileStream stream = new System.IO.FileStream(fullPath, System.IO.FileMode.Create); int n = binStream.Read(buf, 0, BUFFER_SIZE); while (n > 0) { stream.Write(buf, 0, n); n = binStream.Read(buf, 0, BUFFER_SIZE); } stream.Close(); } catch (Exception e) { nsGlobalOutput.output.write("Error: " + e.Message); } finally { binStream.Close(); } return(fullPath); }
/* indexMP3 * indicizza le informazioni estratte dal file MP3 */ public bool indexMP3(page p, mp3 MP3Info) { string outStr; string sql; bool ret; outStr = "\n"; outStr += " + Indexing MP3 [ " + p.GenerateURL() + " ]\n"; outStr += " - Title : " + MP3Info.mp3Title + "\n"; outStr += " - Artist : " + MP3Info.mp3Artist + "\n"; outStr += " - Album : " + MP3Info.mp3Album + "\n"; outStr += " - Genre : " + MP3Info.mp3Genre + "\n"; outStr += " - Duration: " + MP3Info.mp3Length + " seconds\n"; outStr += "\n"; nsGlobalOutput.output.write(outStr); sql = "INSERT INTO mp3 (host_id, filename, mp3_size, mp3_artist, mp3_title, mp3_album, mp3_genre, mp3_duration) " + "VALUES(" + p._hostID + ", " + "'" + myMySQLEscapeString(p._page) + "', " + "'" + MP3Info.mp3Size + "', " + "'" + myMySQLEscapeString(MP3Info.mp3Artist) + "', " + "'" + myMySQLEscapeString(MP3Info.mp3Title) + "', " + "'" + myMySQLEscapeString(MP3Info.mp3Album) + "', " + "'" + myMySQLEscapeString(MP3Info.mp3Genre) + "', " + MP3Info.mp3Length + ")"; GlobalVars.threadsVars.mutexMySQLPageList.WaitOne(); try { ret = GlobalVars.mysqlConn.connPageList.executeSQLQuery(sql); } catch (Exception e) { nsGlobalOutput.output.write("SQL Error: " + e.Message + "\n\nSQL: -===[\n" + sql.Substring(0, 1000) + "\n]===-\n\n"); ret = false; } finally { GlobalVars.threadsVars.mutexMySQLPageList.ReleaseMutex(); } return(ret); }
/* indexPDF * indicizza le informazioni estratte dal file PDF */ public bool indexPDF(page p, int pdfSize, string pdf2text) { string outStr; string sql; bool ret; outStr = "\n"; outStr += " + Indexing PDF [ " + p.GenerateURL() + " ]\n"; nsGlobalOutput.output.write(outStr); html htmp = new html(); pdf2text = htmp.removeUnWantedChars(pdf2text); addContent2Index(p._hostID, p._hostname, p._page, p._title, p._anchorText, p._depthLevel, pdf2text, pdf2text); sql = "INSERT INTO pdf (host_id, filename, pdf_size, pdf_text) " + "VALUES(" + p._hostID + ", " + "'" + myMySQLEscapeString(p._page) + "', " + "'" + pdfSize + "', " + "'" + myMySQLEscapeString(pdf2text) + "') "; GlobalVars.threadsVars.mutexMySQLPageList.WaitOne(); try { ret = GlobalVars.mysqlConn.connPageList.executeSQLQuery(sql); } catch (Exception e) { nsGlobalOutput.output.write("SQL Error: " + e.Message + "\n\nSQL: -===[\n" + sql.Substring(0, 1000) + "\n]===-\n\n"); ret = false; } finally { GlobalVars.threadsVars.mutexMySQLPageList.ReleaseMutex(); } return(ret); }
public string getURL(page p, bool followRedirects) { return(getURL(p.GenerateURL(), p, followRedirects)); }