private void UnsubsribeComponent(string ComponentName) { ComponentName = ComponentName.ToUpper(); if (this.CNDTable.ContainsComponentRegistry(ComponentName)) { CNDAddressingReg reg = this.CNDTable.GetCNDAddressingRegister(ComponentName); this.CNDTable.RemoveComponentRegistry(ComponentName); this._remoteComponentLinkTable.DestroyLinkWithRemoteComponent(ComponentName); this.SaveCNDTable(); this.BroadCastRegistryRemoval(reg); try { if (CNDTableStatusChangedEvent != null) { CNDTableStatusChangedEvent(); } } catch (Exception) { } } }
private void SubscribeComponent(string ComponentName, string HostName, string ipAdress, int P2PPortNumber, string AppName, string ProcessID) { //'creates a new registration and adds to the directory //Dim newReg As CNDAddressingReg = New CNDAddressingReg(ComponentName, HostName, ipAdress, listeningTCPPort, AppName, ProcessID, Now) ComponentName = ComponentName.ToUpper(); if (this.CNDTable.ContainsComponentRegistry(ComponentName)) { this.UnsubsribeComponent(ComponentName); } this.CNDTable.AddComponentRegistry(ComponentName, HostName, ipAdress, P2PPortNumber, AppName, ProcessID); CNDAddressingReg reg = this.CNDTable.GetCNDAddressingRegister(ComponentName); this._remoteComponentLinkTable.CreateLinkWithRemoteComponent(reg); this.SaveCNDTable(); this.BroadCastNewRegistryInsertion(reg); try { if (CNDTableStatusChangedEvent != null) { CNDTableStatusChangedEvent(); } } catch (Exception) { } }
private void BroadCastRegistryRemoval(CNDAddressingReg CNDTableReg) { SocketData dsReg = new SocketData(CNDServiceDefinitions.CND_EXISTING_REGISTRATION_REMOVE, CNDServiceDefinitions.CND_EXISTING_REGISTRATION_REMOVE); dsReg.AttributesTable.AddAttribute(CNDServiceDefinitions.COMPONENT_NAME, CNDTableReg.ComponentName); byte[] compressedData = null; compressedData = UtilitiesLibrary.Services.DataCompression.DataCompressionUtilities.CompressData(dsReg.DataBytes); this._MultiCastDataReplicationServer.BroadCastData(compressedData); }
internal void DestroyLinkWithRemoteComponent(CNDAddressingReg addressingReg) { if (this._remoteComponentLinkTable.ContainsKey(addressingReg.ComponentName)) { P2PPortClient client = (P2PPortClient)this._remoteComponentLinkTable[addressingReg.ComponentName]; this._remoteComponentLinkTable.Remove(addressingReg.ComponentName); client.ConnectionLost -= P2PPortClient_ConnectionLost; client.Disconnect(); client.Dispose(); } }
internal static CNDAddressingReg GetAddressingRegister(CustomHashTable table) { if (!table.Contains(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Component Name]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_HOST_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Hostname]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[P2PPortNumber]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[IPAddress]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Application Name]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Application Process ID]\' is missing.")); } if (!table.Contains(CNDServiceDefinitions.CND_TABLE_REGISTRATION_DATETIME)) { throw (new Exception("Can\'t get a CNDAddressingReg from Table because the parameter \'[Registration Date Time]\' is missing.")); } string compName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME)); compName = compName.ToUpper(); string hostName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_HOST_NAME)); string P2PPortNumber = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER)); string IPAddress = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS)); string ApplicationName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME)); string ApplicationProcessID = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID)); string RegistrationDateTime = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_REGISTRATION_DATETIME)); int PortNumber = Convert.ToInt32(P2PPortNumber); CNDAddressingReg reg = new CNDAddressingReg(compName, hostName, IPAddress, PortNumber, ApplicationName, ApplicationProcessID, RegistrationDateTime); return(reg); }
private RemoteComponentComunicationsHandler GetRemoteHandlerForComponent(string RemoteComponentName) { try { CNDAddressingReg reg = default(CNDAddressingReg); reg = this._CNDClient.ResolveAddress(RemoteComponentName); RemoteComponentComunicationsHandler handler = new RemoteComponentComunicationsHandler(RemoteComponentName, reg.HostName, reg.IPAddress, reg.P2PPortNumber); return(handler); } catch (Exception ex) { throw (new Exception("Unable to send data to component name \'" + RemoteComponentName + "\' becuase it is not posible to resolve its network location. Error: " + ex.Message)); } }
private void BroadCastNewRegistryInsertion(CNDAddressingReg CNDTableReg) { SocketData dsReg = new SocketData(CNDServiceDefinitions.CND_NEW_REGISTRATION_INSERT, CNDServiceDefinitions.CND_NEW_REGISTRATION_INSERT); dsReg.AttributesTable.AddAttribute(CNDServiceDefinitions.COMPONENT_NAME, CNDTableReg.ComponentName); dsReg.AttributesTable.AddAttribute(CNDServiceDefinitions.HOST_NAME, CNDTableReg.HostName); dsReg.AttributesTable.AddAttribute(CNDServiceDefinitions.P2P_PORT_NUMBER, System.Convert.ToString(CNDTableReg.P2PPortNumber)); dsReg.AttributesTable.AddAttribute(CNDServiceDefinitions.IP_ADDRESS, CNDTableReg.IPAddress); dsReg.AttributesTable.AddAttribute(CNDServiceDefinitions.APPLICATION_NAME, CNDTableReg.AppDomain); dsReg.AttributesTable.AddAttribute(CNDServiceDefinitions.APPLICATION_PROCESS_ID, System.Convert.ToString(CNDTableReg.ProcessID)); dsReg.AttributesTable.AddAttribute(CNDServiceDefinitions.REGISTRATION_DATETIME, CNDTableReg.SubscriptionDateTime); byte[] compressedData = null; compressedData = UtilitiesLibrary.Services.DataCompression.DataCompressionUtilities.CompressData(dsReg.DataBytes); this._MultiCastDataReplicationServer.BroadCastData(compressedData); }
private void NewComponentRegistrationDetected(CNDAddressingReg ComponentCNDRegister) { try { //when a remote component is registred in the CNDService then is detected and is creted locally // a handler to communicate with it RemoteComponentComunicationsHandler newhandler = this.GetRemoteHandlerForComponent(ComponentCNDRegister.ComponentName); this._remoteHandlersContainer.AddNewHandler(newhandler); if (CNDTableChangedEvent != null) { CNDTableChangedEvent(this.CNDTable); } } catch (Exception ex) { CustomEventLog.WriteEntry(ex); } }
private void ComponentUnregistrationDetected(CNDAddressingReg ComponentCNDRegister) { try { if (this._remoteHandlersContainer.ContainsHandlerForRemoteComponent(ComponentCNDRegister.ComponentName)) { RemoteComponentComunicationsHandler handler = default(RemoteComponentComunicationsHandler); handler = this._remoteHandlersContainer.GetHandler(ComponentCNDRegister.ComponentName); this._remoteHandlersContainer.RemoveExistingHandler(handler); if (CNDTableChangedEvent != null) { CNDTableChangedEvent(this.CNDTable); } } } catch (Exception ex) { CustomEventLog.WriteEntry(ex); } }
internal void CreateLinkWithRemoteComponent(CNDAddressingReg addressingReg) { if (this.ContainsLinkToRemoteComponent(addressingReg)) { //removes the old link this.DestroyLinkWithRemoteComponent(addressingReg); } //creates a remote P2PPortClient in order to create a link with the remote component and know when it //shutdows thorugh the port client event that detects the disconnection Services.P2PCommunicationsScheme.P2PPortClient _remotePortClientLink = new Services.P2PCommunicationsScheme.P2PPortClient(addressingReg.HostName, addressingReg.IPAddress, addressingReg.P2PPortNumber, addressingReg.ComponentName); try { _remotePortClientLink.Connect(); _remotePortClientLink.ConnectionLost += P2PPortClient_ConnectionLost; this._remoteComponentLinkTable.Add(addressingReg.ComponentName, _remotePortClientLink); } catch (Exception ex) { throw (new Exception("Error creating a link to remote component: " + ex.Message)); } }
internal CNDAddressingReg GetCNDAddressingRegister(string ComponentName) { UtilitiesLibrary.Data.CustomHashTable table = default(UtilitiesLibrary.Data.CustomHashTable); table = this.GetComponentRegistry(ComponentName); if (!(table == null)) { string compName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME)); compName = compName.ToUpper(); string hostName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_HOST_NAME)); string P2PPortNumber = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER)); string IPAddress = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS)); string ApplicationName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME)); string ApplicationProcessID = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID)); string RegistrationDateTime = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_REGISTRATION_DATETIME)); int portNumber = Convert.ToInt32(P2PPortNumber); CNDAddressingReg reg = new CNDAddressingReg(ComponentName, hostName, IPAddress, portNumber, ApplicationName, ApplicationProcessID, RegistrationDateTime); return(reg); } else { return(null); } }
internal bool ContainsLinkToRemoteComponent(CNDAddressingReg addressingReg) { return(this._remoteComponentLinkTable.ContainsKey(addressingReg.ComponentName)); }