-
Notifications
You must be signed in to change notification settings - Fork 355
/
TemplatesSample.cs
116 lines (104 loc) · 4.71 KB
/
TemplatesSample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2017 DAIMTO : www.daimto.com
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by DAIMTO-Google-apis-Sample-generator 1.0.0
// Template File Name: Methodtemplate.tt
// Build date: 01/02/2017 22:33:13
// C# generater version: 1.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// About
//
// Unoffical sample for the dataflow v1b3 API for C#.
// This sample is designed to be used with the Google .Net client library. (https://github.com/google/google-api-dotnet-client)
//
// API Description: Develops and executes data processing patterns like ETL, batch computation, and continuous computation.
// API Documentation Link https://cloud.google.com/dataflow
//
// Discovery Doc https://www.googleapis.com/discovery/v1/apis/dataflow/v1b3/rest
//
//------------------------------------------------------------------------------
// Installation
//
// This sample code uses the Google .Net client library
//
// NuGet package:
//
// Location: https://www.nuget.org/packages/Google.Apis.dataflow.v1b3/
// Install Command: PM> Install-Package Google.Apis.dataflow.v1b3
//
//------------------------------------------------------------------------------
using Google.Apis.dataflow.v1b3;
using Google.Apis.dataflow.v1b3.Data;
using System;
namespace GoogleSamplecSharpSample.dataflowv1b3.Methods
{
public static class TemplatesSample
{
/// <summary>
/// Creates a dataflow job from a template.
/// Documentation https://developers.google.com/dataflow/v1b3/reference/templates/create
/// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong.
/// </summary>
/// <param name="service">Authenticated dataflow service.</param>
/// <param name="projectId">The project which owns the job.</param>
/// <param name="body">A valid dataflow v1b3 body.</param>
/// <returns>JobResponse</returns>
public static Job Create(dataflowService service, string projectId, CreateJobFromTemplateRequest body)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException("service");
if (body == null)
throw new ArgumentNullException("body");
if (projectId == null)
throw new ArgumentNullException(projectId);
// Make the request.
return service.Templates.Create(body, projectId).Execute();
}
catch (Exception ex)
{
throw new Exception("Request Templates.Create failed.", ex);
}
}
}
public static class SampleHelpers
{
/// <summary>
/// Using reflection to apply optional parameters to the request.
///
/// If the optonal parameters are null then we will just return the request as is.
/// </summary>
/// <param name="request">The request. </param>
/// <param name="optional">The optional parameters. </param>
/// <returns></returns>
public static object ApplyOptionalParms(object request, object optional)
{
if (optional == null)
return request;
System.Reflection.PropertyInfo[] optionalProperties = (optional.GetType()).GetProperties();
foreach (System.Reflection.PropertyInfo property in optionalProperties)
{
// Copy value from optional parms to the request. They should have the same names and datatypes.
System.Reflection.PropertyInfo piShared = (request.GetType()).GetProperty(property.Name);
if (property.GetValue(optional, null) != null) // TODO Test that we do not add values for items that are null
piShared.SetValue(request, property.GetValue(optional, null), null);
}
return request;
}
}
}