From 1b4f5bf782a50eb9aee02fbaddb415fc5dbb56e9 Mon Sep 17 00:00:00 2001 From: femsci Date: Thu, 7 Dec 2023 16:50:10 +0100 Subject: [PATCH] skel --- .gitignore | 2 ++ Nyanlabs.Pubresolv.sln | 27 ++++++++++++++ README.md | 3 ++ src/Nyanlabs.Pubresolv/Doi.cs | 36 +++++++++++++++++++ src/Nyanlabs.Pubresolv/IResolver.cs | 6 ++++ .../Nyanlabs.Pubresolv.csproj | 9 +++++ src/Nyanlabs.Pubresolv/Pubresolv.cs | 9 +++++ 7 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100644 Nyanlabs.Pubresolv.sln create mode 100644 README.md create mode 100644 src/Nyanlabs.Pubresolv/Doi.cs create mode 100644 src/Nyanlabs.Pubresolv/IResolver.cs create mode 100644 src/Nyanlabs.Pubresolv/Nyanlabs.Pubresolv.csproj create mode 100644 src/Nyanlabs.Pubresolv/Pubresolv.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afec7c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/obj/ +**/bin/ diff --git a/Nyanlabs.Pubresolv.sln b/Nyanlabs.Pubresolv.sln new file mode 100644 index 0000000..8f18253 --- /dev/null +++ b/Nyanlabs.Pubresolv.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{66E15B3B-99D3-4443-A623-359B0C4EEBD6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyanlabs.Pubresolv", "src\Nyanlabs.Pubresolv\Nyanlabs.Pubresolv.csproj", "{1F6A79FC-2745-4421-B329-A956E4B9E671}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1F6A79FC-2745-4421-B329-A956E4B9E671}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F6A79FC-2745-4421-B329-A956E4B9E671}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F6A79FC-2745-4421-B329-A956E4B9E671}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F6A79FC-2745-4421-B329-A956E4B9E671}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {1F6A79FC-2745-4421-B329-A956E4B9E671} = {66E15B3B-99D3-4443-A623-359B0C4EEBD6} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md new file mode 100644 index 0000000..b054aaf --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# pubresolv + +Scientific document resolver for academic proxies diff --git a/src/Nyanlabs.Pubresolv/Doi.cs b/src/Nyanlabs.Pubresolv/Doi.cs new file mode 100644 index 0000000..6fa9566 --- /dev/null +++ b/src/Nyanlabs.Pubresolv/Doi.cs @@ -0,0 +1,36 @@ +using System.Diagnostics.CodeAnalysis; +using System.Text.RegularExpressions; + +namespace Nyanlabs.Pubresolv; + +public readonly struct Doi +{ + public Doi(string doi) + { + var match = Regex.Match(doi, @"^10\.(?\d{4})\/(?.*)$", RegexOptions.Compiled); + try + { + Prefix = short.Parse(match.Groups["prefix"].Value); + Suffix = match.Groups["suffix"].Value; + } + catch (Exception) + { + throw new ArgumentException($"Invalid DOI string: {doi}"); + } + } + + public short Prefix { get; } + public string Suffix { get; } + + public override readonly string ToString() => $"10.{Prefix}/{Suffix}"; + public override readonly bool Equals([NotNullWhen(true)] object? obj) + { + return obj is Doi doi && doi.Prefix == Prefix && doi.Suffix == Suffix; + } + + public static bool operator ==(Doi left, Doi right) => left.Equals(right); + + public static bool operator !=(Doi left, Doi right) => !(left == right); + + public override int GetHashCode() => HashCode.Combine(Prefix, Suffix); +} diff --git a/src/Nyanlabs.Pubresolv/IResolver.cs b/src/Nyanlabs.Pubresolv/IResolver.cs new file mode 100644 index 0000000..7200099 --- /dev/null +++ b/src/Nyanlabs.Pubresolv/IResolver.cs @@ -0,0 +1,6 @@ +namespace Nyanlabs.Pubresolv; + +public interface IResolver +{ + public Task Resolve(Doi doi); +} diff --git a/src/Nyanlabs.Pubresolv/Nyanlabs.Pubresolv.csproj b/src/Nyanlabs.Pubresolv/Nyanlabs.Pubresolv.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/src/Nyanlabs.Pubresolv/Nyanlabs.Pubresolv.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/src/Nyanlabs.Pubresolv/Pubresolv.cs b/src/Nyanlabs.Pubresolv/Pubresolv.cs new file mode 100644 index 0000000..ca7fd1c --- /dev/null +++ b/src/Nyanlabs.Pubresolv/Pubresolv.cs @@ -0,0 +1,9 @@ +namespace Nyanlabs.Pubresolv; + +public class Pubresolv +{ + public ICollection GetResolvers() + { + throw new NotImplementedException(); + } +}