Example #1
0
        public static ItemLocation FromRelativeFilePath(string file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (!file.StartsWith(Path.DirectorySeparatorChar.ToString()))
            {
                throw new ArgumentException($"path: {file} does not start with {Path.DirectorySeparatorChar}");
            }

            string fileName            = Path.GetFileName(file);
            string folderPath          = Path.GetDirectoryName(file);
            IEnumerable <string> paths = folderPath.Split(Path.DirectorySeparatorChar);

            return(ItemLocation.FromFolderTree(paths).SetName(fileName));
        }
Example #2
0
        public static IEnumerable <ItemLocation> GetDistinctFolders(IEnumerable <ItemLocation> locations)
        {
            //TODO: Tests


            List <ItemLocation> ret = new List <ItemLocation>();

            foreach (var loc in locations)
            {
                List <string> folders = new List <string>();
                foreach (string folder in loc.Folders)
                {
                    folders.Add(folder);
                    ItemLocation l = ItemLocation.FromFolderTree(folders);
                    if (!ret.Contains(l))
                    {
                        ret.Add(l);
                    }
                }
            }

            return(ret);
        }