ScrewTurn.Wiki.SettingsStorageProvider.StoreOutgoingLinks C# (CSharp) Method

StoreOutgoingLinks() public method

Stores the outgoing links of a page, overwriting existing data.
If page or outgoingLinks are null. If page or outgoingLinks are empty.
public StoreOutgoingLinks ( string page, string outgoingLinks ) : bool
page string The full name of the page.
outgoingLinks string The full names of the pages that page links to.
return bool
        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;
        }