Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
        private static ExceptionPolicyImpl GetExceptionPolicy(Exception exception, string policyName, ExceptionPolicyFactory factory)
        {
            try
            {
                return(factory.Create(policyName));
            }
            catch (ConfigurationErrorsException configurationException)
            {
                try
                {
                    DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultExceptionHandlingEventLogger>();
                    logger.LogConfigurationError(configurationException, policyName);
                }
                catch { }

                throw;
            }
            catch (Exception ex)
            {
                try
                {
                    string exceptionMessage = ExceptionUtility.FormatExceptionHandlingExceptionMessage(policyName, ex, null, exception);

                    DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultExceptionHandlingEventLogger>();
                    logger.LogInternalError(policyName, exceptionMessage);
                }
                catch { }

                throw new ExceptionHandlingException(ex.Message, ex);
            }
        }
        public void CanBuildLogWriterStructureHolder()
        {
            LogWriterStructureHolder setup
                = EnterpriseLibraryFactory.BuildUp <LogWriterStructureHolder>(configurationSource);

            Assert.IsNotNull(setup);
            Assert.AreEqual(2, setup.TraceSources.Count);
        }
Exemplo n.º 4
0
        public void CanStillCreateLoggerWithoutConfigurationSectionPresent()
        {
            DictionaryConfigurationSource configSource = new DictionaryConfigurationSource();

            DefaultEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultEventLogger>(configSource);

            Assert.IsFalse(logger.EventLoggingEnabled);
        }
Exemplo n.º 5
0
 internal static void TryLogConfigurationFailure(ConfigurationErrorsException configurationException)
 {
     try
     {
         DefaultLoggingEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultLoggingEventLogger>();
         logger.LogConfigurationError(configurationException);
     }
     catch
     { }
 }
Exemplo n.º 6
0
        public void CanCreateGenericDatabase()
        {
            Database database = EnterpriseLibraryFactory.BuildUp <Database>("OdbcDatabase");

            Assert.IsNotNull(database);
            Assert.AreSame(typeof(GenericDatabase), database.GetType());
            DbCommand command = database.GetStoredProcCommand("ignore");

            Assert.AreSame(typeof(OdbcCommand), command.GetType());
        }
        public void InstrumentationNotWiredWhenConfigurationValuesAllFalse()
        {
            DictionaryConfigurationSource section = new DictionaryConfigurationSource();

            section.Add(InstrumentationConfigurationSection.SectionName,
                        new InstrumentationConfigurationSection(false, false, false, "fooApplicationInstanceName"));
            EventSource source
                = EnterpriseLibraryFactory.BuildUp <EventSource>("ignore", new DictionaryConfigurationSource());

            Assert.IsFalse(source.IsWired);
        }
Exemplo n.º 8
0
        public void CanCreateThroughObjectBuilder()
        {
            DictionaryConfigurationSource       configSource  = new DictionaryConfigurationSource();
            InstrumentationConfigurationSection configSection = new InstrumentationConfigurationSection();

            configSection.EventLoggingEnabled = true;
            configSource.Add(InstrumentationConfigurationSection.SectionName, configSection);
            DefaultEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultEventLogger>(configSource);

            Assert.IsTrue(logger.EventLoggingEnabled);
        }
Exemplo n.º 9
0
        public void AttemptingToReadEncryptedDataWithoutDecryptingThrowsException()
        {
            IStorageEncryptionProvider encryptionProvider = null;

            encryptionProvider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>("Fred");

            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = unencryptedBackingStore.Load();
        }
Exemplo n.º 10
0
        public void CanBuildDefaultLogger()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(InstrumentationConfigurationSection.SectionName, new InstrumentationConfigurationSection(true, true, true));

            DefaultCachingEventLogger logger
                = EnterpriseLibraryFactory.BuildUp <DefaultCachingEventLogger>(configurationSource);

            Assert.IsNotNull(logger);
        }
Exemplo n.º 11
0
 private static void TryLogConfigurationError(ConfigurationErrorsException configurationException, string instanceName)
 {
     try
     {
         DefaultSecurityEventLogger eventLogger = EnterpriseLibraryFactory.BuildUp <DefaultSecurityEventLogger>();
         if (eventLogger != null)
         {
             eventLogger.LogConfigurationError(instanceName, Resources.ErrorAuthorizationConfigurationFailedMessage, configurationException);
         }
     }
     catch { }
 }
        public void SetUp()
        {
            logWriter = EnterpriseLibraryFactory.BuildUp <LogWriter>();
            MockTraceListener.Reset();
            ErrorsMockTraceListener.Reset();

            emptyTraceSource = new LogSource("none");
            if (emptyTraceSource.Listeners.Count == 1)
            {
                emptyTraceSource.Listeners.RemoveAt(0);
            }
        }
