Sage.Views.ViewModel.AddViewLibraryReference C# (CSharp) Method

AddViewLibraryReference() private method

private AddViewLibraryReference ( string libraryName ) : void
libraryName string
return void
        internal void AddViewLibraryReference(string libraryName)
        {
            var config = context.ProjectConfiguration;
            if (!config.ResourceLibraries.ContainsKey(libraryName))
            {
                log.ErrorFormat("View '{0}' is referencing non-existent library '{1}'",
                    this.ViewConfiguration.Info.ConfigName, libraryName);

                return;
            }

            this.AddLibraryReference(libraryName);
        }

Usage Example

コード例 #1
0
ファイル: ViewConfiguration.cs プロジェクト: igorfrance/sage
        /// <summary>
        /// Discovers any module XML elements in the current configuration, and creates and processed their matching module instances.
        /// </summary>
        /// <returns>
        /// An object that contains the result of processing this configuration.
        /// </returns>
        public ViewModel Process()
        {
            ViewModel model = new ViewModel(this, configElement);

            foreach (string moduleId in this.Modules.Keys)
            {
                var moduleElement = (XmlElement) model.ConfigNode.SelectSingleNode(string.Format("//mod:*[@id='{0}']", moduleId), XmlNamespaces.Manager);
                string moduleName = moduleElement.LocalName;
                string moduleCategory = moduleElement.GetAttribute("category");

                string moduleKey = string.IsNullOrWhiteSpace(moduleCategory)
                    ? moduleName
                    : moduleCategory + "/" + moduleName;

                ModuleConfiguration moduleConfig;
                if (this.Context.ProjectConfiguration.Modules.TryGetValue(moduleKey, out moduleConfig))
                {
                    XmlElement moduleDefaults = moduleConfig.GetDefault(this.Context);
                    if (moduleDefaults != null)
                        this.SynchronizeElements(moduleElement, moduleDefaults);
                }

                IModule module = this.Modules[moduleId];
                ModuleResult result = null;
                try
                {
                    var startTime = DateTime.Now.Ticks;
                    result = module.ProcessElement(moduleElement, this);

                    var elapsed = new TimeSpan(DateTime.Now.Ticks - startTime);
                    log.DebugFormat("Completed processing module {0} in {1}ms", moduleConfig.Key, elapsed.Milliseconds);
                }
                catch (Exception ex)
                {
                    log.ErrorFormat("Error procesing module element {0}: {1}", moduleKey, ex.Message);
                }
                finally
                {
                    if (result == null)
                    {
                        moduleElement.ParentNode.RemoveChild(moduleElement);
                    }
                    else
                    {
                        model.AddModuleResult(moduleKey, result);
                        if (result.ResultElement != null)
                        {
                            XmlNode newElement = moduleElement.OwnerDocument.ImportNode(result.ResultElement, true);
                            moduleElement.ParentNode.ReplaceChild(newElement, moduleElement);
                        }
                    }
                }
            }

            // this section adds library reference for <sage:library[@ref]/> elements
            XmlNodeList libraries = model.ConfigNode.SelectNodes(LibrarySelectXpath, XmlNamespaces.Manager);
            foreach (XmlElement library in libraries)
            {
                string libraryName = library.GetAttribute("ref");
                model.AddViewLibraryReference(libraryName);
                library.ParentNode.RemoveChild(library);
            }

            return model;
        }