public Schema CreateAvroSchema(string projectId, string schemaId, string pathToDefinition) { SchemaServiceClient schemaService = SchemaServiceClient.Create(); var schemaName = SchemaName.FromProjectSchema(projectId, schemaId); string schemaDefinition = File.ReadAllText(pathToDefinition); Schema schema = new Schema { Name = schemaName.ToString(), Type = Schema.Types.Type.Avro, Definition = schemaDefinition }; CreateSchemaRequest createSchemaRequest = new CreateSchemaRequest { Parent = "projects/" + projectId, SchemaId = schemaId, Schema = schema }; try { schema = schemaService.CreateSchema(createSchemaRequest); Console.WriteLine($"Schema {schema.Name} created."); } catch (RpcException e) when(e.Status.StatusCode == StatusCode.AlreadyExists) { Console.WriteLine($"Schema {schemaName} already exists."); } return(schema); }
public void DeleteSchema(string projectId, string schemaId) { SchemaServiceClient schemaService = SchemaServiceClient.Create(); SchemaName schemaName = SchemaName.FromProjectSchema(projectId, schemaId); schemaService.DeleteSchema(schemaName); }
public IEnumerable <Schema> ListSchemas(string projectId) { SchemaServiceClient schemaService = SchemaServiceClient.Create(); ProjectName projectName = ProjectName.FromProject(projectId); var schemas = schemaService.ListSchemas(projectName); return(schemas); }
/// <summary>Snippet for GetSchema</summary> public void GetSchemaResourceNames() { // Snippet: GetSchema(SchemaName, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) SchemaName name = SchemaName.FromProjectSchema("[PROJECT]", "[SCHEMA]"); // Make the request Schema response = schemaServiceClient.GetSchema(name); // End snippet }
/// <summary>Snippet for GetSchema</summary> public void GetSchema() { // Snippet: GetSchema(string, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) string name = "projects/[PROJECT]/schemas/[SCHEMA]"; // Make the request Schema response = schemaServiceClient.GetSchema(name); // End snippet }
/// <summary>Snippet for ValidateSchema</summary> public void ValidateSchemaResourceNames() { // Snippet: ValidateSchema(ProjectName, Schema, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) ProjectName parent = ProjectName.FromProject("[PROJECT]"); Schema schema = new Schema(); // Make the request ValidateSchemaResponse response = schemaServiceClient.ValidateSchema(parent, schema); // End snippet }
/// <summary>Snippet for ValidateSchema</summary> public void ValidateSchema() { // Snippet: ValidateSchema(string, Schema, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) string parent = "projects/[PROJECT]"; Schema schema = new Schema(); // Make the request ValidateSchemaResponse response = schemaServiceClient.ValidateSchema(parent, schema); // End snippet }
public Schema GetSchema(string projectId, string schemaId) { SchemaServiceClient schemaService = SchemaServiceClient.Create(); SchemaName schemaName = SchemaName.FromProjectSchema(projectId, schemaId); GetSchemaRequest request = new GetSchemaRequest { Name = schemaName.ToString(), View = SchemaView.Full }; return(schemaService.GetSchema(request)); }
/// <summary>Snippet for ValidateSchema</summary> public void ValidateSchemaRequestObject() { // Snippet: ValidateSchema(ValidateSchemaRequest, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) ValidateSchemaRequest request = new ValidateSchemaRequest { ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), Schema = new Schema(), }; // Make the request ValidateSchemaResponse response = schemaServiceClient.ValidateSchema(request); // End snippet }
/// <summary>Snippet for DeleteSchema</summary> public void DeleteSchemaRequestObject() { // Snippet: DeleteSchema(DeleteSchemaRequest, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) DeleteSchemaRequest request = new DeleteSchemaRequest { SchemaName = SchemaName.FromProjectSchema("[PROJECT]", "[SCHEMA]"), }; // Make the request schemaServiceClient.DeleteSchema(request); // End snippet }
/// <summary>Snippet for GetSchema</summary> public void GetSchemaRequestObject() { // Snippet: GetSchema(GetSchemaRequest, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) GetSchemaRequest request = new GetSchemaRequest { SchemaName = SchemaName.FromProjectSchema("[PROJECT]", "[SCHEMA]"), View = SchemaView.Unspecified, }; // Make the request Schema response = schemaServiceClient.GetSchema(request); // End snippet }
/// <summary>Snippet for ListSchemas</summary> public void ListSchemasRequestObject() { // Snippet: ListSchemas(ListSchemasRequest, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) ListSchemasRequest request = new ListSchemasRequest { ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), View = SchemaView.Unspecified, }; // Make the request PagedEnumerable <ListSchemasResponse, Schema> response = schemaServiceClient.ListSchemas(request); // Iterate over all response items, lazily performing RPCs as required foreach (Schema item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over pages (of server-defined size), performing one RPC per page foreach (ListSchemasResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Schema item in page) { // Do something with each item Console.WriteLine(item); } } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <Schema> singlePage = response.ReadPage(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (Schema item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for ValidateMessage</summary> public void ValidateMessageRequestObject() { // Snippet: ValidateMessage(ValidateMessageRequest, CallSettings) // Create client SchemaServiceClient schemaServiceClient = SchemaServiceClient.Create(); // Initialize request argument(s) ValidateMessageRequest request = new ValidateMessageRequest { ParentAsProjectName = ProjectName.FromProject("[PROJECT]"), SchemaName = SchemaName.FromProjectSchema("[PROJECT]", "[SCHEMA]"), Message = ByteString.Empty, Encoding = Encoding.Unspecified, }; // Make the request ValidateMessageResponse response = schemaServiceClient.ValidateMessage(request); // End snippet }