This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

Extension ID

com.castsoftware.dotnet.gcp

What's new

See GCP .NET - 1.0 - Release Notes.

In what situation should you install this extension?

This extension should be used for analyzing .NET source code using any of the supported Google Cloud Platform Bigtable and CloudStorage services. 

Supported services and frameworks

Framework →

Services 

SDK 

2.x

SDK 

3.x

SDK 

4.x

Bigtable(tick)(error)N/A
CloudStorage(tick)(tick)(tick)
PubSub(tick) (tick)  N/A

Objects

IconDescription

DotNet GCP Bigtable Table

DotNet GCP Unknown Bigtable Table

DotNet GCP CloudStorage Bucket

DotNet GCP CloudStorage Unknown Bucket

DotNet GCP PubSub Publisher

DotNet GCP PubSub Unknown Publisher

DotNet GCP PubSub Subscription

DotNet GCP PubSub Receiver

DotNet GCP PubSub Unknown Receiver

Support for SDK

Support for Cloud Bigtable APIs for SDK v2

For the following methods of the clients Google.Cloud.Bigtable.V2.BigtableClient and Google.Cloud.Bigtable.Admin.V2.BigtableTableAdminClient, links are created to the Table:

Link TypeClientMethods
useInsertLink

Google.Cloud.Bigtable.V2.BigtableClient

mutateRow, mutateRows, mutateRowAsync, mutateRowsAsync

checkAndMutateRow, checkAndMutateRowAsync

useUpdateLinkGoogle.Cloud.Bigtable.V2.BigtableClient

readModifyWriteRow, readModifyWriteRowAsync

mutateRow, mutateRows, mutateRowAsync, mutateRowsAsync

checkAndMutateRow, checkAndMutateRowAsync

useSelectLink

Google.Cloud.Bigtable.V2.BigtableClient

readRow, readRowAsync, readRows, SampleRowKeys

useDeleteLink

Google.Cloud.Bigtable.V2.BigtableClient

mutateRow, mutateRows,  mutateRowAsync, mutateRowsAsync

checkAndMutateRow, checkAndMutateRowAsync

useDeleteLinkGoogle.Cloud.Bigtable.Admin.V2.BigtableTableAdminClient

dropAllRows, dropAllRowsAsync, dropRowRange, dropRowRangeAsync

What results you can expect?

The analysis of the following source code will create a Dotnet GCP Bigtable Table object named Hello-Bigtable with a useSelectLink.

When the name of a given referred table in the code is not resolved, an unknown table object will be created with name Unknown. There can be a maximum of one unknown table per project.

Example:

using Google.Cloud.Bigtable.Admin.V2;
using Google.Cloud.Bigtable.V2;
using System;

namespace GoogleCloudSamples.Bigtable
{
    public class HelloWorld
    {

        private const string projectId = "YOUR-PROJECT-ID";
        private const string instanceId = "YOUR-INSTANCE-ID";
        private const string tableId = "Hello-Bigtable";

        Google.Cloud.Bigtable.Common.V2.TableName tableName = new Google.Cloud.Bigtable.Common.V2.TableName(projectId, instanceId, tableId);
        BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();
        BigtableClient bigtableClient = BigtableClient.Create();

        bigtableTableAdminClient.CreateTable(new InstanceName(projectId, instanceId,tableId)
                        
        private static void ReadRowMethod()
        {
            
            RowFilter filter = RowFilters.CellsPerRowLimit(1);
            int rowIndex = 0;

            Row rowRead = bigtableClient.ReadRow(tableName, rowKey: rowKeyPrefix + rowIndex, filter: filter); 
        }
     }
}

Support for CloudStorage

Supported CloudStorage APIs for SDK v2, v3 and v4

For the following methods of the client Google.Cloud.Storage.V1.StorageClient, we create links to the Bucket:

Link TypeClientMethods
useInsertLink

Google.Cloud.Storage.V1.StorageClient

UploadObject, UploadObjectAsync

useUpdateLink

Google.Cloud.Storage.V1.StorageClient

CopyObject

useSelectLink

Google.Cloud.Storage.V1.StorageClient

DowloadObject, DownloadObjectAsync

CopyObject

useDeleteLink

Google.Cloud.Storage.V1.StorageClient

DeleteObject, DeleteObjectAsync

What results you can expect?

The analysis of the following source code will create a Dotnet GCP CloudStorage Bucket object named your-unique-bucket-name with a useDeleteLink.

When the name of a given referred bucket in the code is not resolved, an unknown bucket object will be created with name Unknown. There can be a maximum of one unknown bucket per project.

Example:

using Google.Cloud.Storage.V1;
using System;

public class DeleteFileSample
{
    public void DeleteFile(
        string bucketName = "your-unique-bucket-name",
        string objectName = "your-object-name")
    {
        var storage = StorageClient.Create();
        storage.DeleteObject(bucketName, objectName);
        Console.WriteLine($"Deleted {objectName}.");
    }
}

Support for PubSub

Supported PubSub APIs for SDK v2 and v3

The following APIs are supported:

Object CreatedMethods
Publisher

Google.Cloud.PubSub.V1.PublisherServiceApiClient.Publish

Google.Cloud.PubSub.V1.PublisherServiceApiClient.PublishAsync

Google.Cloud.PubSub.V1.PublisherClient.PublishAsync

Google.Cloud.PubSub.V1.PublisherClientImpl.PublishAsync

Subscription

Google.Cloud.PubSub.V1.SubscriberServiceApiClient.CreateSubscription

Google.Cloud.PubSub.V1.SubscriberServiceApiClient.CreateSubscriptionAsync

Google.Cloud.PubSub.V1.SubscriberServiceApiClientImpl.CreateSubscription

Google.Cloud.PubSub.V1.SubscriberServiceApiClientImpl.CreateSubscriptionAsync

Receiver

Google.Cloud.PubSub.V1.SubscriberClient.StartAsync

Google.Cloud.PubSub.V1.SubscriberServiceApiClient.StartAsync

Google.Cloud.PubSub.V1.SubscriberServiceApiClient.Pull

Google.Cloud.PubSub.V1.SubscriberServiceApiClient.PullAsync

Google.Cloud.PubSub.V1.SubscriberServiceApiClient.StreamingPull

Google.Cloud.PubSub.V1.SubscriberServiceApiClientImpl.Pull

Google.Cloud.PubSub.V1.SubscriberServiceApiClientImpl.PullAsync

Google.Cloud.PubSub.V1.SubscriberServiceApiClientImpl.StreamingPull

