Google Cloud Libraries for .NET

repository·main·Indexed 22 days ago

https://github.com/googleapis/google-cloud-dotnet

Idiomatic .NET client libraries for Google Cloud Platform services, providing NuGet packages for various APIs including BigQuery, Cloud Logging, Cloud Storage, Compute Engine, and Vertex AI. The repository includes tools for running benchmarks, integration testing, and a console formatter for ASP.NET Core logging.

Tokens
84.7K
Snippets
216
Records
369
Agent score
74%

What's inside google-cloud-dotnet

  1. Overview of Google Cloud Libraries for .NET

    main
    Google Cloud Libraries for .NET provide idiomatic client libraries for interacting with Google Cloud Platform services within the .NET ecosystem. These libraries are designed to follow .NET patterns and best practices, making it easier for developers to integrate Google Cloud services into their applications.
  2. Getting started with Google Cloud Datastore for .NET

    main

    To work with Google Cloud Datastore in .NET, use the DatastoreDb class. DatastoreDb acts as a high-level wrapper around DatastoreClient, simplifying operations by assuming all actions occur on the same partition and providing built-in support for page streaming on structured query results.

    For a full introduction with runnable code samples, refer to the Datastore Quickstart.

  3. Getting started with Google Cloud Translation V2

    main

    The Google.Cloud.Translation.V2 library provides a high-level wrapper around the Google.Apis.Translate.v2 generated library. It simplifies translation tasks through two primary client classes:

    • TranslationClient: For standard translation operations.
    • AdvancedTranslationClient: For more advanced features or specific model requirements.

    Authentication is primarily handled via OAuth2, though API key authentication is supported for migration purposes.

  4. Use Google.Cloud.Logging.Console for ASP.NET Core logging

    main
    Google.Cloud.Logging.Console is a console formatter that outputs log entries as JSON using the schema expected by Google Cloud Logging. It is designed to be a lightweight, non-invasive way to integrate logging when running ASP.NET Core (or any framework using Microsoft.Extensions.Logging) on Google Cloud Platform. By using this formatter, your console logs are automatically parsed into structured logs in Google Cloud Logging.
  5. Available Google Cloud .NET Packages

    main

    The following NuGet packages are available for use in .NET projects. You can find the latest versions and documentation via the provided links.

    | Package | Latest version | Description |
    |---------|----------------|-------------|
    | [Google.Test.V1](https://googleapis.dev/dotnet/Google.Test.V1/latest) | [![NuGet](https://img.shields.io/nuget/v/Google.Test.V1)](https://nuget.org/packages/Google.Test.V1) | [Test Product](https://google.com) |
    | [Google.Test.V2](https://googleapis.dev/dotnet/Google.Test.V2/latest) | [![NuGet](https://img.shields.io/nuget/v/Google.Test.V2)](https://nuget.org/packages/Google.Test.V2) | [Test Product 2](https://google.com) |
  6. Handle timestamp projections in Datastore queries

    main

    When performing a query that includes a projection, any timestamp fields are returned as integer values. To correctly convert these back into usable .NET types, use the following conversion methods on the Value object:

    • Value.ToDateTimeFromProjection(): Converts integer or timestamp values to DateTime.
    • Value.ToDateTimeOffsetFromProjection(): Converts integer or timestamp values to DateTimeOffset.
  7. Manage the lifecycle of Translation clients

    main

    When using TranslationClient or AdvancedTranslationClient, it is highly recommended to reuse a single client object throughout your application's lifecycle.

    While you can create clients frequently, doing so can lead to issues with memory and network connection usage. If your architecture requires frequent creation of new client objects, ensure you explicitly dispose of them to facilitate timely resource clean-up.

  8. Specify a field mask in Google Maps Places V1 requests

    main

    Many methods in the Google Maps Places V1 API require a field mask to determine which specific fields are returned in the response. This helps optimize performance and reduce payload size.

    To specify a field mask in the .NET client library, you must include the mask in the CallSettings object passed to the method call. To return all available fields, use the wildcard character * as the field mask value.

    // Example of using CallSettings to specify a field mask
    // Replace 'field_name_1,field_name_2' with the actual fields you want to retrieve
    var callSettings = new CallSettings
    {
        Header = new Dictionary<string, string>
        {
            { "x-goog-fieldmask", "field_name_1,field_name_2" }
        }
    };
    
    // Use the callSettings when calling a method on the PlacesClient
    // var response = client.SomeMethod(request, callSettings);
  9. Identify BigQuery entities using References

    main

    The canonical way to identify entities in the BigQuery API is through specific reference objects. This ensures type safety and consistency when performing operations. Common reference types include:

    • DatasetReference
    • JobReference
    • TableReference
    • ProjectReference

    You can construct these references manually, via the BigQueryClient, or through a parent entity (for example, using BigQueryDataset.GetTableReference to get a reference to a table within that dataset).