Exemple #1
0
        /// <summary>
        /// Initializes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        public override void Initialize(CategoryPropertyItem item)
        {
            base.Initialize(item);

            this.FilterLogic = GroupFilterLoginEnum.And;
            mFilters.Clear();
            if (item.PropertyItems != null)
            {
                GroupFilterLoginEnum logic = GroupFilterLoginEnum.And;
                if (ConfigurationAccessHelper.ParseEnumValue <GroupFilterLoginEnum>(item.PropertyItems, CONFIG_FILTER_LOGIC, ref logic))
                {
                    this.FilterLogic = logic;
                }

                CategoryPropertyItem filterItems = ConfigurationAccessHelper.GetCategoryPropertyByPath(item.PropertyItems, CONFIG_FILTERS);
                if (filterItems != null && filterItems.PropertyItems != null)
                {
                    foreach (CategoryPropertyItem filterItem in filterItems.PropertyItems)
                    {
                        try
                        {
                            Type filterType           = TypeHelper.GetTypeFromString(filterItem.EntryValue, TypeLookupModeEnum.AllowAll, true, true, true);
                            IErrorReportFilter filter = (IErrorReportFilter)filterType.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
                            filter.Initialize(filterItem);
                            mFilters.Add(filter);
                        }
                        catch (Exception ex)
                        {
                            if (LOGGER.IsErrorEnabled)
                            {
                                LOGGER.Error(string.Format("GROUP_FILTER, failed to create error report filter. Type: '{0}'", filterItem.EntryValue), ex);
                            }
                        }
                    }
                }
            }
            this.IsInitialized = true;
        }
        private void SectionHandler_OnConfigurationChanged(object sender, EventArgs e)
        {
            List <IErrorReportPackageSink> sinks    = new List <IErrorReportPackageSink>();
            CategoryPropertyItem           rootItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(ErrorReportConfiguration.Settings.CategoryPropertyItems, CONFIG_SINKS);

            if (rootItem != null)
            {
                if (rootItem.PropertyItems != null)
                {
                    foreach (CategoryPropertyItem sinkItem in rootItem.PropertyItems)
                    {
                        try
                        {
                            Type sinkType = TypeHelper.GetTypeFromString(sinkItem.EntryValue, TypeLookupModeEnum.AllowAll, true, true, true);
                            IErrorReportPackageSink sink = (IErrorReportPackageSink)sinkType.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
                            sink.Initialize(sinkItem);
                            sinks.Add(sink);
                        }
                        catch (Exception ex)
                        {
                            if (LOGGER.IsErrorEnabled)
                            {
                                LOGGER.Error(string.Format("ERROR_REPORT_SERVICE, failed to create error report sink. Type: '{0}'", sinkItem.EntryValue), ex);
                            }
                        }
                    }
                }
            }

            IErrorReportFilter filter = null;

            rootItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(ErrorReportConfiguration.Settings.CategoryPropertyItems, CONFIG_FILTER);
            if (rootItem != null)
            {
                try
                {
                    Type filterType = TypeHelper.GetTypeFromString(rootItem.EntryValue, TypeLookupModeEnum.AllowAll, true, true, true);
                    filter = (IErrorReportFilter)filterType.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
                    filter.Initialize(rootItem);
                }
                catch (Exception ex)
                {
                    filter = null;
                    if (LOGGER.IsErrorEnabled)
                    {
                        LOGGER.Error(string.Format("ERROR_REPORT_SERVICE, failed to create error report filter. Type: '{0}'", rootItem.EntryValue), ex);
                    }
                }
            }

            lock (mReportPackageSinks)
            {
                mErrorReportFilter = filter;
                mReportPackageSinks.ForEach(s => s.Close());
                mReportPackageSinks.Clear();
                mReportPackageSinks.AddRange(sinks);
                sinks.Clear();
                if (LOGGER.IsInfoEnabled)
                {
                    LOGGER.Info(string.Format("ERROR_REPORT_SERVICE, current active sink(s): {0}", mReportPackageSinks.Count.ToString()));
                }
            }
        }