Пример #1
0
 public bool CompleteWithError(Exception ex)
 {
     Status = (int)AsyncOperationStatus.Complete;
     if (UserAsyncResult == null)
     {
         return(true);
     }
     if (!UserAsyncResult.InternalPeekCompleted)
     {
         UserAsyncResult.InvokeCallback(ex);
     }
     return(false);
 }
Пример #2
0
            public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
            {
                this.Write(buffer, offset, count);
                LazyAsyncResult result = new LazyAsyncResult(null, state, callback);

                result.InvokeCallback(null);
                return(result);
            }
            public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, Object state)
            {
                Write(buffer, offset, count);
                LazyAsyncResult ar = new LazyAsyncResult(null, state, callback);

                ar.InvokeCallback(null);
                return(ar);
            }
 protected override IAsyncResult BeginGetTokenCore(TimeSpan timeout, AsyncCallback callback, object state)
 {
     if (this.cachedSecurityToken != null)
     {
         LazyAsyncResult lazyAsyncResult = new LazyAsyncResult(null, state, callback);
         ExTraceGlobals.RightsManagementTracer.TraceDebug(0L, "Got cached saml token. Invoking callback.");
         lazyAsyncResult.InvokeCallback();
         return(lazyAsyncResult);
     }
     this.latencyTracker.BeginTrackRmsLatency(RmsOperationType.RequestDelegationToken);
     return(this.securityTokenService.BeginIssueToken(this.CreateDelegationTokenRequest(), callback, state));
 }
Пример #5
0
        private static void StableUnicastAddressTableCallback(object param)
        {
            EventWaitHandle handle = param as EventWaitHandle;

            if (handle != null)
            {
                handle.Set();
            }
            else
            {
                LazyAsyncResult asyncResult = (LazyAsyncResult)param;
                asyncResult.InvokeCallback();
            }
        }
Пример #6
0
        internal IAsyncResult BeginSend(BaseWriter writer, bool sendEnvelope, bool allowUnicode,
                                        AsyncCallback?callback, object?state)
        {
            PrepareHeaders(sendEnvelope, allowUnicode);
            writer.WriteHeaders(Headers, allowUnicode);

            if (Content != null)
            {
                return(Content.BeginSend(writer, callback, allowUnicode, state));
            }
            else
            {
                LazyAsyncResult result    = new LazyAsyncResult(this, state, callback);
                IAsyncResult    newResult = writer.BeginGetContentStream(EmptySendCallback, new EmptySendContext(writer, result));
                if (newResult.CompletedSynchronously)
                {
                    writer.EndGetContentStream(newResult).Close();
                    result.InvokeCallback();
                }
                return(result);
            }
        }
Пример #7
0
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, Object state)
 {
     Write(buffer, offset, count);
     LazyAsyncResult ar = new LazyAsyncResult(null, state, callback);
     ar.InvokeCallback(null);
     return ar;
 }
