Ejemplo n.º 1
0
 public void Setup()
 {
     this.distributorServiceTestFacade = new DistributorServiceTestFacade();
     this.listener    = new MsmqListener(this.distributorServiceTestFacade, 1000);
     this.eventLogger = distributorServiceTestFacade.EventLogger;
     this.mockQ       = new MockMsmqLogDistributor(Context);
 }
Ejemplo n.º 2
0
 public MsmqListener(DistributorService distributorService, int timerInterval, string msmqPath)
 {
     this.distributorService = distributorService;
     this.QueueTimerInterval = timerInterval;
     this.eventLogger        = distributorService.EventLogger;
     this.logDistributor     = new MsmqLogDistributor(EnterpriseLibraryFactory.BuildUp <LogWriter>(), msmqPath, this.eventLogger);
 }
Ejemplo n.º 3
0
        public void EventSourceExistsWhenDistributedServicePaused()
        {
            DistributorEventLogger eventLogger = new DistributorEventLogger(EventSourceName);

            eventLogger.LogServicePaused();

            Assert.IsTrue(EventLog.SourceExists(eventLogger.EventSource));
        }
Ejemplo n.º 4
0
        public void EventSourceExistsWhenDistributedServiceFailure()
        {
            DistributorEventLogger eventLogger = new DistributorEventLogger(EventSourceName);

            eventLogger.LogServiceFailure("Failure", new Exception(), TraceEventType.Critical);

            Assert.IsTrue(EventLog.SourceExists(eventLogger.EventSource));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initialize a new instance of the <see cref="MsmqListener"/>.
        /// </summary>
        /// <param name="distributorService">Distributor service inheriting from <see cref="System.ServiceProcess.ServiceBase"/>.</param>
        /// <param name="timerInterval">Interval to check for new messages.</param>
        /// <param name="msmqPath">The name of the queue to get messages from.</param>
        public MsmqListener(DistributorService distributorService, int timerInterval, string msmqPath)
        {
            this.distributorService = distributorService;
            this.QueueTimerInterval = timerInterval;
            this.eventLogger        = distributorService.EventLogger;

            this.logDistributor = new MsmqLogDistributor(msmqPath, this.eventLogger);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initialize a new instance of the <see cref="MsmqListener"/>.
        /// </summary>
        /// <param name="distributorService">Distributor service inheriting from <see cref="System.ServiceProcess.ServiceBase"/>.</param>
        /// <param name="timerInterval">Interval to check for new messages.</param>
        /// <param name="msmqPath">The name of the queue to get messages from.</param>
        public MsmqListener(DistributorService distributorService, int timerInterval, string msmqPath)
        {
            this.distributorService = distributorService;
            this.QueueTimerInterval = timerInterval;
            this.eventLogger        = distributorService.EventLogger;

            this.logDistributor = new MsmqLogDistributor(EnterpriseLibraryContainer.Current.GetInstance <LogWriter>(), msmqPath, this.eventLogger);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initialize a new instance of the <see cref="MsmqListener"/>.
        /// </summary>
        /// <param name="distributorService">Distributor service inheriting from <see cref="System.ServiceProcess.ServiceBase"/>.</param>
        /// <param name="timerInterval">Interval to check for new messages.</param>
        public MsmqListener(DistributorService distributorService, int timerInterval)
        {
            this.distributorService = distributorService;
            this.QueueTimerInterval = timerInterval;
            this.eventLogger        = distributorService.EventLogger;

            this.logDistributor = new MsmqLogDistributor(ConfigurationManager.GetCurrentContext(), this.eventLogger);
        }
Ejemplo n.º 8
0
        public void Setup()
        {
            this.distributorServiceTestFacade = new DistributorServiceTestFacade();
            this.eventLogger  = distributorServiceTestFacade.EventLogger;
            this.mockListener = new MockMsmqListener(this.distributorServiceTestFacade, 1000);

            this.distributorServiceTestFacade.QueueListener = mockListener;

            CommonUtil.SetDistributionStrategy("Msmq");
        }
Ejemplo n.º 9
0
        public void ServiceResumedWritesToEventLog()
        {
            DistributorEventLogger logger = new DistributorEventLogger(TestEventSource);

            using (var eventLog = new EventLogTracker(GetEventLog()))
            {
                logger.LogServiceResumed();

                Assert.AreEqual(1, eventLog.NewEntries().Count(ev => EventIsFromLogger(ev, logger)));
            }
        }
        public void ServicePausedWritesToEventLog()
        {
            DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName);

            using (EventLog eventLog = GetEventLog())
            {
                int eventCount = eventLog.Entries.Count;
                logger.LogServicePaused();
                Assert.AreEqual(eventCount + 1, eventLog.Entries.Count);
            }
        }
        public void ServiceFailureWithExceptionWritesToEventLog()
        {
            DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName);

            using (EventLog eventLog = GetEventLog())
            {
                int eventCount = eventLog.Entries.Count;
                logger.LogServiceFailure(message, GetException(), TraceEventType.Error);
                Assert.AreEqual(eventCount + 1, eventLog.Entries.Count);
            }
        }
Ejemplo n.º 12
0
        public void ServiceFailureWithoutExceptionWritesToEventLog()
        {
            DistributorEventLogger logger = new DistributorEventLogger(TestEventSource);

            using (var eventLog = new EventLogTracker(GetEventLog()))
            {
                logger.LogServiceFailure(message, null, TraceEventType.Error);

                Assert.AreEqual(1,
                                eventLog.NewEntries().Count(ev => EventIsFromLogger(ev, logger)));
            }
        }
        public void ServiceFailureWithExceptionFiresWmiEvent()
        {
            DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName);

            using (WmiEventWatcher eventListener = new WmiEventWatcher(1))
            {
                logger.LogServiceFailure(message, GetException(), TraceEventType.Error);
                eventListener.WaitForEvents();
                Assert.AreEqual(1, eventListener.EventsReceived.Count);
                Assert.AreEqual("DistributorServiceFailureEvent", eventListener.EventsReceived[0].ClassPath.ClassName);
                Assert.IsTrue(((string)eventListener.EventsReceived[0].GetPropertyValue("FailureMessage")).StartsWith(message));
            }
        }
        public void ServicePausedFiresWmiEvent()
        {
            DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName);

            using (WmiEventWatcher eventListener = new WmiEventWatcher(1))
            {
                logger.LogServicePaused();
                eventListener.WaitForEvents();
                Assert.AreEqual(1, eventListener.EventsReceived.Count);
                Assert.AreEqual("DistributorServiceLifecycleEvent", eventListener.EventsReceived[0].ClassPath.ClassName);
                Assert.AreEqual(false, eventListener.EventsReceived[0].GetPropertyValue("Started"));
            }
        }
