Example #1
0
        /// <summary>
        /// Collect resource from the subpath
        /// </summary>
        /// <param name="SubPath"></param>
        /// <param name="FileExtension"></param>
        /// <returns></returns>
        public List <string> collectResources(string SubPath, string FileExtension)
        {
            var name = Paths.BeginWhack(Paths.CombinePaths(Root, SubPath));
            var list = (from r in _resources
                        where r.getPath().ToLower().Equals(name.ToLower()) && (r.Extension.ToLower() == FileExtension.ToLower() || FileExtension == "*.*" || String.IsNullOrEmpty(FileExtension))
                        select r).ToList();

            var maxlist = new List <FileResource>();

            foreach (var resource in list)
            {
                var item = maxlist.FirstOrDefault(m => m.Name == resource.Name);
                if (item == null)
                {
                    maxlist.Add(resource);
                }
                else
                {
                    if (resource.Version > item.Version)
                    {
                        item.Version      = resource.Version;
                        item.RelativeName = resource.RelativeName;
                        item.Name         = resource.Name;
                    }
                }
            }

            // select Utility.Paths.CombinePaths(_root, r.FullName)
            var result = maxlist.Select(s => s.RelativeName);

            return(result.ToList());
        }
Example #2
0
        public static FileResources getFileResources(List <String> Resources, String Host, String Root)
        {
            List <FileResource> resources = new List <FileResource>();

            foreach (String s in Resources)
            {
                if (String.IsNullOrEmpty(Path.GetFileName(s)))
                {
                    continue;
                }

                var    regobj  = Regex.Match(Path.GetFileName(s), @"(\.\d{1,3})?(\.[a-zA-Z]{1,4})$");
                string name    = Path.GetFileName(s);
                int    version = 0;
                // Version + File Extension Match
                if (regobj.Groups[1].Success && regobj.Groups[2].Success)
                {
                    int.TryParse(regobj.Groups[1].Value.Substring(1), out version);
                    name = String.Format("{0}{1}", Path.GetFileName(s).Substring(0, regobj.Groups[1].Index), Path.GetExtension(s));
                }

                FileResource fr;
                resources.Add(fr = new FileResource()
                {
                    RelativeName = Paths.BeginWhack(s),
                    Extension    = Path.GetExtension(s),
                    Name         = name,
                    Host         = Host,
                    Version      = version
                });
            }
            return(new FileResources(resources, Host, Root));
        }
Example #3
0
        internal static void recurseResources(List <FileResource> resources, DirectoryObj DirObj, String Host)
        {
            foreach (var d in DirObj.DirectoryInfo.GetDirectories())
            {
                recurseResources(resources, new DirectoryObj()
                {
                    Root = DirObj.Root, DirectoryInfo = d
                }, Host);
            }

            foreach (var f in DirObj.DirectoryInfo.GetFiles())
            {
                int    version = 0;
                string name;
                var    regobj      = Regex.Match(f.FullName, @"(\.\d{1,3})?(\.[a-zA-Z]{1,4})$");
                var    newresource = new FileResource();

                // Version + File Extension Match
                if (regobj.Groups[1].Success && regobj.Groups[2].Success)
                {
                    int.TryParse(regobj.Groups[1].Value.Substring(1), out version);
                    newresource.Version = version;
                    // strip version from fullname
                    name = String.Format("{0}{1}", f.FullName.Substring(0, regobj.Groups[1].Index), f.Extension);
                }
                else
                {
                    name = f.FullName;
                }

                resources.Add(new FileResource()
                {
                    RelativeName = Paths.BeginWhack(f.FullName.Substring(DirObj.Root.Length).ToLower().Replace("\\", "/")),
                    Name         = name,
                    Host         = Host,
                    Extension    = Path.GetExtension(f.FullName.ToLower()),
                    Version      = version
                });
            }
        }