Skip to content

Commit 41c3fff

Browse files
authored
Merge branch 'development' into 5244-regenerate-sdk
2 parents f7b5b43 + 83deca5 commit 41c3fff

File tree

12 files changed

+351
-2
lines changed

12 files changed

+351
-2
lines changed

IBM.WatsonDeveloperCloud.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IBM.WatsonDeveloperCloud.La
119119
EndProject
120120
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IBM.WatsonDeveloperCloud.LanguageTranslator.v3.UnitTests", "test\IBM.WatsonDeveloperCloud.LanguageTranslator.v3.UnitTests\IBM.WatsonDeveloperCloud.LanguageTranslator.v3.UnitTests.csproj", "{F1D7E642-0F19-497F-89E6-8D0FD747C595}"
121121
EndProject
122+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBM.WatsonDeveloperCloud.VisRec.v3.Example", "examples\IBM.WatsonDeveloperCloud.VisRec.v3.Example\IBM.WatsonDeveloperCloud.VisRec.v3.Example.csproj", "{019DEDBF-2929-4AB3-AA58-A6C9D42604FC}"
123+
EndProject
122124
Global
123125
GlobalSection(SolutionConfigurationPlatforms) = preSolution
124126
Debug|Any CPU = Debug|Any CPU
@@ -293,6 +295,10 @@ Global
293295
{F1D7E642-0F19-497F-89E6-8D0FD747C595}.Debug|Any CPU.Build.0 = Debug|Any CPU
294296
{F1D7E642-0F19-497F-89E6-8D0FD747C595}.Release|Any CPU.ActiveCfg = Release|Any CPU
295297
{F1D7E642-0F19-497F-89E6-8D0FD747C595}.Release|Any CPU.Build.0 = Release|Any CPU
298+
{019DEDBF-2929-4AB3-AA58-A6C9D42604FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
299+
{019DEDBF-2929-4AB3-AA58-A6C9D42604FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
300+
{019DEDBF-2929-4AB3-AA58-A6C9D42604FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
301+
{019DEDBF-2929-4AB3-AA58-A6C9D42604FC}.Release|Any CPU.Build.0 = Release|Any CPU
296302
EndGlobalSection
297303
GlobalSection(SolutionProperties) = preSolution
298304
HideSolutionNode = FALSE
@@ -354,6 +360,7 @@ Global
354360
{B71E13FA-0A6E-4B90-B509-6B2D690554C9} = {65D78D49-E54F-4952-A1D4-7C8D0EDAA1B3}
355361
{5DAAA089-EDCA-448F-835E-1EB1CAEB0226} = {65D78D49-E54F-4952-A1D4-7C8D0EDAA1B3}
356362
{F1D7E642-0F19-497F-89E6-8D0FD747C595} = {65D78D49-E54F-4952-A1D4-7C8D0EDAA1B3}
363+
{019DEDBF-2929-4AB3-AA58-A6C9D42604FC} = {A1BC3262-1837-40D9-A530-DCFE679927C2}
357364
EndGlobalSection
358365
GlobalSection(ExtensibilityGlobals) = postSolution
359366
SolutionGuid = {B9D9D17B-1C17-402F-B701-DC671528690A}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using IBM.WatsonDeveloperCloud.Util;
19+
using Newtonsoft.Json;
20+
using Newtonsoft.Json.Linq;
21+
using System;
22+
using System.IO;
23+
24+
namespace IBM.WatsonDeveloperCloud.VisRec.v3.Example
25+
{
26+
class Example
27+
{
28+
private static string credentials = string.Empty;
29+
private static string _apikey;
30+
private static string _endpoint;
31+
private static string _versionDate = "2016-05-20";
32+
33+
static void Main(string[] args)
34+
{
35+
#region Get Credentials
36+
if (string.IsNullOrEmpty(credentials))
37+
{
38+
var parentDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.Parent.FullName;
39+
string credentialsFilepath = parentDirectory + Path.DirectorySeparatorChar + "sdk-credentials" + Path.DirectorySeparatorChar + "credentials.json";
40+
if (File.Exists(credentialsFilepath))
41+
{
42+
try
43+
{
44+
credentials = File.ReadAllText(credentialsFilepath);
45+
credentials = Utility.AddTopLevelObjectToJson(credentials, "VCAP_SERVICES");
46+
}
47+
catch (Exception e)
48+
{
49+
throw new Exception(string.Format("Failed to load credentials: {0}", e.Message));
50+
}
51+
}
52+
else
53+
{
54+
Console.WriteLine("Credentials file does not exist.");
55+
}
56+
57+
VcapCredentials vcapCredentials = JsonConvert.DeserializeObject<VcapCredentials>(credentials);
58+
var vcapServices = JObject.Parse(credentials);
59+
60+
Credential credential = vcapCredentials.GetCredentialByname("visual-recognition-sdk-cf")[0].Credentials;
61+
_endpoint = credential.Url;
62+
_apikey = credential.ApiKey;
63+
}
64+
#endregion
65+
66+
VisualRecognitionServiceExample _visualRecognitionExample = new VisualRecognitionServiceExample(_apikey, _versionDate);
67+
Console.ReadKey();
68+
}
69+
}
70+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\IBM.WatsonDeveloperCloud.VisualRecognition.v3\IBM.WatsonDeveloperCloud.VisualRecognition.v3.csproj" />
10+
<ProjectReference Include="..\..\src\IBM.WatsonDeveloperCloud\IBM.WatsonDeveloperCloud.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
/**
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using IBM.WatsonDeveloperCloud.VisualRecognition.v3;
19+
using IBM.WatsonDeveloperCloud.VisualRecognition.v3.Model;
20+
using Newtonsoft.Json;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.IO;
24+
using System.Text;
25+
using System.Threading.Tasks;
26+
27+
namespace IBM.WatsonDeveloperCloud.VisRec.v3.Example
28+
{
29+
class VisualRecognitionServiceExample
30+
{
31+
private string _apikey;
32+
private string _versionDate;
33+
private VisualRecognitionService _service;
34+
private string _localGiraffeFilePath = @"VisualRecognitionTestData/giraffe_to_classify.jpg";
35+
private string _imageUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bb/Kittyply_edit1.jpg/1200px-Kittyply_edit1.jpg";
36+
37+
#region Constructor
38+
public VisualRecognitionServiceExample(string apikey, string versionDate)
39+
{
40+
41+
_service = new VisualRecognitionService(apikey, versionDate);
42+
_service.Client.BaseClient.Timeout = TimeSpan.FromMinutes(120);
43+
44+
ClassifyImage();
45+
ClassifyUrl();
46+
//ListAllClassifiers();
47+
48+
Console.WriteLine("\n~ VisualRecognition examples complete.");
49+
}
50+
#endregion
51+
52+
private void ClassifyImage()
53+
{
54+
using (FileStream fs = File.OpenRead(_localGiraffeFilePath))
55+
{
56+
var result = Classify(fs, imagesFileContentType: "image/jpeg");
57+
}
58+
}
59+
60+
private void ClassifyUrl()
61+
{
62+
var result = Classify(url: _imageUrl);
63+
}
64+
65+
private void ListAllClassifiers()
66+
{
67+
var listClassifiersResult = ListClassifiers();
68+
}
69+
70+
#region Generated
71+
#region Classify
72+
private ClassifiedImages Classify(System.IO.FileStream imagesFile = null, string acceptLanguage = null, string url = null, float? threshold = null, List<string> owners = null, List<string> classifierIds = null, string imagesFileContentType = null, Dictionary<string, object> customData = null)
73+
{
74+
Console.WriteLine("\nAttempting to Classify()");
75+
var result = _service.Classify(imagesFile: imagesFile, acceptLanguage: acceptLanguage, url: url, threshold: threshold, owners: owners, classifierIds: classifierIds, imagesFileContentType: imagesFileContentType, customData: customData);
76+
77+
if (result != null)
78+
{
79+
Console.WriteLine("Classify() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
80+
}
81+
else
82+
{
83+
Console.WriteLine("Failed to Classify()");
84+
}
85+
86+
return result;
87+
}
88+
#endregion
89+
90+
#region DetectFaces
91+
private DetectedFaces DetectFaces(System.IO.FileStream imagesFile = null, string url = null, string imagesFileContentType = null, Dictionary<string, object> customData = null)
92+
{
93+
Console.WriteLine("\nAttempting to DetectFaces()");
94+
var result = _service.DetectFaces(imagesFile: imagesFile, url: url, imagesFileContentType: imagesFileContentType, customData: customData);
95+
96+
if (result != null)
97+
{
98+
Console.WriteLine("DetectFaces() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
99+
}
100+
else
101+
{
102+
Console.WriteLine("Failed to DetectFaces()");
103+
}
104+
105+
return result;
106+
}
107+
#endregion
108+
109+
#region CreateClassifier
110+
private Classifier CreateClassifier(CreateClassifier createClassifier, Dictionary<string, object> customData = null)
111+
{
112+
Console.WriteLine("\nAttempting to CreateClassifier()");
113+
var result = _service.CreateClassifier(createClassifier: createClassifier, customData: customData);
114+
115+
if (result != null)
116+
{
117+
Console.WriteLine("CreateClassifier() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
118+
}
119+
else
120+
{
121+
Console.WriteLine("Failed to CreateClassifier()");
122+
}
123+
124+
return result;
125+
}
126+
#endregion
127+
128+
#region DeleteClassifier
129+
private BaseModel DeleteClassifier(string classifierId, Dictionary<string, object> customData = null)
130+
{
131+
Console.WriteLine("\nAttempting to DeleteClassifier()");
132+
var result = _service.DeleteClassifier(classifierId: classifierId, customData: customData);
133+
134+
if (result != null)
135+
{
136+
Console.WriteLine("DeleteClassifier() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
137+
}
138+
else
139+
{
140+
Console.WriteLine("Failed to DeleteClassifier()");
141+
}
142+
143+
return result;
144+
}
145+
#endregion
146+
147+
#region GetClassifier
148+
private Classifier GetClassifier(string classifierId, Dictionary<string, object> customData = null)
149+
{
150+
Console.WriteLine("\nAttempting to GetClassifier()");
151+
var result = _service.GetClassifier(classifierId: classifierId, customData: customData);
152+
153+
if (result != null)
154+
{
155+
Console.WriteLine("GetClassifier() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
156+
}
157+
else
158+
{
159+
Console.WriteLine("Failed to GetClassifier()");
160+
}
161+
162+
return result;
163+
}
164+
#endregion
165+
166+
#region ListClassifiers
167+
private Classifiers ListClassifiers(bool? verbose = null, Dictionary<string, object> customData = null)
168+
{
169+
Console.WriteLine("\nAttempting to ListClassifiers()");
170+
var result = _service.ListClassifiers(verbose: verbose, customData: customData);
171+
172+
if (result != null)
173+
{
174+
Console.WriteLine("ListClassifiers() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
175+
}
176+
else
177+
{
178+
Console.WriteLine("Failed to ListClassifiers()");
179+
}
180+
181+
return result;
182+
}
183+
#endregion
184+
185+
#region UpdateClassifier
186+
private Classifier UpdateClassifier(UpdateClassifier updateClassifier, Dictionary<string, object> customData = null)
187+
{
188+
Console.WriteLine("\nAttempting to UpdateClassifier()");
189+
var result = _service.UpdateClassifier(updateClassifier: updateClassifier, customData: customData);
190+
191+
if (result != null)
192+
{
193+
Console.WriteLine("UpdateClassifier() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
194+
}
195+
else
196+
{
197+
Console.WriteLine("Failed to UpdateClassifier()");
198+
}
199+
200+
return result;
201+
}
202+
#endregion
203+
204+
#region GetCoreMlModel
205+
private Task<Stream> GetCoreMlModel(string classifierId, Dictionary<string, object> customData = null)
206+
{
207+
Console.WriteLine("\nAttempting to GetCoreMlModel()");
208+
var result = _service.GetCoreMlModel(classifierId: classifierId, customData: customData);
209+
210+
if (result != null)
211+
{
212+
Console.WriteLine("GetCoreMlModel() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
213+
}
214+
else
215+
{
216+
Console.WriteLine("Failed to GetCoreMlModel()");
217+
}
218+
219+
return result;
220+
}
221+
#endregion
222+
223+
#region DeleteUserData
224+
private BaseModel DeleteUserData(string customerId, Dictionary<string, object> customData = null)
225+
{
226+
Console.WriteLine("\nAttempting to DeleteUserData()");
227+
var result = _service.DeleteUserData(customerId: customerId, customData: customData);
228+
229+
if (result != null)
230+
{
231+
Console.WriteLine("DeleteUserData() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented));
232+
}
233+
else
234+
{
235+
Console.WriteLine("Failed to DeleteUserData()");
236+
}
237+
238+
return result;
239+
}
240+
#endregion
241+
242+
#endregion
243+
}
244+
}
646 KB
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Jeffrey",
3+
"type": "Giraffe",
4+
"best friend": "Turtle"
5+
}
56.6 KB
Loading

0 commit comments

Comments
 (0)