コード例 #1
0
            static void OnSendCompletedCallback(IAsyncResult result)
            {
                if (result.CompletedSynchronously)
                {
                    return;
                }

                SendAsyncResult thisPtr = (SendAsyncResult)result.AsyncState;

                Exception completionException = null;

                try
                {
                    thisPtr.OnSendCompleted(result);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    completionException = e;
                }

                thisPtr.Complete(false, completionException);
            }
コード例 #2
0
ファイル: UdpOutputChannel.cs プロジェクト: dox0/DotNet471RS3
            private static void OnRetransmitMessage(object state)
            {
                SendAsyncResult thisPtr             = (SendAsyncResult)state;
                bool            completeSelf        = false;
                Exception       completionException = null;

                try
                {
                    completeSelf = thisPtr.ContinueRetransmission(RetransmitState.WaitCompleted);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    completionException = e;
                    completeSelf        = true;
                }

                if (completeSelf)
                {
                    thisPtr.CompleteAndCleanup(false, completionException);
                }
            }
コード例 #3
0
                static void SendCompleteCallback(IAsyncResult result)
                {
                    if (result.CompletedSynchronously)
                    {
                        return;
                    }

                    SendAsyncResult thisPtr = (SendAsyncResult)result.AsyncState;

                    Exception completionException = null;

                    try
                    {
                        thisPtr.CompleteSend(result);
                    }
#pragma warning suppress 56500 // [....], transferring exception to another thread
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }
                        completionException = e;
                    }
                    thisPtr.Complete(false, completionException);
                }
コード例 #4
0
            static void OnEnterComplete(object state, Exception asyncException)
            {
                SendAsyncResult thisPtr             = (SendAsyncResult)state;
                bool            completeSelf        = false;
                Exception       completionException = asyncException;

                if (completionException != null)
                {
                    completeSelf = true;
                }
                else
                {
                    try
                    {
                        completeSelf = thisPtr.WriteCore();
                    }
#pragma warning suppress 56500 // [....], transferring exception to another thread
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        completeSelf        = true;
                        completionException = e;
                    }
                }

                if (completeSelf)
                {
                    thisPtr.Cleanup(completionException == null, asyncException == null);
                    thisPtr.Complete(false, completionException);
                }
            }
コード例 #5
0
                static void OnInnerSend(IAsyncResult result)
                {
                    if (result.CompletedSynchronously)
                    {
                        return;
                    }

                    SendAsyncResult thisPtr = (SendAsyncResult)result.AsyncState;

                    Exception completionException = null;

                    try
                    {
                        thisPtr.innerChannel.EndSend(result);
                    }
#pragma warning suppress 56500 // Microsoft, transferring exception to another thread
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        completionException = e;
                    }

                    thisPtr.Cleanup(completionException == null);
                    thisPtr.Complete(false, completionException);
                }
コード例 #6
0
                static void OnOpen(IAsyncResult result)
                {
                    if (result.CompletedSynchronously)
                    {
                        return;
                    }

                    SendAsyncResult thisPtr = (SendAsyncResult)result.AsyncState;

                    Exception completionException = null;
                    bool      completeSelf        = false;

                    try
                    {
                        thisPtr.CompleteOpen(result);
                        completeSelf = thisPtr.SendMessage();
                    }
#pragma warning suppress 56500 // Microsoft, transferring exception to another thread
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        completeSelf        = true;
                        completionException = e;
                    }

                    if (completeSelf)
                    {
                        thisPtr.Cleanup(completionException == null);
                        thisPtr.Complete(false, completionException);
                    }
                }
コード例 #7
0
            static void OnFinalizeCorrelationCompletedCallback(IAsyncResult result)
            {
                if (result.CompletedSynchronously)
                {
                    return;
                }

                SendAsyncResult thisPtr = (SendAsyncResult)result.AsyncState;

                Exception completionException = null;
                bool      completeSelf;

                try
                {
                    completeSelf = thisPtr.OnFinalizeCorrelationCompleted(result);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    completionException = e;
                    completeSelf        = true;
                }

                if (completeSelf)
                {
                    thisPtr.Complete(false, completionException);
                }
            }
 protected override void OnEndSend(IAsyncResult result)
 {
     if (TD.MessageSentByTransportIsEnabled())
     {
         TD.MessageSentByTransport(this.RemoteAddress.Uri.AbsoluteUri);
     }
     SendAsyncResult.End(result);
 }
