Esempio n. 1
0
        private static List <Type> GetEffectsFromAssemblies(Assembly[] assemblies, IList <Triple <Assembly, Type, Exception> > errorsResult)
        {
            List <Type> effects = new List <Type>();

            foreach (Assembly assembly in assemblies)
            {
                GetEffectsFromAssembly(assembly, effects, errorsResult);
            }

            List <Type> removeUs = new List <Type>();

            foreach (Type effectType in effects)
            {
                Exception bannedEx = IsBannedEffect(effectType);

                if (bannedEx != null)
                {
                    removeUs.Add(effectType);
                    errorsResult.Add(Triple.Create(effectType.Assembly, effectType, bannedEx));
                }
            }

            foreach (Type removeThisType in removeUs)
            {
                effects.Remove(removeThisType);
            }

            return(effects);
        }
Esempio n. 2
0
        private static Type[] GetTypesFromAssembly(Assembly assembly, IList <Triple <Assembly, Type, Exception> > errorsResult)
        {
            Type[] types;

            try
            {
                types = assembly.GetTypes();
            }

            catch (ReflectionTypeLoadException rex)
            {
                List <Type> typesList = new List <Type>();
                Type[]      rexTypes  = rex.Types;

                foreach (Type rexType in rexTypes)
                {
                    if (rexType != null)
                    {
                        typesList.Add(rexType);
                    }
                }

                foreach (Exception loadEx in rex.LoaderExceptions)
                {
                    // Set Type to null, and the error dialog will look at the exception, see it is a TypeLoadException,
                    // and use the TypeName property from there.
                    errorsResult.Add(Triple.Create <Assembly, Type, Exception>(assembly, null, loadEx));
                }

                types = typesList.ToArray();
            }

            return(types);
        }
Esempio n. 3
0
        private List <Triple <Assembly, Type, Exception> > RemoveDuplicates(IList <Triple <Assembly, Type, Exception> > allErrors)
        {
            // Exception has reference identity, but we want to collate based on the message contents

            Set <Triple <Assembly, Type, string> >     internedList = new Set <Triple <Assembly, Type, string> >();
            List <Triple <Assembly, Type, Exception> > noDupesList  = new List <Triple <Assembly, Type, Exception> >();

            for (int i = 0; i < allErrors.Count; ++i)
            {
                Triple <Assembly, Type, string> interned = Triple.Create(
                    allErrors[i].First, allErrors[i].Second, string.Intern(allErrors[i].Third.ToString()));

                if (!internedList.Contains(interned))
                {
                    internedList.Add(interned);
                    noDupesList.Add(allErrors[i]);
                }
            }

            return(noDupesList);
        }
Esempio n. 4
0
        private void AddEffectsToMenu()
        {
            // Fill the menu with the effect names, and "..." if it is configurable
            EffectsCollection effectsCollection = Effects;

            Type[] effectTypes   = effectsCollection.Effects;
            bool   withShortcuts = EnableEffectShortcuts;

            List <Effect> newEffects = new List <Effect>();

            foreach (Type type in effectsCollection.Effects)
            {
                try
                {
                    ConstructorInfo ci     = type.GetConstructor(Type.EmptyTypes);
                    Effect          effect = (Effect)ci.Invoke(null);

                    if (FilterEffects(effect))
                    {
                        newEffects.Add(effect);
                    }
                }

                catch (Exception ex)
                {
                    // We don't want a DLL that can't be figured out to cause the app to crash
                    //continue;
                    AppWorkspace.ReportEffectLoadError(Triple.Create(type.Assembly, type, ex));
                }
            }

            newEffects.Sort((lhs, rhs) => string.Compare(lhs.Name, rhs.Name, true));

            List <string> subMenuNames = new List <string>();

            foreach (Effect effect in newEffects)
            {
                if (!string.IsNullOrEmpty(effect.SubMenuName))
                {
                    subMenuNames.Add(effect.SubMenuName);
                }
            }

            subMenuNames.Sort((lhs, rhs) => string.Compare(lhs, rhs, true));

            string lastSubMenuName = null;

            foreach (string subMenuName in subMenuNames)
            {
                if (subMenuName == lastSubMenuName)
                {
                    // skip duplicate names
                    continue;
                }

                PdnMenuItem subMenu = new PdnMenuItem(subMenuName, null, null);
                DropDownItems.Add(subMenu);
                lastSubMenuName = subMenuName;
            }

            foreach (Effect effect in newEffects)
            {
                AddEffectToMenu(effect, withShortcuts);
            }
        }