コード例 #1
0
        private void OnRemoteSideConnected(RemoteSideIDType remoteSideID)
        {
            System.Diagnostics.Debug.WriteLine("New connection: {0}!", remoteSideID.ToString());

            if (RemoteSideConnected != null)
            {
                RemoteSideConnected(this, new RemoteSideConnectedEventArgs(remoteSideID));
            }
        }
コード例 #2
0
        public virtual RemoteResponse ExecuteRequest(RemoteRequest request)
        {
            ThrowIfNotInitialized();

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            RemoteResponse ret = null;

            RemoteSideIDType remoteID = request.RemoteID;

            if (remoteID == null)
            {
                throw new InvalidOperationException("Remote call without remote side id!"); //LOCSTR
            }

            var wrapper = remoteSide;
            IRemoteSideCommunicationContract currentContract = wrapper.GetCurrentRemoteSideCommunicationContract();

            try
            {
                bool isNewRemoteSide = false;
                bool lockTaken       = false;
                try
                {
                    syncRoot.Enter(ref lockTaken);

                    RemoteRequestStarted(remoteID, request);

                    IRemoteSideCommunicationContract lastKnownContract = null;
                    if (communicationContractsByRemoteSideIDDict.TryGetValue(remoteID, out lastKnownContract))
                    {
                        // known client comes in again
                        if (lastKnownContract != currentContract)
                        {
                            communicationContractsByRemoteSideIDDict[remoteID] = currentContract;
                            remoteSideIDsByCommunicationContractDict.Remove(lastKnownContract);
                            remoteSideIDsByCommunicationContractDict.Add(currentContract, remoteID);

                            wrapper.Closed  += new EventHandler(Channel_Closed);
                            wrapper.Faulted += new EventHandler(Channel_Faulted);

                            RemoteSideReconnected(remoteID);
                            //Log.Debug("Client {0} reconnected.", remoteID.ToString()); //LOCSTR
                            System.Diagnostics.Debug.WriteLine("Client {0} reconnected.", remoteID.ToString()); //LOCSTR
                        }

                        KnownRemoteSideRequest(remoteID);
                    }
                    else
                    {
                        wrapper.Closed  += new EventHandler(Channel_Closed);
                        wrapper.Faulted += new EventHandler(Channel_Faulted);

                        remoteSideIDsByCommunicationContractDict.Add(currentContract, remoteID);
                        communicationContractsByRemoteSideIDDict.Add(remoteID, currentContract);

                        NewRemoteSideConnected(remoteID);

                        isNewRemoteSide = true;
                    }
                }
                finally
                {
                    if (lockTaken)
                    {
                        syncRoot.Exit();
                    }
                }

                if (isNewRemoteSide)
                {
                    OnRemoteSideConnected(remoteID);
                }

                // process request
                ret = remoteOperationHandler.ExecuteRequest(request, typeof(RemoteCallableTypeAttribute), typeof(RemoteCallableFuncAttribute));
            }
            finally
            {
                RemoteRequestFinished(remoteID, request);
            }

            return(ret);
        }