  • For the Publisher methods, a Dotnet GCP PubSub Publisher object is created. Its name is that of the topic.
  • For the Receiver methods, a Dotnet GCP PubSub Receiver object is created. Its name is that of the subscription. 
  • A subscription object of type Dotnet GCP PubSub Subscription, is created to imply that it is subscribed to the given topic. Hence its name is that of the subscription with name of the topic as the property. A publisher object is linked to subscription object when the topic name matches and the subscription object is linked to receiver object when the subscription name matches. 

What results you can expect?

The analysis of the following source code will create a Dotnet GCP PubSub Publisher object named topicId with a callLink and a Dotnet GCP PubSub Receiver object named subscriptionId with a callLink.

When the name of a given referred publisher in the code is not resolved, an unknown publisher object will be created with name Unknown. When the name of a given referred subscriber in the code is not resolved, an unknown receiver object will be created with name Unknown.

Publisher example:

public class PublishMessagesAsyncSample
{
    public async Task<int> PublishMessagesAsync(string project, string topic, IEnumerable<string> messageTexts)
    {
        TopicName topicName = TopicName.FromProjectTopic("projectId", "topicId");
        PublisherClient publisher = await PublisherClient.CreateAsync(topicName);

        int publishedMessageCount = 0;
        var publishTasks = messageTexts.Select(async text =>
        {
            try
            {
                string message = await publisher.PublishAsync(text);
                Console.WriteLine($"Published message {message}");
                Interlocked.Increment(ref publishedMessageCount);
            }
            catch (Exception exception)
            {
                Console.WriteLine($"An error ocurred when publishing message {text}: {exception.Message}");
            }
        });
        await Task.WhenAll(publishTasks);
        return publishedMessageCount;
    }
}

Subscription example:

public class CreateSubscriptionSample
{
    public Subscription CreateSubscription(string project, string topic, string subscription)
    {
        SubscriberServiceApiClient subscriber = SubscriberServiceApiClient.Create();
        TopicName topicName = TopicName.FromProjectTopic("projectId", "topicId");

        SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription("projectId", "subscriptionId");
        Subscription subscription = null;

        try
        {
            subscription = subscriber.CreateSubscription(subscriptionName, topicName, pushConfig: null, ackDeadlineSeconds: 60);
        }
        catch (RpcException e) when (e.Status.StatusCode == StatusCode.AlreadyExists)
        {
            // Already exists.  That's fine.
        }
        return subscription;
    }
}

Receiver example:

public class PullMessagesAsyncSample
{
    public async Task<int> PullMessagesAsync(string project, string subscription, bool acknowledge)
    {
        SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription("projectId", "subscriptionId");
        SubscriberClient subscriber = await SubscriberClient.CreateAsync(subscriptionName);
        // SubscriberClient runs your message handle function on multiple
        // threads to maximize throughput.
        int messageCount = 0;
        Task startTask = subscriber.StartAsync((PubsubMessage message, CancellationToken cancel) =>
        {
            string text = System.Text.Encoding.UTF8.GetString(message.Data.ToArray());
            Console.WriteLine($"Message {message.MessageId}: {text}");
            Interlocked.Increment(ref messageCount);
            return Task.FromResult(acknowledge ? SubscriberClient.Reply.Ack : SubscriberClient.Reply.Nack);
        });
        // Run for 5 seconds.
        await Task.Delay(5000);
        await subscriber.StopAsync(CancellationToken.None);
        // Lets make sure that the start task finished successfully after the call to stop.
        await startTask;
        return messageCount;
    }
}

Known limitations

  • LinkType is not evaluated for mutateRow calls, all linkTypes are created by default for bigtable.