public void Initialize(ApplicationStartupParameters appParameters)
        {
            try
            {
                if (_queue == null)
                {
                    _queue = new MessageQueue(DoSend);
                }

                CompositionTarget.Rendering += CompositionTargetRendering;

                _sender = new ServerMessageSender();
                _sender.ApplicationStarted += StartApplicationCompleted;
                _sender.ChannelFaulted     += ChannelFaulted;
                _sender.MessageReceived    += OnServerEventReceived;
                _sender.ChannelOpening     += OnChannelOpening;
                _sender.ChannelOpened      += OnChannelOpened;
                _sender.Intialize();
            }
            catch (Exception ex)
            {
                var args = new ServerChannelFaultEventArgs
                {
                    Error = ex
                };
                ChannelFaulted(this, args);
            }
        }
        private void ChannelFaulted(object sender, ServerChannelFaultEventArgs e)
        {
            string formattedMessage = e.ErrorMessage ?? e.Error.Message;

            UIThread.Execute(() =>
            {
                if (CriticalError != null)
                {
                    CriticalError(formattedMessage, EventArgs.Empty);
                }
            });
        }
Пример #3
0
 private void OnChannelFaulted(object sender, EventArgs e)
 {
     if (_connectionOpened)
     {
         var args = new ServerChannelFaultEventArgs
         {
             ErrorMessage = _connectionOpened
                                               ? ErrorMessages.ConnectionLost
                                               : String.Format(ErrorMessages.UnableToConnectTo,
                                                               _proxy.InnerChannel.RemoteAddress.Uri)
         };
         if (ChannelFaulted != null)
         {
             ChannelFaulted(this, args);
         }
     }
     _connectionOpened = false;
 }
Пример #4
0
        private void OnError(Exception exception)
        {
            if (!_connectionOpened)
            {
                Platform.Log(LogLevel.Error, exception, "Received exception after the connection has closed.");
                return;
            }

            var errorArgs = new ServerChannelFaultEventArgs
            {
                Error = exception
            };

            if (exception is FaultException <SessionValidationFault> )
            {
                var fault = exception as FaultException <SessionValidationFault>;
                errorArgs.ErrorMessage = fault.Detail.ErrorMessage;
            }
            else if (exception is FaultException <OutOfResourceFault> )
            {
                var fault = exception as FaultException <OutOfResourceFault>;
                errorArgs.ErrorMessage = fault.Detail.ErrorMessage;
            }
            else if (exception is CommunicationException)
            {
                if (!NetworkInterface.GetIsNetworkAvailable())
                {
                    errorArgs.ErrorMessage = ErrorMessages.ConnectionLost;
                }
                else
                {
                    var sb = new StringBuilder();
                    sb.AppendLine(String.Format("{0}: {1}", exception.GetType(), exception.Message));
                    sb.AppendLine(SR.StackTrace + ":");
                    sb.AppendLine(exception.StackTrace);


                    if (exception.InnerException != null)
                    {
                        sb.AppendLine(String.Format("{0}: {1}", exception.InnerException.GetType(), exception.InnerException.Message));
                        sb.AppendLine(SR.StackTrace + ":");
                        sb.AppendLine(exception.InnerException.StackTrace);
                    }

                    errorArgs.ErrorMessage = sb.ToString();
                }
            }
            else
            {
                var sb = new StringBuilder();
                sb.AppendLine(String.Format("{0}", exception.Message));
                sb.AppendLine(SR.StackTrace + ":");
                sb.AppendLine(exception.StackTrace);

                if (exception.InnerException != null)
                {
                    sb.AppendLine(String.Format("{0}: {1}", exception.InnerException.GetType(), exception.InnerException.Message));
                    sb.AppendLine(SR.StackTrace + ":");
                    sb.AppendLine(exception.InnerException.StackTrace);
                }

                errorArgs.ErrorMessage = sb.ToString();
            }

            Platform.Log(LogLevel.Error, "Received error on channel: {0}", errorArgs.ErrorMessage);

            if (ChannelFaulted != null)
            {
                ChannelFaulted(this, errorArgs);
            }

            _connectionOpened = false;
        }