Skip to content

Commit

Permalink
Added Code to read AppData
Browse files Browse the repository at this point in the history
Added Code to read configuration from AppData
  • Loading branch information
subodhjena committed Dec 31, 2013
1 parent 5fd093e commit 642a9aa
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 11 deletions.
9 changes: 5 additions & 4 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0"?>
<configuration>

<configSections>
<section name="abot" type="Abot.Core.AbotConfigurationSectionHandler, Abot"/>
</configSections>

<abot>
<crawlBehavior
maxConcurrentThreads="20"
Expand All @@ -24,8 +25,7 @@
minAvailableMemoryRequiredInMb="0"
maxMemoryUsageInMb="0"
maxMemoryUsageCacheTimeInSeconds="0"
maxCrawlDepth="100"
/>
maxCrawlDepth="100"/>
<politeness
isRespectRobotsDotTextEnabled="false"
robotsDotTextUserAgentString="abot"
Expand All @@ -36,4 +36,5 @@
<add key="SomeCustomConfigKey2" value="someValue2"/>
</extensionValues>
</abot>
</configuration>

</configuration>
2 changes: 2 additions & 0 deletions AppData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ConnectionString,data source=localhost;initial catalog=FileCrawler;Integrated security=true
WebsiteName,http://www.google.com/
11 changes: 9 additions & 2 deletions CrawlerDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/// <summary>
/// Method to Insert a new URL to the specified table to Database
/// </summary>
Expand Down
43 changes: 43 additions & 0 deletions FileTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,49 @@ public List<String> 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;
Expand Down
15 changes: 10 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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
Expand Down

0 comments on commit 642a9aa

Please sign in to comment.