static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ZyanConnection connection = LoginAndConnect(); if (connection != null) { try { CalcForm form = new CalcForm(); ICalculator proxy = connection.CreateProxy <ICalculator>(); form.Out_AddNumbers = Asynchronizer <AdditionRequest> .WireUp(proxy.In_AddNumbers); proxy.Out_SendResult = SyncContextSwitcher <decimal> .WireUp(form.In_ReceiveResult); Application.Run(form); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Dispose(); } } }
static bool ConectarZServer() { _newConn = null; TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true); try { _newConn = new ZyanConnection(_serverUrl, protocol, false); } catch (System.Net.Sockets.SocketException) { // Indica servidor apagado o imposible de conectar, ignorar y retornar false return(false); } if (_newConn == null) { // No se establecio conexion return(false); } else { _proxy = _newConn.CreateProxy <IMonitor>(); // connections // conectando input y output // Las acciones de salida del form, a metodos del proxy, para su transmision remota al servidor. _theForm.Out_GetClientConfig = Asynchronizer <RemReqClientData> .WireUp(_proxy.In_RequestClientData); _theForm.Out_GetSystemConfig = Asynchronizer <RemReqSystemData> .WireUp(_proxy.In_RequestSystemData); _theForm.Out_GetQueueInfo = Asynchronizer <RemReqQueueData> .WireUp(_proxy.In_RequestQueueData); _theForm.Out_GetLogFile = Asynchronizer <RemReqLogFile> .WireUp(_proxy.In_RequestLogFile); _theForm.Out_GetConsoleText = Asynchronizer <RemReqConsoleText> .WireUp(_proxy.In_RequestConsoleText); // La salida del servidor remoto, a controladores de solicitud del formulario. _proxy.Out_SendClientConfig = SyncContextSwitcher <RemReplyClientData> .WireUp(_theForm.In_ClientDataList); _proxy.Out_SendSystemConfigData = SyncContextSwitcher <RemReplySystemData> .WireUp(_theForm.In_SystemConfigData); _proxy.Out_SendQueueData = SyncContextSwitcher <RemReplyQueueInfo> .WireUp(_theForm.In_QueueInfo); _proxy.Out_SendLogFile = SyncContextSwitcher <RemReplyLogFile> .WireUp(_theForm.In_LogFile); _proxy.Out_SendError = SyncContextSwitcher <RemReplyConsoleText> .WireUp(_theForm.In_Error); _proxy.Out_SendConsoleText = SyncContextSwitcher <RemReplyConsoleText> .WireUp(_theForm.In_ConsoleText); // estableciendo control sobre estado de la conexion _newConn.Disconnected += _newConn_Disconnected; _newConn.PollingInterval = TimeSpan.FromSeconds(1); _newConn.PollingEnabled = true; return(true); } }
/* * internal static bool ConectarServidor() * { * const string methodName = "ConectarServidor"; * * try * { * Log.WriteEntry(ClassName, methodName, TraceEventType.Information, "Conectando con servidor."); * * var connection = new ZyanConnection(_connString); * var service = connection.CreateProxy<IMessageHandler>(); * * _connection = connection; * _proxy = service; * * Log.WriteEntry(ClassName, methodName, TraceEventType.Information, "Conexion realizada con exito."); * return true; * } * catch (Exception ex) * { * Log.WriteEntry(ClassName, methodName, TraceEventType.Error, string.Format("Error: {0}", ex.Message)); * return false; * } * } */ internal static bool ConectarServidor() { const string methodName = "ConectarServidor"; try { Log.WriteEntry(ClassName, methodName, TraceEventType.Information, "Conectando con servidor."); var connection = new ZyanConnection(_connString); var service = connection.CreateProxy <IMessageHandler>(); _connection = connection; _proxy = service; // Conectando input y output. // Las acciones de salida, a metodos del proxy, para su transmision remota al servidor. // Comandos Out_AsistenciaUpdateCommand = Asynchronizer <AsistenciaUpdateCommand> .WireUp(_proxy.In_AsistenciaUpdateCommand); // Consultas Out_AsistenciaQuery = Asynchronizer <AsistenciaQuery> .WireUp(_proxy.In_AsistenciaQuery); // La respuesta del servidor remoto, a acciones de entrada. // Comandos _proxy.Out_AsistenciaUpdateCommandResult = SyncContextSwitcher <CommandStatus> .WireUp(In_AsistenciaUpdateCommandResult); // Consultas _proxy.Out_AsistenciaQuery = SyncContextSwitcher <AsistenciaQueryResult> .WireUp(In_AsistenciaQueryResult); // Estableciendo controlador de sesion. _connection.Disconnected += _zyanConn_Disconnected; // Estableciendo monitoreo de la conexion. _connection.PollingInterval = TimeSpan.FromSeconds(3); _connection.PollingEnabled = true; Log.WriteEntry(ClassName, methodName, TraceEventType.Information, "Conexion realizada con exito."); return(true); } catch (Exception ex) { Log.WriteEntry(ClassName, methodName, TraceEventType.Error, string.Format("Error: {0}", ex.Message)); return(false); } }
private bool Connect(string arg) { try { if (_zConnection != null) { _zConnection.Dispose(); } TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true); Hashtable credentials = new Hashtable(); credentials.Add(AuthRequestMessage.CREDENTIAL_USERNAME, "zc"); credentials.Add(AuthRequestMessage.CREDENTIAL_PASSWORD, "zc"); _zConnection = new ZyanConnection(arg, protocol, credentials, false, true); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); this.chkConect.Checked = false; return(false); } this.chkConect.Checked = true; IMonitor relMonitor = _zConnection.CreateProxy <IMonitor>(); //this.Out_GetClient = Asynchronizer<int>.WireUp(relMonitor.In_RequestClientDataList); //this.Out_GetSystem = Asynchronizer<int>.WireUp(relMonitor.In_RequestSystemConfigData); this.Out_GetAllData = Asynchronizer <RequestDataEvent> .WireUp(relMonitor.In_RequestData); relMonitor.Out_SendClientDataList = SyncContextSwitcher <ClientDataList> .WireUp(this.In_GetClient); relMonitor.Out_SendSystemConfigData = SyncContextSwitcher <SystemConfigData> .WireUp(this.In_GetSys); return(true); }
static private bool ConectarZServer(string url) { Log.WriteEntry(ClassName, "ConectarZServer", TraceEventType.Verbose, "Conectando al servidor Zyan remoto: " + url); ZyanConnection _newConn = null; try { _newConn = new ZyanConnection(url); } catch (System.Net.Sockets.SocketException) { // Indica servidor apagado o imposible de conectar, ignorar y retornar false. return(false); } catch (Exception ex) { // Registrar otro tipo de excepcion para depurar Log.WriteEntry(ClassName, "ConectarZServer", TraceEventType.Error, "Exception: " + ex.Message); return(false); } if (_newConn == null) { // No se establecio conexion. return(false); } else { _proxy = _newConn.CreateProxy <IMonitor>(); // Conectando input y output. // Las acciones de salida del form, a metodos del proxy, para su transmision remota al servidor. // Acciones que solicitan envio de datos. _theForm.Out_GetClientConfig = Asynchronizer <RemReqClientData> .WireUp(_proxy.In_RequestClientData); _theForm.Out_GetSystemConfig = Asynchronizer <RemReqSystemData> .WireUp(_proxy.In_RequestSystemData); _theForm.Out_GetQueueInfo = Asynchronizer <RemReqQueueData> .WireUp(_proxy.In_RequestQueueData); _theForm.Out_GetLogFile = Asynchronizer <RemReqLogFile> .WireUp(_proxy.In_RequestLogFile); _theForm.Out_GetConsoleText = Asynchronizer <RemReqConsoleText> .WireUp(_proxy.In_RequestConsoleText); // Acciones que solicitan modificar objetos. _theForm.Out_SendCreateClient = Asynchronizer <RemReqCreateClient> .WireUp(_proxy.In_RequestClientCreate); _theForm.Out_SendClientUpdate = Asynchronizer <RemReqUpdateClient> .WireUp(_proxy.In_RequestClientUpdate); _theForm.Out_SendClientDelete = Asynchronizer <RemReqDeleteClient> .WireUp(_proxy.In_RequestClientDelete); _theForm.Out_SendSystemUpdate = Asynchronizer <RemReqUpdateSystem> .WireUp(_proxy.In_RequestSystemUpdate); _theForm.Out_SendClientPause = Asynchronizer <RemReqPauseClient> .WireUp(_proxy.In_RequestClientPause); _theForm.Out_SendClientResume = Asynchronizer <RemReqResumeClient> .WireUp(_proxy.In_RequestClientResume); // La salida del servidor remoto, a controladores de solicitud del formulario. _proxy.Out_SendClientConfig = SyncContextSwitcher <RemReplyClientData> .WireUp(_theForm.In_ClientDataList); _proxy.Out_SendSystemConfigData = SyncContextSwitcher <RemReplySystemData> .WireUp(_theForm.In_SystemConfigData); _proxy.Out_SendQueueData = SyncContextSwitcher <RemReplyQueueInfo> .WireUp(_theForm.In_QueueInfo); _proxy.Out_SendLogFile = SyncContextSwitcher <RemReplyLogFile> .WireUp(_theForm.In_LogFile); _proxy.Out_SendError = SyncContextSwitcher <RemReplyConsoleText> .WireUp(_theForm.In_Error); _proxy.Out_SendConsoleText = SyncContextSwitcher <RemReplyConsoleText> .WireUp(_theForm.In_ConsoleText); // Guardando referencia a nueva conexion. _zyanConn = _newConn; // Estableciendo controlador de sesion _zyanConn.Disconnected += _zyanConn_Disconnected; // Estableciendo monitoreo de la conexion _zyanConn.PollingInterval = TimeSpan.FromSeconds(1.5); _zyanConn.PollingEnabled = true; return(true); } }