Skip to content

Commit 48974bc

Browse files
committed
dotnet10
1 parent 8c27e8a commit 48974bc

File tree

9 files changed

+130
-75
lines changed

9 files changed

+130
-75
lines changed

Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFramework>net9.0</TargetFramework>
4-
<LangVersion>13</LangVersion>
3+
<TargetFramework>net10.0</TargetFramework>
4+
<LangVersion>14</LangVersion>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<EnableNETAnalyzers>true</EnableNETAnalyzers>
@@ -22,8 +22,8 @@
2222
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2323
<PackageReadmeFile>README.md</PackageReadmeFile>
2424
<Product>Managed Code - MarkItDown</Product>
25-
<Version>0.0.7</Version>
26-
<PackageVersion>0.0.7</PackageVersion>
25+
<Version>10.0.0</Version>
26+
<PackageVersion>10.0.0</PackageVersion>
2727
</PropertyGroup>
2828

2929
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">

Directory.Packages.props

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
<Project>
22
<ItemGroup>
3-
<PackageVersion Include="AngleSharp" Version="1.3.0" />
4-
<PackageVersion Include="AWSSDK.Rekognition" Version="4.0.2.8" />
5-
<PackageVersion Include="AWSSDK.S3" Version="4.0.7.10" />
6-
<PackageVersion Include="AWSSDK.Textract" Version="4.0.2.8" />
7-
<PackageVersion Include="AWSSDK.TranscribeService" Version="4.0.4" />
3+
<PackageVersion Include="AngleSharp" Version="1.3.1" />
4+
<PackageVersion Include="AWSSDK.Rekognition" Version="4.0.3.2" />
5+
<PackageVersion Include="AWSSDK.S3" Version="4.0.11.1" />
6+
<PackageVersion Include="AWSSDK.Textract" Version="4.0.3.2" />
7+
<PackageVersion Include="AWSSDK.TranscribeService" Version="4.0.4.5" />
88
<PackageVersion Include="Azure.AI.FormRecognizer" Version="4.1.0" />
99
<PackageVersion Include="Azure.AI.OpenAI" Version="2.1.0" />
1010
<PackageVersion Include="Azure.AI.Vision.ImageAnalysis" Version="1.0.0" />
11-
<PackageVersion Include="Azure.Storage.Blobs" Version="12.25.0" />
11+
<PackageVersion Include="Azure.Storage.Blobs" Version="12.26.0" />
1212
<PackageVersion Include="Azure.Identity" Version="1.17.0" />
1313
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
1414
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.3.0" />
1515
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="1.2.25" />
16-
<PackageVersion Include="Google.Cloud.DocumentAI.V1" Version="3.22.0" />
17-
<PackageVersion Include="Google.Cloud.Speech.V1" Version="3.8.0" />
18-
<PackageVersion Include="Google.Cloud.Vision.V1" Version="3.7.0" />
19-
<PackageVersion Include="ManagedCode.MimeTypes" Version="1.0.5" />
20-
<PackageVersion Include="ManagedCode.Storage.Aws" Version="9.2.1" />
21-
<PackageVersion Include="ManagedCode.Storage.Azure" Version="9.2.1" />
22-
<PackageVersion Include="ManagedCode.Storage.Core" Version="9.2.1" />
23-
<PackageVersion Include="ManagedCode.Storage.FileSystem" Version="9.2.1" />
24-
<PackageVersion Include="ManagedCode.Storage.Gcp" Version="9.2.1" />
25-
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.10.0" />
16+
<PackageVersion Include="Google.Cloud.DocumentAI.V1" Version="3.23.0" />
17+
<PackageVersion Include="Google.Cloud.Speech.V1" Version="3.9.0" />
18+
<PackageVersion Include="Google.Cloud.Vision.V1" Version="3.8.0" />
19+
<PackageVersion Include="ManagedCode.MimeTypes" Version="1.0.7" />
20+
<PackageVersion Include="ManagedCode.Storage.Aws" Version="10.0.0" />
21+
<PackageVersion Include="ManagedCode.Storage.Azure" Version="10.0.0" />
22+
<PackageVersion Include="ManagedCode.Storage.Core" Version="10.0.0" />
23+
<PackageVersion Include="ManagedCode.Storage.FileSystem" Version="10.0.0" />
24+
<PackageVersion Include="ManagedCode.Storage.Gcp" Version="10.0.0" />
25+
<PackageVersion Include="Microsoft.Extensions.AI" Version="10.0.0" />
2626
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.9.1-preview.1.25474.6" />
27-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.10" />
28-
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.10" />
29-
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.10" />
30-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
27+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
28+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
29+
<PackageVersion Include="Microsoft.Extensions.Options" Version="10.0.0" />
30+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
3131
<PackageVersion Include="MimeKit" Version="4.14.0" />
3232
<PackageVersion Include="Moq" Version="4.20.72" />
3333
<PackageVersion Include="PdfPig" Version="0.1.11" />
3434
<PackageVersion Include="PDFtoImage" Version="5.1.1" />
35-
<PackageVersion Include="Sep" Version="0.11.2" />
35+
<PackageVersion Include="Sep" Version="0.11.5" />
3636
<PackageVersion Include="Shouldly" Version="4.3.0" />
37-
<PackageVersion Include="Testcontainers.Azurite" Version="4.7.0" />
37+
<PackageVersion Include="Testcontainers.Azurite" Version="4.8.1" />
3838
<PackageVersion Include="SkiaSharp" Version="3.119.1" />
39-
<PackageVersion Include="Spectre.Console" Version="0.51.1" />
40-
<PackageVersion Include="System.Text.Encoding.CodePages" Version="9.0.10" />
41-
<PackageVersion Include="System.Text.Json" Version="9.0.10" />
42-
<PackageVersion Include="YoutubeExplode" Version="6.5.5" />
39+
<PackageVersion Include="Spectre.Console" Version="0.53.0" />
40+
<PackageVersion Include="YoutubeExplode" Version="6.5.6" />
4341
<PackageVersion Include="xunit" Version="2.9.3" />
44-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
42+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
4543
</ItemGroup>
4644
</Project>

