コード例 #1
0
        /// <summary>
        /// Gets the scripts.
        /// </summary>
        /// <param name="components">The components.</param>
        /// <param name="scripts">The scripts.</param>
        /// <returns></returns>
        public static IList <string> GetScripts(IEnumerable <string> components, IEnumerable <string> scripts)
        {
            if (components == null)
            {
                components = new List <string>();
            }

            if (scripts == null)
            {
                scripts = new List <string>();
            }

            var originalScripts = scripts.ToList();

            if (!components.Any())
            {
                return(originalScripts);
            }

            var dependencyScripts = new List <string>();

            foreach (var comp in components)
            {
                dependencyScripts.AddRange(ComponentsDependencyResolver.GetComponentDependencies(comp, DependencyType.Scripts));
            }

            return(ComponentsDependencyResolver.OrderScripts(dependencyScripts, originalScripts));
        }
コード例 #2
0
        private void PopulateModulesForScripts(IEnumerable <string> scripts)
        {
            if (scripts == null || scripts.Count() == 0)
            {
                return;
            }

            var modules = ComponentsDependencyResolver.GetModulesByScripts(scripts);

            this.ModuleDependencies = this.ModuleDependencies.Concat(modules);
        }
コード例 #3
0
        /// <summary>
        /// Gets the modules where components are defined.
        /// </summary>
        /// <param name="components">The components.</param>
        /// <returns></returns>
        public static IList <string> GetModules(IEnumerable <string> components)
        {
            if (components == null)
            {
                components = new List <string>();
            }

            var modules = new List <string>();

            foreach (var comp in components)
            {
                modules.AddRange(ComponentsDependencyResolver.GetComponentDependencies(comp, DependencyType.Modules));
            }

            return(modules);
        }
コード例 #4
0
        private void PopulateComponentsScriptReferences(DesignerViewConfigModel designerViewConfigModel)
        {
            if (designerViewConfigModel == null)
            {
                return;
            }

            if (designerViewConfigModel.Components != null && designerViewConfigModel.Components.Count > 0)
            {
                if (designerViewConfigModel.Scripts == null)
                {
                    designerViewConfigModel.Scripts = new List <string>();
                }

                designerViewConfigModel.Scripts = ComponentsDependencyResolver.GetScripts(designerViewConfigModel.Components, designerViewConfigModel.Scripts);
            }
        }
コード例 #5
0
        /// <summary>
        /// Populates the script references and dependant modules.
        /// </summary>
        /// <param name="widgetName">Name of the widget.</param>
        /// <param name="viewConfigs">The view configs.</param>
        protected void PopulateDependencies(string widgetName, IEnumerable <KeyValuePair <string, DesignerViewConfigModel> > viewConfigs)
        {
            var packagesManager = new PackageManager();
            var packageName     = packagesManager.GetCurrentPackage();

            var designerWidgetName = FrontendManager.ControllerFactory.GetControllerName(typeof(DesignerController));

            var viewScriptReferences = new List <string>(this.views.Count());

            foreach (var view in this.views)
            {
                var scriptFileName = this.GetViewScriptFileName(view);
                var scriptPath     = this.GetScriptPath(scriptFileName, widgetName, packageName);
                if (VirtualPathManager.FileExists(scriptPath))
                {
                    viewScriptReferences.Add(this.GetScriptReferencePath(widgetName, scriptFileName));
                }
                else
                {
                    scriptPath = this.GetScriptPath(scriptFileName, designerWidgetName, packageName);

                    if (VirtualPathManager.FileExists(scriptPath))
                    {
                        viewScriptReferences.Add(this.GetScriptReferencePath(designerWidgetName, scriptFileName));
                    }
                    else
                    {
                        var viewConfig = viewConfigs.Where(v => v.Key == view).SingleOrDefault();
                        this.ModuleDependencies = this.ModuleDependencies.Concat(ComponentsDependencyResolver.GetModules(viewConfig.Value.Components)).Distinct();
                    }
                }
            }

            var configuredScriptReferences = viewConfigs
                                             .Where(c => c.Value.Scripts != null)
                                             .SelectMany(c => c.Value.Scripts);

            this.scriptReferences = viewScriptReferences
                                    .Union(configuredScriptReferences)
                                    .Distinct();
        }
コード例 #6
0
        /// <summary>
        /// Generates the view configuration if its missing from the file system.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="viewLocations">Locations where view files can be found.</param>
        /// <param name="viewFilesMappings">Map of the view file location for each view.</param>
        /// <returns>Config for the given view.</returns>
        protected DesignerViewConfigModel GenerateViewConfig(string view, IEnumerable <string> viewLocations, Dictionary <string, string> viewFilesMappings)
        {
            var viewFilePath = this.GetViewFilePath(view, viewLocations, viewFilesMappings);

            if (!string.IsNullOrEmpty(viewFilePath))
            {
                using (var fileStream = VirtualPathManager.OpenFile(viewFilePath))
                {
                    var components = ComponentsDependencyResolver.ExtractComponents(fileStream);
                    var scripts    = ComponentsDependencyResolver.GetScripts(components, null);

                    // If view that exists has been parsed and no components are used in it - no point in cycling trough the other views
                    return(new DesignerViewConfigModel()
                    {
                        Scripts = scripts, Components = components, IsGenerated = true
                    });
                }
            }

            return(null);
        }
コード例 #7
0
        private static IEnumerable <string> GetComponentDependencies(string component, DependencyType dependencyType)
        {
            var allDependencies = new List <string>();

            if (!string.IsNullOrEmpty(component) && ComponentsDependencyResolver.ComponentsDefinitionsDictionary.Value.ContainsKey(component))
            {
                var componentDefinitionObject = ComponentsDependencyResolver.ComponentsDefinitionsDictionary.Value[component];

                if (dependencyType == DependencyType.Scripts)
                {
                    if (componentDefinitionObject.Scripts != null)
                    {
                        allDependencies.AddRange(componentDefinitionObject.Scripts);
                    }
                }
                else
                {
                    if (componentDefinitionObject.AngularModules != null)
                    {
                        allDependencies.AddRange(componentDefinitionObject.AngularModules);
                    }
                }

                if (componentDefinitionObject.Components != null && dependencyType == DependencyType.Scripts)
                {
                    foreach (var comp in componentDefinitionObject.Components)
                    {
                        allDependencies.AddRange(ComponentsDependencyResolver.GetComponentDependencies(comp, dependencyType));
                    }
                }
            }
            else
            {
                Log.Write(string.Format(System.Globalization.CultureInfo.InvariantCulture, "The component {0} could not be resolved", component));
            }

            return(allDependencies.Distinct());
        }