예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptRegistrar"/> class.
        /// </summary>
        /// <param name="scripts">The scripts.</param>
        /// <param name="scriptableComponents">The scriptable components.</param>
        /// <param name="viewContext">The view context.</param>
        /// <param name="assetItemMerger">The asset merger.</param>
        /// <param name="scriptWrapper">The script wrapper.</param>
        public ScriptRegistrar(WebAssetItemCollection scripts, IList <IScriptableComponent> scriptableComponents,
                               ViewContext viewContext, IWebAssetItemMerger assetItemMerger, ScriptWrapperBase scriptWrapper)
        {
            // If the instance object is null.
            if (scripts == null)
            {
                throw new System.ArgumentNullException("scripts");
            }
            if (scriptableComponents == null)
            {
                throw new System.ArgumentNullException("scriptableComponents");
            }
            if (viewContext == null)
            {
                throw new System.ArgumentNullException("viewContext");
            }
            if (assetItemMerger == null)
            {
                throw new System.ArgumentNullException("assetItemMerger");
            }
            if (scriptWrapper == null)
            {
                throw new System.ArgumentNullException("scriptWrapper");
            }

            if (viewContext.HttpContext.Items[Key] != null)
            {
                throw new InvalidOperationException("Only one script registrar is allowed in a single request");
            }

            viewContext.HttpContext.Items[Key] = this;

            DefaultGroup = new WebAssetItemGroup("default", false)
            {
                DefaultPath = WebAssetDefaultSettings.ScriptFilesPath
            };
            Scripts = scripts;
            Scripts.Insert(0, DefaultGroup);

            this.scriptableComponents = scriptableComponents;
            ViewContext      = viewContext;
            AssetMerger      = assetItemMerger;
            ScriptWrapper    = scriptWrapper;
            AssetHandlerPath = WebAssetHttpHandler.DefaultPath;

            OnDocumentReadyActions    = new List <Action>();
            OnDocumentReadyStatements = new List <string>();
            OnWindowUnloadActions     = new List <Action>();
            OnWindowUnloadStatements  = new List <string>();
        }
예제 #2
0
        /// <summary>
        /// Gets the Component Factory for the extended UI.
        /// </summary>
        /// <param name="helper">The MVC html helper to extend.</param>
        /// <returns>The compoent factory reference for each UI.</returns>
        public static Extended.ComponentFactory NequeoUI(this HtmlHelper helper)
        {
            // If the instance object is null.
            if (helper == null)
            {
                throw new System.ArgumentNullException("helper");
            }

            ViewContext     viewContext = helper.ViewContext;
            HttpContextBase httpContext = viewContext.HttpContext;

            Extended.ComponentFactory factory = httpContext.Items[KeyExtended] as Extended.ComponentFactory;

            if (factory == null)
            {
                // Get the current service locator singleton instance.
                Nequeo.Runtime.IServiceLocator locator = Extended.Factory.Runtime.ServiceLocator.Current;
                Extended.Factory.Runtime.ServiceLocator.Register(locator);

                // Collect information on the current page
                // including all style sheets and scripts
                // that may already be added, do not add these
                // style sheets or scripts if already present.
                Extended.WebAsset.IWebAssetItemMerger           assetItemMerger = locator.Resolve <Extended.WebAsset.IWebAssetItemMerger>();
                Extended.UI.ScriptWrapperBase                   scriptWrapper   = locator.Resolve <Extended.UI.ScriptWrapperBase>();
                Extended.Factory.IClientSideObjectWriterFactory clientSideObjectWriterFactory =
                    locator.Resolve <Extended.Factory.IClientSideObjectWriterFactory>();

                Extended.UI.StyleSheetRegistrar styleSheetRegistrar = new Extended.UI.StyleSheetRegistrar(
                    new Extended.WebAsset.WebAssetItemCollection(Extended.WebAsset.WebAssetDefaultSettings.StyleSheetFilesPath),
                    viewContext, assetItemMerger);

                Extended.UI.ScriptRegistrar scriptRegistrar = new Extended.UI.ScriptRegistrar(
                    new Extended.WebAsset.WebAssetItemCollection(Extended.WebAsset.WebAssetDefaultSettings.ScriptFilesPath),
                    new List <Extended.Factory.IScriptableComponent>(), viewContext, assetItemMerger, scriptWrapper);

                Extended.UI.StyleSheetRegistrarBuilder styleSheetRegistrarBuilder = new Extended.UI.StyleSheetRegistrarBuilder(styleSheetRegistrar);
                Extended.UI.ScriptRegistrarBuilder     scriptRegistrarBuilder     = new Extended.UI.ScriptRegistrarBuilder(scriptRegistrar);

                // Execute the component factory.
                factory = new Extended.ComponentFactory(helper, clientSideObjectWriterFactory, styleSheetRegistrarBuilder, scriptRegistrarBuilder);
                helper.ViewContext.HttpContext.Items[KeyExtended] = factory;
            }

            // Return the compoent factory instance.
            return(factory);
        }