Example #1
0
            public DispatchSessionAsyncResult(ListenerSessionConnection session, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.session = session;
                DuplicateContext duplicateContext = null;

                try
                {
                    duplicateContext = session.WorkerProcess.DuplicateConnection(session);
                }
                catch (ServiceActivationException e)
                {
                    int    traceCode;
                    string traceDescription;
                    if (session.WorkerProcess is TcpWorkerProcess)
                    {
                        traceCode        = ListenerTraceCode.MessageQueueDuplicatedSocketError;
                        traceDescription = SR.GetString(SR.TraceCodeMessageQueueDuplicatedSocketError);
                    }
                    else
                    {
                        traceCode        = ListenerTraceCode.MessageQueueDuplicatedPipeError;
                        traceDescription = SR.GetString(SR.TraceCodeMessageQueueDuplicatedPipeError);
                    }

                    if (DiagnosticUtility.ShouldTraceError)
                    {
                        ListenerTraceUtility.TraceEvent(TraceEventType.Error, traceCode, traceDescription, this, e);
                    }
                    this.Complete(true, e);
                    return;
                }

                IAsyncResult result = this.session.WorkerProcess.ConnectionDuplicator.BeginDuplicate(duplicateContext,
                                                                                                     dispatchSessionCallback, this);

                if (result.CompletedSynchronously)
                {
                    CompleteDuplicateSession(result);
                    this.Complete(true);
                }
            }
 private bool HandleOnVia(DuplicateContext duplicateContext)
 {
     if (this.onDuplicatedViaCallback != null)
     {
         lock (this.ThisLock)
         {
             if (this.onDuplicatedViaCallback == null)
             {
                 return true;
             }
             if (this.onDuplicatedViaCallback != null)
             {
                 try
                 {
                     int num = this.onDuplicatedViaCallback(duplicateContext.Via);
                     this.connectionBufferSize = num;
                     this.onDuplicatedViaCallback = null;
                 }
                 catch (Exception exception)
                 {
                     if (DiagnosticUtility.ShouldTraceInformation)
                     {
                         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                     }
                     string faultCode = null;
                     if (exception is ServiceActivationException)
                     {
                         faultCode = "http://schemas.microsoft.com/ws/2006/05/framing/faults/ServiceActivationFailed";
                     }
                     else if (exception is EndpointNotFoundException)
                     {
                         faultCode = "http://schemas.microsoft.com/ws/2006/05/framing/faults/EndpointNotFound";
                     }
                     IConnection connection = this.BuildConnectionFromData(duplicateContext, 0x2000);
                     if (faultCode != null)
                     {
                         this.SendFault(connection, faultCode);
                         return false;
                     }
                     connection.Abort();
                     if (!(exception is CommunicationObjectAbortedException))
                     {
                         throw;
                     }
                     return false;
                 }
             }
         }
     }
     return true;
 }
 IAsyncResult IConnectionDuplicator.BeginDuplicate(DuplicateContext duplicateContext, AsyncCallback callback, object state)
 {
     IAsyncResult result2;
     try
     {
         if (!this.HandleOnVia(duplicateContext))
         {
             return new SharedConnectionListener.DuplicateConnectionAsyncResult(callback, state);
         }
         SharedConnectionListener.DuplicateConnectionAsyncResult result = new SharedConnectionListener.DuplicateConnectionAsyncResult(this.BuildConnectionFromData(duplicateContext, this.connectionBufferSize), callback, state);
         this.parent.OnConnectionAvailable(result);
         result2 = result;
     }
     catch (Exception exception)
     {
         if (DiagnosticUtility.ShouldTraceError)
         {
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error);
         }
         throw;
     }
     return result2;
 }
 private IConnection BuildConnectionFromData(DuplicateContext duplicateContext, int connectionBufferSize)
 {
     if (this.isTcp)
     {
         return this.BuildDuplicatedTcpConnection((TcpDuplicateContext) duplicateContext, connectionBufferSize);
     }
     return this.BuildDuplicatedNamedPipeConnection((NamedPipeDuplicateContext) duplicateContext, connectionBufferSize);
 }