Beispiel #1
0
        public Dynamic.Net.Base.INetSession CreateSession(Dynamic.Net.Base.INetApplication application, Dynamic.Net.Base.INetProtocol protocol, Dynamic.Net.Base.INetServer server, System.Net.Sockets.Socket client)
        {
            SocketSession      s      = new AsyncTcpSession(application, protocol, server, client);
            SocketServerConfig config = null;

            if (server is SocketServerBase)
            {
                config = (server as SocketServerBase).Config;
            }
            if (config != null)
            {
                s.Timeout     = TimeSpan.FromMinutes(config.SessionTimeout);
                s.TimeoutType = config.TimeoutType;
            }

            return(s);
        }
Beispiel #2
0
        private void LoadDefaultConfiguration()
        {
            // Identity

            EntityID    = Guid.NewGuid();
            Description = "HL7 Inbound Adapter";
            DeviceName  = HL7InboundDeviceName;
            Name        = Program.Context.AppName;

            // Default Transferring(routing) Contract

            Interaction = InteractionTypes.Publisher | InteractionTypes.Requester;
            Direction   = DirectionTypes.Inbound;
            //PublishConfig.Publication.MessageTypeList.Add(MessageRegistry.HL7V2_NotificationMessageType);
            //PublishConfig.Publication.MessageTypeList.Add(MessageRegistry.HL7V2XML_NotificationMessageType);
            PublishConfig.Publication.MessageTypeList.Add(MessageRegistry.GENERIC_NotificationMessageType);
            //PublishConfig.Publication.MessageTypeList.Add(MessageRegistry.DataTrackingLogMessageType);
            ResponseConfig  = null;
            SubscribeConfig = null;

            // Other Default Configuration

            SocketConfig = new SocketServerConfig();

            //EnableHL7XMLTransform = true;
            MessageProcessingType                   = MessageProcessType.HL7v2XML;
            HL7XMLTransformerType                   = NHL7ToolkitTransformer.DEVICE_NAME;
            InboundMessageDispatching.Model         = MessageDispatchModel.Custom;
            InboundMessageDispatching.CriteriaXPath = "/Message/Body/node()/MSH/FIELD.9/FIELD_ITEM/COMPONENT.2";
            InboundMessageDispatching.CriteriaPublishValueExpression = "A01|A04|A05|A08|A40|A31";
            InboundMessageDispatching.CriteriaRequestValueExpression = "Q23|Q22";
            InboundMessageDispatching.GenerateResponseXmlMLLPPayloadWithXSLTExtensions = true;

            // in order to support 0A as segment separator
            MessagePreprocessing.Enable = false;
            MessagePreprocessing.Replacements.Add(new ReplacementRule()
            {
                MatchExpression = "\n" /* 0A */, ReplaceExpression = "\r"                                                           /* 0D */
            });
            MessagePreprocessing.Replacements.Add(new ReplacementRule()
            {
                MatchExpression = "\r\r" /* 0D0D */, ReplaceExpression = "\r"                                                           /* 0D */
            });
        }
        /// <summary>
        /// 新建一个CommandServer
        /// </summary>
        /// <param name="ipAddress">监听的IP地址,如果传入空对应于IPAddress.Any</param>
        /// <param name="port">监听端口</param>
        /// <param name="appName">应用名称,表示此服务的名称,对功能无关紧要</param>
        /// <param name="serverName">服务名称,表示服务使用的内部TCP监听服务的名称,对功能无关紧要</param>
        /// <param name="useProtocol">所使用的协议</param>
        /// <param name="sessionFactory">创建内部Session的工厂, 注意:工厂所创建的Session必须是WebSocketSession的子类</param>
        public CommandServer(string ipAddress, int port, string appName, string serverName, string useProtocol, ISocketSessionFactory sessionFactory)
        {
            logger = LoggerManager.GetLogger("CommandServer." + (appName == "" ? "UnName" : appName));
            DefaultCommandParser = new WSBinaryCommandType();
            this.SessionFactory  = sessionFactory;

            IP             = ipAddress;
            Port           = port;
            RequestTimeout = TimeSpan.FromMinutes(2);
            SessionList    = new Dictionary <string, CommandSession>();
            Protocol       = useProtocol;
            IsAync         = true;
            CommandList    = new List <ICommand>();

            CommandList.Add(new SetCommandParserRequest());

            CommandParser = new List <ICommandParser>()
            {
                new WSCommandType(),
                new WSBinaryCommandType()
            };

            CommandAliveTime = TimeSpan.FromMinutes(2);

            IPAddress address = IPAddress.Any;

            if (!String.IsNullOrEmpty(ipAddress))
            {
                address = IPAddress.Parse(IP);
            }

            application = new WebSocketApplication();
            application.Setup(appName);
            AsyncTcpServer server = new AsyncTcpServer();

            ServerConfig = new SocketServerConfig()
            {
                Address             = address,
                AddressFamily       = System.Net.Sockets.AddressFamily.InterNetwork,
                MaxConnectionNumber = 1000,
                Name           = serverName,
                Port           = Port,
                SessionTimeout = (long)TimeSpan.FromMinutes(5).TotalMilliseconds,
                TimeoutType    = Dynamic.Net.Session.SessionTimeoutType.Unknown, //不过期
                ServerType     = NetServerType.ASyncTcp
            };
            server.Setup(ServerConfig, application, new WebSocketProtocol(), sessionFactory);


            application.AddServer(server);


            application.SwitchingProtocol += new EventHandler <SwitchingProtocolEventArgs>(SwitchingProtocol);

            application.SessionStarted += new EventHandler(SessionStarted);

            application.SessionClosed      += new EventHandler(SessionClosed);
            application.HandshakeCompleted += new EventHandler(HandshakeCompleted);

            application.MessageReceived += new EventHandler <MessageReceivedEventArgs>(MessageReceived);
        }