public IEventInformationCollection Create()
        {
            Log.Info("Discovering events");

            var e = new EventInformationCollection {
                Events = new List <IEventInformation>()
            };

            foreach (var t in AppDomain
                     .CurrentDomain
                     .GetAssemblies().SelectMany(assembly => assembly.GetTypes()))
            {
                foreach (var info in t.GetEvents(BindingFlags.Static |
                                                 BindingFlags.Public |
                                                 BindingFlags.FlattenHierarchy))
                {
                    e.Events.Add(new EventInformation
                    {
                        FullName  = t.FullName + "." + info.Name,
                        EventName = info.Name,
                        TypeName  = t.FullName,
                        TypeAssemblyQualifiedName = t.AssemblyQualifiedName
                    });
                }
            }

            e.Events = e.Events.OrderBy(x => x.FullName).ToList();
            Log.Info(string.Format("Found {0} events at starup", e.Events.Count));

            return(e);
        }
        public IEventInformationCollection Create()
        {
            Log.Info("Discovering events");

            var e = new EventInformationCollection {Events = new List<IEventInformation>()};

            var assemblies = AppDomain
                .CurrentDomain
                .GetAssemblies();


            try
            {
                foreach (var t in assemblies.SelectMany(assembly => assembly.GetTypes()))
                {
                    foreach (var info in t.GetEvents(BindingFlags.Static |
                                                     BindingFlags.Public |
                                                     BindingFlags.FlattenHierarchy))
                    {

                        e.Events.Add(new EventInformation
                        {
                            FullName = t.FullName + "." + info.Name,
                            EventName = info.Name,
                            TypeName = t.FullName,
                            TypeAssemblyQualifiedName = t.AssemblyQualifiedName
                        });

                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                var sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    var exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                var errorMessage = sb.ToString();
                throw new Exception(errorMessage);
            }

            e.Events = e.Events.OrderBy(x => x.FullName).ToList();
            Log.Info(string.Format("Found {0} events at starup", e.Events.Count));

            return e;

        }
示例#3
0
        public IEventInformationCollection Create()
        {
            Log.Info("Discovering events");

            var e = new EventInformationCollection {
                Events = new List <IEventInformation>()
            };

            var assemblies = AppDomain
                             .CurrentDomain
                             .GetAssemblies();


            try
            {
                foreach (var t in assemblies.SelectMany(assembly => assembly.GetTypes()))
                {
                    foreach (var info in t.GetEvents(BindingFlags.Static |
                                                     BindingFlags.Public |
                                                     BindingFlags.FlattenHierarchy))
                    {
                        e.Events.Add(new EventInformation
                        {
                            FullName  = t.FullName + "." + info.Name,
                            EventName = info.Name,
                            TypeName  = t.FullName,
                            TypeAssemblyQualifiedName = t.AssemblyQualifiedName
                        });
                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                var sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    var exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                var errorMessage = sb.ToString();
                throw new Exception(errorMessage);
            }

            e.Events = e.Events.OrderBy(x => x.FullName).ToList();
            Log.Info(string.Format("Found {0} events at starup", e.Events.Count));

            return(e);
        }
示例#4
0
        /// <summary>
        /// Test event item information collection
        /// </summary>
        /// <typeparam name="T">type of event enumerator</typeparam>
        /// <param name="sourceName">event source name</param>
        /// <param name="itemDataList">test data list</param>
        private static void TestGeneric <T>(string sourceName, Tuple <string, int, EventLevel>[] itemDataList)
        {
            var informationCollection = new EventInformationCollection <T>();

            Assert.AreEqual(sourceName ?? typeof(T).Name, informationCollection.SourceName);

            EventItemInformation itemInformaion;

            foreach (var testItemData in itemDataList)
            {
                var id = (T)Enum.Parse(typeof(T), testItemData.Item1);
                itemInformaion = informationCollection[id];
                Assert.IsNotNull(itemInformaion);
                Assert.AreEqual(testItemData.Item1, itemInformaion.Name);
                Assert.AreEqual(testItemData.Item2, itemInformaion.Id);
                Assert.AreEqual(testItemData.Item3, itemInformaion.Level);
            }

            var invalidId = (T)(object)(itemDataList.Length * 2);

            Assert.IsNull(informationCollection[invalidId]);
        }