From 642a9aa5da974ff6074d031a521402fafcbf3c25 Mon Sep 17 00:00:00 2001 From: Subodh Jena Date: Tue, 31 Dec 2013 15:23:43 +0530 Subject: [PATCH] Added Code to read AppData Added Code to read configuration from AppData --- App.config | 9 +++++---- AppData.csv | 2 ++ CrawlerDB.cs | 11 +++++++++-- FileTypes.cs | 43 +++++++++++++++++++++++++++++++++++++++++++ Program.cs | 15 ++++++++++----- 5 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 AppData.csv diff --git a/App.config b/App.config index e862e58..ab37448 100644 --- a/App.config +++ b/App.config @@ -1,9 +1,10 @@  +
- + + maxCrawlDepth="100"/> - \ No newline at end of file + + \ No newline at end of file diff --git a/AppData.csv b/AppData.csv new file mode 100644 index 0000000..70b9099 --- /dev/null +++ b/AppData.csv @@ -0,0 +1,2 @@ +ConnectionString,data source=localhost;initial catalog=FileCrawler;Integrated security=true +WebsiteName,http://www.google.com/ \ No newline at end of file diff --git a/CrawlerDB.cs b/CrawlerDB.cs index fc24ebc..2f7df07 100644 --- a/CrawlerDB.cs +++ b/CrawlerDB.cs @@ -2,13 +2,20 @@ using System.Data.SqlClient; using System.Data; using System.Globalization; +using System.Configuration; + namespace FileCrawler { public class CrawlerDB { - public const string DB_CONN_STRING = "data source=SUBODH;initial catalog=FileCrawler;Integrated security=true"; + public String DB_CONN_STRING = null; + + public CrawlerDB(String connection) + { + DB_CONN_STRING = connection; + } - #region "Inserts new url to database|SaveFileURLToDB(String tableName, String hostName, string fileType, string fileDescription,string fileUrl)" + #region "Inserts new url to database | SaveFileURLToDB" /// /// Method to Insert a new URL to the specified table to Database /// diff --git a/FileTypes.cs b/FileTypes.cs index 43099bc..9b9a029 100644 --- a/FileTypes.cs +++ b/FileTypes.cs @@ -22,6 +22,49 @@ public List GetFileTypesToDownlaod(String p) return fileList; } + public String GetConnectionString(String p) + { + int counter = 0; + string line; + String returnVal = "Please Update the app data file."; + + // Read the file and display it line by line. + reader = new System.IO.StreamReader(p); + while ((line = reader.ReadLine()) != null) + { + String[] connectionString = line.Trim().Split(','); + if (connectionString[0].ToString() == "ConnectionString") + { + returnVal = connectionString[1]; + } + counter++; + } + + reader.Close(); + return returnVal; + } + public String GetHostToCrawlString(String p) + { + int counter = 0; + string line; + String returnVal = "Please Update the app data file."; + + // Read the file and display it line by line. + reader = new System.IO.StreamReader(p); + while ((line = reader.ReadLine()) != null) + { + String[] connectionString = line.Trim().Split(','); + if (connectionString[0].ToString() == "WebsiteName") + { + returnVal = connectionString[1]; + } + counter++; + } + + reader.Close(); + return returnVal; + } + private void ReadCSVToOne(String filePath) { int counter = 0; diff --git a/Program.cs b/Program.cs index c3d6acb..117ec8b 100644 --- a/Program.cs +++ b/Program.cs @@ -9,24 +9,29 @@ using System.IO; using System.Data.SqlClient; using System.Data; +using System.Configuration; namespace FileCrawler { class Program { - static String webURL = @"http://ebooks.allfree-stuff.com/"; - #region "Fields and Object Declaration" + static String connectionString; + static String webURL; + static string appDataPath = @"C:\Users\sjena\Documents\GitHub\FileCrawler\AppData.csv"; + static String fileTypePath = @"C:\Users\sjena\Documents\GitHub\FileCrawler\FileTypes"; - static String fileTypePath = @"C:\Users\Subodhlc\Documents\Visual Studio 2012\Projects\FileCrawler\FileCrawler\FileTypes"; - static CrawlerDB crawalerDatabase = new CrawlerDB(); + static CrawlerDB crawalerDatabase = new CrawlerDB(connectionString); static FileTypes fileTyp = new FileTypes(); static List filters; - #endregion static void Main(string[] args) { + //Read Configuration from File + connectionString = fileTyp.GetConnectionString(appDataPath); + webURL = fileTyp.GetHostToCrawlString(appDataPath); + //Will Get the FileTypes to Download filters = fileTyp.GetFileTypesToDownlaod(fileTypePath); //Will use app.config for confguration