Exemplo n.º 13
0
 private static void TryLogConfigurationError(ConfigurationErrorsException configurationException, string instanceName)
 {
     try
     {
         DefaultDataEventLogger eventLogger = EnterpriseLibraryFactory.BuildUp <DefaultDataEventLogger>();
         if (eventLogger != null)
         {
             eventLogger.LogConfigurationError(configurationException, instanceName);
         }
     }
     catch { }
 }
Exemplo n.º 14
0
        public void CanBuildCustomAuthorizationProviderFromSystemConfiguration()
        {
            IConfigurationSource configurationSource
                = new SystemConfigurationSource();

            IAuthorizationProvider custom
                = EnterpriseLibraryFactory.BuildUp <IAuthorizationProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomAuthorizationProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomAuthorizationProvider)custom).customValue);
        }
Exemplo n.º 15
0
 private static void TryLogConfigurationError(ConfigurationErrorsException configurationException, string hashInstance, string template)
 {
     try
     {
         DefaultCryptographyEventLogger eventLogger = EnterpriseLibraryFactory.BuildUp <DefaultCryptographyEventLogger>();
         if (eventLogger != null)
         {
             eventLogger.LogConfigurationError(hashInstance, template, configurationException);
         }
     }
     catch { }
 }
Exemplo n.º 16
0
        public void CanCreateOracleDatabase()
        {
            Database database = EnterpriseLibraryFactory.BuildUp <Database>("OracleTest");

            Assert.IsNotNull(database);
            Assert.AreSame(typeof(OracleDatabase), database.GetType());
            DbCommand dbCommand1 = database.GetStoredProcCommand(OracleTestStoredProcedureInPackageWithTranslation);

            Assert.AreEqual((object)OracleTestTranslatedStoredProcedureInPackageWithTranslation, dbCommand1.CommandText);
            DbCommand dbCommand2 = database.GetStoredProcCommand(OracleTestStoredProcedureInPackageWithoutTranslation);

            Assert.AreEqual((object)OracleTestStoredProcedureInPackageWithoutTranslation, dbCommand2.CommandText);
        }
        public void SetUp()
        {
            AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);

            logWriter = EnterpriseLibraryFactory.BuildUp <LogWriter>();
            MockTraceListener.Reset();
            ErrorsMockTraceListener.Reset();

            emptyTraceSource = new LogSource("none");
            if (emptyTraceSource.Listeners.Count == 1)
            {
                emptyTraceSource.Listeners.RemoveAt(0);
            }
        }
Exemplo n.º 18
0
        public void InstrumentationIsTurnedOffWhenPassingNoConfigurationSource()
        {
            int initialValue = GetCounterValue(performanceCounterTracesPerSecondName, operation);

            LogWriter logWriter = EnterpriseLibraryFactory.BuildUp <LogWriter>();

            using (Tracer tracer = new Tracer(operation, logWriter, null))
            {
                int i = new Random().Next();
            }
            int valueAfterTracing = GetCounterValue(performanceCounterTracesPerSecondName, operation);

            Assert.IsTrue(valueAfterTracing == initialValue);
        }
Exemplo n.º 19
0
        private static TracerInstrumentationListener GetInstrumentationListener(IConfigurationSource configurationSource)
        {
            TracerInstrumentationListener instrumentationListener;

            if (configurationSource != null)
            {
                instrumentationListener = EnterpriseLibraryFactory.BuildUp <TracerInstrumentationListener>(configurationSource);
            }
            else
            {
                instrumentationListener = new TracerInstrumentationListener(false);
            }

            return(instrumentationListener);
        }
Exemplo n.º 20
0
 public void UpdateLogWriter(object sender, ConfigurationChangedEventArgs args)
 {
     if (logWriter != null)
     {
         try
         {
             LogWriterStructureHolder newStructureHolder
                 = EnterpriseLibraryFactory.BuildUp <LogWriterStructureHolder>(configurationSource);
             logWriter.ReplaceStructureHolder(newStructureHolder);
         }
         catch (ConfigurationErrorsException configurationException)
         {
             logWriter.ReportConfigurationFailure(configurationException);
         }
     }
 }
            public static CacheManager Create(string name, IConfigurationSource configurationSource)
            {
                CachingConfigurationView configurationView   = new CachingConfigurationView(configurationSource);
                CacheManagerData         objectConfiguration = configurationView.GetCacheManagerData(name);

                IBackingStore backingStore =
                    EnterpriseLibraryFactory.BuildUp <IBackingStore>(objectConfiguration.CacheStorage, configurationSource);

                return(new MockCacheManagerFactoryHelper().BuildCacheManager(
                           name,
                           backingStore,
                           objectConfiguration.MaximumElementsInCacheBeforeScavenging,
                           objectConfiguration.NumberToRemoveWhenScavenging,
                           objectConfiguration.ExpirationPollFrequencyInSeconds,
                           new CachingInstrumentationProvider()));
            }
        public void LogWriterCanGetConfiguredCategories()
        {
            LogWriter logWriter = EnterpriseLibraryFactory.BuildUp <LogWriter>();

            LogSource source = null;

            foreach (string key in logWriter.TraceSources.Keys)
            {
                logWriter.TraceSources.TryGetValue(key, out source);
                Assert.IsNotNull(source, key);
                Assert.AreEqual(key, source.Name);
            }

            source = null;
            logWriter.TraceSources.TryGetValue("AppTest", out source);
            logWriter.Dispose();

            Assert.IsNotNull(source);
        }
