示例#1
0
        /// <summary>
        /// Gets the default <see cref="FormatterData"></see>
        /// </summary>
        /// <returns><see cref="FormatterData"></see> defined for default logging formatter</returns>
        public FormatterData GetDefaultFormatterData()
        {
            DistributorSettings settings = GetDistributorSettings();

            // it is ok if this is null
            return(settings.Formatters[settings.DefaultFormatter]);
        }
示例#2
0
        /// <summary>
        /// <para>Saves the configuration settings created for the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public override void Save(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);

            if (configurationContext.IsValidSection(DistributorSettings.SectionName))
            {
                DistributorSettingsNode distributorSettingsNode = null;
                try
                {
                    IUIHierarchy hierarchy = ServiceHelper.GetCurrentHierarchy(serviceProvider);
                    distributorSettingsNode = hierarchy.FindNodeByType(typeof(DistributorSettingsNode)) as DistributorSettingsNode;
                    if (distributorSettingsNode == null)
                    {
                        return;
                    }
                    DistributorSettings distributorSettings = distributorSettingsNode.DistributorSettings;
                    configurationContext.WriteConfiguration(DistributorSettings.SectionName, distributorSettings);
                }
                catch (ConfigurationException e)
                {
                    ServiceHelper.LogError(serviceProvider, distributorSettingsNode, e);
                }
                catch (InvalidOperationException e)
                {
                    ServiceHelper.LogError(serviceProvider, distributorSettingsNode, e);
                }
            }
        }
示例#3
0
 /// <summary>
 /// Creates node with specified configuration data.
 /// </summary>
 /// <param name="distributorSettings">The specified configuration data.</param>
 public DistributorSettingsNode(DistributorSettings distributorSettings) : base()
 {
     this.onDefaultCategoryNodeRemoved  = new ConfigurationNodeChangedEventHandler(OnDefaultCategoryNodeRemoved);
     this.onDefaultCategoryNodeRenamed  = new ConfigurationNodeChangedEventHandler(OnDefaultCategoryNodeRenamed);
     this.onDefaultFormatterNodeRemoved = new ConfigurationNodeChangedEventHandler(OnDefaultFormatterNodeRemoved);
     this.onDefaultFormatterNodeRenamed = new ConfigurationNodeChangedEventHandler(OnDefaultFormatterNodeRenamed);
     this.distributorSettings           = distributorSettings;
 }
示例#4
0
        public void GetDatabaseSinkFromConfigFile()
        {
            DistributorSettings settings = (DistributorSettings)ConfigurationManager.GetConfiguration(DistributorSettings.SectionName);
            DatabaseSinkData    dbData   = settings.SinkDataCollection["DatabaseSink2"] as DatabaseSinkData;

            Assert.AreEqual("LoggingDb", dbData.DatabaseInstanceName);
            Assert.AreEqual("WriteLog", dbData.StoredProcName);
        }
示例#5
0
        public AdminConfigurationModel GetHotelAdminConfigurationDetail(int distributorID, int settingID)
        {
            DistributorSettings     result = entity.DistributorSettings.Where(x => x.SettingId == settingID && x.DistributorID == distributorID).FirstOrDefault();
            AdminConfigurationModel model  = new AdminConfigurationModel();

            model.HotelSettingID = (int)result.SettingId;
            model.HotelByPass    = result != null ? ByPass.HotelAllow : ByPass.HotelDisallow;
            return(model);
        }
示例#6
0
        public void AdminConfigurationEdit(AdminConfigurationModel model)
        {
            DistributorSettings result = entity.DistributorSettings.Where(x => x.SettingId == model.SettingID && x.DistributorID == model.DistributorID).FirstOrDefault();

            if (model.ByPass == ByPass.Disallow)
            {
                entity.DeleteObject(result);
                entity.SaveChanges();
            }
        }
示例#7
0
        /// <summary>
        /// <para>Adds to the dictionary configuration data for
        /// the enterpriselibrary.configurationSettings configuration section.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        /// <param name="configurationDictionary">
        /// <para>A <see cref="ConfigurationDictionary"/> to add
        /// configuration data to.</para></param>
        public override void BuildContext(IServiceProvider serviceProvider, ConfigurationDictionary configurationDictionary)
        {
            DistributorSettingsNode node = GetDistributorSettingsNode(serviceProvider);

            if (node != null)
            {
                DistributorSettings settings = node.DistributorSettings;
                configurationDictionary[DistributorSettings.SectionName] = settings;
            }
        }
示例#8
0
        /// <summary>
        /// Gets the <see cref="FormatterData"></see> defined for the named logging formatter
        /// </summary>
        /// <param name="formatterName">Name of the logging formatter to retrieve</param>
        /// <returns><see cref="FormatterData"></see> defined for named logging formatter</returns>
        public FormatterData GetFormatterData(string formatterName)
        {
            ArgumentValidation.CheckForNullReference(formatterName, "formatterName");
            ArgumentValidation.CheckForEmptyString(formatterName, "formatterName");

            DistributorSettings     settings = GetDistributorSettings();
            FormatterDataCollection formatterDataCollection = settings.Formatters;

            // it is ok for a formatter to be null
            return(formatterDataCollection[formatterName]);
        }
