Esempio n. 1
0
        public static bool TryFrom(string folder, string name, out FileResource resource, bool extensionOptional = false)
        {
            resource = FileName.TryFrom(name, out var parsedName, extensionOptional)
        ? new FileResource(FolderResource.From(folder), parsedName)
        : null;

            return(resource != null);
        }
Esempio n. 2
0
        public static IOResource From(string value, bool strict = true)
        {
            var resource = FileResource.From(value, strict: false) ?? FolderResource.From(value, strict: false) as IOResource;

            ExpectNot(strict && resource == null, "Value is not an I/O resource");

            return(resource);
        }
Esempio n. 3
0
        public static bool TryFrom(string value, out IOResource resource)
        {
            if (FileResource.TryFrom(value, out var file))
            {
                resource = file;
            }
            else
            {
                resource = FolderResource.From(value);
            }

            return(resource != null);
        }
Esempio n. 4
0
        public static FolderLink FromLocal(string value, bool strict = true)
        {
            var parsedFolder = FolderResource.From(value, strict);

            if (parsedFolder != null && parsedFolder.Path.Segments.Count > 0)
            {
                var path = parsedFolder.Path.Segments.Count == 1
                                        ? LinkPath.Root
                                        : LinkPath.From(parsedFolder.Path.Segments.Skip(1));

                return(new FolderLink(parsedFolder.Path.Segments[0], FolderResource.From(path)));
            }

            Expect(strict, "Cannot parse folder link: " + value);

            return(null);
        }
Esempio n. 5
0
        public static bool TryFromLocal(string value, out FolderLink link)
        {
            link = null;

            var path = FolderResource.From(value).Path;

            if (path.Segments.Any())
            {
                var root = path.Segments[0];

                var resource = path.Segments.Count == 1
          ? LinkPath.Root
          : LinkPath.From(path.Segments.Skip(1));

                link = new FolderLink(root, FolderResource.From(resource));
            }

            return(link != null);
        }
Esempio n. 6
0
        public static bool TryFromUnc(string value, out FolderLink link)
        {
            link = null;

            if (!String.IsNullOrEmpty(value) && HasUncPrefix(value))
            {
                var path = FolderResource.From(value.Substring(2)).Path;

                var root = $@"\\{path.Segments[0]}";

                var resource = path.Segments.Count == 1
          ? LinkPath.Root
          : LinkPath.From(path.Segments.Skip(1));

                link = new FolderLink(root, FolderResource.From(resource), isUnc: true);
            }

            return(link != null);
        }
Esempio n. 7
0
        public static FolderLink FromUnc(string value, bool strict = true)
        {
            if (!String.IsNullOrEmpty(value) && value.StartsWith(@"\\"))
            {
                var parsedFolder = FolderResource.From(value.Substring(2), strict);

                if (parsedFolder != null)
                {
                    var root = @"\\" + parsedFolder.Path.Segments[0].ToString();

                    var path = parsedFolder.Path.Segments.Count == 1
                                                ? LinkPath.Root
                                                : LinkPath.From(parsedFolder.Path.Segments.Skip(1));

                    return(new FolderLink(root, FolderResource.From(path), isUnc: true));
                }
            }

            ExpectNot(strict, "Cannot parse UNC link: " + value);

            return(null);
        }
Esempio n. 8
0
        public static bool TryFrom(string value, out FileResource resource, bool extensionOptional = false)
        {
            resource = null;

            var parsedFolder = FolderResource.From(value);

            var file = parsedFolder.Path.Segments.LastOrDefault()?.ToString();

            if (file != null)
            {
                if (FileName.TryFrom(file, out var parsedFile, extensionOptional))
                {
                    if (!parsedFolder.TryUp(out var folderUp))
                    {
                        folderUp = parsedFolder;
                    }

                    resource = new FileResource(folderUp, parsedFile);
                }
            }

            return(resource != null);
        }
Esempio n. 9
0
        public new static FileResource From(string value, bool strict = true)
        {
            var parsedFolder = FolderResource.From(value, strict);

            if (parsedFolder != null)
            {
                var fileSegment = parsedFolder.Path.Segments.LastOrDefault();

                if (fileSegment != null)
                {
                    var parsedName = FileName.From(fileSegment.ToString(), strict);

                    if (parsedName != null)
                    {
                        return(new FileResource(parsedFolder.Up(strict: false), parsedName));
                    }
                }
            }

            ExpectNot(strict, "Cannot parse file resource");

            return(null);
        }
Esempio n. 10
0
 public static FileResource From(string folder, FileName name) =>
 From(FolderResource.From(folder), name);
Esempio n. 11
0
        public static FileResource From(string folder, string name, bool strict = true)
        {
            var parsedFolder = FolderResource.From(folder, strict);

            return(parsedFolder == null ? null : From(parsedFolder, name, strict));
        }
Esempio n. 12
0
        public static bool TryFrom(LinkText root, string resource, out FolderLink link)
        {
            link = From(root, FolderResource.From(resource));

            return(true);
        }
Esempio n. 13
0
        public static FolderLink From(LinkText root, string resource, bool strict = true)
        {
            var parsedResource = FolderResource.From(resource, strict);

            return(parsedResource == null ? null : From(root, resource));
        }