示例#1
0
 public void CloseApplication(ApplicationAdapterEndPoint endPoint)
 {
     endPoint.UnhandledException -= UnhandledExceptionEventHandler;
     endPoint.MessageReceived    -= MessageReceivedEventHandler;
     endPoint.Dispose();
     OnEndPointDestroyed(endPoint);
 }
        public override void Invoke(CreateSessionRequest request)
        {
            try
            {
                ApplicationAdapter applicationAdapter = MessageEngine.Instance.AdapterProxy.GetAdapterById("app") as ApplicationAdapter;

                if (MessageEngine.Instance.AdapterProxy.ResolveUriToEndPoint(new Uri("app://" + request.SessionId)) == null)
                {
                    lock (Session.SyncLock)
                    {
                        Session.ClientIP       = ((Uri)SourceMessage.Metadata.Read("ReceiveUri")).Host;
                        Session.TerminalId     = request.TerminalId;
                        Session.ClientPlatform = request.ClientPlatform;
                        Session.ClientVersion  = request.ClientVersion;
                        ApplicationAdapterEndPoint endPoint = applicationAdapter.StartApplication(request.ApplicationName, Session.Id);
                        Session.ApplicationEndPoint = endPoint;
                    }
                }

                CreateSessionResponse response = new CreateSessionResponse();

                TransmitResponseMessage(response);
            }
            catch
            {
                SessionManager.Instance.DestroySession(request.SessionId);
                throw;
            }
        }
示例#3
0
        public ApplicationAdapterEndPoint StartApplication(string applicationName, string sessionId)
        {
            ApplicationAdapterEndPoint endPoint = null;

            try
            {
                if (string.IsNullOrEmpty(sessionId))
                {
                    throw new ArgumentNullException("sessionId");
                }

                ClientSession session = SessionManager.Instance[sessionId];

                if (session == null)
                {
                    throw new SessionNotFoundException(string.Format("Invalid session ID: \"{0}\"", sessionId));
                }

                var applicationElement = (from ApplicationElement e in _config.ApplicationCollection
                                          where e.Name == applicationName
                                          select e).FirstOrDefault();

                if (applicationElement == null)
                {
                    throw new ArgumentException("Invalid application name.", "applicationName");
                }

                endPoint = new ApplicationAdapterEndPoint(this, applicationName, sessionId);

                string arguments = applicationElement.Arguments;

                foreach (PropertyInfo propertyInfo in session.GetType().GetProperties())
                {
                    if (propertyInfo.PropertyType == typeof(string))
                    {
                        arguments = arguments.Replace(string.Format("@{0}", propertyInfo.Name), propertyInfo.GetValue(session, null) as string);
                    }
                }

                endPoint.UnhandledException += UnhandledExceptionEventHandler;
                endPoint.MessageReceived    += MessageReceivedEventHandler;
                OnEndPointCreated(endPoint);
                endPoint.StartApplication(applicationElement.ExecutablePath, arguments, _desktopManager.DesktopName);

                return(endPoint);
            }
            catch (Exception ex)
            {
                if (endPoint != null)
                {
                    CloseApplication(endPoint);
                }

                throw new AdapterException("Failed to start application.", ex);
            }
        }
示例#4
0
        /// <summary>
        /// Transmits a message over the adapter protocol.
        /// </summary>
        /// <param name="msg">The message to transmit.</param>
        public override void TransmitMessage(MultiPartMessage msg)
        {
            Uri sendUri = (Uri)msg.Metadata.Read("SendUri");

            ApplicationAdapterEndPoint endPoint
                = (ApplicationAdapterEndPoint)MessageEngine.Instance.AdapterProxy.ResolveUriToEndPoint(sendUri);

            if (endPoint == null)
            {
                throw new AdapterException("Failed to transmit message to Uri: \"" + sendUri + "\". The EndPoint does not exist.");
            }

            try
            {
                endPoint.TransmitMessage(msg);
            }
            catch (Exception ex)
            {
                throw new AdapterException("Failed to transmit message to EndPoint: \"" + ToString() + "\".", ex);
            }
        }