示例#9
0
        /// <summary>
        /// Gets the <see cref="CategoryData"></see> defined for the named logging category
        /// </summary>
        /// <param name="categoryName">Name of the logging category to retrieve</param>
        /// <returns><see cref="CategoryData"></see> defined for named logging category</returns>
        public CategoryData GetCategoryData(string categoryName)
        {
            ArgumentValidation.CheckForNullReference(categoryName, "categoryName");
            ArgumentValidation.CheckForEmptyString(categoryName, "categoryName");

            DistributorSettings    settings = GetDistributorSettings();
            CategoryDataCollection categoryDataCollection = settings.CategoryDataCollection;

            // ok for the category data to be null
            return(categoryDataCollection[categoryName]);
        }
示例#10
0
        /// <summary>
        /// Gets the default <see cref="CategoryData"></see> defined for the logging category
        /// </summary>
        /// <returns><see cref="CategoryData"></see> defined for the default logging category</returns>
        public CategoryData GetDefaultCategoryData()
        {
            DistributorSettings settings            = GetDistributorSettings();
            CategoryData        defaultCategoryData = settings.CategoryDataCollection[settings.DefaultCategory];

            if (defaultCategoryData == null)
            {
                throw new ConfigurationException(SR.ExceptionCannotLoadDefaultCategory(settings.DefaultCategory));
            }
            return(defaultCategoryData);
        }
示例#11
0
        public void DistributorSettingsPropertiesTest()
        {
            DistributorSettings settings = ConfigurationManager.GetConfiguration(DistributorSettings.SectionName) as DistributorSettings;

            DistributorSettingsNode settingsNode = new DistributorSettingsNode(settings);

            GeneratedApplicationNode.Nodes.Add(settingsNode);
            settingsNode.ResolveNodeReferences();
            Assert.AreEqual(settings.DefaultCategory, settingsNode.DefaultCategory.Name);
            Assert.AreEqual(settings.DefaultFormatter, settingsNode.DefaultFormatter.Name);
        }
示例#12
0
 public void AdminBusConfigurationAdd(AdminConfigurationModel model)
 {
     if (model.BusByPass == ByPass.BusAllow)
     {
         DistributorSettings datamodel = new DistributorSettings
         {
             DistributorID = model.DistributorID,
             SettingId     = model.BusSettingID
         };
         entity.AddToDistributorSettings(datamodel);
         entity.SaveChanges();
     }
 }
示例#13
0
        /// <summary>
        /// Gets the <see cref="SinkData"></see> associated with the named logging sink
        /// </summary>
        /// <param name="sinkName">Name of the sink as defined in configuration</param>
        /// <returns><see cref="SinkData"></see> defined for named logging sink</returns>
        public virtual SinkData GetSinkData(string sinkName)
        {
            ArgumentValidation.CheckForNullReference(sinkName, "sinkName");
            ArgumentValidation.CheckForEmptyString(sinkName, "sinkName");

            DistributorSettings settings = GetDistributorSettings();

            SinkData sinkData = settings.SinkDataCollection[sinkName];

            if (null == sinkData)
            {
                throw new ConfigurationException(SR.ExceptionNoSinkDefined(sinkName));
            }
            return(sinkData);
        }
示例#14
0
        public void RuntimeTest()
        {
            GeneratedHierarchy.Open();
            Assert.AreEqual(0, ConfigurationErrorsCount);

            ConfigurationContext builder = GeneratedHierarchy.ConfigurationContext;

            if (builder.IsValidSection(DistributorSettings.SectionName))
            {
                DistributorSettings distributorSettings = builder.GetConfiguration(DistributorSettings.SectionName) as DistributorSettings;
                if (distributorSettings != null)
                {
                    DistributorSettingsNode distributorSettingsNode = new DistributorSettingsNode(distributorSettings);
                    foreach (ConfigurationNode node in distributorSettingsNode.Nodes)
                    {
                        if (node is SinkCollectionNode)
                        {
                            SinkCollectionNode sinkCollectionNode = (SinkCollectionNode)node;
                            Assert.AreEqual(4, sinkCollectionNode.SinkDataCollection.Count);
                        }
                        else if (node is FormatterCollectionNode)
                        {
                            FormatterCollectionNode formatterCollectionNode = (FormatterCollectionNode)node;
                            Assert.AreEqual(4, formatterCollectionNode.FormatterDataCollection.Count);
                        }
                        else if (node is CategoryCollectionNode)
                        {
                            CategoryCollectionNode categoryCollectionNode = (CategoryCollectionNode)node;
                            Assert.AreEqual(2, categoryCollectionNode.CategoryDataCollection.Count);
                        }
                    }

                    MsmqDistributorServiceNode msmqNode =
                        new MsmqDistributorServiceNode(distributorSettings.DistributorService);
                    Assert.IsNotNull(msmqNode.MsmqPath);
                }
                else
                {
                    Assert.Fail(String.Format("Can not load section: {0}", DistributorSettings.SectionName));
                }
            }
        }