Пример #8
0
        public IAsyncResult BeginProcessRequest(HttpContext context, IAsyncResult asyncResult, ProxyHandler.ProxiedRequestInfo proxyinfo)
        {
            LazyAsyncResult lazyAsyncResult = (LazyAsyncResult)asyncResult;

            this.proxyInfo = proxyinfo;
            this.remoteUri = this.proxyInfo.RemoteUri;
            this.userName  = this.proxyInfo.User;
            try
            {
                AirSyncDiagnostics.TraceDebug <Uri, string>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest called for serverName: {0}, user {1}", this.remoteUri, this.userName);
                if (!string.Equals(context.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) && !string.Equals(context.Request.HttpMethod, "OPTIONS", StringComparison.OrdinalIgnoreCase))
                {
                    context.Response.StatusCode = 405;
                    lazyAsyncResult.InvokeCallback();
                    return(lazyAsyncResult);
                }
                UriBuilder uriBuilder = new UriBuilder(this.proxyInfo.RemoteUri);
                if (!string.IsNullOrEmpty(context.Request.Url.Query))
                {
                    if (!string.IsNullOrEmpty(context.Request.Url.Fragment))
                    {
                        string str = context.Request.Url.Fragment.Remove(0, 1);
                        uriBuilder.Query = context.Request.Url.Query.Remove(0, 1) + "%23" + str;
                    }
                    else
                    {
                        uriBuilder.Query = context.Request.Url.Query.Remove(0, 1);
                    }
                }
                this.cachedUri = uriBuilder.Uri;
                HttpWebRequest httpWebRequest = this.CopyClientRequest(context.Request, this.cachedUri);
                WindowsImpersonationContext windowsImpersonationContext = null;
                IAsyncResult asyncResult2 = null;
                try
                {
                    if (this.proxyInfo.RequiresImpersonation)
                    {
                        windowsImpersonationContext = ((WindowsIdentity)context.User.Identity).Impersonate();
                    }
                    else
                    {
                        NetworkServiceImpersonator.Initialize();
                        windowsImpersonationContext = NetworkServiceImpersonator.Impersonate();
                        httpWebRequest.Credentials  = CredentialCache.DefaultCredentials;
                    }
                    this.backEndWebRequest   = httpWebRequest;
                    this.frontEndResult      = lazyAsyncResult;
                    this.frontEndHttpContext = context;
                    try
                    {
                        this.clientRequestStream = this.frontEndHttpContext.Request.InputStream;
                    }
                    catch (COMException innerException)
                    {
                        this.protocolLogger.SetValue(ProtocolLoggerData.Error, "InputStreamUnavailable");
                        throw new AirSyncPermanentException(HttpStatusCode.ServiceUnavailable, StatusCode.ServerErrorRetryLater, innerException, false);
                    }
                    this.issueTime             = ExDateTime.Now;
                    this.pendingAsyncOperation = ProxyHandler.PendingOperationState.BackEndGetRequestStream;
                    asyncResult2 = this.backEndWebRequest.BeginGetRequestStream(new AsyncCallback(this.BackEndGetRequestStream), null);
                }
                finally
                {
                    if (windowsImpersonationContext != null)
                    {
                        windowsImpersonationContext.Undo();
                        windowsImpersonationContext.Dispose();
                    }
                }
                if (asyncResult2 != null && !asyncResult2.CompletedSynchronously)
                {
                    this.RegisterTimeoutWaitHandle(asyncResult2, (int)GlobalSettings.ProxyHandlerShortTimeout.TotalMilliseconds);
                }
            }
            catch (Exception ex)
            {
                AirSyncUtility.ExceptionToStringHelper arg = new AirSyncUtility.ExceptionToStringHelper(ex);
                AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest caught an exception\r\n{0}", arg);
                if (this.backEndWebRequest != null)
                {
                    this.backEndWebRequest.Abort();
                    this.backEndWebRequest = null;
                }
                if (ex is WebException)
                {
                    AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, this, "ProxyHandler.BeginProcessRequest swallowing exception and returning HTTP 500");
                    try
                    {
                        this.TryUnregisterTimeoutWaitHandle();
                        this.frontEndHttpContext.Response.StatusCode = 500;
                        this.frontEndResult.InvokeCallback();
                        goto IL_2F0;
                    }
                    catch (HttpException ex2)
                    {
                        AirSyncUtility.ExceptionToStringHelper arg2 = new AirSyncUtility.ExceptionToStringHelper(ex2);
                        AirSyncDiagnostics.TraceError <AirSyncUtility.ExceptionToStringHelper>(ExTraceGlobals.RequestsTracer, this, "HttpException was thrown while setting the StatusCode.\r\n{0}", arg2);
                        goto IL_2F0;
                    }
                    goto IL_2EE;
IL_2F0:
                    return(lazyAsyncResult);
                }
IL_2EE:
                throw;
            }
            return(lazyAsyncResult);
        }
Пример #9
0
		private void DoBeginAccept(LazyAsyncResult asyncResult)
		{
			if (this.m_RightEndPoint == null)
				throw new InvalidOperationException("net_sockets_mustbind");

			if (!this.isListening)
				throw new InvalidOperationException("net_sockets_mustlisten");

			bool flag = false;
			SocketError socketError = SocketError.Success;
			Queue acceptQueue = this.GetAcceptQueue();
			bool flag2 = false;

			try
			{
				Monitor.Enter(this, ref flag2);
				if (acceptQueue.Count == 0)
				{
					SocketAddress socketAddress = this.m_RightEndPoint.Serialize();
					this.InternalSetBlocking(false);
					SafeCloseSocket safeCloseSocket = null;
					try
					{
						safeCloseSocket = SafeCloseSocket.Accept(this.m_Handle, socketAddress.m_Buffer, ref socketAddress.m_Size);
						socketError = (SocketError)(safeCloseSocket.IsInvalid ? Marshal.GetLastWin32Error() : 0);
					}
					catch (ObjectDisposedException)
					{
						socketError = SocketError.NotSocket;
					}
					if (socketError != SocketError.WouldBlock)
					{
						if (socketError == SocketError.Success)
						{
							asyncResult.Result = this.CreateAcceptSocket(safeCloseSocket, this.m_RightEndPoint.Create(socketAddress), false);
						}
						else
						{
							asyncResult.ErrorCode = (int)socketError;
						}
						this.InternalSetBlocking(true);
						flag = true;
					}
					else
					{
						acceptQueue.Enqueue(asyncResult);
						if (!this.SetAsyncEventSelect(AsyncEventBits.FdAccept))
						{
							acceptQueue.Dequeue();
							throw new ObjectDisposedException(base.GetType().FullName);
						}
					}
				}
				else
				{
					acceptQueue.Enqueue(asyncResult);
				}
			}
			finally
			{
				if (flag2)
					Monitor.Exit(this);
			}

			if (!flag)
				return;

			if (socketError == SocketError.Success)
			{
				asyncResult.InvokeCallback();
				return;
			}

			SocketException ex = new SocketException(socketError);
			this.UpdateStatusAfterSocketError(ex);
			throw ex;
		}