Пример #1
0
 public void AddRegistry(string registryTypeName)
 {
     _pluginGraph.Log.Try(() => {
         Type type = new TypePath(registryTypeName).FindType();
         var registry = (Registry) Activator.CreateInstance(type);
         registry.As<IPluginGraphConfiguration>().Configure(_pluginGraph);
     }).AndReportErrorAs(290, registryTypeName);
 }
Пример #2
0
        public void can_parse_assembly_qualified_generics()
        {
            Type sampleGenericType = typeof (IConcept<AWidget>);
            string genericAssemblyQualifiedName = sampleGenericType.AssemblyQualifiedName;

            var path = new TypePath(genericAssemblyQualifiedName);
            path.FindType().ShouldEqual(sampleGenericType);
        }
Пример #3
0
 public void OverrideProfile(TypePath typePath, string instanceKey)
 {
     _pluginGraph.Log.WithType(typePath, "while trying to add an override for a Profile", pluginType =>
     {
         var instance = new ReferencedInstance(instanceKey);
         _pluginGraph.SetDefault(_lastProfile, pluginType, instance);
     });
 }
Пример #4
0
        public DoctorReport RunReport(string bootstrapperTypeName)
        {
            var report = new DoctorReport
            {
                Result = DoctorResult.Success
            };

            IBootstrapper bootstrapper;
            try
            {
                var path = new TypePath(bootstrapperTypeName);
                Type bootstrapperType = path.FindType();
                bootstrapper = (IBootstrapper) Activator.CreateInstance(bootstrapperType);
            }
            catch (Exception e)
            {
                report.Result = DoctorResult.BootstrapperCouldNotBeFound;
                report.ErrorMessages = e.ToString();

                return report;
            }

            try
            {
                bootstrapper.BootstrapStructureMap();

                PluginGraph graph = ObjectFactory.PluginGraph;

                if (graph.Log.ErrorCount > 0)
                {
                    report.ErrorMessages = graph.Log.BuildFailureMessage();
                    report.Result = DoctorResult.ConfigurationErrors;
                }
                else
                {
                    writeConfigurationAndValidate(report, graph);
                }

                return report;
            }
            catch (StructureMapConfigurationException ex)
            {
                report.ErrorMessages = ex.Message;
                report.Result = DoctorResult.ConfigurationErrors;

                return report;
            }
            catch (Exception ex)
            {
                report.Result = DoctorResult.BootstrapperFailure;
                report.ErrorMessages = ex.ToString();

                return report;
            }
        }
Пример #5
0
        public void ParseInstanceElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));

            _builder.ConfigureFamily(pluginTypePath, family => {
                InstanceMemento memento = ConfigurationParser.CreateMemento(element);
                var instance = memento.ToInstance(this, family.PluginType);

                family.AddInstance(instance);
            });
        }
Пример #6
0
        public void ParseInstanceElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));

            _builder.ConfigureFamily(pluginTypePath, family =>
            {
                InstanceMemento memento =
                    _mementoCreator.CreateMemento(element);
                family.AddInstance(memento);
            });
        }
Пример #7
0
        public Plugin PluginFor(string name)
        {
            if (name == null) throw new ArgumentNullException("name");

            if (name.Contains(","))
            {
                var pluggedType = new TypePath(name).FindType();
                return PluginCache.GetPlugin(pluggedType);
            }

            return _aliases.Has(name) ? PluginCache.GetPlugin(_aliases[name]) : null;
        }
Пример #8
0
        public void ParseAlias(XmlElement element)
        {
            var attribute = element.GetAttribute("Key");
            var typeName = element.GetAttribute("Type");

            if (attribute.IsEmpty() || typeName.IsEmpty())
            {
                throw new MalformedAliasException(element.OuterXml);
            }

            _aliases[attribute] = new TypePath(typeName).FindType();
        }
Пример #9
0
        public void ParseDefaultElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));

            _builder.ConfigureFamily(pluginTypePath, family =>
            {
                InstanceScope scope = findScope(element);
                family.SetScopeTo(scope);

                InstanceMemento memento = _mementoCreator.CreateMemento(element);
                family.AddDefaultMemento(memento);
            });
        }
Пример #10
0
 public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
 {
     try
     {
         Type pluginType = pluginTypePath.FindType();
         PluginFamily family = _pluginGraph.Families[pluginType];
         action(family);
     }
     catch (Exception ex)
     {
         _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.AssemblyQualifiedName);
     }
 }
Пример #11
0
        public void Call_the_action_on_configure_family_if_the_pluginType_is_found()
        {
            var typePath = new TypePath(typeof (IGateway));

            bool iWasCalled = false;
            var builder = new GraphBuilder(new PluginGraph());
            builder.ConfigureFamily(typePath, f => {
                Assert.AreEqual(typeof (IGateway), f.PluginType);
                iWasCalled = true;
            });

            Assert.IsTrue(iWasCalled);
        }
Пример #12
0
        public void ParseDefaultElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));

            _builder.ConfigureFamily(pluginTypePath, family => {
                var scope = findScope(element);
                family.SetScopeTo(scope);

                InstanceMemento memento = ConfigurationParser.CreateMemento(element);
                var instance = memento.ToInstance(this, family.PluginType);
                family.SetDefault(instance);
            });
        }
Пример #13
0
        private void createOverrideInstance(string fullName, XmlElement instanceElement, WriteOverride function,
                                            string profileName)
        {
            string key = Profile.InstanceKeyForProfile(profileName);
            InstanceMemento memento = _creator.CreateMemento(instanceElement);
            memento.InstanceKey = key;

            var familyPath = new TypePath(fullName);

            _graphBuilder.ConfigureFamily(familyPath, family =>
            {
                family.AddInstance(memento);
                function(fullName, key);
            });
        }
Пример #14
0
 public void AddRegistry(string registryTypeName)
 {
     var type = new TypePath(registryTypeName).FindType();
     var registry = (Registry) Activator.CreateInstance(type);
     registry.As<IPluginGraphConfiguration>().Configure(_pluginGraph);
 }
Пример #15
0
 public void CanBuildTypeCreatedFromType()
 {
     var path = new TypePath(GetType());
     path.FindType();
 }
Пример #16
0
        private Plugin getPluginByType(PluginFamily family)
        {
            string pluggedTypeName = getPluggedType();
            if (string.IsNullOrEmpty(pluggedTypeName))
            {
                return null;
            }

            Type pluggedType = new TypePath(pluggedTypeName).FindType();
            return PluginCache.GetPlugin(pluggedType);
        }
Пример #17
0
 public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
 {
     var pluginType = pluginTypePath.FindType();
     var family = _pluginGraph.Families[pluginType];
     action(family);
 }
Пример #18
0
 public void WithType(TypePath path, string context, Action<Type> action)
 {
     try
     {
         Type type = path.FindType();
         action(type);
     }
     catch (StructureMapException ex)
     {
         RegisterError(ex);
     }
     catch (Exception ex)
     {
         RegisterError(131, ex, path.AssemblyQualifiedName, context);
     }
 }