public static Boolean TryParse(SocketData incommingData, out MachineStatusData resultdata) { if (incommingData.DataName == MachineStatusData.MESSAGE_ID) { string lineName = ""; string machineName = ""; string statusAsString = ""; //we use the custom hashtable that is transportd in the socketData and not the native attributes table CustomHashTable _table = (CustomHashTable)incommingData.Value; if ( _table.ContainsKey(MachineStatusData.LINE_NAME) && _table.ContainsKey(MachineStatusData.MACHINE_NAME) && _table.ContainsKey(MachineStatusData.MACHINE_STATUS) ) { lineName = (string)_table.Item(MachineStatusData.LINE_NAME); machineName = (string)_table.Item(MachineStatusData.MACHINE_NAME); statusAsString = (string)_table.Item(MachineStatusData.MACHINE_STATUS); MachineStatus status = GetStatusFromString(statusAsString); resultdata = new MachineStatusData(lineName, machineName, status); //pending to implement return(true); } else { //it is not possible to parse as the ALDS data type requiered resultdata = null; return(false); } } else { resultdata = null; return(false); } }
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); }
internal void ConnectoToPublication(DPE_PublicationConnectionHandler_Type connectionHandlerType, string publicationName, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { //***************************************************************************** //request to the server the connection parameters of the publication P2PDataRequest dataREquest = new P2PDataRequest(DPE_ServerDefs.DPE_CMD_PUBLICATION_SUBSCRIPTION_DATA); dataREquest.AddRequestParameter(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, publicationName); P2PData publicationPArams = null; string msg = ""; Services.P2PCommunicationsScheme.P2PPortClient publicationsInformationRetrieveP2PPortClient = null; int trialsCount = 0; publicationsInformationRetrieveP2PPortClient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsInformationRetrieve_PortNumber); publicationsInformationRetrieveP2PPortClient.Connect(); //performs a while cycle until the client gets the connection parameters while (true) { try { publicationPArams = publicationsInformationRetrieveP2PPortClient.RetrieveData(dataREquest); break; } catch (Exception ex) { trialsCount++; if (trialsCount >= MAX_DATA_CONNECTION_PARAMETERS_INQUIRY_TRIALS) { msg = "Error trying to connect to publication \'" + publicationName + "\': " + ex.Message; throw (new Exception(msg)); } } System.Threading.Thread.Sleep(10); } try { publicationsInformationRetrieveP2PPortClient.Dispose(); } catch (Exception) { } CustomHashTable paramsList = (CustomHashTable)publicationPArams.Value; string publicationHostNAme = System.Convert.ToString(paramsList.Item(DPE_PublicationsDefinitions.DPE_PUBLICATION_HOSTNAME)); int publicationPort = System.Convert.ToInt32(paramsList.Item(DPE_PublicationsDefinitions.DPE_PUBLICATION_PORT)); //***************************************************************************** //CREATION OF THE PUBLICATION HANDLER and CONNECTION WITH publication DPE_PublicationConnectionHandler publicationConnectionHandler = default(DPE_PublicationConnectionHandler); publicationConnectionHandler = this.CreatePublicationConnectionHandler(connectionHandlerType, this._STXDataSocketClient, publicationName, publicationHostNAme, publicationPort, connectionMode); //***************************************************************************** //Ciclic process in order to allow the server to register the client socket connection . -> to synchronize the client registration //by ser client with the server event to log the publication event msg = "Error trying to perform the client connection registration to the publication \'" + publicationName + "\' : "; //***************************************************************************** //registration of the client connection to a publication in the server //the client sends to the server a information telling to which publication has already connected //and also for the TCP client mode to tell the publication to which port send the data int connectionRegistrationTrialCounter = 0; bool connectionRegistration = false; //preparation of the connection information into a p2p data P2PData clientPubCnnData = new P2PData(DPE_ServerDefs.DPE_CMD_CLIENT_PUBLICATION_CONNECTION_REGISTRATION, DPE_ServerDefs.DPE_CMD_CLIENT_PUBLICATION_CONNECTION_REGISTRATION); clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_CLIENT_ID, this._STXDataSocketClient.ClientID); clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, publicationName); clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_CONNECTION_HANDLER_ID, publicationConnectionHandler.HandlerID); //---------------------HANDLING FOR THE CONNECTION MODE ------------------------------ string connectionModeAsString = ""; connectionModeAsString = DPE_ServerDefs.Get_STXDSS_PublicationConnectionMode_ToAString(connectionMode); clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_CLIENT_CONNECTION_MODE, connectionModeAsString); msg = "Error trying to perform the client connection registration to the publication \'" + publicationName + "\' : "; //sends to server the information to the server several times until the information reaches the server Services.P2PCommunicationsScheme.P2PPortClient publicationsClientRegistrationP2PPortClient = default(Services.P2PCommunicationsScheme.P2PPortClient); publicationsClientRegistrationP2PPortClient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsClientRegistration_PortNumber); publicationsClientRegistrationP2PPortClient.Connect(); while (connectionRegistration == false) { try { publicationsClientRegistrationP2PPortClient.SendData(P2PDataSendMode.SyncrhonicalSend, clientPubCnnData); connectionRegistration = true; publicationsClientRegistrationP2PPortClient.Dispose(); CustomEventLog.WriteEntry(EventLogEntryType.SuccessAudit, "Connection to publication \'" + publicationName + "\' succesfull"); break; } catch (Exception ex) { System.Threading.Thread.Sleep(10); connectionRegistrationTrialCounter++; if (connectionRegistrationTrialCounter >= MAX_CONNECTION_REGISTRATION_TRIALS) { msg = msg + ex.Message; try { publicationsClientRegistrationP2PPortClient.Dispose(); } catch (Exception) { } try { this.DisposeConnectionHandler(publicationName); } catch (Exception) { } throw (new Exception(msg)); } } } }