/// <summary> /// Serializa un objeto de este tipo /// </summary> /// <param name="directory">El directorio donde serializarlo debe terminar con el simbolo "/"</param> /// <param name="configuration">El objeto configuración a serializar</param> public static void save(String directory, Configuration configuration) { try { if (configuration != null) { XmlSerializer mySerializer = new XmlSerializer(typeof(Configuration)); StreamWriter myWriter = new StreamWriter(File.Open(directory + "CommLayer.conf", FileMode.Create, FileAccess.Write)); mySerializer.Serialize(myWriter, configuration); myWriter.Close(); } } catch (ThreadAbortException e) { throw e; } catch (Exception) { //throw; } }
public void init() { try { //incializamos una configuracion configuration = new Configuration(); //OS configuration.NetData.OpSystem = OpSystemType.WIN7; //configuramos los controles statusControl.connectNotification += connect; statusControl.disConnectNotification += disconnect; chatControl.NetUser = configuration.NetUser; //configuramos los sub protocolos SubProtocolList subProtocols = new SubProtocolList(); chatProtocol = new ChatProtocol(chatControl); subProtocols.add(SubProtocol.Chat.Types.CHATPROTOCOL, chatProtocol); fileTransferProtocol = new FileTransferProtocol(fileControl, fileListControl, createFileData()); subProtocols.add(SubProtocol.FileTransfer.Types.FILETRANSFERPROTOCOL, fileTransferProtocol); pingProtocol = new PingProtocol(this); subProtocols.add(SubProtocol.Ping.Types.PINGPROTOCOL, pingProtocol); chatControl.ChatProtocol = chatProtocol; fileListControl.FileTransferProtocol = fileTransferProtocol; //Configuramos los tipos de mensajes que no pertenecen a subprotocolos MessageTypeList messageTypeList = new MessageTypeList(); //se crea el objeto de comunicación communication = new Communication(configuration, subProtocols, messageTypeList); //Se setean los handlers de los eventos de usuarios communication.addUserEvent += netUserControl.addUserHandler; communication.addUserEvent += fileTransferProtocol.sendFileListRequest; communication.addUserEvent += networkGraphControl.addUserHandler; communication.refreshUserEvent += netUserControl.refreshUserHandler; communication.refreshUserEvent += networkGraphControl.refreshUserHandler; communication.refreshLocalUserEvent += netUserControl.refreshLocalUserHandler; communication.refreshLocalUserEvent += networkGraphControl.refreshLocalUserHandler; communication.removeUserEvent += netUserControl.removeUserHandler; communication.removeUserEvent += fileListControl.removeFileList; communication.removeUserEvent += networkGraphControl.removeUserHandler; //Se setean los handlers de los eventos de conexion communication.connectEvent += statusControl.connectHandler; communication.connectEvent += fileTransferProtocol.start; communication.connectingEvent += statusControl.connectingHandler; communication.disconnectEvent += statusControl.disconnectHandler; communication.disconnectEvent += fileTransferProtocol.stop; communication.disconnectEvent += clear; communication.disconnectingEvent += statusControl.disconnectingHandler; communication.reconnectingEvent += statusControl.reconnectingHandler; communication.reconnectingEvent += fileTransferProtocol.stop; communication.reconnectingEvent += clear; //Se setean los handlers de los eventos del sistems communication.exceptionEvent += exceptionHandler; communication.netInformationEvent += netInformationHandler; //iniciamos el consumidor de eventos communication.startEventConsumer(); //Se abre el archivo para log FileInfo t = new FileInfo("CommLayer.log"); Tex = t.AppendText(); } catch (Exception e) { MessageBox.Show("Ups!: " + e.Message); Close(); } }
/// <summary> /// Constructo Parametrizado /// </summary> /// <param name="configuration">El objeto con los datos de configuración previamente llenado</param> /// <param name="subProtocols">Lista de SubProtocolos</param> /// <param name="extraMessageTypes">Tipos de mensajes no especificados en los sub protocolos</param> public Communication(Configuration configuration, SubProtocolList subProtocols, MessageTypeList extraMessageTypes) { try { this.configuration = configuration; if (extraMessageTypes != null) { messageTypes = extraMessageTypes.Collection; } else { messageTypes = new Hashtable(); } if (subProtocols != null) { Hashtable sub = subProtocols.Collection; foreach (DictionaryEntry en in sub) { SubProtocolI subProtocol = (SubProtocolI)en.Value; Hashtable spMessageTypes = subProtocol.getMessageTypes().Collection; foreach (DictionaryEntry de in spMessageTypes) { messageTypes.Add(de.Key, de.Value); } subProtocol.sendMessageEvent += internalSendMessage; } this.subProtocols = sub; } netHandler = new NetHandler(configuration.NetData, this); eventQueuePC = new EventQueuePC(); eventConsumer = new Thread(new ThreadStart(consumeEvent)); eventConsumerStarted = false; eventConsumerLock = new Object(); init(); } catch (ThreadAbortException e) { throw e; } catch (Exception e) { throw e; } }
public void init() { try { //se inicializa la configuración configuration = new Configuration(); configuration.NetData.OpSystem = NetLayer.OpSystemType.WINMOBILE5POCKETPC; //Configuración de controles statusControl.connectNotification += connect; statusControl.disConnectNotification += disconnect; chatControl.NetUser = configuration.NetUser; //Configuración de subprotocolos SubProtocolList subProtocols = new SubProtocolList(); chatProtocol = new ChatProtocol(chatControl); subProtocols.add(SubProtocol.Chat.Types.CHATPROTOCOL, chatProtocol); fileTransferProtocol = new FileTransferProtocol(fileControl, fileListControl, createFileData()); subProtocols.add(SubProtocol.FileTransfer.Types.FILETRANSFERPROTOCOL, fileTransferProtocol); pingProtocol = new PingProtocol(this); subProtocols.add(SubProtocol.Ping.Types.PINGPROTOCOL, pingProtocol); chatControl.ChatProtocol = chatProtocol; fileListControl.FileTransferProtocol = fileTransferProtocol; //se crea el objeto de comunicación communication = new Communication(configuration, subProtocols, null); //Se setean los handlers de los eventos de usuarios communication.addUserEvent += netUserControl.addUserHandler; communication.addUserEvent += fileTransferProtocol.sendFileListRequest; communication.refreshUserEvent += netUserControl.refreshUserHandler; communication.refreshLocalUserEvent += netUserControl.refreshLocalUserHandler; communication.removeUserEvent += netUserControl.removeUserHandler; communication.removeUserEvent += fileListControl.removeFileList; //Se setean los handlers de los eventos de conexion communication.connectEvent += statusControl.connectHandler; communication.connectEvent += fileTransferProtocol.start; communication.connectingEvent += statusControl.connectingHandler; communication.disconnectEvent += statusControl.disconnectHandler; communication.disconnectEvent += fileTransferProtocol.stop; communication.disconnectEvent += clear; communication.disconnectingEvent += statusControl.disconnectingHandler; communication.reconnectingEvent += statusControl.reconnectingHandler; communication.reconnectingEvent += fileTransferProtocol.stop; communication.reconnectingEvent += clear; //se setean los handlers de los eventos del sistema communication.exceptionEvent += exceptionHandler; communication.netInformationEvent += log; //iniciamos el consumidor de eventos communication.startEventConsumer(); } catch (Exception e) { MessageBox.Show("Ups!: " + e.Message); Close(); } }