示例#1
0
        /// <summary>
        /// Raises the <see cref="Initializing"/> event.
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnInitializing(EventArgs e)
        {
            if (this.Initializing != null)
            {
                this.Initializing(this, e);
            }

            string[] temp = new string[] { "Serenity.dll" };

            foreach (string modulePath in temp)
            {
                foreach (var module in Module.LoadModules(modulePath))
                {
                    DirectoryResource modTree = new DirectoryResource()
                    {
                        Name = module.Name,
                        Owner = this
                    };

                    modTree.Add(module.Resources);

                    if (this.RootResource is DirectoryResource)
                    {
                        ((DirectoryResource)this.RootResource).Add(modTree);
                    }
                    this.modules.Add(module);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Overloaded. Builds a resource tree.
        /// </summary>
        /// <param name="resourceNamespace"></param>
        /// <returns></returns>
        protected virtual IEnumerable<Resource> BuildResourceTree(string resourceNamespace)
        {
            if (resourceNamespace == null)
            {
                resourceNamespace = this.ModuleAssembly.GetName().Name + ".";
            }
            else if (!resourceNamespace.EndsWith("."))
            {
                resourceNamespace += ".";
            }
            Assembly asm = this.ModuleAssembly;

            List<Resource> resources = new List<Resource>();

            foreach (string fullPath in from p in asm.GetManifestResourceNames()
                                        where p.StartsWith(resourceNamespace)
                                        select p)
            {
                var parts = fullPath.Substring(resourceNamespace.Length).Split('.');
                string name;

                if (parts.Length < 2)
                {
                    name = parts[0];
                }
                else
                {
                    name = parts[parts.Length - 2] + "." + parts[parts.Length - 1];
                }

                Resource res;
                if (parts.Length < 3)
                {
                    resources.Add(new ResourceResource(name, asm.GetManifestResourceStream(fullPath)));
                }
                else
                {
                    res = resources.Find(r => r.Name == parts[0]);

                    if (res == null)
                    {
                        res = new DirectoryResource(parts[0]);
                        resources.Add(res);
                    }
                    for (int i = 1; i < parts.Length - 2; i++)
                    {
                        Resource prev = res;
                        res = res.GetChild(parts[i]);
                        if (res == null)
                        {
                            res = new DirectoryResource(parts[i]);
                        }
                        prev.Add(res);
                    }
                    //TODO: Figure out if theres some way to determine the
                    //      created and modified date of an embedded resource.
                    res.Add(new ResourceResource(name, asm.GetManifestResourceStream(fullPath)));
                }

            }
            return resources;
        }