Exemplo n.º 23
0
        public void DecryptedDataCanBeReadBackFromDatabase()
        {
            IStorageEncryptionProvider encryptionProvider = null;

            encryptionProvider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>("Fred");

            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = encryptingBackingStore.Load();

            CacheItem retrievedItem = (CacheItem)dataInCache["key"];

            Assert.AreEqual("key", retrievedItem.Key);
            Assert.AreEqual("value", retrievedItem.Value);
            Assert.AreEqual(CacheItemPriority.Normal, retrievedItem.ScavengingPriority);
            Assert.AreEqual(typeof(MockRefreshAction), retrievedItem.RefreshAction.GetType());
            Assert.AreEqual(typeof(AlwaysExpired), retrievedItem.GetExpirations()[0].GetType());
        }
        public void CanBuildCustomHashProviderFromGivenConfiguration()
        {
            CustomHashProviderData customData
                = new CustomHashProviderData("custom", typeof(MockCustomHashProvider));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CryptographySettings settings = new CryptographySettings();

            settings.HashProviders.Add(customData);
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(CryptographyConfigurationView.SectionName, settings);

            IHashProvider custom
                = EnterpriseLibraryFactory.BuildUp <IHashProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomHashProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomHashProvider)custom).customValue);
        }
        public void CanBuildCustomBackingStoreFromGivenConfiguration()
        {
            CustomCacheStorageData customData
                = new CustomCacheStorageData("custom", typeof(MockCustomStorageBackingStore));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CacheManagerSettings settings = new CacheManagerSettings();

            settings.BackingStores.Add(customData);
            settings.CacheManagers.Add(new CacheManagerData("ignore", 0, 0, 0, "custom"));
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(CacheManagerSettings.SectionName, settings);

            IBackingStore custom
                = EnterpriseLibraryFactory.BuildUp <IBackingStore>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomStorageBackingStore), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomStorageBackingStore)custom).customValue);
        }
Exemplo n.º 26
0
        private void Initialize(string operation, IConfigurationSource configurationSource)
        {
            if (configurationSource != null)
            {
                instrumentationListener = EnterpriseLibraryFactory.BuildUp <TracerInstrumentationListener>(configurationSource);
            }
            else
            {
                instrumentationListener = new TracerInstrumentationListener(false);
            }

            StartLogicalOperation(operation);
            if (IsTracingEnabled())
            {
                instrumentationListener.TracerOperationStarted(PeekLogicalOperationStack() as string);

                stopwatch         = Stopwatch.StartNew();
                tracingStartTicks = Stopwatch.GetTimestamp();

                WriteTraceStartMessage(startTitle);
            }
        }
        public void CanBuildCustomHashProviderFromSavedConfiguration()
        {
            CustomHashProviderData customData
                = new CustomHashProviderData("custom", typeof(MockCustomHashProvider));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CryptographySettings settings = new CryptographySettings();

            settings.HashProviders.Add(customData);

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(1);

            sections[CryptographyConfigurationView.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            IHashProvider custom
                = EnterpriseLibraryFactory.BuildUp <IHashProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomHashProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomHashProvider)custom).customValue);
        }
        public void CanBuildCustomBackingStoreFromSavedConfiguration()
        {
            CustomCacheStorageData customData
                = new CustomCacheStorageData("custom", typeof(MockCustomStorageBackingStore));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CacheManagerSettings settings = new CacheManagerSettings();

            settings.BackingStores.Add(customData);
            settings.CacheManagers.Add(new CacheManagerData("ignore", 0, 0, 0, "custom"));

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(1);

            sections[CacheManagerSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            IBackingStore custom
                = EnterpriseLibraryFactory.BuildUp <IBackingStore>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomStorageBackingStore), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomStorageBackingStore)custom).customValue);
        }
Exemplo n.º 29
0
 public void CreatedDatabaseIsInstrumented()
 {
     Database database = EnterpriseLibraryFactory.BuildUp <Database>("Service_Dflt");
 }
 /// <summary>
 /// Creates a new instance of <see cref="LogWriter"/> based on the configuration in the <see cref="IConfigurationSource"/>
 /// instance of the factory.
 /// </summary>
 /// <returns></returns>
 public LogWriter Create()
 {
     return(EnterpriseLibraryFactory.BuildUp <LogWriter>(configurationSource));
 }