Skip to content

Commit

Permalink
Modified to get the Current Machine Name and User
Browse files Browse the repository at this point in the history
Modified to get the Current Machine Name and User
  • Loading branch information
subodhjena committed Dec 31, 2013
1 parent a7a571f commit 5fd093e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 11 additions & 1 deletion CrawlerDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ public class CrawlerDB
{
public const string DB_CONN_STRING = "data source=SUBODH;initial catalog=FileCrawler;Integrated security=true";

#region "Inserts new url to database|SaveFileURLToDB(String tableName, String hostName, string fileType, string fileDescription,string fileUrl)"
/// <summary>
/// Method to Insert a new URL to the specified table to Database
/// </summary>
/// <param name="tableName">The Table name to which the URL will be Inserted</param>
/// <param name="hostName">The url host</param>
/// <param name="fileType">the type of file to be Inserted</param>
/// <param name="fileDescription">File Description</param>
/// <param name="fileUrl">The URL of the file</param>
public void SaveFileURLToDB(String tableName, String hostName, string fileType, string fileDescription,string fileUrl)
{
using (SqlConnection con = new SqlConnection(DB_CONN_STRING))
Expand All @@ -22,7 +31,7 @@ public void SaveFileURLToDB(String tableName, String hostName, string fileType,
command.Parameters.Add(new SqlParameter("fileDescription", fileDescription));
command.Parameters.Add(new SqlParameter("url", fileUrl));
command.Parameters.Add(new SqlParameter("createdDt", DateTime.Now.ToString()));
command.Parameters.Add(new SqlParameter("createdByName", "Subodh"));
command.Parameters.Add(new SqlParameter("createdByName",Environment.MachineName + "/" + Environment.UserName));
command.Parameters.Add(new SqlParameter("updatedDt", DBNull.Value));
command.Parameters.Add(new SqlParameter("updatedByName", DBNull.Value));
command.ExecuteNonQuery();
Expand All @@ -39,6 +48,7 @@ public void SaveFileURLToDB(String tableName, String hostName, string fileType,
}
}
}
#endregion

}
}
Expand Down
12 changes: 8 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@ namespace FileCrawler
{
class Program
{
static String webURL = @"http://ebooks.allfree-stuff.com/";

#region "Fields and Object Declaration"

static String webURL = @"http://ebooks.allfree-stuff.com/";
static String fileTypePath = @"C:\Users\Subodhlc\Documents\Visual Studio 2012\Projects\FileCrawler\FileCrawler\FileTypes";
static CrawlerDB crawalerDatabase = new CrawlerDB();
static FileTypes fileTyp = new FileTypes();
static List<String> filters;

#endregion


static void Main(string[] args)
{
//Will Get the FileTypes to Download
filters = fileTyp.GetFileTypesToDownlaod(fileTypePath);

//Will use app.config for confguration
PoliteWebCrawler crawler = new PoliteWebCrawler();

#region "Crawler Events"
crawler.PageCrawlStartingAsync += crawler_ProcessPageCrawlStarting;
crawler.PageCrawlCompletedAsync += crawler_ProcessPageCrawlCompleted;
crawler.PageCrawlDisallowedAsync += crawler_PageCrawlDisallowed;
crawler.PageLinksCrawlDisallowedAsync += crawler_PageLinksCrawlDisallowed;
#endregion

CrawlResult result = crawler.Crawl(new Uri(webURL));
if (result.ErrorOccurred)
Expand All @@ -45,6 +46,7 @@ static void Main(string[] args)
Console.WriteLine("Crawl of {0} completed without error.", result.RootUri.AbsoluteUri);
}

#region "Crawler Event Delegates"
static void crawler_ProcessPageCrawlStarting(object sender, PageCrawlStartingArgs e)
{
PageToCrawl pageToCrawl = e.PageToCrawl;
Expand Down Expand Up @@ -74,6 +76,7 @@ static void crawler_PageCrawlDisallowed(object sender, PageCrawlDisallowedArgs e
Console.WriteLine("Did not crawl page {0} due to {1}", pageToCrawl.Uri.AbsoluteUri, e.DisallowedReason);
SavePageCrawlDisallowed(pageToCrawl.Uri.AbsoluteUri);
}
#endregion

//Saving the file links
private static void SaveURLSuccess(string p)
Expand Down Expand Up @@ -102,7 +105,7 @@ private static void SavePageCrawlDisallowed(string p)
WriteToDB(p);
}

//DB Writes
#region "Inserts new url to database"
private static void WriteToDB(string p)
{
try
Expand Down Expand Up @@ -131,6 +134,7 @@ private static void WriteToDB(string p)
System.Console.WriteLine("**************************************");
}
}
#endregion

}
}

0 comments on commit 5fd093e

Please sign in to comment.