internal PublicationConnectionClientMatchRegister(DPE_Client client, string publicationConnectionHandlerID, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { this._client = client; this._publicationConnectionHandlerID = publicationConnectionHandlerID; this._connectionMode = connectionMode; this._insertionDateTime = DateTime.Now; }
//Public Sub New(ByVal cnnType As STXDSSC_PublicationConnectionHandler_Type, ByVal STXDSSPublicationName As String, ByVal STXDSSConnectionMode As DPE_PublicationConnectionMode, ByVal ReconnectionToPublicationThread As Threading.Thread) public PublicationConnectionTaskInfo(DPE_PublicationConnectionHandler_Type cnnType, string STXDSSPublicationName, DPE_ServerDefs.DPE_PublicationConnectionMode STXDSSConnectionMode) { this.creationDateTime = DateTime.Now; this.connectionType = cnnType; this.publicationName = STXDSSPublicationName; this.connectionMode = STXDSSConnectionMode; //Me.ConnectionThread = ReconnectionToPublicationThread this.keepScheduledConnectionTask = true; }
public DPE_PublicationConnectionHandler(DPE_PublicationConnectionHandler_Type handlerType, DPE_DataPublicationsClient client, string PublicationName, string PublicationHostName, int publicationsSocketsServerPortNumber, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { //************************************************************************************* this._STXDSSC_PublicationsProxyConnectionsServerClient = DPE_PublicationsConnectionsProxyServerClient.GetInstance(client.PublicationsMainServerDataBaseConnectionString); this._STXDSSC_PublicationsProxyConnectionsServerClient.ConnectionWithProxyServerLost += this._STXDSSC_PublicationsProxyConnectionsServerClient_ConnectionWithProxyServerLost; this._STXDSSC_PublicationsProxyConnectionsServerClient.Connect(); this._handlerType = handlerType; this._STXDataSocketClient = client; this._publicationName = PublicationName; this._publicationHostNAme = PublicationHostName; this._publicationPort = publicationsSocketsServerPortNumber; this._connectionMode = connectionMode; //************************************************************************************* //creates the server socket client to the publication's socket server in order to use it as endpoint to detect //when the publication goes off line string clientName = this._publicationName + Guid.NewGuid().ToString(); this._PublicationSocketsServerClient = new SocketsServerClient(clientName, this._publicationHostNAme, this._publicationPort); this._PublicationSocketsServerClient.DataReceived += publicationSocketClient_DataReceived; this._PublicationSocketsServerClient.ConnectionLost += publicationSocketClient_ConnectionLost; this._PublicationSocketsServerClient.Connect(); //becuase only the subscriptors clients will receive data from the publication if (handlerType == DPE_PublicationConnectionHandler_Type.subscriptorHandler) { //***************************************************************************************** try { //asks the proxy server to have a handle to create a sql reader to read locally the publications update this._DSSPublicationsSQLReader = this._STXDSSC_PublicationsProxyConnectionsServerClient.GetPublicationSocketsServerListenerClient(this._publicationName, this._publicationHostNAme); this._DSSPublicationsSQLReader.dataResetFromPublication += EventHandling_DSSPublicationsSQLReader_dataResetFromPublication; this._DSSPublicationsSQLReader.dataUpdateFromPublication += EventHandling_DSSPublicationsSQLReader_dataUpdateFromPublication; this._DSSPublicationsSQLReader.StartReading(); this._STXDSSC_PublicationsProxyConnectionsServerClient.LogClientConnectionFromPublication(this._STXDSSC_PublicationsProxyConnectionsServerClient.SocketsServerClientID, this._STXDataSocketClient, this._publicationName); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } else if (handlerType == DPE_PublicationConnectionHandler_Type.publisherHandler) { this._DSSPublicationsSQLWriter = new DPE_PublicationsSQLWriter(client.PublicationsMainServerDataBaseConnectionString, this._publicationName); } }
internal void ScheduleConnectionTaskToAPublication(string PublicationName, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { //this function is intended to be used by subscribers clients try { if (!this._tableOfConnectionRegistersForScheduledConnectionTasks.ContainsKey(PublicationName)) { string msg = ""; msg = "Task to connect with publication \'" + PublicationName + "\' was scheduled and started"; CustomEventLog.WriteEntry(EventLogEntryType.Information, msg); PublicationConnectionTaskInfo reg = new PublicationConnectionTaskInfo(DPE_PublicationConnectionHandler_Type.subscriptorHandler, PublicationName, connectionMode); lock (this._tableOfConnectionRegistersForScheduledConnectionTasks) { this._tableOfConnectionRegistersForScheduledConnectionTasks.Add(PublicationName, reg); } lock (this._queueOfScheduledConnectionTasks) { this._queueOfScheduledConnectionTasks.Enqueue(reg); } if (this._publicationsConnectionThread == null) { this._publicationsConnectionThread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadedFcn_ConnectionToEnqueuedDataPublications)); this._publicationsConnectionThread.IsBackground = true; this._publicationsConnectionThread.Priority = System.Threading.ThreadPriority.Normal; this._publicationsConnectionThread.Start(); } } } catch (Exception ex) { CustomEventLog.WriteEntry(ex); } }
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 DPE_PublicationConnectionHandler CreatePublicationConnectionHandler(DPE_PublicationConnectionHandler_Type handlerType, DPE_DataPublicationsClient client, string PublicationName, string PublicationHostName, int publicationsSocketsServerPortNumber, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { //*********************************************************************************************** //creates the handler according to the type of connection DPE_PublicationConnectionHandler publicationCnnHandler = null; publicationCnnHandler = new DPE_PublicationConnectionHandler(handlerType, client, PublicationName, PublicationHostName, publicationsSocketsServerPortNumber, connectionMode); if (!(publicationCnnHandler == null)) { try { //evaluates if the client is not the publisher of the publication, in order to avoid thepublisher client to //receive its own publication update if (!this._STXDataSocketClient.PublicationsPostManager.ContainsPublicationDefinition(PublicationName)) { if (publicationCnnHandler.HandlerType == DPE_PublicationConnectionHandler_Type.subscriptorHandler) { publicationCnnHandler.PublicationDataReceived += STXDSSPublicationConnectionHandler_PublicationDataReceived; publicationCnnHandler.PublicationDataResetReceived += STXDSSPublicationConnectionHandler_PublicationDataResetReceived; } } //for both type of handlers is created a handler to the connectio lost event in order to know when a connection to a publication //is lost publicationCnnHandler.ConnectionToPublicationLost += STXDSSPublicationConnectionHandler_ConnectionLost; } catch (Exception) { publicationCnnHandler.PublicationDataReceived -= STXDSSPublicationConnectionHandler_PublicationDataReceived; publicationCnnHandler.ConnectionToPublicationLost -= STXDSSPublicationConnectionHandler_ConnectionLost; publicationCnnHandler.PublicationDataResetReceived -= STXDSSPublicationConnectionHandler_PublicationDataResetReceived; } try { this._STXDSSPublicationConnectionHandlersContainer.AddPublicationConnectionHandler(publicationCnnHandler); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } if (handlerType == DPE_PublicationConnectionHandler_Type.subscriptorHandler) { //--------------------------------------- //saves into a has table the publication name and its connection mode for further reference when is needed to perfofm //automatic reconnections just for connections handlers defined as subscriptors handler PublicationConnectionInfo cnnInfo = new PublicationConnectionInfo(); cnnInfo.connectionType = handlerType; cnnInfo.PublicationName = PublicationName; cnnInfo.ConnectionMode = connectionMode; try { //saves the connection information for the subscriptors connection type handlers if (this._tableOfConnectionInfoRegistersOfConnectionsToPublications.ContainsKey(PublicationName)) { this._tableOfConnectionInfoRegistersOfConnectionsToPublications.Remove(PublicationName); } this._tableOfConnectionInfoRegistersOfConnectionsToPublications.Add(PublicationName, cnnInfo); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } } //--------------------------------------- return(publicationCnnHandler); }
internal void STXDSSClientConnectionIdentificationAndConnection(DPE_Client client, string publicationConnectionHandlerID, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { if (client.ClientID != this.publisherSTXDSSClient.ClientID) { //only registers as sbscriptors other client different from the publisher if (this._STXDSS_PublicationClientConnectionsManager.Set_STXDSSClientConnection(client, publicationConnectionHandlerID, connectionMode)) { //------------------------------------------------------------------------------------------ //sends to the client the last update of the publication SocketsServerClientConnectionHandler handler = default(SocketsServerClientConnectionHandler); handler = this._STXDSS_PublicationClientConnectionsManager.GetClientPublicationConnectionHandler(client); if (!(handler == null)) { if (connectionMode == DPE_ServerDefs.DPE_PublicationConnectionMode.ReceiveLastPublicationStatus) { this.SchedulePublicationUpdateOnClientConnection(handler); } } //------------------------------------------------------------------------------------------- try { this.RaiseNewConnectionEvent(client); } catch (Exception) { } } } }
internal dynamic Set_STXDSSClientConnection(DPE_Client client, string publicationConnectionHandlerID, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { if (this._PendingSocketClientMatchWithSTXDSSClientTable.ContainsKey(publicationConnectionHandlerID)) { SocketsServerClientConnectionHandler socketConnectionHandler = default(SocketsServerClientConnectionHandler); socketConnectionHandler = (SocketsServerClientConnectionHandler)this._PendingSocketClientMatchWithSTXDSSClientTable[publicationConnectionHandlerID]; if (socketConnectionHandler == null) { throw (new Exception("There is not registered a socket connection handler of the client \'" + client.Name + "\' in the publication named \'" + this._publicationOwner.PublicationName + "\'")); } this.RegisterNewSubscriptorToPublication(client, socketConnectionHandler, connectionMode); //regisers in a table the relation of the socket client that belong to the stxdssclient for //further reference if (!this._socketConnectionHandlerToClientREferenceTable.ContainsKey(socketConnectionHandler.ClientID)) { this._socketConnectionHandlerToClientREferenceTable.Add(socketConnectionHandler.ClientID, client); } //regiosters the relation of the socket connection woth the client for further reference if (!this._STXDSSClientTosocketConnectionHandlerReferenceTable.ContainsKey(client.ClientID)) { this._STXDSSClientTosocketConnectionHandlerReferenceTable.Add(client.ClientID, socketConnectionHandler); } //removes from a table the pending match registration this.UnlogPendingSocketClientMatchConnectionWithSTXDSSClientTable(socketConnectionHandler); return(true); } else { //the connection to the publication throuh the socket server don't exists when this happens so then the match is scheduled in a task PublicationConnectionClientMatchRegister matchLog = new PublicationConnectionClientMatchRegister(client, publicationConnectionHandlerID, connectionMode); this._posponedMatchQueue.Enqueue(matchLog); this._posponedMatchTimer.Start(); return(false); } }
private void RegisterNewSubscriptorToPublication(DPE_Client subscriptorClient, SocketsServerClientConnectionHandler connectionHandler, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { try { DataRow clientRow = this._STXDSSClienstSubscribedRegistryTable.NewRow(); clientRow["Client Name"] = subscriptorClient.Name; clientRow["Client ID"] = subscriptorClient.ClientID; clientRow["Client HostName"] = subscriptorClient.HostName; clientRow["Client AppDomain"] = subscriptorClient.ApplicationDomainName; clientRow["Connection Date Time"] = System.Convert.ToString(DateTime.Now); clientRow["Client Network ID"] = System.Convert.ToString(connectionHandler.ClientID); string cnnmode = ""; switch (connectionMode) { case DPE_ServerDefs.DPE_PublicationConnectionMode.NotReceiveLastPublicationStatus: cnnmode = "Not Receive Last Status"; break; case DPE_ServerDefs.DPE_PublicationConnectionMode.ReceiveLastPublicationStatus: cnnmode = "Receive Last Status"; break; default: cnnmode = "Undefined Status"; break; } clientRow["Connection Mode"] = cnnmode; lock (this._STXDSSClienstSubscribedRegistryTable) { this._STXDSSClienstSubscribedRegistryTable.Rows.Add(clientRow); } CustomEventLog.DisplayEvent(EventLogEntryType.Information, "Client \'" + subscriptorClient.Name + "\' connected to publication \'" + this._publicationOwner.PublicationName + "\'"); } catch (Exception) { } }