-
Notifications
You must be signed in to change notification settings - Fork 355
/
Copy pathWorkItemsSample.cs
159 lines (144 loc) · 7 KB
/
WorkItemsSample.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// 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 WorkItemsSample
{
/// <summary>
/// Reports the status of dataflow WorkItems leased by a worker.
/// Documentation https://developers.google.com/dataflow/v1b3/reference/workItems/reportStatus
/// 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 WorkItem's job.</param>
/// <param name="location">The location which contains the WorkItem's job.</param>
/// <param name="jobId">The job which the WorkItem is part of.</param>
/// <param name="body">A valid dataflow v1b3 body.</param>
/// <returns>ReportWorkItemStatusResponseResponse</returns>
public static ReportWorkItemStatusResponse ReportStatus(dataflowService service, string projectId, string location, string jobId, ReportWorkItemStatusRequest 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);
if (location == null)
throw new ArgumentNullException(location);
if (jobId == null)
throw new ArgumentNullException(jobId);
// Make the request.
return service.WorkItems.ReportStatus(body, projectId, location, jobId).Execute();
}
catch (Exception ex)
{
throw new Exception("Request WorkItems.ReportStatus failed.", ex);
}
}
/// <summary>
/// Leases a dataflow WorkItem to run.
/// Documentation https://developers.google.com/dataflow/v1b3/reference/workItems/lease
/// 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">Identifies the project this worker belongs to.</param>
/// <param name="location">The location which contains the WorkItem's job.</param>
/// <param name="jobId">Identifies the workflow job this worker belongs to.</param>
/// <param name="body">A valid dataflow v1b3 body.</param>
/// <returns>LeaseWorkItemResponseResponse</returns>
public static LeaseWorkItemResponse Lease(dataflowService service, string projectId, string location, string jobId, LeaseWorkItemRequest 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);
if (location == null)
throw new ArgumentNullException(location);
if (jobId == null)
throw new ArgumentNullException(jobId);
// Make the request.
return service.WorkItems.Lease(body, projectId, location, jobId).Execute();
}
catch (Exception ex)
{
throw new Exception("Request WorkItems.Lease 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;
}
}
}