Ejemplo n.º 15
0
        /// <summary/>
        /// <exclude/>
        /// <devdoc>
        /// Initialization of the service.  Start the queue listener and write status to event log.
        /// </devdoc>
        public void InitializeComponent()
        {
            try
            {
                // Use the default settings for log name and application name.
                // This is done to ensure the Windows service starts correctly.
                this.ApplicationName = DefaultApplicationName;

                this.eventLogger = new DistributorEventLogger();
                this.eventLogger.AddMessage(Resources.InitializeComponentStartedMessage, Resources.InitializeComponentStarted);
                this.status = ServiceStatus.OK;

                IConfigurationSource configurationSource = GetConfigurationSource();

                MsmqDistributorSettings distributorSettings = MsmqDistributorSettings.GetSettings(configurationSource);
                if (distributorSettings == null)
                {
                    throw new ConfigurationErrorsException(string.Format(
                                                               CultureInfo.CurrentCulture,
                                                               Resources.ExceptionCouldNotFindConfigurationSection,
                                                               MsmqDistributorSettings.SectionName));
                }

                this.queueListener = CreateListener(this, distributorSettings.QueueTimerInterval, distributorSettings.MsmqPath);

                this.ApplicationName = this.ServiceName;
                this.ApplicationName = distributorSettings.ServiceName;
                this.eventLogger.AddMessage(NameTag, this.ApplicationName);

                this.eventLogger.EventSource = this.ApplicationName;
                this.eventLogger.AddMessage(Resources.InitializeComponentCompletedMessage, Resources.InitializeComponentCompleted);
            }
            catch (LoggingException loggingException)
            {
                this.eventLogger.LogServiceFailure(
                    string.Format(CultureInfo.CurrentCulture, Resources.ServiceStartError, this.ApplicationName),
                    loggingException,
                    TraceEventType.Error);

                throw;
            }
            catch (Exception ex)
            {
                this.eventLogger.LogServiceFailure(
                    string.Format(CultureInfo.CurrentCulture, Resources.ServiceStartError, this.ApplicationName),
                    ex,
                    TraceEventType.Error);

                throw new LoggingException(Resources.ErrorInitializingService, ex);
            }
        }
