public ITemplateDefinition PartOf(string packageName)
 {
     _nameManager.AddResolutionHandler(NameResolutionPhase.ResolvePackageNames, nm =>
     {
         _package = nm.ResolvePackage(packageName);
         ((ITemplate)_template).Package = _package;
     });
     return(this);
 }
        IComponentDefinition IComponentDefinition.PartOf(string packageName)
        {
            if (string.IsNullOrEmpty(packageName))
            {
                return(this);
            }

            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolvePackageNames,
                (nm, c, n) => c.Package = nm.ResolvePackage(n),
                _component,
                packageName);

            return(this);
        }
Esempio n. 3
0
        IRegionDefinition IRegionDefinition.PartOf(string packageName)
        {
            if (string.IsNullOrEmpty(packageName))
            {
                return(this);
            }

            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolvePackageNames,
                (nm, r, n) =>
            {
                r.Package = nm.ResolvePackage(n);
            },
                _region,
                packageName);

            return(this);
        }
        IPageDefinition IPageDefinition.PartOf(string packageName)
        {
            if (string.IsNullOrEmpty(packageName))
            {
                return(this);
            }

            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolvePackageNames,
                (nm, p, n) => p.Package = nm.ResolvePackage(n),
                _page,
                packageName);

            return(this);
        }
Esempio n. 5
0
        IDataProviderDefinition IDataProviderDefinition.DependsOn(string dataProviderName)
        {
            var dataConsumer = _dataProvider as IDataConsumer;

            if (dataConsumer == null)
            {
                throw new DataProviderBuilderException("This data provider is not a consumer of data");
            }

            if (string.IsNullOrEmpty(dataProviderName))
            {
                throw new DataProviderBuilderException("You must provide the name of the data provider that this data provider depends on");
            }

            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolveElementReferences,
                (nm, c, n) => c.HasDependency(nm.ResolveDataProvider(n)),
                dataConsumer,
                dataProviderName);

            return(this);
        }
        IPackageDefinition IPackageDefinition.Module(string moduleName)
        {
            if (string.IsNullOrEmpty(moduleName))
            {
                return(this);
            }

            _nameManager.AddResolutionHandler(
                NameResolutionPhase.ResolveElementReferences,
                (nm, p, n) => p.Module = nm.ResolveModule(n),
                _package,
                moduleName);

            return(this);
        }
Esempio n. 7
0
        public void Should_run_phased_resolution_actions()
        {
            var handlerCount = 0;
            var currentPhase = NameResolutionPhase.ResolvePackageNames;
            Action <INameManager, NameResolutionPhase> expectPhase = (nm, p) =>
            {
                Assert.IsTrue(p >= currentPhase);
                currentPhase = p;
                handlerCount++;
            };

            var r = new Random();

            for (var i = 0; i < 1000; i++)
            {
                var phase = (NameResolutionPhase)(r.Next((int)NameResolutionPhase.ResolvePackageNames, (int)NameResolutionPhase.InitializeRunables + 1));
                _nameManager.AddResolutionHandler(phase, expectPhase, phase);
            }

            _nameManager.Bind();

            Assert.AreEqual(1000, handlerCount);
        }
Esempio n. 8
0
        private void Configure(AttributeSet attributes, IRegion region)
        {
            if (region == null)
            {
                return;
            }

            if (attributes.IsRegion != null)
            {
                if (!string.IsNullOrEmpty(attributes.IsRegion.Name))
                {
                    region.Name = attributes.IsRegion.Name;
                }
            }

            var hasComponent = false;

            if (attributes.UsesComponents != null)
            {
                if (attributes.UsesComponents.Count > 1)
                {
                    throw new RegionBuilderException("Regions can only host one component but you " +
                                                     "have more than one [UsesComponent] attribute on " + attributes.Type.DisplayName());
                }

                if (attributes.UsesComponents.Count == 1)
                {
                    hasComponent = true;

                    _nameManager.AddResolutionHandler(
                        NameResolutionPhase.ResolveElementReferences,
                        (nm, r, n) => r.Content = nm.ResolveComponent(n, r.Package),
                        region,
                        attributes.UsesComponents[0].ComponentName);
                }
            }

            if (attributes.UsesLayout != null)
            {
                if (hasComponent)
                {
                    throw new RegionBuilderException("Regions can only host one element, you " +
                                                     "can not have more than one [UseXxxx] attributes on region " + attributes.Type.DisplayName());
                }

                _nameManager.AddResolutionHandler(
                    NameResolutionPhase.ResolveElementReferences,
                    (nm, r, n) => r.Content = nm.ResolveLayout(n, r.Package),
                    region,
                    attributes.UsesLayout.LayoutName);
            }

            //if (attributes.UsesTemplate != null)
            //{
            //    if (hasComponent)
            //        throw new RegionBuilderException("Regions can only host one element, you " +
            //            "can not have more than one [UseXxxx] attributes on region " + attributes.Type.DisplayName());

            //    var component = new TemplateComponent();
            //    component.Template(attributes.UsesTemplate.TemplatePath);
            //    region.Content = component;
            //}
        }
Esempio n. 9
0
 public IService Build()
 {
     _nameManager.AddResolutionHandler(NameResolutionPhase.InitializeRunables, () => _service.Initialize());
     return(_service);
 }