コード例 #9
0
        public async Task <SendAsyncResult> SendAsync(PushUpdatesRequest request)
        {
            return(await Task.Run(async() =>
            {
                var result = new SendAsyncResult
                {
                    Status = true
                };
                try
                {
                    //prepare file name
                    var dir = $"{AppDomain.CurrentDomain.BaseDirectory}\\Logs";
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    var fileName = $"dump_{DateTime.UtcNow.ToString("yyMMdd_HHmmss")}";
                    // serialize JSON to a string and then write string to a file
                    File.WriteAllText(Path.Combine(dir, fileName), JsonConvert.SerializeObject(request));

                    // example how to canvert screenshot byte array back to image
                    if (request.Screenshots != null && request.Screenshots.Screenshots.Any())
                    {
                        foreach (var screenshot in request.Screenshots.Screenshots)
                        {
                            ImageConverter converter = new ImageConverter();
                            var img = (Image)converter.ConvertFrom(screenshot.Image);
                            img.Save($"{AppDomain.CurrentDomain.BaseDirectory}\\Logs\\{screenshot.Id.ToString()}.jpg", ImageFormat.Jpeg);
                            img.Dispose();
                        }
                    }

                    // example of sending request to authorized API
                    var signinInfo = _storageService.LoadSignInInfo();
                    HttpClient apiClient = null;
                    if (signinInfo != null)
                    {
                        apiClient = new HttpClient(new IdentityHttpHandler(storageService: _storageService, refreshToken: signinInfo.RefreshToken, accessToken: signinInfo.AccessToken));
                    }
                    else
                    {
                        apiClient = new HttpClient();
                    }
                    apiClient.BaseAddress = new Uri("https://demo.identityserver.io/api/");
                    var apiResult = await apiClient.GetAsync("test");
                    _logger.LogDebug(JsonConvert.SerializeObject(apiResult));
                    _logger.LogDebug($"Result content: {JArray.Parse(await apiResult.Content.ReadAsStringAsync()).ToString()}");
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.ToString());
                    result.Status = false;
                    result.ErrorMessage = Resources.APIStubErrorMessage;
                }
                return result;
            }));
        }
コード例 #10
0
ファイル: UdpOutputChannel.cs プロジェクト: dox0/DotNet471RS3
 protected override void OnEndSend(IAsyncResult result)
 {
     if (result is CompletedAsyncResult)
     {
         CompletedAsyncResult.End(result);
     }
     else
     {
         SendAsyncResult.End(result);
     }
 }
コード例 #11
0
            public static void End(IAsyncResult result)
            {
                if (TD.MessageSentByTransportIsEnabled())
                {
                    SendAsyncResult thisPtr = result as SendAsyncResult;
                    if (thisPtr != null)
                    {
                        TD.MessageSentByTransport(thisPtr.eventTraceActivity, thisPtr.channel.RemoteAddress.Uri.AbsoluteUri);
                    }
                }

                AsyncResult.End <SendAsyncResult>(result);
            }
コード例 #12
0
            static void OnSendComplete(object state)
            {
                SendAsyncResult thisPtr = (SendAsyncResult)state;

                thisPtr.message.CompleteCallback = null;
                thisPtr.message.UserToken        = null;
                DeliveryState      deliveryState = thisPtr.message.State;
                TransactionalState txnState      = deliveryState as TransactionalState;

                if (txnState != null)
                {
                    deliveryState = txnState.Outcome;
                }

                thisPtr.outcome = (Outcome)deliveryState;
                thisPtr.Complete(false);
            }
コード例 #13
0
                static void OnSend(IAsyncResult result)
                {
                    if (result.CompletedSynchronously)
                    {
                        return;
                    }

                    SendAsyncResult thisPtr             = (SendAsyncResult)result.AsyncState;
                    Exception       completionException = null;

                    try
                    {
                        thisPtr.CompleteSend(result);
                    }
                    catch (Exception e)
                    {
                        completionException = e;
                    }

                    thisPtr.Complete(false, completionException);
                }
