Beispiel #1
0
        public static List <WebPage.Component> GetResourceComponents(Assembly a, string resourcePath, bool relativePaths = false)
        {
            List <WebPage.Component> components = new List <WebPage.Component>();

            string[] validExtensions = new string[] { "css", "js" };

            string[] arr = a.GetManifestResourceNames().Where(x =>
            {
                return(x.StartsWith(resourcePath) &&
                       validExtensions.Any(y => x.EndsWith($".{y}")));
            }).ToArray();

            foreach (string rName in arr)
            {
                WebPage.ComponentType type = WebPage.ComponentType.Unknown;
                switch (rName.Substring(rName.LastIndexOf('.') + 1))
                {
                case "css":
                    type = WebPage.ComponentType.Style;
                    break;

                case "js":
                    type = WebPage.ComponentType.Script;
                    break;

                default:
                    continue;
                }

                string data = LoadStringResource(a, rName);

                string newPath = rName;
                if (relativePaths)
                {
                    newPath = rName.ToLower().Replace(resourcePath.ToLower(), "").Trim('.');

                    string namePath = newPath.Substring(0, newPath.LastIndexOf('.'));

                    if (namePath.EndsWith(".min"))
                    {
                        namePath = namePath.Substring(0, namePath.LastIndexOf(".")).Replace(".", "/") + ".min";
                    }
                    else
                    {
                        namePath = namePath.Replace(".", "/");
                    }

                    newPath = namePath + newPath.Substring(newPath.LastIndexOf('.'));
                }

                WebPage.Component comp = new WebPage.Component(newPath, data, type);
                components.Add(comp);
            }
            return(components);
        }
Beispiel #2
0
 public void AddData(string path, WebPage.Component component)
 {
     _data.Add(path.ToLower(), component);
 }