Ejemplo n.º 16
0
        public void SetUp()
        {
            CommonUtil.DeletePrivateTestQ();
            CreateQueueForTesting();
            clientSource = new LogSource("unnamed", SourceLevels.All);
            clientSource.Listeners.Add(
                new MsmqTraceListener("unnamed", CommonUtil.MessageQueuePath, new BinaryLogFormatter(),
                                      MessagePriority.Normal, false, new TimeSpan(0, 1, 0), new TimeSpan(0, 1, 0),
                                      false, true, false, MessageQueueTransactionType.Single));
            LogSource distributorSource = new LogSource("unnamed", SourceLevels.All);

            distributorSource.Listeners.Add(new MockTraceListener());
            Dictionary <string, LogSource> traceSources = new Dictionary <string, LogSource>();

            logWriter       = new LogWriter(new List <ILogFilter>(), traceSources, distributorSource, null, new LogSource("errors"), "default", false, false);
            eventLogger     = new DistributorEventLogger();
            msmqDistributor = new MsmqLogDistributor(logWriter, CommonUtil.MessageQueuePath, eventLogger);
            msmqDistributor.StopReceiving = false;
        }
Ejemplo n.º 17
0
        /// <summary/>
        /// <exclude/>
        /// <devdoc>
        /// Initialization of the service.  Start the queue listener and write status to event log.
        /// </devdoc>
        public void InitializeComponent()
        {
            try
            {
                // Use the default settings for log name and application name.
                // This is done to ensure the windows service starts correctly.
                this.ApplicationName = DefaultApplicationName;

                this.eventLogger = new DistributorEventLogger();
                this.eventLogger.AddMessage(SR.InitializeComponentStartedMessage, SR.InitializeComponentStarted);
                this.status = ServiceStatus.OK;

                DistributorSettings distributorSettings = (DistributorSettings)ConfigurationManager.GetConfiguration(DistributorSettings.SectionName);

                this.queueListener = new MsmqListener(this, distributorSettings.DistributorService.QueueTimerInterval);

                //this.ApplicationName = this.ServiceName;
                this.ApplicationName = distributorSettings.DistributorService.ServiceName;
                this.eventLogger.AddMessage("name", this.ApplicationName);

                this.eventLogger.ApplicationName = this.ApplicationName;
                this.eventLogger.AddMessage(SR.InitializeComponentCompletedMessage, SR.InitializeComponentCompleted);
            }
            catch (LoggingException loggingException)
            {
                this.eventLogger.AddMessage(Header, SR.ServiceStartError(this.ApplicationName));

                this.eventLogger.WriteToLog(loggingException, Severity.Error);
                throw;
            }
            catch (Exception ex)
            {
                this.eventLogger.AddMessage(Header, SR.ServiceStartError(this.ApplicationName));

                this.eventLogger.WriteToLog(ex, Severity.Error);
                throw new LoggingException(SR.ErrorInitializingService, ex);
            }
            catch
            {
                throw new LoggingException(SR.ErrorInitializingService);
            }
        }