コード例 #14
0
            static void OnWriteComplete(object asyncState)
            {
                SendAsyncResult thisPtr             = (SendAsyncResult)asyncState;
                Exception       completionException = null;

                try
                {
                    thisPtr.channel.FinishWritingMessage();
                }
#pragma warning suppress 56500 // [....], transferring exception to another thread
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    completionException = e;
                }

                thisPtr.Cleanup(completionException == null, true);
                thisPtr.Complete(false, completionException);
            }
コード例 #15
0
            static void OnEnterComplete(object state, Exception asyncException)
            {
                SendAsyncResult sendAsyncResult = (SendAsyncResult)state;

                if (asyncException != null)
                {
                    sendAsyncResult.Complete(false, asyncException);
                }
                else
                {
                    Exception completionException = null;
                    try
                    {
                        sendAsyncResult.channel.sendQueue.EnqueueAndDispatch(sendAsyncResult.message, sendAsyncResult.channel.onItemDequeued, false);
                    }
                    catch (Exception e)
                    {
                        completionException = e;
                    }

                    sendAsyncResult.Complete(false, completionException);
                }
            }
コード例 #16
0
ファイル: UdpOutputChannel.cs プロジェクト: dox0/DotNet471RS3
            private static void OnSocketSendComplete(IAsyncResult result)
            {
                if (result.CompletedSynchronously)
                {
                    return;
                }

                SendAsyncResult thisPtr             = (SendAsyncResult)result.AsyncState;
                bool            completeSelf        = false;
                Exception       completionException = null;

                try
                {
                    completeSelf = thisPtr.ContinueTransmitting(result);

                    if (completeSelf && thisPtr.retransmissionEnabled)
                    {
                        completeSelf = thisPtr.BeginRetransmission();
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    completionException = e;
                    completeSelf        = true;
                }

                if (completeSelf)
                {
                    thisPtr.CompleteAndCleanup(false, completionException);
                }
            }
コード例 #17
0
 public void EndSend(IAsyncResult result)
 {
     SendAsyncResult.End(result);
 }
コード例 #18
0
 void EndSend(IAsyncResult asyncResult)
 {
     SendAsyncResult.End(asyncResult);
 }
コード例 #19
0
ファイル: HttpChannelHelpers.cs プロジェクト: mind0n/hive
        IAsyncResult BeginSendCore(HttpResponseMessage httpResponseMessage, TimeSpan timeout, AsyncCallback callback, object state)
        {
            bool throwing = true;
            try
            {
                bool suppressEntityBody;
                if (httpResponseMessage != null)
                {
                    suppressEntityBody = this.PrepareHttpSend(httpResponseMessage);
                }
                else
                {
                    suppressEntityBody = PrepareHttpSend(message);
                }

                this.TraceHttpSendStart();
                IAsyncResult result = new SendAsyncResult(this, httpResponseMessage, suppressEntityBody, timeout, callback, state);
                throwing = false;
                return result;
            }
            finally
            {
                if (throwing)
                {
                    Abort();
                }
            }
        }
コード例 #20
0
 protected override void OnEndSend(IAsyncResult result)
 {
     SendAsyncResult.End(result);
 }
コード例 #21
0
            public static void End(IAsyncResult result)
            {
                SendAsyncResult thisPtr = AsyncResult.End <SendAsyncResult>(result);

                thisPtr.dispatcher.Release();
            }
コード例 #22
0
 /// <summary>
 /// Ends the asynchronous send operation.
 /// </summary>
 /// <param name="result">The <see cref="IAsyncResult"/> returned by the begin method.</param>
 /// <returns>The delivery outcome.</returns>
 public Outcome EndSendMessage(IAsyncResult result)
 {
     return(SendAsyncResult.End(result));
 }
コード例 #23
0
 public virtual IAsyncResult BeginSend(TimeSpan timeout, AsyncCallback callback, object state)
 {
     IAsyncResult result2;
     bool flag = true;
     try
     {
         bool suppressEntityBody = this.PrepareHttpSend(this.message);
         IAsyncResult result = new SendAsyncResult(this, suppressEntityBody, timeout, callback, state);
         flag = false;
         result2 = result;
     }
     finally
     {
         if (flag)
         {
             this.Abort();
         }
     }
     return result2;
 }
コード例 #24
0
 public void EndSend(IAsyncResult result)
 {
     SendAsyncResult <TChannel> .End(result);
 }
コード例 #25
0
 void EndSendViaTopic(IAsyncResult ar)
 {
     SendAsyncResult.End(ar);
 }
 public IAsyncResult BeginSend(object registrant, Message message, Uri via, ITransportFactorySettings settings, TimeSpan timeout, AsyncCallback callback, object state, SecurityProtocol securityProtocol)
 {
     TimeoutHelper helper = new TimeoutHelper(timeout);
     MessageBuffer encodedMessage = null;
     Message message2 = null;
     ulong maxValue = ulong.MaxValue;
     PeerMessagePropagation localAndRemote = PeerMessagePropagation.LocalAndRemote;
     int messageSize = -1;
     SendAsyncResult result = new SendAsyncResult(callback, state);
     AsyncCallback callback2 = Fx.ThunkCallback(new AsyncCallback(result.OnFloodComplete));
     try
     {
         PeerFlooder flooder;
         byte[] primarySignatureValue;
         lock (this.ThisLock)
         {
             this.ThrowIfNotOpen();
             flooder = this.flooder;
         }
         int maxBufferSize = (int) Math.Min(this.maxReceivedMessageSize, settings.MaxReceivedMessageSize);
         Guid guid = this.ProcessOutgoingMessage(message, via);
         this.SecureOutgoingMessage(ref message, via, timeout, securityProtocol);
         if (message is SecurityAppliedMessage)
         {
             ArraySegment<byte> buffer = this.encoder.WriteMessage(message, 0x7fffffff, this.bufferManager);
             message2 = this.encoder.ReadMessage(buffer, this.bufferManager);
             primarySignatureValue = (message as SecurityAppliedMessage).PrimarySignatureValue;
             messageSize = buffer.Count;
         }
         else
         {
             message2 = message;
             primarySignatureValue = guid.ToByteArray();
         }
         encodedMessage = message2.CreateBufferedCopy(maxBufferSize);
         string contentType = settings.MessageEncoderFactory.Encoder.ContentType;
         if (this.messagePropagationFilter != null)
         {
             using (Message message3 = encodedMessage.CreateMessage())
             {
                 localAndRemote = ((IPeerNodeMessageHandling) this).DetermineMessagePropagation(message3, PeerMessageOrigination.Local);
             }
         }
         if (((localAndRemote & PeerMessagePropagation.Remote) != PeerMessagePropagation.None) && (maxValue == 0L))
         {
             localAndRemote &= ~PeerMessagePropagation.Remote;
         }
         IAsyncResult result2 = null;
         if ((localAndRemote & PeerMessagePropagation.Remote) != PeerMessagePropagation.None)
         {
             result2 = flooder.BeginFloodEncodedMessage(primarySignatureValue, encodedMessage, helper.RemainingTime(), callback2, null);
             if (System.ServiceModel.DiagnosticUtility.ShouldTraceVerbose)
             {
                 TraceUtility.TraceEvent(TraceEventType.Verbose, 0x4003e, System.ServiceModel.SR.GetString("TraceCodePeerChannelMessageSent"), this, message);
             }
         }
         else
         {
             result2 = new CompletedAsyncResult(callback2, null);
         }
         if ((localAndRemote & PeerMessagePropagation.Local) != PeerMessagePropagation.None)
         {
             using (Message message4 = encodedMessage.CreateMessage())
             {
                 int i = message4.Headers.FindHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                 if (i >= 0)
                 {
                     message4.Headers.AddUnderstood(i);
                 }
                 using (MessageBuffer buffer3 = message4.CreateBufferedCopy(maxBufferSize))
                 {
                     this.DeliverMessageToClientChannels(registrant, buffer3, via, message.Headers.To, contentType, messageSize, -1, null);
                 }
             }
         }
         result.OnLocalDispatchComplete(result);
     }
     finally
     {
         message.Close();
         if (message2 != null)
         {
             message2.Close();
         }
         if (encodedMessage != null)
         {
             encodedMessage.Close();
         }
     }
     return result;
 }
コード例 #27
0
        public IAsyncResult BeginSend(object registrant, Message message, Uri via,
            ITransportFactorySettings settings, TimeSpan timeout, AsyncCallback callback, object state, SecurityProtocol securityProtocol)
        {
            PeerFlooder localFlooder;
            int factoryMaxReceivedMessageSize;
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            MessageBuffer messageBuffer = null;
            Message securedMessage = null;
            ulong hopcount = PeerTransportConstants.MaxHopCount;
            PeerMessagePropagation propagateFlags = PeerMessagePropagation.LocalAndRemote;
            int messageSize = (int)-1;
            byte[] id;
            SendAsyncResult result = new SendAsyncResult(callback, state);
            AsyncCallback onFloodComplete = Fx.ThunkCallback(new AsyncCallback(result.OnFloodComplete));

            try
            {
                lock (ThisLock)
                {
                    ThrowIfNotOpen();
                    localFlooder = flooder;
                }

                // we know this will fit in an int because of our MaxReceivedMessageSize restrictions
                factoryMaxReceivedMessageSize = (int)Math.Min(maxReceivedMessageSize, settings.MaxReceivedMessageSize);
                Guid guid = ProcessOutgoingMessage(message, via);
                SecureOutgoingMessage(ref message, via, timeout, securityProtocol);
                if ((message is SecurityAppliedMessage))
                {
                    ArraySegment<byte> buffer = encoder.WriteMessage(message, int.MaxValue, bufferManager);
                    securedMessage = encoder.ReadMessage(buffer, bufferManager);
                    id = (message as SecurityAppliedMessage).PrimarySignatureValue;
                    messageSize = (int)buffer.Count;
                }
                else
                {
                    securedMessage = message;
                    id = guid.ToByteArray();
                }

                messageBuffer = securedMessage.CreateBufferedCopy(factoryMaxReceivedMessageSize);
                string contentType = settings.MessageEncoderFactory.Encoder.ContentType;
                if (this.messagePropagationFilter != null)
                {
                    using (Message filterMessage = messageBuffer.CreateMessage())
                    {
                        propagateFlags = ((IPeerNodeMessageHandling)this).DetermineMessagePropagation(filterMessage, PeerMessageOrigination.Local);
                    }
                }

                if ((propagateFlags & PeerMessagePropagation.Remote) != PeerMessagePropagation.None)
                {
                    if (hopcount == 0)
                        propagateFlags &= ~PeerMessagePropagation.Remote;
                }

                // flood it out
                IAsyncResult ar = null;
                if ((propagateFlags & PeerMessagePropagation.Remote) != 0)
                {
                    ar = localFlooder.BeginFloodEncodedMessage(id, messageBuffer, timeoutHelper.RemainingTime(), onFloodComplete, null);
                    if (DiagnosticUtility.ShouldTraceVerbose)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.PeerChannelMessageSent, SR.GetString(SR.TraceCodePeerChannelMessageSent), this, message);
                    }
                }
                else
                {
                    ar = new CompletedAsyncResult(onFloodComplete, null);
                }
                if (ar == null)
                {
                    Fx.Assert("SendAsyncResult must have an Async Result for onFloodComplete");
                }

                // queue up the pre-encoded message for local channels
                if ((propagateFlags & PeerMessagePropagation.Local) != 0)
                {
                    using (Message msg = messageBuffer.CreateMessage())
                    {
                        int i = msg.Headers.FindHeader(SecurityJan2004Strings.Security, SecurityJan2004Strings.Namespace);
                        if (i >= 0)
                        {
                            msg.Headers.AddUnderstood(i);
                        }
                        using (MessageBuffer clientBuffer = msg.CreateBufferedCopy(factoryMaxReceivedMessageSize))
                        {
                            DeliverMessageToClientChannels(registrant, clientBuffer, via, message.Headers.To, contentType, messageSize, -1, null);
                        }
                    }
                }
                result.OnLocalDispatchComplete(result);
            }
            finally
            {
                message.Close();
                if (securedMessage != null)
                    securedMessage.Close();
                if (messageBuffer != null)
                    messageBuffer.Close();
            }

            return result;
        }
コード例 #28
0
 public static void End(IAsyncResult result)
 {
     SendAsyncResult thisPtr = AsyncResult.End <SendAsyncResult>(result);
 }