/// <summary> /// Initializes the ETP client. /// </summary> public async Task InitEtpClient() { try { Runtime.Invoke(() => Runtime.Shell.StatusBarText = "Connecting..."); _log.Debug($"Establishing ETP connection for {Model.Connection}"); Client = Model.Connection.CreateEtpClient(Model.ApplicationName, Model.ApplicationVersion); EtpExtender = Client.CreateEtpExtender(Model.RequestedProtocols); EtpExtender.Register(LogObjectDetails, onOpenSession: OnOpenSession, onGetResourcesResponse: OnGetResourcesResponse, onObject: OnObject, onObjectPart: OnObjectPart, onOpenChannel: OnOpenChannel); Client.SocketClosed += OnClientSocketClosed; Client.Output = LogClientOutput; await Client.OpenAsync(); } catch (Exception ex) { Runtime.Invoke(() => Runtime.Shell.StatusBarText = "Error"); Runtime.ShowError("Error connecting to server.", ex); } }
private void OnServerSessionConnected(object sender, IEtpSession session) { var server = session as IEtpServer; if (server == null) { return; } server.Output = LogClientOutput; _server = server; var message = $"[{server.SessionId}] ETP client connected."; LogClientOutput(message, true); _log.Debug(message); EtpExtender = server.CreateEtpExtender(Model.RequestedProtocols); EtpExtender.Register(LogObjectDetails, onOpenSession: OnOpenSession, onCloseSession: OnCloseSession, onGetResourcesResponse: OnGetResourcesResponse, onObject: OnObject, onObjectPart: OnObjectPart, onOpenChannel: OnOpenChannel); }
/// <summary> /// Initializes the ETP client. /// </summary> private void InitEtpClient() { try { Runtime.Invoke(() => StatusBarText = "Connecting..."); var applicationName = GetType().Assembly.FullName; var applicationVersion = GetType().GetAssemblyVersion(); Client = Connection.CreateEtpClient(applicationName, applicationVersion); BindableCollection <EtpProtocolItem> requestedProtocols = new BindableCollection <EtpProtocolItem>(); requestedProtocols.Add(new EtpProtocolItem(Energistics.Etp.v11.Protocols.Discovery, "store", true)); EtpExtender = Client.CreateEtpExtender(requestedProtocols); EtpExtender.Register(onOpenSession: OnOpenSession, onCloseSession: CloseEtpClient, onGetResourcesResponse: OnGetResourcesResponse); Client.SocketClosed += OnClientSocketClosed; Client.OpenAsync(); } catch (Exception) { Runtime.Invoke(() => StatusBarText = "Error Connecting"); } }