src/MarkItDown.Cli/MarkItDown.Cli.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
65
<ImplicitUsings>enable</ImplicitUsings>
76
<Nullable>enable</Nullable>
87
<RuntimeIdentifiers>win-x64;linux-x64;osx-arm64</RuntimeIdentifiers>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using Google.Apis.Auth.OAuth2;
6+
7+
namespace MarkItDown.Intelligence.Providers.Google;
8+
9+
internal static class GoogleCredentialResolver
10+
{
11+
private static readonly Type GoogleCredentialInterfaceType = typeof(GoogleCredential)
12+
.Assembly
13+
.GetType("Google.Apis.Auth.OAuth2.IGoogleCredential", throwOnError: true)!;
14+
15+
private static readonly MethodInfo FromJsonGenericDefinition = typeof(CredentialFactory)
16+
.GetMethods(BindingFlags.Public | BindingFlags.Static)
17+
.Single(m => m.Name == nameof(CredentialFactory.FromJson) && m.IsGenericMethodDefinition && m.GetParameters().Length == 1);
18+
19+
private static readonly MethodInfo FromFileGenericDefinition = typeof(CredentialFactory)
20+
.GetMethods(BindingFlags.Public | BindingFlags.Static)
21+
.Single(m => m.Name == nameof(CredentialFactory.FromFile) && m.IsGenericMethodDefinition && m.GetParameters().Length == 1);
22+
23+
private static readonly MethodInfo FromJsonConcrete = FromJsonGenericDefinition.MakeGenericMethod(GoogleCredentialInterfaceType);
24+
private static readonly MethodInfo FromFileConcrete = FromFileGenericDefinition.MakeGenericMethod(GoogleCredentialInterfaceType);
25+
26+
private static readonly MethodInfo ToGoogleCredentialMethod = GoogleCredentialInterfaceType
27+
.GetMethod("ToGoogleCredential", BindingFlags.Public | BindingFlags.Instance)!;
28+
29+
public static GoogleCredential? Resolve(
30+
GoogleCredential? explicitCredential,
31+
string? jsonCredentials,
32+
string? credentialsPath,
33+
IReadOnlyList<string>? scopes)
34+
{
35+
var credential = explicitCredential
36+
?? (!string.IsNullOrWhiteSpace(jsonCredentials) ? CreateFromJson(jsonCredentials) : null)
37+
?? (!string.IsNullOrWhiteSpace(credentialsPath) ? CreateFromFile(credentialsPath) : null);
38+
39+
if (credential is null)
40+
{
41+
return null;
42+
}
43+
44+
if (scopes is { Count: > 0 } && credential.IsCreateScopedRequired)
45+
{
46+
credential = credential.CreateScoped(scopes);
47+
}
48+
49+
return credential;
50+
}
51+
52+
private static GoogleCredential CreateFromJson(string json)
53+
{
54+
var result = FromJsonConcrete.Invoke(null, new object[] { json }) ?? throw new InvalidOperationException("Failed to parse Google credentials JSON.");
55+
return ConvertToGoogleCredential(result);
56+
}
57+
58+
private static GoogleCredential CreateFromFile(string path)
59+
{
60+
var result = FromFileConcrete.Invoke(null, new object[] { path }) ?? throw new InvalidOperationException("Failed to load Google credential file.");
61+
return ConvertToGoogleCredential(result);
62+
}
63+
64+
private static GoogleCredential ConvertToGoogleCredential(object instance)
65+
{
66+
var credential = ToGoogleCredentialMethod.Invoke(instance, Array.Empty<object>());
67+
return credential as GoogleCredential ?? throw new InvalidOperationException("Unable to convert Google credential.");
68+
}
69+
}

