/// <summary> /// Called by the pipeline to invoke the component. /// </summary> /// <param name="msg">The message to process.</param> /// <returns>A collection of messages produced by this component.</returns> public override Collection <MultiPartMessage> Invoke(MultiPartMessage msg) { Collection <MultiPartMessage> resultCollection = new Collection <MultiPartMessage>(); resultCollection.Add(msg); if (MessageEngine.Instance.Tracing.Switch.Level != SourceLevels.Off) { ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]); if (contextListener != null) { string sessionId = msg.Properties.ReadAsString("SerialNumber"); if ((MessageEngine.Instance.Tracing.Switch.Level & SourceLevels.Verbose) == SourceLevels.Verbose) { MessageEngine.Instance.Tracing.TraceData(TraceEventType.Verbose, 0, string.Format("TraceContextComponent: Switching context to: \"{0}\"", sessionId)); } if (!contextListener.IsContextInitialized(sessionId)) { contextListener.InitializeContext(sessionId, new RollingFileTraceListener(Path.Combine(logPath, sessionId + ".log"), maxLogSize)); } contextListener.Context = sessionId; } } return(resultCollection); }
internal void InternalInit() { ContextTraceListener contextListener = ((ContextTraceListener)Trace.Listeners["ContextTraceListener"]); if (contextListener != null) { if (!contextListener.IsContextInitialized(this.name)) { try { contextListener.InitializeContext(this.name, new RollingFileTraceListener(logType.FileName, logType.MaxFileSize)); } catch (IOException ex) { contextListener.InitializeContext(this.name, new TextWriterTraceListener(Console.Out)); if (Tracing.TraceError) { Trace.WriteLine("Failed to initialize file logging, directing to console instead."); Trace.WriteLine(ex); } } } } Init(); }
/// <summary> /// Invokes the subscriber for processing of the message. /// </summary> /// <param name="msg">A reference to the subscribed message.</param> public override void Invoke(MultiPartMessage msg) { ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]); if (contextListener != null) { contextListener.ResetContext(); } }
private void MessageReceivedEventHandler(object sender, AdapterReceiveEventArgs e) { ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]); if (contextListener != null) { contextListener.ResetContext(); } }
internal void InternalStop() { try { Stop(); } finally { ContextTraceListener.Reset(); } }
/// <summary> /// Called by the pipeline to invoke the component. /// </summary> /// <param name="msg">The message to process.</param> /// <returns>A collection of messages produced by this component.</returns> public override Collection <MultiPartMessage> Invoke(MultiPartMessage msg) { Collection <MultiPartMessage> resultCollection = new Collection <MultiPartMessage>(); resultCollection.Add(msg); if (MessageEngine.Instance.Tracing.Switch.Level != SourceLevels.Off) { ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]); if (contextListener != null) { contextListener.Context = null; string sessionId = msg.Metadata.ReadAsString("SessionId"); ClientSession session = SessionManager.Instance[sessionId]; if (session != null) { string name = null; string ip = null; lock (session.SyncLock) { name = session.TerminalId; ip = session.ClientIP; } if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(ip)) { string context = string.Format("{0}_{1}", name, ip.Replace('.', '_')); if ((MessageEngine.Instance.Tracing.Switch.Level & SourceLevels.Verbose) == SourceLevels.Verbose) { MessageEngine.Instance.Tracing.TraceData(TraceEventType.Verbose, 0, string.Format("TraceContextComponent: Switching context to: \"{0}\"", context)); } if (!contextListener.IsContextInitialized(context)) { contextListener.InitializeContext(context, new RollingFileTraceListener(Path.Combine(logPath, context + ".log"), maxLogSize)); } contextListener.Context = context; } } } } return(resultCollection); }
protected void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e) { ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]); if (contextListener != null) { contextListener.ResetContext(); } if ((MessageEngine.Instance.Tracing.Switch.Level & SourceLevels.Critical) == SourceLevels.Critical) { MessageEngine.Instance.Tracing.TraceData(TraceEventType.Critical, 0, e.ExceptionObject); } }
/// <summary> /// Called by the pipeline to invoke the component. /// </summary> /// <param name="msg">The message to process.</param> /// <returns>A collection of messages produced by this component.</returns> public override Collection <MultiPartMessage> Invoke(MultiPartMessage msg) { string serialNumber = msg.Properties.ReadAsString("SerialNumber"); if (!CanProcess(msg)) { ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]); if (contextListener != null) { contextListener.ResetContext(); } return(null); } Collection <MultiPartMessage> resultCollection = new Collection <MultiPartMessage>(); resultCollection.Add(msg); return(resultCollection); }
/// <summary> /// Initializes the instance. Use this method to construct pipelines and subscribe to messages. /// </summary> public override void Initialize() { ServerSection config = ConfigurationManager.GetSection(ServerSection.SectionKey) as ServerSection; MessagingSection engineConfig = ConfigurationManager.GetSection(MessagingSection.SectionKey) as MessagingSection; ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]); if (contextListener == null) { contextListener = new ContextTraceListener(new RollingFileTraceListener(Path.Combine(config.LogPath, InstanceName + ".log"), config.MaxLogSize)); contextListener.TraceOutputOptions = TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.DateTime; contextListener.Name = "ContextTraceListener"; MessageEngine.Instance.Tracing.Listeners.Add(contextListener); } PropertyCollection tcpAdapterConfig = new PropertyCollection(); tcpAdapterConfig.Write("TcpAdapterPort", config.TcpAdapter.Port); tcpAdapterConfig.Write("TcpEndPointTimeout", config.TcpAdapter.SocketIdleTimeout * 1000); TcpAdapter tcpAdapter = new TcpAdapter(tcpAdapterConfig, "tcp"); tcpAdapter.MessageReceived += new EventHandler <AdapterReceiveEventArgs>(MessageReceivedEventHandler); ComponentPipeline tcpReceivePipeline = new ComponentPipeline(PipelineType.Receive); PropertyCollection receiveCfg = new PropertyCollection(); tcpReceivePipeline.AddComponent(typeof(StreamToMessageDisassembler), receiveCfg); PropertyCollection traceCfg = new PropertyCollection(); traceCfg.Write("MaxLogSize", config.MaxLogSize); traceCfg.Write("LogPath", config.LogPath); tcpReceivePipeline.AddComponent(typeof(TraceContextComponent), traceCfg); ComponentPipeline tcpSendPipeline = new ComponentPipeline(PipelineType.Send); PropertyCollection appAdapterConfig = new PropertyCollection(); appAdapterConfig.Write("ApplicationIdleTimeout", 999999999); ApplicationAdapter appAdapter = new ApplicationAdapter(appAdapterConfig, "app"); appAdapter.EndPointDestroyed += EndPointDestroyedEventHandler; ComponentPipeline appReceivePipeline = new ComponentPipeline(PipelineType.Receive); ComponentPipeline appSendPipeline = new ComponentPipeline(PipelineType.Send); //Bind adapters to pipelines MessageEngine.Instance.Bind(tcpAdapter, tcpReceivePipeline); MessageEngine.Instance.Bind(tcpAdapter, tcpSendPipeline); MessageEngine.Instance.Bind(appAdapter, appReceivePipeline); MessageEngine.Instance.Bind(appAdapter, appSendPipeline); MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/CreateSessionRequest", new CreateSessionSubscriber()); MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/StateRequest", new StateSubscriber()); MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/EventRequest", new EventSubscriber()); MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/Application", new ApplicationSubscriber()); MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/mobile/ConfigurationRequest", new ConfigurationSubscriber()); //Add subscriber to reset the trace context after threads have finished MessageEngine.Instance.SubscriptionManager.Subscribe(new TraceContextReset()); _remoteInterface = new RemoteInterfaceProxy(SessionManager.Instance); _remoteInterface.Initialize(config.ManagerPort, "IMIServer"); }
/// <summary> /// Initializes the instance. Use this method to construct pipelines and subscribe to messages. /// </summary> public override void Initialize() { VocollectSection config = ConfigurationManager.GetSection(VocollectSection.SectionKey) as VocollectSection; MessagingSection engineConfig = ConfigurationManager.GetSection(MessagingSection.SectionKey) as MessagingSection; ContextTraceListener contextListener = ((ContextTraceListener)MessageEngine.Instance.Tracing.Listeners["ContextTraceListener"]); if (contextListener == null) { contextListener = new ContextTraceListener(new RollingFileTraceListener(Path.Combine(config.LogPath, InstanceName + ".log"), config.MaxLogSize)); contextListener.TraceOutputOptions = TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.DateTime; contextListener.Name = "ContextTraceListener"; MessageEngine.Instance.Tracing.Listeners.Add(contextListener); } PropertyCollection tcpAdapterConfig = new PropertyCollection(); tcpAdapterConfig.Write("TcpAdapterPort", config.TcpAdapter.Port); tcpAdapterConfig.Write("TcpEndPointTimeout", engineConfig.PendingOperationsTimeout); TcpAdapter tcpAdapter = new TcpAdapter(tcpAdapterConfig, "tcp"); tcpAdapter.EndPointCreated += new EventHandler <AdapterEndPointEventArgs>(EndPointCreatedEventHandler); tcpAdapter.MessageReceived += new EventHandler <AdapterReceiveEventArgs>(MessageReceivedEventHandler); ComponentPipeline tcpReceivePipeline = new ComponentPipeline(PipelineType.Receive); PropertyCollection receiveCfg = new PropertyCollection(); receiveCfg.Write("CodePageName", config.CodePageName); tcpReceivePipeline.AddComponent(typeof(StreamToXmlDisassembler), receiveCfg); PropertyCollection traceCfg = new PropertyCollection(); traceCfg.Write("MaxLogSize", config.MaxLogSize); traceCfg.Write("LogPath", config.LogPath); tcpReceivePipeline.AddComponent(typeof(TraceContextComponent), traceCfg); /* * tcpReceivePipeline.AddComponent(typeof(MessageAcknowledgeComponent), ackCfg); */ PropertyCollection transmissionControlCfg = new PropertyCollection(); transmissionControlCfg.Write("PendingOperationsTimeout", engineConfig.PendingOperationsTimeout); tcpReceivePipeline.AddComponent(typeof(TransmissionControlComponent), transmissionControlCfg); PropertyCollection xsltCfg = new PropertyCollection(); xsltCfg.Write("XsltPath", config.XsltPath); tcpReceivePipeline.AddComponent(typeof(XslTransformComponent), xsltCfg); ComponentPipeline tcpSendPipeline = new ComponentPipeline(PipelineType.Send); PropertyCollection sendCfg = new PropertyCollection(); sendCfg.Write("CodePageName", config.CodePageName); tcpSendPipeline.AddComponent(typeof(MessageToStreamAssembler), sendCfg); PropertyCollection whAdapterConfig = new PropertyCollection(); //Read connection strings foreach (ConnectionStringSettings connection in ConfigurationManager.ConnectionStrings) { whAdapterConfig.Write(connection.Name, connection.ConnectionString); } WarehouseAdapter whAdapter = new WarehouseAdapter(whAdapterConfig, "warehouse"); ComponentPipeline whReceivePipeline = new ComponentPipeline(PipelineType.Receive); ComponentPipeline whSendPipeline = new ComponentPipeline(PipelineType.Send); //Bind adapters to pipelines MessageEngine.Instance.Bind(tcpAdapter, tcpReceivePipeline); MessageEngine.Instance.Bind(tcpAdapter, tcpSendPipeline); MessageEngine.Instance.Bind(whAdapter, whReceivePipeline); MessageEngine.Instance.Bind(whAdapter, whSendPipeline); //Add subscribers foreach (Type t in Assembly.GetExecutingAssembly().GetTypes()) { if (t.BaseType == typeof(VocollectSubscriber) && t.Namespace == "Imi.Wms.Voice.Vocollect.Subscribers") { MessageEngine.Instance.SubscriptionManager.Subscribe("http://www.im.se/wms/voice/vocollect/" + t.Name, (SubscriberBase)t.GetConstructor(new Type[] {}).Invoke(new object[] {})); } } //Add subscriber to reset the trace context after threads have finished MessageEngine.Instance.SubscriptionManager.Subscribe(new TraceContextReset()); }