예제 #1
0
            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);
                }
            }
예제 #2
0
            private void _posponedMatchTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                try
                {
                    this._posponedMatchTimer.Stop();

                    PublicationConnectionClientMatchRegister matchLog = null;

                    lock (this._posponedMatchQueue)
                    {
                        matchLog = (PublicationConnectionClientMatchRegister)this._posponedMatchQueue.Dequeue();
                    }

                    if (!(matchLog == null))
                    {
                        if (matchLog.GetElapsedSeconds() < MAX_MATCH_INTERVAL_LAP_IN_SECONDS)
                        {
                            //realizes the matching
                            if (this._PendingSocketClientMatchWithSTXDSSClientTable.ContainsKey(matchLog.PublicationConnectionHandlerID))
                            {
                                SocketsServerClientConnectionHandler socketConnectionHandler = default(SocketsServerClientConnectionHandler);
                                socketConnectionHandler = (SocketsServerClientConnectionHandler)this._PendingSocketClientMatchWithSTXDSSClientTable[matchLog.PublicationConnectionHandlerID];
                                if (socketConnectionHandler == null)
                                {
                                    throw (new Exception("There is not registered a socket connection handler of the client \'" + matchLog.Client.Name + "\' in the publication named \'" + this._publicationOwner.PublicationName + "\'"));
                                }

                                this.RegisterNewSubscriptorToPublication(matchLog.Client, socketConnectionHandler, matchLog.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, matchLog.Client);
                                }

                                //regiosters the relation of the socket connection woth the client for further reference
                                if (!this._STXDSSClientTosocketConnectionHandlerReferenceTable.ContainsKey(matchLog.Client.ClientID))
                                {
                                    this._STXDSSClientTosocketConnectionHandlerReferenceTable.Add(matchLog.Client.ClientID, socketConnectionHandler);
                                }

                                this.UnlogPendingSocketClientMatchConnectionWithSTXDSSClientTable(socketConnectionHandler);

                                //------------------------------------------------------------------------------------------
                                //sends to the client the last update of the publication
                                SocketsServerClientConnectionHandler handler = default(SocketsServerClientConnectionHandler);
                                handler = this.GetClientPublicationConnectionHandler(matchLog.Client);
                                if (!(handler == null))
                                {
                                    if (matchLog.ConnectionMode == DPE_ServerDefs.DPE_PublicationConnectionMode.ReceiveLastPublicationStatus)
                                    {
                                        this._publicationOwner.SchedulePublicationUpdateOnClientConnection(handler);
                                    }
                                }
                                //-------------------------------------------------------------------------------------------


                                try
                                {
                                    this._publicationOwner.RaiseNewConnectionEvent(matchLog.Client);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            else
                            {
                                if (matchLog.GetElapsedSeconds() < MAX_MATCH_INTERVAL_LAP_IN_SECONDS)
                                {
                                    lock (this._posponedMatchQueue)
                                    {
                                        this._posponedMatchQueue.Enqueue(matchLog);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    CustomEventLog.WriteEntry(ex);
                }
                finally
                {
                    if (this._posponedMatchQueue.Count > 0)
                    {
                        this._posponedMatchTimer.Start();
                    }
                }
            }