Exemplo n.º 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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends the error report.
        /// </summary>
        /// <param name="package">The package.</param>
        public void SendErrorReport(ReportPackage package)
        {
            if (package != null)
            {
                if (LOGGER.IsDebugEnabled)
                {
                    LOGGER.Debug("ERROR_REPORT_SERVICE, new error report package arrived.");
                }

                IErrorReportFilter             filter = null;
                List <IErrorReportPackageSink> sinks  = new List <IErrorReportPackageSink>();
                lock (mReportPackageSinks)
                {
                    filter = mErrorReportFilter;
                    sinks.AddRange(mReportPackageSinks);
                }

                bool allowed = true;
                if (filter != null)
                {
                    try
                    {
                        allowed = filter.Filter(package);
                    }
                    catch (Exception ex)
                    {
                        allowed = false;
                        if (LOGGER.IsErrorEnabled)
                        {
                            LOGGER.Error(string.Format("ERROR_REPORT_SERVICE, filter threw an exception. Filter type: '{0}'", filter.GetType().AssemblyQualifiedName), ex);
                        }
                    }
                }

                if (allowed && sinks.Count > 0)
                {
                    foreach (IErrorReportPackageSink sink in sinks)
                    {
                        allowed = true;
                        if (sink.Filter != null)
                        {
                            try
                            {
                                allowed = sink.Filter.Filter(package);
                            }
                            catch (Exception ex)
                            {
                                allowed = false;
                                if (LOGGER.IsErrorEnabled)
                                {
                                    LOGGER.Error(string.Format("ERROR_REPORT_SERVICE, sink filter threw an exception. Sink type: '{0}', filter type: '{1}'", sink.GetType().AssemblyQualifiedName, filter.GetType().AssemblyQualifiedName), ex);
                                }
                            }
                        }

                        if (allowed)
                        {
                            try
                            {
                                sink.ProcessReportPackage(package);
                            }
                            catch (Exception ex)
                            {
                                if (LOGGER.IsErrorEnabled)
                                {
                                    LOGGER.Error(string.Format("ERROR_REPORT_SERVICE, a sink threw an exception. SinkId: '{0}', sink type: '{1}'", sink.SinkId, sink.GetType().AssemblyQualifiedName), ex);
                                }
                            }
                        }
                    }
                    sinks.Clear();
                }
            }
        }
Exemplo n.º 3
0
        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()));
                }
            }
        }