public void Setup()
 {
     this.distributorServiceTestFacade = new DistributorServiceTestFacade();
     this.listener    = new MsmqListener(this.distributorServiceTestFacade, 1000);
     this.eventLogger = distributorServiceTestFacade.EventLogger;
     this.mockQ       = new MockMsmqLogDistributor(Context);
 }
Exemple #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);
 }
Exemple #3
0
        public void EventSourceExistsWhenDistributedServicePaused()
        {
            DistributorEventLogger eventLogger = new DistributorEventLogger(EventSourceName);

            eventLogger.LogServicePaused();

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

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

            Assert.IsTrue(EventLog.SourceExists(eventLogger.EventSource));
        }
        /// <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);
        }
Exemple #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);
        }
Exemple #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);
        }
        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");
        }
Exemple #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);
            }
        }
Exemple #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"));
            }
        }
Exemple #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);
            }
        }
Exemple #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;
        }
        /// <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);
            }
        }
Exemple #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");
        }
Exemple #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);
 }
Exemple #23
0
 public void CanCreateDistributorEventLogger()
 {
     DistributorEventLogger logger = new DistributorEventLogger();
 }
 public void ConstructorWithParams()
 {
     logger = new DistributorEventLogger("myLog");
     Assert.IsNotNull(logger);
     Assert.AreEqual("myLog", logger.EventLogName);
 }
Exemple #25
0
 public void CanCreateDistributorEventLogger()
 {
     DistributorEventLogger logger = new DistributorEventLogger(TestApplicationName);
 }
 public void Constructor()
 {
     logger = new DistributorEventLogger();
     Assert.IsNotNull(logger);
 }
 public MsmqReceiverTestWrapper(LogWriter logWriter,
                                string msmqPath,
                                DistributorEventLogger eventLogger)
     : base(logWriter, msmqPath, eventLogger)
 {
 }
 public void SetUp()
 {
     logger = new DistributorEventLogger("Application");
 }
 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);
 }
Exemple #32
0
 public SanityCheck(DistributorService distributorService)
 {
     this.eventLogger        = distributorService.EventLogger;
     this.distributorService = distributorService;
 }
 public void SetUp()
 {
     logger = new DistributorEventLogger("Application");
 }