Beispiel #1
0
        public virtual void Initialize()
        {
            var data = new PageData(_dependencies, this);

            var elementDependencies = new PageElementDependencies
            {
                DictionaryFactory     = _dependencies.DictionaryFactory,
                DataDependencyFactory = _dependencies.DataDependencyFactory
            };

            if (Layout != null)
            {
                var regionElements = new List <Tuple <string, IRegion, IElement> >();
                foreach (var zoneName in Layout.GetZoneNames())
                {
                    var element = _layoutZones != null && _layoutZones.ContainsKey(zoneName)
                        ? _layoutZones[zoneName]
                        : Layout.GetElement(zoneName);
                    var region = element as IRegion;

                    if (region == null)
                    {
                        region = Layout.GetRegion(zoneName);
                    }
                    else
                    {
                        element = null;
                    }

                    regionElements.Add(new Tuple <string, IRegion, IElement>(zoneName, region, element));
                }
                _layout = new PageLayout(elementDependencies, null, Layout, regionElements, data);
            }

            if (_components == null)
            {
                _pageComponents = new PageComponent[0];
            }
            else
            {
                _pageComponents = _components
                                  .ToList()
                                  .Select(c => new PageComponent(elementDependencies, null, c, data))
                                  .ToArray();

                foreach (var component in _components)
                {
                    data.BeginAddElement(component, null);
                    data.EndAddElement(component);
                }
            }

            _dataContextBuilder = data.RootDataContextBuilder;
            _dataContextBuilder.ResolveSupplies();

            _referencedModules = new List <IModule>();
            var styles    = _dependencies.CssWriterFactory.Create();
            var functions = _dependencies.JavascriptWriterFactory.Create();

#if TRACE
            System.Diagnostics.Trace.WriteLine("Page '" + Name + "' asset deployment");
#endif
            var elements = new HashSet <string>();

            foreach (var element in data.Elements)
            {
                var name = string.IsNullOrEmpty(element.Element.Name)
                    ? element.Element.GetType().Name
                    : element.Element.Name;

                var elementUniqueName = element.Element.ElementType.ToString() + ":" + name;
                if (!elements.Add(elementUniqueName))
                {
                    continue;
                }

                string deployment;
                switch (element.AssetDeployment)
                {
                case AssetDeployment.PerWebsite:
                    deployment = "website assets";
                    _dependencies.AssetManager.AddWebsiteAssets(element.Element);
                    break;

                case AssetDeployment.PerModule:
                    deployment = element.Module.Name + " module";
                    _dependencies.AssetManager.AddModuleAssets(element.Element, element.Module);
                    if (_referencedModules.All(m => m.Name != element.Module.Name))
                    {
                        _referencedModules.Add(element.Module);
                    }
                    break;

                case AssetDeployment.PerPage:
                    deployment = "page assets";
                    _dependencies.AssetManager.AddPageAssets(element.Element, this);
                    break;

                case AssetDeployment.InPage:
                    deployment = "page head";
                    element.Element.WriteStaticCss(styles);
                    element.Element.WriteStaticJavascript(functions);
                    break;

                default:
                    deployment = element.AssetDeployment.ToString().ToLower();
                    break;
                }

#if DEBUG
                System.Diagnostics.Trace.WriteLine("   " + name + " deployed to " + deployment);
#endif
            }

            _inPageCssLines    = styles.ToLines();
            _inPageScriptLines = functions.ToLines();
        }
Beispiel #2
0
 void IDataContextBuilder.ResolveSupplies()
 {
     _dataContextBuilder.ResolveSupplies();
 }