< Summary

Information
Class: ValidateLib.UtilityClasses.IriUtilityClass
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\UtilityClasses\IriUtilityClass.cs
Line coverage
66%
Covered lines: 14
Uncovered lines: 7
Coverable lines: 21
Total lines: 58
Line coverage: 66.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\UtilityClasses\IriUtilityClass.cs

#LineLine coverage
 1namespace ValidateLib.UtilityClasses
 2{
 3    public class IriUtilityClass
 4    {
 5
 6        public static bool IsAbsoluteUrl(string iri)
 7        {
 8
 19            if (Uri.TryCreate(iri, UriKind.Absolute, out Uri? uri))
 10            {
 111                if (uri.Scheme == Uri.UriSchemeFile) return true;
 112                return !string.IsNullOrEmpty(uri.Scheme) && !string.IsNullOrEmpty(uri.Host);
 13            }
 114            return false;
 15        }
 16
 17        public static string PathToFileUrl(string filePath)
 18        {
 019            string url = Uri.EscapeUriString(filePath); // Escape special characters
 020            url = url.Replace("\\", "/"); // Use forward slashes
 021            url = "file://" + url;
 022            return url;
 23        }
 24
 25        public static string? GetMetadataLocation(string metadataUrlOrFilePath)
 26        {
 127            if (Uri.TryCreate(metadataUrlOrFilePath, UriKind.Absolute, out Uri uri) && (uri.Scheme == Uri.UriSchemeHttp 
 28            {
 129                return GetBaseUrlWithPath(metadataUrlOrFilePath);
 30            }
 031            return null;
 32        }
 33
 34        static string GetBaseUrlWithPath(string url)
 35        {
 136            Uri uri = new Uri(url);
 137            string baseUrlWithPath = $"{uri.Scheme}://{uri.Host}{Path.Combine("/", uri.AbsolutePath.TrimStart('/'))}";
 138            return baseUrlWithPath;
 39        }
 40
 41        public static bool IsRemoteIri(string iri)
 42        {
 43            try
 44            {
 145                Uri uri = new Uri(iri);
 146                if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
 147                    return true;
 48                else
 149                    return false;
 50            }
 051            catch (Exception)
 52            {
 053                return false;
 54            }
 55
 156        }
 57    }
 58}