src/MarkItDown/Intelligence/Providers/Google/GoogleDocumentIntelligenceProvider.cs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,15 @@ public GoogleDocumentIntelligenceProvider(GoogleDocumentIntelligenceOptions opti
5454
Endpoint = $"{options.Location}-documentai.googleapis.com"
5555
};
5656

57-
if (options.Credential is not null)
58-
{
59-
builder.Credential = options.Credential;
60-
}
61-
else if (!string.IsNullOrWhiteSpace(options.JsonCredentials))
62-
{
63-
builder.JsonCredentials = options.JsonCredentials;
64-
}
65-
else if (!string.IsNullOrWhiteSpace(options.CredentialsPath))
57+
var credential = GoogleCredentialResolver.Resolve(
58+
options.Credential,
59+
options.JsonCredentials,
60+
options.CredentialsPath,
61+
DocumentProcessorServiceClient.DefaultScopes);
62+
63+
if (credential is not null)
6664
{
67-
builder.CredentialsPath = options.CredentialsPath;
65+
builder.Credential = credential;
6866
}
6967

7068
_client = builder.Build();
@@ -163,17 +161,15 @@ private DocumentProcessorServiceClient ResolveClient(GoogleDocumentIntelligenceO
163161
Endpoint = overrides.Endpoint
164162
};
165163

166-
if (_options.Credential is not null)
167-
{
168-
builder.Credential = _options.Credential;
169-
}
170-
else if (!string.IsNullOrWhiteSpace(_options.JsonCredentials))
171-
{
172-
builder.JsonCredentials = _options.JsonCredentials;
173-
}
174-
else if (!string.IsNullOrWhiteSpace(_options.CredentialsPath))
164+
var credential = GoogleCredentialResolver.Resolve(
165+
_options.Credential,
166+
_options.JsonCredentials,
167+
_options.CredentialsPath,
168+
DocumentProcessorServiceClient.DefaultScopes);
169+
170+
if (credential is not null)
175171
{
176-
builder.CredentialsPath = _options.CredentialsPath;
172+
builder.Credential = credential;
177173
}
178174

179175
return builder.Build();

src/MarkItDown/Intelligence/Providers/Google/GoogleImageUnderstandingProvider.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ public GoogleImageUnderstandingProvider(GoogleVisionOptions options, ImageAnnota
3232
{
3333
var builder = new ImageAnnotatorClientBuilder();
3434

35-
if (options.Credential is not null)
36-
{
37-
builder.Credential = options.Credential;
38-
}
39-
else if (!string.IsNullOrWhiteSpace(options.JsonCredentials))
40-
{
41-
builder.JsonCredentials = options.JsonCredentials;
42-
}
43-
else if (!string.IsNullOrWhiteSpace(options.CredentialsPath))
35+
var credential = GoogleCredentialResolver.Resolve(
36+
options.Credential,
37+
options.JsonCredentials,
38+
options.CredentialsPath,
39+
ImageAnnotatorClient.DefaultScopes);
40+
41+
if (credential is not null)
4442
{
45-
builder.CredentialsPath = options.CredentialsPath;
43+
builder.Credential = credential;
4644
}
4745

4846
_client = builder.Build();

src/MarkItDown/Intelligence/Providers/Google/GoogleMediaTranscriptionProvider.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ public GoogleMediaTranscriptionProvider(GoogleMediaIntelligenceOptions options,
3434
{
3535
var builder = new SpeechClientBuilder();
3636

37-
if (options.Credential is not null)
38-
{
39-
builder.Credential = options.Credential;
40-
}
41-
else if (!string.IsNullOrWhiteSpace(options.JsonCredentials))
42-
{
43-
builder.JsonCredentials = options.JsonCredentials;
44-
}
45-
else if (!string.IsNullOrWhiteSpace(options.CredentialsPath))
37+
var credential = GoogleCredentialResolver.Resolve(
38+
options.Credential,
39+
options.JsonCredentials,
40+
options.CredentialsPath,
41+
SpeechClient.DefaultScopes);
42+
43+
if (credential is not null)
4644
{
47-
builder.CredentialsPath = options.CredentialsPath;
45+
builder.Credential = credential;
4846
}
4947

5048
_client = builder.Build();

src/MarkItDown/MarkItDown.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
<PackageReference Include="Azure.AI.FormRecognizer" />
2828
<PackageReference Include="Azure.AI.Vision.ImageAnalysis" />
2929
<PackageReference Include="Azure.Identity" />
30-
<PackageReference Include="System.Text.Json" />
3130
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
3231
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
3332
<PackageReference Include="Microsoft.Extensions.Options" />
34-
<PackageReference Include="System.Text.Encoding.CodePages" />
3533

3634
<!-- PDF Support -->
3735
<PackageReference Include="PdfPig" />

tests/MarkItDown.Cli.Tests/MarkItDown.Cli.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
76
<IsPackable>false</IsPackable>

0 commit comments

Comments
 (0)