/plugins/Session.cs
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using bytex64.WebThing;

public class Session : WebThingPlugin {
    WebThing wt;
    string CurrentSession = "Default";

    public override void Init(WebThing wt) {
        this.wt = wt;
        if (Config.Arguments.Length == 0) {
            if (Config.Options.ContainsKey("Session")) {
                RestoreSession(Config.Options["Session"]);
            } else if (Options.ContainsKey("Default")) {
                RestoreSession("Default");
            }
        }
    }

    public override void Deinit(WebThing wt) {
        if (Options.ContainsKey("AutoSave") && Config.ParseBool(Options["AutoSave"])) {
            SaveSession(CurrentSession);
        }
    }

    public void RestoreSession(string SessionName) {
        if (Options.ContainsKey(SessionName)) {
            while (wt.Tabs.NPages > 0) {
                WebThingView wtv = wt.Tabs.CurrentPageWidget as WebThingView;
                wt.Tabs.Remove(wtv);
                wtv.Dispose();
            }
            string[] pages = Regex.Split(Options[SessionName], @"\s+");
            foreach (string page in pages) {
                wt.OpenTab(page);
            }
            CurrentSession = SessionName;
        } else {
            Console.WriteLine("Could not restore session {0} because it does not exist.", SessionName);
        }
    }

    public void SaveSession(string SessionName) {
        List<string> Uris = new List<string>();
        foreach (WebThingView wtv in wt.Tabs) {
            Uris.Add(wtv.WebView.MainFrame.Uri);
        }
        Options[SessionName] = String.Join(" ", Uris.ToArray());
        SaveConfig();
    }

    public void DeleteSession(string SessionName) {
        Options.Remove(SessionName);
        SaveConfig();
    }
}