Ejemplo n.º 1
0
        private static void ParseInput()
        {
            using (var reader = new StreamReader("../../students.txt"))
            {
                while (!reader.EndOfStream)
                {
                    var line        = reader.ReadLine();
                    var studentInfo = line.Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

                    studentCourses.AddOrCreate(studentInfo[2], studentInfo[0], studentInfo[1]);
                }
            }
        }
Ejemplo n.º 2
0
        private void GetHandlers(object sender, Exception exception, out IExceptionHandler fallbackHandler, out List <IExceptionHandler> defaultHandlers, out List <IExceptionHandler> customHandlers, out bool skipDefaultHandlers)
        {
            fallbackHandler     = null;
            defaultHandlers     = new List <IExceptionHandler>();
            customHandlers      = new List <IExceptionHandler>();
            skipDefaultHandlers = false;

            var customHandlersDictionary = new SortedDictionary <int, IList <IExceptionHandler> >();

            foreach (var handler in ExceptionHandlers.Where(h => h.Implements(exception)))
            {
                if (handler.GetType().FullName == typeof(GeneralExceptionHandler).FullName)
                {
                    fallbackHandler = handler;
                    continue;
                }

                var defaultHandlerAttribute = handler.GetAttribute <DefaultExceptionHandlerAttribute>();
                if (defaultHandlerAttribute != null)
                {
                    defaultHandlers.Add(handler);
                    continue;
                }

                var handlingOnAttribute = handler.GetAttribute <ExceptionHandlerForAttribute>();
                if (handlingOnAttribute != null)
                {
                    if (!handlingOnAttribute.TypesToHandleOn.Any(t => t.IsInstanceOfType(sender)))
                    {
                        continue;
                    }

                    if (handlingOnAttribute.SkipDefaultHandlers)
                    {
                        skipDefaultHandlers = true;
                    }

                    customHandlersDictionary.AddOrCreate(handlingOnAttribute.PriorityLevel, handler);
                }
            }

            foreach (var customHandlersDictionaryEntry in customHandlersDictionary.Reverse())
            {
                customHandlers.AddRange(customHandlersDictionaryEntry.Value);
            }
        }