public bool StoreOutgoingLinks(string page, string[] outgoingLinks)
{
if(page == null) throw new ArgumentNullException("page");
if(page.Length == 0) throw new ArgumentException("Page cannot be empty", "page");
if(outgoingLinks == null) throw new ArgumentNullException("outgoingLinks");
lock(this) {
// Step 1: remove old values
string[] lines = File.ReadAllLines(GetFullPath(LinksFile));
StringBuilder sb = new StringBuilder(lines.Length * 100);
string testString = page + "|";
foreach(string line in lines) {
if(!line.StartsWith(testString)) {
sb.Append(line);
sb.Append("\r\n");
}
}
lines = null;
// Step 2: add new values
sb.Append(page);
sb.Append("|");
for(int i = 0; i < outgoingLinks.Length; i++) {
if(outgoingLinks[i] == null) throw new ArgumentNullException("outgoingLinks", "Null element in outgoing links array");
if(outgoingLinks[i].Length == 0) throw new ArgumentException("Elements in outgoing links cannot be empty", "outgoingLinks");
sb.Append(outgoingLinks[i]);
if(i != outgoingLinks.Length - 1) sb.Append("|");
}
sb.Append("\r\n");
File.WriteAllText(GetFullPath(LinksFile), sb.ToString());
}
return true;
}