13/05/20 23:04
dylan666
Volevo provare a usare del codice per sfruttare le API di Google Cloud che però è disponibile solo in C# mentre se fosse possibile vorrei portarlo in VB.NET
Il codice è brevissimo e sono riuscito a convertirlo tutto (anche semplificandolo per il mio modo di vedere) e solo UNA riga non mi torna.
Il sorgente sta qui:
github.com/GoogleCloudPlatform/dotnet-docs-samples/blob/master/dlp/api/DlpSample/…
Il l'ho modificato in questo (lo so, i WITH erano più eleganti ma preferisco non usarlo per adesso)
La parte incriminata è la riga di InfoTypes.
Visual studio suggerisce questo:
ReadOnly Property InspectConfig.InfoTypes As Collections.RepeatedField(Of InfoType)
Restricts what info_types to look for. The values must correspond to InfoType values returned by ListlnfoTypes or listed at cloud.google.com/dlp/docs/…. When no InfoTypes or CustomInfoTypes are specified in a request, the system may automatically choose what detectors to run. By
default this may be all types, but may change over time as detectors are updated. If you need precise control and predictability as to what detectors are run you should specify specific InfoTypes listed in the reference, otherwise a default list will be used, which may change over time.
Cosa mi consigliate
Il codice è brevissimo e sono riuscito a convertirlo tutto (anche semplificandolo per il mio modo di vedere) e solo UNA riga non mi torna.
Il sorgente sta qui:
github.com/GoogleCloudPlatform/dotnet-docs-samples/blob/master/dlp/api/DlpSample/…
Il l'ho modificato in questo (lo so, i WITH erano più eleganti ma preferisco non usarlo per adesso)
Imports System.IO Imports Google.Api.Gax.ResourceNames Imports Google.Cloud.Dlp.V2 Imports Google.Protobuf Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click RedactFromImage("PROJECT-NAME-######", "C:\tmp\ID.jpg", "C:\tmp\ID3.jpg") End Sub Function RedactFromImage(ByVal projectId As String, ByVal originalImagePath As String, ByVal redactedImagePath As String) As Object Dim request = New RedactImageRequest request.ParentAsProjectName = New ProjectName(projectId) request.InspectConfig = New InspectConfig request.InspectConfig.MinLikelihood = Likelihood.Likely request.InspectConfig.Limits = New InspectConfig.Types.FindingLimits() request.InspectConfig.Limits.MaxFindingsPerItem = 5 request.InspectConfig.IncludeQuote = True request.InspectConfig.InfoTypes(Name{"PERSON_NAME"}) request.ByteItem = New ByteContentItem request.ByteItem.Type = ByteContentItem.Types.BytesType.ImagePng request.ByteItem.Data = ByteString.FromStream(New FileStream(originalImagePath, FileMode.Open)) Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "C:\tmp\PROJECT-NAME-######.json") Dim client As DlpServiceClient = DlpServiceClient.Create() Dim response = client.RedactImage(request) Console.WriteLine($"Extracted text: {response.ExtractedText}") ' Writes redacted image into file response.RedactedImage.WriteTo(New FileStream(redactedImagePath, FileMode.Create, FileAccess.Write)) Return 0 End Function End Class
La parte incriminata è la riga di InfoTypes.
Visual studio suggerisce questo:
ReadOnly Property InspectConfig.InfoTypes As Collections.RepeatedField(Of InfoType)
Restricts what info_types to look for. The values must correspond to InfoType values returned by ListlnfoTypes or listed at cloud.google.com/dlp/docs/…. When no InfoTypes or CustomInfoTypes are specified in a request, the system may automatically choose what detectors to run. By
default this may be all types, but may change over time as detectors are updated. If you need precise control and predictability as to what detectors are run you should specify specific InfoTypes listed in the reference, otherwise a default list will be used, which may change over time.
Cosa mi consigliate
aaa