예제 #1
0
            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);
                }
            }
            public static DPE_PublicationsSQLReader GetReader(string publicationsDataBaseConnectionString, string publicationName)
            {
                try
                {
                    if (_SQLreadersSingletonTable.ContainsKey(publicationName))
                    {
                        Hashtable pubTable = (Hashtable)(_SQLreadersSingletonTable[publicationName]);

                        if (pubTable.ContainsKey(publicationsDataBaseConnectionString))
                        {
                            DPE_PublicationsSQLReader reader = null;
                            reader = (DPE_PublicationsSQLReader)pubTable[publicationsDataBaseConnectionString];
                            return(reader);
                        }
                        else
                        {
                            DPE_PublicationsSQLReader reader = new DPE_PublicationsSQLReader(publicationsDataBaseConnectionString, publicationName);
                            pubTable.Add(publicationsDataBaseConnectionString, publicationsDataBaseConnectionString);
                            return(reader);
                        }
                    }
                    else
                    {
                        Hashtable table = new Hashtable();
                        DPE_PublicationsSQLReader reader = new DPE_PublicationsSQLReader(publicationsDataBaseConnectionString, publicationName);

                        table.Add(publicationsDataBaseConnectionString, reader);

                        _SQLreadersSingletonTable.Add(publicationName, table);

                        return(reader);
                    }
                }
                catch (Exception ex)
                {
                    CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString());
                    return(null);
                }
            }