GitHunt
OM

omaray/gcloud-dotnet

Google Cloud Client Library for .NET

Google Cloud .NET Client

.NET idiomatic client libraries for Google Cloud Platform services.

Build Status

This client supports the following Google Cloud Platform services:

Note: This client is a work-in-progress, and may occasionally
make backwards-incompatible changes. The layout of the repository
is likely to change, and names (of everything - assemblies,
namespaces, types, members...) should be regarded as provisional.

If you need support for other Google APIs, check out the Google .NET API Client library.

Example Applications

Requirements

In order to build the code in this repository, you will need
to install DNVM. You do not need DNVM to use the code,
provided as NuGet packages.

Most projects in this repository require gRPC, which has a
component written in native code. Using that component from DNX
currently requires a workaround; on Windows please run fix_dnx_grpc.bat
before running any gRPC code.

Specifying a Project ID

Most gcloud-dotnet libraries require a project ID. If you don't remember yours (or haven't created a project yet), navigate to the Google Developers Console to view your project ID (or create a new project and get the ID then). Once done, record the value and make sure to pass it as a parameter to the methods that require it.

Authentication

Every API call needs to be authenticated. In order to successfully make a call, first ensure that the necessary Google Cloud APIs are enabled for your project and that you've downloaded the right set of keys (if it applies to you) as explained in the authentication document.

Next, choose a method for authenticating API requests from within your project:

  1. When using gcloud-dotnet libraries from within Compute/App Engine, no additional authentication steps are necessary.
  2. When using gcloud-dotnet libraries elsewhere, you can do one of the following:
    • Define the environment variable GOOGLE_APPLICATION_CREDENTIALS to be the location of the key. For example:

      set GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json
      
    • If running locally for development/testing, you can authenticate using the Google Cloud SDK. Download the SDK if you haven't already, then login by running the following in the command line:

      gcloud auth login
      

Google BigQuery

The BigQuery client library is in pre-release state and is more likely to have significant surface changes over time. Still, if you would like to experiment with it, we would welcome your feedback.

Installation

The package is available on Google's public MyGet feed, where you'll also find the right Package Source to add in Visual Studio. Once done, the package can be installed in the following manner:

PM> Install-Package Google.Bigquery.V2 -Prerelease

Example

using Google.Bigquery.V2;
...

var client = BigqueryClient.Create(projectId);

// Create the dataset if it doesn't exist.
var dataset = client.GetOrCreateDataset("mydata");

// Create the table if it doesn't exist.
var table = dataset.GetOrCreateTable("scores", new SchemaBuilder
{
    { "player", SchemaFieldType.String },
    { "gameStarted", SchemaFieldType.Timestamp },
    { "score", SchemaFieldType.Integer }
}.Build());

// Insert a single row. There are many other ways of inserting
// data into a table.
table.InsertRow(new Dictionary<string, object>
{
    { "player", "Bob" },
    { "score", 85 },
    { "gameStarted", new DateTime(2000, 1, 14, 10, 30, 0, DateTimeKind.Utc) }
});

Google Cloud Datastore

The Cloud Datastore client library is in pre-release state and is more likely to have significant surface changes over time. Still, if you would like to experiment with it, we would welcome your feedback.

Installation

The package is available on Google's public MyGet feed, where you'll also find the right Package Source to add in Visual Studio. Once done, the package can be installed in the following manner:

PM> Install-Package Google.Datastore.V1Beta3 -Prerelease

Example

using Google.Datastore.V1Beta3;
...

var client = DatastoreClient.Create();

var keyFactory = new KeyFactory(projectId, namespaceId, "message");
var entity = new Entity
{
    Key = keyFactory.CreateInsertionKey(),
    ["created"] = DateTime.UtcNow,
    ["text"] = "Text of the message"
};
var transaction = client.BeginTransaction(projectId).Transaction;
var commitResponse = client.Commit(projectId, Mode.TRANSACTIONAL, transaction, new[] { entity.ToInsert() });
var insertedKey = commitResponse.MutationResults[0].Key;

Google Cloud Logging

The Cloud Logging client library is in pre-release state and is more likely to have significant surface changes over time. Still, if you would like to experiment with it, we would welcome your feedback.

Installation

The package is available on Google's public MyGet feed, where you'll also find the right Package Source to add in Visual Studio. Once done, the package can be installed in the following manner:

PM> Install-Package Google.Logging.V2 -Prerelease

Example

using Google.Logging.V2;
...

Code coming soon

Google Cloud Pub/Sub

The Cloud Pub/Sub client library is in pre-release state and is more likely to have significant surface changes over time. Still, if you would like to experiment with it, we would welcome your feedback.

Installation

The package is available on Google's public MyGet feed, where you'll also find the right Package Source to add in Visual Studio. Once done, the package can be installed in the following manner:

PM> Install-Package Google.Pubsub.V1 -Prerelease

Example

using Google.Pubsub.V1;
...

Code coming soon...

Google Cloud Storage

The Cloud Storage client library is in a more advanced state. However, there is no guarantee that the API surface will stay stable until we reach 1.0 - but we have high confidence that the libraries work and are usable.

Installation

The package is available on NuGet and can be installed in the following manner:

PM> Install-Package Google.Storage.V1 -Prerelease

Example

using Google.Storage.V1;
...

var client = StorageClient.Create();

// Create a bucket
var bucketName = Guid.NewGuid().ToString(); // must be globally unique
var bucket = client.CreateBucket(projectId, bucketName);

// Upload some files
var content = Encoding.UTF8.GetBytes("hello, world");
var obj1 = client.UploadObject(bucketName, "file1.txt", "text/plain", new MemoryStream(content));
var obj2 = client.UploadObject(bucketName, "folder1/file2.txt", "text/plain", new MemoryStream(content));

// List objects
foreach (var obj in client.ListObjects(bucketName, ""))
{
    Console.WriteLine(obj.Name);
}

// Download file
using (var stream = File.OpenWrite("file1.txt"))
{
    client.DownloadObject(bucketName, "file1.txt", stream);
}

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information on how to get started.

Versioning

These libraries follow Semantic Versioning.

Anything with a major version of zero (0.y.z) should not be
considered stable - anything may change at any time.

License

Apache 2.0 - See LICENSE for more information.