示例#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(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);
            }
        }
示例#16
0
        public void WriteEntryWithMissingDefaultFormatter()
        {
            DistributorSettings settings = (DistributorSettings)ConfigurationManager.GetConfiguration(DistributorSettings.SectionName);

            string originalFormatter = settings.DefaultFormatter;

            settings.DefaultFormatter = null;
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            entry.Category = "AppTest";

            Logger.Write(entry);

            EventLog log    = new EventLog(CommonUtil.EventLogName);
            string   actual = log.Entries[log.Entries.Count - 2].Message;

            Assert.IsTrue(actual.IndexOf(SR.MissingDefaultFormatter) > -1, "formatter message");

            settings.DefaultFormatter = originalFormatter;
        }
示例#17
0
        public void MissingDefaultFormatter()
        {
            DistributorSettings settings = (DistributorSettings)Context.GetConfiguration(DistributorSettings.SectionName);

            string originalFormatter = settings.DefaultFormatter;

            settings.DefaultFormatter = null;
            LogEntry entry = CommonUtil.GetDefaultLogEntry();

            entry.Category = "AppError";
            logDistributor.ProcessLog(entry);

            string eventLogEntry = CommonUtil.GetLastEventLogEntry();

            Assert.IsTrue(eventLogEntry.IndexOf(SR.MissingDefaultFormatter) > -1, "formatter message");
            Assert.AreEqual(entry.Message, MockLogSink.GetLastEntry().Message, "message");
            Assert.AreEqual(entry.Category, MockLogSink.GetLastEntry().Category, "categry");

            settings.DefaultFormatter = originalFormatter;
        }
示例#18
0
        /// <summary>
        /// <para>Opens the configuration settings and registers them with the application.</para>
        /// </summary>
        /// <param name="serviceProvider">
        /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para>
        /// </param>
        public override void Open(IServiceProvider serviceProvider)
        {
            ConfigurationContext configurationContext = ServiceHelper.GetCurrentConfigurationContext(serviceProvider);

            if (configurationContext.IsValidSection(DistributorSettings.SectionName))
            {
                DistributorSettings     distributorSettings     = null;
                DistributorSettingsNode distributorSettingsNode = null;
                try
                {
                    distributorSettings     = (DistributorSettings)configurationContext.GetConfiguration(DistributorSettings.SectionName);
                    distributorSettingsNode = new DistributorSettingsNode(distributorSettings);
                    ConfigurationNode configurationNode = GetLoggingSettingsNode(serviceProvider);
                    configurationNode.Nodes.Add(distributorSettingsNode);
                }
                catch (ConfigurationException e)
                {
                    ServiceHelper.LogError(serviceProvider, distributorSettingsNode, e);
                }
            }
        }
示例#19
0
        private static DistributorSettings GenerateDistributorSettings()
        {
            DistributorSettings result = new DistributorSettings();

            result.DefaultCategory  = "AppError";
            result.DefaultFormatter = "XmlFormat";

            result.DistributorService = new MsmqDistributorServiceData("Enterprise Library Logging Distributor Service", @".\Private$\entlib", 1000);

            result.SinkDataCollection.Add(new CustomSinkData("MockSink", typeof(MockLogSink).AssemblyQualifiedName));

            result.Formatters.Add(new TextFormatterData("XmlFormat", "<![CDATA[<EntLibLog>{newline}{tab}<message>{message}</message>{newline}{tab}<timestamp>{timestamp}</timestamp>{newline}{tab}<title>{title}</title>{newline}</EntLibLog>]]>"));

            CategoryData data = new CategoryData();

            data.Name = "AppError";
            data.DestinationDataCollection.Add(new DestinationData("MockSink", "MockSink"));
            result.CategoryDataCollection.Add(data);

            return(result);
        }
示例#20
0
        private void SetName()
        {
            LoggingException ex = new LoggingException(SR.InstallerCannotReadServiceName);

            this.serviceName = DistributorService.DefaultApplicationName;

            string path = Directory.GetCurrentDirectory();

            using (ConfigurationContext context = ConfigurationManager.CreateContext(Path.Combine(path, ConfigurationFileName)))
            {
                LoggingConfigurationView view     = new LoggingConfigurationView(context);
                DistributorSettings      settings = view.GetDistributorSettings();

                if (settings.DistributorService == null)
                {
                    throw ex;
                }
                if (settings.DistributorService.ServiceName != null && settings.DistributorService.ServiceName.Length > 0)
                {
                    this.serviceName = settings.DistributorService.ServiceName;
                }
            }
        }
示例#21
0
 public void Init()
 {
     distributorSettings = DistributorSchemaBuilder.GetDistributorSettings();
 }
 public void Init()
 {
     distributorSettings = DistributorSchemaBuilder.GetDistributorSettings();
 }