public LoggingDialog()
        {
            InitializeComponent();

            _defaultIcon = Icon.FromHandle(ImageResources.ServiceShowLog.GetHicon());
            _errorIcon   = Icon.FromHandle(ImageResources.AgentStateError.GetHicon());

            this.Icon = _defaultIcon;

            btnConfigure.FlatAppearance.BorderSize = 0;
            btnConfigure.Image = ImageResources.ServiceConfigure;
            btnClear.FlatAppearance.BorderSize = 0;
            btnClear.Image = ImageResources.LogClear;
            btnStartStop.FlatAppearance.BorderSize = 0;
            btnStartStop.Image = ImageResources.LogPause;
            btnShow.FlatAppearance.BorderSize = 0;
            btnShow.Image = ImageResources.LogShow;

            gridLog.Columns.Add("timestamp", "Date");
            gridLog.Columns.Add("level", "Level");
            gridLog.Columns.Add("source", "Source");
            gridLog.Columns.Add("agentId", "Agent ID");
            gridLog.Columns.Add("message", "Message");
            gridLog.Columns.Add("exception", "Exception");

            gridLog.Columns["timestamp"].AutoSizeMode = BestFitColumnMode.DisplayedCells;
            gridLog.Columns["level"].AutoSizeMode     = BestFitColumnMode.DisplayedCells;
            gridLog.Columns["source"].AutoSizeMode    = BestFitColumnMode.DisplayedCells;
            gridLog.Columns["agentId"].AutoSizeMode   = BestFitColumnMode.DisplayedCells;
            gridLog.Columns["message"].AutoSizeMode   = BestFitColumnMode.DisplayedCells;
            gridLog.Columns["exception"].AutoSizeMode = BestFitColumnMode.DisplayedCells;

            gridLog.Columns["message"].MaxWidth   = gridLog.Width;
            gridLog.Columns["exception"].MaxWidth = gridLog.Width;
            gridLog.AutoSizeColumnsMode           = GridViewAutoSizeColumnsMode.Fill;
            gridLog.AllowAutoSizeColumns          = true;
            gridLog.AllowColumnResize             = true;

            gridLog.BestFitColumns();

            TelerikHelper.RegisterTooltipForRadControl(this, ttMain, gridLog);
        }
        public MultiagentUI()
        {
            InitializeComponent();

            _mainSynchronizationContext = SynchronizationContext.Current;
            _uiThemeSubject             = new BehaviorSubjectSlim <UITheme>(_uiThemes[DisplayMode.Night]);

            txtInformation.TextChanged += (s, e) => this.Text = string.Format("Multiagent v{0} (Legendary Edition) - {1}", this.GetType().Assembly.GetName().Version, txtInformation.Text);

            // http://www.iconarchive.com/show/oxygen-icons-by-oxygen-icons.org.html

            btnServiceStartStop.FlatAppearance.BorderSize = 0;
            btnServiceConfigure.FlatAppearance.BorderSize = 0;
            btnServiceShowLog.FlatAppearance.BorderSize   = 0;
            btnDisplayMode.FlatAppearance.BorderSize      = 0;
            btnAgentActivate.FlatAppearance.BorderSize    = 0;
            btnAgentDeactivate.FlatAppearance.BorderSize  = 0;
            btnAgentRecycle.FlatAppearance.BorderSize     = 0;
            btnAgentShowMainGui.FlatAppearance.BorderSize = 0;
            btnAgentCloseAllGui.FlatAppearance.BorderSize = 0;

            btnAgentActivate.Image    = ImageResources.AgentActivate;
            btnAgentDeactivate.Image  = ImageResources.AgentDeactivate;
            btnAgentRecycle.Image     = ImageResources.AgentRecycle;
            btnAgentShowMainGui.Image = ImageResources.AgentShowGui;
            btnAgentCloseAllGui.Image = ImageResources.AgentCloseGui;

            btnServiceConfigure.Image = ImageResources.ServiceConfigure;
            btnServiceShowLog.Image   = ImageResources.ServiceShowLog;
            btnDisplayMode.Image      = ImageResources.ServiceDisplayDay;

            var stateDescriptionExpr = string.Format(
                "IIF(reachable=false,'Disconnected', IIF(state={0},'Created', IIF(state={1},'Ready', IIF(state={2},'Activating', IIF(state={3},'Activated', IIF(state={4},'Deactivating', IIF(state={5},'Disposed', IIF(state={6},'Failed', 'Unknown'))))))))",
                (int)AgentState.Created,
                (int)AgentState.Idle,
                (int)AgentState.Activating,
                (int)AgentState.Activated,
                (int)AgentState.Deactivating,
                (int)AgentState.Disposed,
                (int)AgentState.Failed);

            _agents = new DataTable("agents");
            _agents.Columns.Add(new DataColumn("peer", typeof(string))
            {
                Caption = "Peer"
            });
            _agents.Columns.Add(new DataColumn("id", typeof(string))
            {
                Caption = "ID"
            });
            _agents.Columns.Add(new DataColumn("name", typeof(string))
            {
                Caption = "Name"
            });
            _agents.Columns.Add(new DataColumn("description", typeof(string))
            {
                Caption = "Description"
            });
            _agents.Columns.Add(new DataColumn("isInternal", typeof(bool))
            {
                Caption = "IsInternal (internal)"
            });
            _agents.Columns.Add(new DataColumn("state", typeof(AgentState))
            {
                Caption = "AgentState (internal)"
            });
            _agents.Columns.Add(new DataColumn("reachable", typeof(bool))
            {
                Caption = "Reachable (internal)"
            });
            _agents.Columns.Add(new DataColumn("stateDescription", typeof(string), stateDescriptionExpr)
            {
                Caption = "State"
            });
            _agents.PrimaryKey = new[] { _agents.Columns["id"] };

            gridAgents.DataSource = _agents.DefaultView;
            gridAgents.Columns["id"].IsVisible         = false;
            gridAgents.Columns["isInternal"].IsVisible = false;
            gridAgents.Columns["reachable"].IsVisible  = false;
            gridAgents.Columns["state"].IsVisible      = false;

            gridAgents.SortDescriptors.Add("id", ListSortDirection.Ascending);
            gridAgents.GroupDescriptors.Add("peer", ListSortDirection.Ascending);

            // completely load every themes now to avoid deadlocking (in ThemeRepository.FindTheme)
            // when loading a new theme while multiple forms are opened on 1+N different UI threads
            foreach (var theme in _uiThemes)
            {
                ThemeRepository.FindTheme(theme.Value.Theme.ThemeName);
            }

            TelerikHelper.RegisterTooltipForRadControl(this, ttMain, gridAgents);
        }