Ejemplo n.º 18
0
        public void EntryIsWrittenWhenMSMQGeneralCategory()
        {
            LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace();
            var msmqListener = new MsmqTraceListener("TestMSMQProg", MsmqUtil.MessageQueuePath, new BinaryLogFormatter(),
                                                     MessagePriority.Normal, false, new TimeSpan(0, 1, 0), new TimeSpan(0, 1, 0),
                                                     false, true, false, MessageQueueTransactionType.None);

            msmqListener.Filter = new EventTypeFilter(SourceLevels.All);

            MsmqUtil.ValidateMsmqIsRunning();
            MsmqUtil.DeletePrivateTestQ();
            MsmqUtil.CreatePrivateTestQ();

            LogSource clientSource      = new LogSource("TestMSMQProg", new[] { msmqListener }, SourceLevels.All);
            LogSource distributorSource = new LogSource("TestMSMQProg", new[] { new MockTraceListener() }, SourceLevels.All);

            Dictionary <string, LogSource> traceSources = new Dictionary <string, LogSource>();

            this.writer = new LogWriter(new List <ILogFilter>(), traceSources, distributorSource, null, new LogSource("errors"), "General", false, false);
            Logger.SetLogWriter(this.writer);

            DistributorEventLogger eventLogger     = new DistributorEventLogger();
            MsmqLogDistributor     msmqDistributor = new MsmqLogDistributor(MsmqUtil.MessageQueuePath, eventLogger);

            msmqDistributor.StopReceiving = false;

            LogEntry logEntry = MsmqUtil.GetDefaultLogEntry();

            logEntry.Categories = new string[] { "MockCategoryOne" };
            logEntry.Message    = MsmqUtil.MsgBody;
            logEntry.Severity   = TraceEventType.Information;

            clientSource.TraceData(logEntry.Severity, 1, logEntry);

            msmqDistributor.CheckForMessages();

            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            Assert.AreEqual(MsmqUtil.MsgBody, MockTraceListener.LastEntry.Message, "Body");
        }
Ejemplo n.º 19
0
 public void ExceptionIsThrownWhenCreatingAnEmptyDistributorEventLogger()
 {
     DistributorEventLogger eventLogger = new DistributorEventLogger(string.Empty);
 }
 /// <summary>
 /// Setup the queue and the formatter of the messages.
 /// </summary>
 public MsmqLogDistributor(string msmqPath, DistributorEventLogger eventLogger)
 {
     this.msmqPath    = msmqPath;
     this.eventLogger = eventLogger;
 }
 public MsmqReceiverTestWrapper(string msmqPath, DistributorEventLogger eventLogger)
     : base(msmqPath, eventLogger)
 {
 }
 public void Constructor()
 {
     logger = new DistributorEventLogger();
     Assert.IsNotNull(logger);
 }
Ejemplo n.º 23
0
 public void CanCreateDistributorEventLogger()
 {
     DistributorEventLogger logger = new DistributorEventLogger();
 }
 public void ConstructorWithParams()
 {
     logger = new DistributorEventLogger("myLog");
     Assert.IsNotNull(logger);
     Assert.AreEqual("myLog", logger.EventLogName);
 }
Ejemplo n.º 25
0
 public void CanCreateDistributorEventLogger()
 {
     DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName);
 }
 public void Constructor()
 {
     logger = new DistributorEventLogger();
     Assert.IsNotNull(logger);
 }
Ejemplo n.º 27
0
 public MsmqReceiverTestWrapper(LogWriter logWriter,
                                string msmqPath,
                                DistributorEventLogger eventLogger)
     : base(logWriter, msmqPath, eventLogger)
 {
 }
 public void SetUp()
 {
     logger = new DistributorEventLogger("Application");
 }
Ejemplo n.º 29
0
 public MsmqLogDistributor(LogWriter logWriter, string msmqPath, DistributorEventLogger eventLogger)
 {
     this.logWriter   = logWriter;
     this.msmqPath    = msmqPath;
     this.eventLogger = eventLogger;
 }
 public void ConstructorWithParams()
 {
     logger = new DistributorEventLogger("myLog");
     Assert.IsNotNull(logger);
     Assert.AreEqual("myLog", logger.EventLogName);
 }
 private static bool EventIsFromLogger(EventLogEntry entry, DistributorEventLogger logger)
 {
     return(entry.Source == logger.EventSource);
 }
Ejemplo n.º 32
0
 public SanityCheck(DistributorService distributorService)
 {
     this.eventLogger        = distributorService.EventLogger;
     this.distributorService = distributorService;
 }
 public void SetUp()
 {
     logger = new DistributorEventLogger("Application");
 }