public void btnRequestData_Click(System.Object sender, System.EventArgs e) { try { this.Cursor = Cursors.WaitCursor; if (this.txtDataNameToRequest.Text.Length <= 0) { throw (new Exception("No data name to request")); } P2PData data = default(P2PData); P2PDataRequest request = new P2PDataRequest(this.txtDataNameToRequest.Text); data = this._p2pPortclient.RetrieveData(request); this.CfDataDisplayCtrl1.ShowData(data.Value); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.Cursor = Cursors.Default; this.dgrdGeneralStatistics.DataSource = this._p2pPortclient.Statistics.GeneralStatisticsTable; this.dgrdRequestStats.DataSource = this._p2pPortclient.Statistics.DataRequestsStatisticsTable; } }
public CommunicationsDataRequest(string remoteAddresseComponentName, string senderComponentName, string DataNameToRequest) { DataNameToRequest = DataNameToRequest.ToUpper(); this._senderComponentName = senderComponentName; this._remoteAddresseComponentName = remoteAddresseComponentName; this._p2pDataRequest = new P2PDataRequest(DataNameToRequest); this._p2pDataRequest.AddRequestParameter("DATA_TYPE", "CommunicationsDataRequest"); this._p2pDataRequest.AddRequestParameter("SENDER_COMPONENT", senderComponentName); this._p2pDataRequest.AddRequestParameter("ADDRESSE_COMPONENT", remoteAddresseComponentName); }
internal void LogFailedDataRequestEvent(P2PDataRequest dataRequest) { try { this._LogFailedDataRequestEventQueue.Enqueue(dataRequest); } catch (Exception) { } }
internal void LogFailedDataRequestEvent(P2PDataRequest dataRequest) { try { this.LogFailedDataRequestEventsOnTable(dataRequest); } catch (Exception) { } }
private P2PData Handle_GetComponentAddressingRegistry_Request(P2PDataRequest request) { string componentName = ""; componentName = request.GetRequestParameter(CNDServiceDefinitions.COMPONENT_NAME); if (componentName == null) { throw (new Exception("Can\'t resolve the Addressing because the paramter \'COMPONENT_NAME\' was missing in the data request.")); } if (!this.CNDTable.ContainsComponentRegistry(componentName)) { throw (new Exception("Can\'t resolve the Addressig for component \'" + componentName + "\' because is not registered on the Service")); } CustomHashTable cnsREgister = this.CNDTable.GetComponentRegistry(componentName); P2PData register = new P2PData("CND_ADDRESSING_REGISTER", cnsREgister); return(register); }
public void tmrAutoRequest_Tick(System.Object sender, System.EventArgs e) { try { P2PData data = default(P2PData); P2PDataRequest request = new P2PDataRequest(this.txtDataNameToRequest.Text); data = this._p2pPortclient.RetrieveData(request); this.CfDataDisplayCtrl1.ShowData(data.Value); } catch (Exception ex) { this.lstErrorsOnAutoRequest.Items.Add(ex.Message); } finally { this.dgrdGeneralStatistics.DataSource = this._p2pPortclient.Statistics.GeneralStatisticsTable; this.dgrdRequestStats.DataSource = this._p2pPortclient.Statistics.DataRequestsStatisticsTable; } }
public P2PDataRetrievalException(P2PDataRequest request, string errorMessage) : base("Error on P2PPort operation data request of \'" + request.RequestedDataName + "\' : " + errorMessage) { }
internal static void PrepareDataToSend(SocketAsyncEventArgs e, P2PDataRequest dataRequest) { Byte[] SerializedData = dataRequest.Serialize(); DataPreparationHandler.PrepareAndBufferData(e, SerializedData); }
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)); } } } }
internal static P2PDataRequest ParseAndGet_P2PDataRequest_FromXMLDataString(string XMLString) { System.IO.StringReader sr = null; System.Xml.XmlTextReader m_xmlr = null; try { sr = new System.IO.StringReader(XMLString); m_xmlr = new System.Xml.XmlTextReader(sr); m_xmlr.WhitespaceHandling = System.Xml.WhitespaceHandling.None; } catch (System.Xml.XmlException) { string msg; msg = "Error trying to get XML format from P2PDataRequest Data string [" + XMLString + "]"; } catch (Exception ex) { string msg = ""; msg = "Error trying to parse P2PDataRequest XML string : " + ex.Message; throw (new Exception(msg)); } m_xmlr.Read(); string HeaderIdentifier = m_xmlr.Name; if (HeaderIdentifier != "P2P_DATAREQUEST") { throw (new System.Xml.XmlException("Invalid P2PDataRequest header " + HeaderIdentifier + ". Must be \'P2P_DATAREQUEST\'")); } else { string datanameToRequest = m_xmlr.GetAttribute("datanameToRequest"); if (datanameToRequest == null) { throw (new Exception("No dataname to retrieve attribute found in the P2PDataRequest XML String")); } m_xmlr.Read(); string AttributesSectionName = m_xmlr.Name; if (AttributesSectionName != "DATA_REQUEST_PARAMETERS") { throw (new Exception("Invalid section name \'" + AttributesSectionName + "\'")); } string parametersCountStr = m_xmlr.GetAttribute("ParametersCount"); int numOfParameters = 0; CustomHashTable parametersTable = null; if (!(parametersCountStr == null)) { numOfParameters = System.Convert.ToInt32(parametersCountStr); if (numOfParameters > 0) { string attrTableXMLString = m_xmlr.ReadInnerXml(); DataVariable tableVar = default(DataVariable); tableVar = XMLDataFormatting.RetrieveDataVariableFromXMLString(attrTableXMLString); parametersTable = (CustomHashTable)tableVar.Data; } } else { throw (new Exception("The parameter \'AttrCount\' is missing on the XML string of the section \'REQUEST_ATTRIBUTES\'")); } P2PDataRequest dataRq = default(P2PDataRequest); if (numOfParameters > 0) { if (!(parametersTable == null)) { dataRq = new P2PDataRequest(datanameToRequest, parametersTable); } else { dataRq = new P2PDataRequest(datanameToRequest); } } else { dataRq = new P2PDataRequest(datanameToRequest); } return(dataRq); } }
internal static dynamic GetP2PDataRequestFailure(P2PDataRequest request, string errorMessage) { P2PDataRequestFailure p2pdatREqFail = new P2PDataRequestFailure(request, errorMessage); return(p2pdatREqFail); }
public P2PDataRequestTimeOutException(P2PDataRequest request) : base("Time out on P2PPort data request operation of data :" + request.RequestedDataName + "\'.") { }
public P2PDataRetrievalUnexpectedException(P2PDataRequest request) : base("Unexpected Error on P2P port client operation retrieving data \'" + request.RequestedDataName + "\'") { }
private void LogFailedDataRequestEventsOnTable(P2PDataRequest dataRequest) { if (!(dataRequest == null)) { string selectionCriteria = ""; DataRow[] resultRows = null; //***************************************************************************** //updates the general statistics table //***************************************************************************** try { lock (this._generalStatisticsTable) { selectionCriteria = "[Client Port Event] = \'Failed Data Request\'"; resultRows = this._generalStatisticsTable.Select(selectionCriteria); if (resultRows.Length <= 0) { DataRow row = this._generalStatisticsTable.NewRow(); row["Client Port Event"] = "Failed Data Request"; row["Count"] = 1; this._generalStatisticsTable.Rows.Add(row); } else { long count = (long)(resultRows[0]["Count"]); count++; resultRows[0]["Count"] = count; resultRows[0].AcceptChanges(); } } } catch (Exception ex) { string msg = "Error updating P2PPortClient General Statistics Table : " + ex.ToString(); CustomEventLog.WriteEntry(EventLogEntryType.Error, msg); } //***************************************************************************** //updates the data request statistics table //***************************************************************************** try { lock (this._dataRequestStatisticsTable) { selectionCriteria = "DataName = \'" + dataRequest.RequestedDataName + "\'"; resultRows = this._dataRequestStatisticsTable.Select(selectionCriteria); if (resultRows.Length <= 0) { //the dataname with the datatype is not registered DataRow row = this._dataRequestStatisticsTable.NewRow(); row["DataName"] = dataRequest.RequestedDataName; row["Successful"] = 0; row["Failed"] = 1; row["FirstRequestDateTime"] = DateTime.Now; row["LastRequestDateTime"] = DateTime.Now; this._dataRequestStatisticsTable.Rows.Add(row); } else { //the dataname with the datatype is registered long count = (long)(resultRows[0]["Failed"]); count++; resultRows[0]["Failed"] = count; resultRows[0]["LastRequestDateTime"] = DateTime.Now; resultRows[0].AcceptChanges(); } } } catch (Exception ex) { string msg = "Error updating P2PPortClient Data Requests Statistics Table : " + ex.ToString(); CustomEventLog.WriteEntry(EventLogEntryType.Error, msg); } } }
// function that mainly process the received data in the server port private void ProcessReceivedData(P2PPortClientHandler client) { try { if (!(client == null)) { try { //***************************************** //tries to deserialize to a P2PDATA //***************************************** P2PData data = P2PData.Deserialize(client.ReceiveDataBuffer); this.Statistics.LogDataReceptionEvent(data); try { //catches if an exception ocurrs to avoid the programm exist from the reading thread //because of a failure in the object that implements the interface. ((IUseP2PCommunicationsScheme)this._portOwnerComponent).ReceiveData(data, this.ListeningPortNumber); Services.P2PCommunicationsScheme.Data.P2PDataDeliveryResult successfulDataDelivery = Services.P2PCommunicationsScheme.Data.P2PDataDeliveryResult.GetSucceedDeliveryResult(data); client.handlerSocket.Send(successfulDataDelivery.Serialize()); //*************************************************************************************** } catch (Exception ex) { Services.P2PCommunicationsScheme.Data.P2PDataDeliveryResult failureDataDelivery = Services.P2PCommunicationsScheme.Data.P2PDataDeliveryResult.GetFailureDeliveryResult(data, ex.Message); client.handlerSocket.Send(failureDataDelivery.Serialize()); //*************************************************************************************** } } catch (Exception ex) { //***************************************** //tries to deserialize to a P2P_DATA_DELIVERY_RESULT //***************************************** P2PDataRequest dataRequest = default(P2PDataRequest); P2PData dataRequested = default(P2PData); try { dataRequest = P2PDataRequest.Deserialize(client.ReceiveDataBuffer); try { dataRequested = ((IUseP2PCommunicationsScheme)this._portOwnerComponent).RetrieveData(dataRequest, this.ListeningPortNumber); if (!(dataRequested == null)) { this.Statistics.LogSuccesfulDataRequestEvent(dataRequest); client.handlerSocket.Send(dataRequested.Serialize()); //*************************************************************************************** } else { this.Statistics.LogFailedDataRequestEvent(dataRequest); string portOwnerName = ((IUseP2PCommunicationsScheme)this._portOwnerComponent).P2PPortOwnerName; if (portOwnerName == null) { portOwnerName = "UNKNOWN"; } string errorMessage = "The remote object \'" + portOwnerName + "\' can\'t handle the requested data named \'" + dataRequest.RequestedDataName + "\'"; P2PDataRequestFailure reqFAilure = P2PDataRequestFailure.GetP2PDataRequestFailure(dataRequest, errorMessage); client.handlerSocket.Send(reqFAilure.Serialize()); //*************************************************************************************** } } catch (Exception ex2) { this.Statistics.LogFailedDataRequestEvent(dataRequest); string portOwnerName = ((IUseP2PCommunicationsScheme)this._portOwnerComponent).P2PPortOwnerName; if (portOwnerName == null) { portOwnerName = "UNKNOWN"; } string errorMessage = ex2.Message; P2PDataRequestFailure reqFAilure = P2PDataRequestFailure.GetP2PDataRequestFailure(dataRequest, errorMessage); client.handlerSocket.Send(reqFAilure.Serialize()); //*************************************************************************************** } } catch (Exception) { string msg = ""; msg = "Error processing incomming data from P2PPort client : " + ex.ToString(); CustomEventLog.WriteEntry(EventLogEntryType.Error, msg); } } } } catch (Exception ex) { string msg = ""; msg = "Error processing incomming data from P2PPort client : " + ex.ToString(); CustomEventLog.WriteEntry(EventLogEntryType.Error, msg); } }
public P2PData RetrieveData(P2PDataRequest request) { return(this.RetrieveData(request, P2PNetworkingDefinitions.READ_TIME_OUT_SECONDS)); }
private P2PData RetrieveData(P2PDataRequest request, int timeOutInSeconds) { bool dataRetrieved = false; byte[] bufferToBeSend = null; Exception exception = null; int OPERATION_TIME_OUT_IN_MS = timeOutInSeconds * 1000; bufferToBeSend = request.Serialize(); lock (this._socketPortBlockingFlag) { try { if (!(this._socketStream == null)) { //initialization of control flags this._dataRetrievedIsAvailable = false; this._dataRetrievalErrorIsAvailable = false; this._unexpectedErrorOcurred = false; //sends the data request using the socket stream try { //********************************************************************************* this._socketStream.Write(bufferToBeSend, 0, bufferToBeSend.Length); //********************************************************************************* //crates a signaled thread thar waits until the controls flags changes because a data or error is received //in the read socket thread WaitDataRequest_AR_Event.Reset(); ThreadPool.QueueUserWorkItem(WaitingRequestResponseThredFcn, WaitDataRequest_AR_Event); if (WaitDataRequest_AR_Event.WaitOne(OPERATION_TIME_OUT_IN_MS, true)) { //the working method activated the signal so an event is availabel according with the //activated control flags if (this._dataRetrievedIsAvailable) { this.Statistics.LogSuccesfulDataRequestEvent(request); dataRetrieved = true; } else if (this._dataRetrievalErrorIsAvailable) { this.Statistics.LogFailedDataRequestEvent(request); exception = new P2PDataRetrievalException(request, this._P2PDataRequestFailureReceived.ErrorMessage); } else if (this._connectionWithRemotePortLost) { this.Statistics.LogFailedDataRequestEvent(request); exception = new P2PPortConnectionException(); } else if (this._unexpectedErrorOcurred) { this.Statistics.LogFailedDataRequestEvent(request); if (!(this._unexpectedErrorMEssage == null)) { if (this._unexpectedErrorMEssage.Length > 0) { exception = new P2PDataRetrievalUnexpectedException(request, this._unexpectedErrorMEssage); } else { exception = new P2PDataRetrievalUnexpectedException(request); } } else { exception = new P2PDataRetrievalUnexpectedException(request); } } } else { //timeout waiting for the response this.Statistics.LogFailedDataRequestEvent(request); exception = new P2PDataRequestTimeOutException(request); } } catch (Exception ex) { throw (ex); } } else { exception = new Exception("Socket stream invalid of not available."); } } catch (Exception ex) { exception = ex; } } if (!(exception == null)) { throw (exception); } else { if (dataRetrieved) { return(this._P2PDataRetrievedFromRemotePort); } else { return(null); } } }
private P2PDataRequestFailure(P2PDataRequest P2PDataRequest, string errorMessage) { this._operationID = P2PDataRequest.P2PDataOperationID; this._errorMessage = errorMessage; }