public GuiWindow(ImGuiWindow wnd, AppConfig ac) { _wnd = wnd; _ac = ac; log.Debug($"Running with masterIp={_ac.MasterIP}, masterPort={_ac.MasterPort}"); _clientIdent = new Net.ClientIdent(_ac.ClientId, Net.EMsgRecipCateg.Gui); // client name will be assigned automatically (a guid) _client = new Net.Client(_clientIdent, _ac.MasterIP, _ac.MasterPort, autoConn: true); _client.MessageReceived += OnMessage; _reflStates = new ReflectedStateRepo(_client); _txKillAll = _wnd.GetImage("Resources/skull.png"); _menuRenderer = new GuiWinMenuRenderer(_wnd, _reflStates); _errorRenderer = new ErrorRenderer(_wnd); _appTreeRenderer = new AppTreeRenderer(_wnd, _reflStates); _planTreeRenderer = new PlanTreeRenderer(_wnd, _reflStates); _scriptTreeRenderer = new ScriptTreeRenderer(_wnd, _reflStates); _reflStates.OnReset += Reset; _reflStates.OnAppsReceived += _appTreeRenderer.Reset; _reflStates.OnPlansReceived += _planTreeRenderer.Reset; _reflStates.OnScriptsReceived += _scriptTreeRenderer.Reset; Reset(); }
/// <summary> /// Creates a dirigent client endpoint based on protbuf messaging. /// </summary> /// <param name="ident">if Name is empty, will be assigned a GUID matching the one from NetCoreServer's client instance</param> /// <param name="autoConn">If autoConn==false, connects once and throws if failed. autoConn==true, try to connect until succeedes; and reconnects if connection is lost; never throws .</param> public Client(Net.ClientIdent ident, string masterIP, int masterPort, bool autoConn = false) { _ident = ident; _masterIP = masterIP; _masterPort = masterPort; Net.Message.RegisterProtobufTypeMaps(); _protoClient = new ProtoClient(_masterIP, _masterPort, autoConn); if (string.IsNullOrEmpty(_ident.Name)) { _ident.Name = _protoClient.Id.ToString(); } // as the first thing when connected, tell the master who we are _protoClient.Connected = () => { _protoClient.SendMessage(_ident); }; if (autoConn) // if we want autoconnecting, do not wait for it... { _protoClient.ConnectAsync(); } else // if we do not want autoconnecting, throw exception on disconnection { _protoClient.Disconnected = () => { throw new MasterConnectionTimeoutException(_masterIP, _masterPort); }; } }
void SetIdent(Net.ClientIdent ident) { //_outgMsgMask = ident.SubscribedTo; //Name = ident.Sender; Ident = ident; // notify server _server.ClientIdentified(this); }
public frmMain( AppConfig ac, NotifyIcon notifyIcon, string machineId // empty if no local agent was started with the GUI ) { _ac = ac; _machineId = machineId; // FIXME: this is only valid if we are running a local agent! How do we know?? _clientIdent = new Net.ClientIdent() { Sender = Guid.NewGuid().ToString(), SubscribedTo = Net.EMsgRecipCateg.Gui }; _notifyIcon = notifyIcon; _allowLocalIfDisconnected = true; log.Debug($"Running with masterIp={_ac.MasterIP}, masterPort={_ac.MasterPort}"); InitializeComponent(); if (Common.Properties.Settings.Default.GridRowSpacing > 0) { this.gridPlans.RowTemplate.Height = Common.Properties.Settings.Default.GridRowSpacing; this.gridApps.RowTemplate.Height = Common.Properties.Settings.Default.GridRowSpacing; } if (Common.Properties.Settings.Default.GridButtonSpacing > 0) { this.hdrPlanStart.Width = Common.Properties.Settings.Default.GridButtonSpacing; this.hdrPlanStop.Width = Common.Properties.Settings.Default.GridButtonSpacing; this.hdrPlanKill.Width = Common.Properties.Settings.Default.GridButtonSpacing; this.hdrPlanRestart.Width = Common.Properties.Settings.Default.GridButtonSpacing; this.hdrKillIcon.Width = Common.Properties.Settings.Default.GridButtonSpacing; this.hdrLaunchIcon.Width = Common.Properties.Settings.Default.GridButtonSpacing; this.hdrRestartIcon.Width = Common.Properties.Settings.Default.GridButtonSpacing; } registerHotKeys(); //setDoubleBuffered(gridApps, true); // not needed anymore, DataViewGrid does not flicker _planRepo = new List <PlanDef>(); _client = new Net.Client(_clientIdent, ac.MasterIP, ac.MasterPort, autoConn: true); _client.MessageReceived += OnMessage; _reflStates = new ReflectedStateRepo(_client); bool firstGotPlans = true; _reflStates.OnPlansReceived += () => { if (firstGotPlans) { selectPlan(ac.StartupPlan); } firstGotPlans = false; // udate current plan reference in case the plan def has changed if (_currentPlan is not null) { _currentPlan = _reflStates.GetPlanDef(_currentPlan.Name); } }; _ctrl = _reflStates; // start ticking log.DebugFormat("MainForm's timer period: {0}", ac.TickPeriod); tmrTick.Interval = ac.TickPeriod; tmrTick.Enabled = true; }