public RootController()
            : base(new RootElement ("Netstat"))
        {
            Settings = Settings.Instance;

            section = new Section ();
            Root.Add (section);

            displayedEntries = new Dictionary<NetstatEntry,DateTime> ();

            RefreshRequested += (sender, e) => {
                Populate ();
                ReloadComplete ();
            };

            Settings.Modified += (sender, e) => InvokeOnMainThread (() => {
                displayedEntries.Clear ();
                Populate ();
            });

            timer = NSTimer.CreateRepeatingTimer (1.0, () => {
                if (View.Hidden || !Settings.AutoRefresh)
                    return;
                Populate ();
            });
            NSRunLoop.Main.AddTimer (timer, NSRunLoopMode.Default);
        }
        public SettingsController()
            : base(new RootElement ("Settings"), true)
        {
            Settings = Settings.Instance;

            var section = new Section ();
            Root.Add (section);

            var showListening = new BooleanElement ("Show listening sockets", Settings.ShowListening);
            showListening.ValueChanged += (sender, e) => {
                Settings.ShowListening = showListening.Value;
            };
            section.Add (showListening);

            var showLocal = new BooleanElement ("Show local connections", Settings.ShowLocal);
            showLocal.ValueChanged += (sender, e) => {
                Settings.ShowLocal = showLocal.Value;
            };
            section.Add (showLocal);

            var autoRefresh = new BooleanElement ("Auto refresh", Settings.AutoRefresh);
            autoRefresh.ValueChanged += (sender, e) => {
                Settings.AutoRefresh = autoRefresh.Value;
            };
            section.Add (autoRefresh);

            var filterSection = new Section ();
            Root.Add (filterSection);

            var usePortFilter = new BooleanElement ("Use Port filter", Settings.UsePortFilter);
            usePortFilter.ValueChanged += (sender, e) => {
                Settings.UsePortFilter = usePortFilter.Value;
            };
            filterSection.Add (usePortFilter);

            var portFilter = new EntryElement ("Port filter", "<port>", Settings.PortFilter.ToString ());
            portFilter.Changed += (sender, e) => {
                int port;
                if (!int.TryParse (portFilter.Value, out port))
                    portFilter.Value = Settings.PortFilter.ToString ();
                else
                    Settings.PortFilter = port;
            };
            filterSection.Add (portFilter);

            var spSection = new Section ();
            Root.Add (spSection);

            var connectionLimit = new EntryElement ("Connection limit", "<number>", Settings.ConnectionLimit.ToString ());
            connectionLimit.Changed += (sender, e) => {
                int value;
                if (!int.TryParse (connectionLimit.Value, out value))
                    connectionLimit.Value = Settings.ConnectionLimit.ToString ();
                else
                    Settings.ConnectionLimit = value;
            };
            spSection.Add (connectionLimit);

            var spIdle = new EntryElement ("SP idle time", "<idle-time>", Settings.ServicePointIdleTime.ToString ());
            spIdle.Changed += (sender, e) => {
                int value;
                if (!int.TryParse (spIdle.Value, out value))
                    spIdle.Value = Settings.ServicePointIdleTime.ToString ();
                else
                    Settings.ServicePointIdleTime = value;
            };
            spSection.Add (spIdle);

            Settings.Modified += (sender, e) => InvokeOnMainThread (() => {
                var newPfValue = Settings.PortFilter.ToString ();
                if (!string.Equals (portFilter.Value, newPfValue)) {
                    portFilter.Value = newPfValue;
                    Root.Reload (portFilter, UITableViewRowAnimation.Automatic);
                }

                if (usePortFilter.Value != Settings.UsePortFilter) {
                    usePortFilter.Value = Settings.UsePortFilter;
                    Root.Reload (usePortFilter, UITableViewRowAnimation.Automatic);
                }
            });
        }