Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3839d39

Browse filesBrowse files
committed
c# client source code
c# client source code
1 parent 126a58a commit 3839d39
Copy full SHA for 3839d39
Expand file treeCollapse file tree

21 files changed

+381
-0
lines changed
Open diff view settings
Collapse file
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharpClient", "csharpClient\csharpClient.csproj", "{6502B24D-41C0-40C8-846F-2BCA6AAEDABD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{6502B24D-41C0-40C8-846F-2BCA6AAEDABD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{6502B24D-41C0-40C8-846F-2BCA6AAEDABD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{6502B24D-41C0-40C8-846F-2BCA6AAEDABD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{6502B24D-41C0-40C8-846F-2BCA6AAEDABD}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Collapse file
47.5 KB
Binary file not shown.
Collapse file
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>
Collapse file
+225Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
using System.IO;
8+
using System.Net;
9+
10+
using System.Runtime.Serialization;
11+
using System.Runtime.Serialization.Json;
12+
13+
using Newtonsoft.Json;
14+
using Newtonsoft.Json.Linq;
15+
16+
namespace csharpClient
17+
{
18+
class Program
19+
{
20+
public static string PostHttp(string url, string body, string contentType)
21+
{
22+
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
23+
24+
httpWebRequest.ContentType = contentType;
25+
httpWebRequest.Method = "POST";
26+
httpWebRequest.Timeout = 80000;
27+
28+
byte[] btBodys = Encoding.UTF8.GetBytes(body);
29+
httpWebRequest.ContentLength = btBodys.Length;
30+
httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);
31+
32+
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
33+
string htmlCharset = "GBK";
34+
Encoding htmlEncoding = Encoding.GetEncoding(htmlCharset);
35+
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), htmlEncoding);
36+
string responseContent = streamReader.ReadToEnd();
37+
38+
httpWebResponse.Close();
39+
streamReader.Close();
40+
httpWebRequest.Abort();
41+
httpWebResponse.Close();
42+
43+
return responseContent;
44+
}
45+
46+
[DataContract]
47+
[Serializable]
48+
public class head
49+
{
50+
[DataMember]
51+
public string method { get; set; }
52+
[DataMember]
53+
public int time { get; set; }
54+
[DataMember]
55+
public string service { get; set; }
56+
57+
}
58+
59+
[DataContract]
60+
[Serializable]
61+
public class status
62+
{
63+
public status()
64+
{
65+
this.code = 0;
66+
this.msg = "";
67+
}
68+
[DataMember]
69+
public int code { get; set; }
70+
[DataMember]
71+
public string msg { get; set; }
72+
73+
}
74+
75+
[DataContract]
76+
[Serializable]
77+
public class probs
78+
{
79+
public probs()
80+
{
81+
this.prob = 0.0;
82+
this.cat = "";
83+
}
84+
[DataMember]
85+
public double prob { get; set; }
86+
[DataMember]
87+
public string cat { get; set; }
88+
89+
}
90+
91+
[DataContract]
92+
[Serializable]
93+
public class probslast
94+
{
95+
public probslast()
96+
{
97+
this.prob = 0.0;
98+
this.cat = "";
99+
this.last = true;
100+
}
101+
[DataMember]
102+
public bool last { get; set; }
103+
[DataMember]
104+
public double prob { get; set; }
105+
[DataMember]
106+
public string cat { get; set; }
107+
108+
}
109+
110+
[DataContract]
111+
[Serializable]
112+
public class classes
113+
{
114+
[DataMember]
115+
public probs _probs1 { get; set; }
116+
[DataMember]
117+
public probs _probs2 { get; set; }
118+
[DataMember]
119+
public probslast _probslast { get; set; }
120+
121+
122+
}
123+
124+
[DataContract]
125+
[Serializable]
126+
public class predictions
127+
{
128+
public predictions()
129+
{
130+
this._classes = new classes();
131+
this.uri = "";
132+
this.loss = 0;
133+
}
134+
135+
[DataMember]
136+
public string uri { get; set; }
137+
[DataMember]
138+
public int loss { get; set; }
139+
[DataMember]
140+
public classes _classes { get; set; }
141+
}
142+
143+
[DataContract]
144+
[Serializable]
145+
public class body
146+
{
147+
public body()
148+
{
149+
this._predictions = new predictions();
150+
}
151+
[DataMember]
152+
public predictions _predictions { get; set; }
153+
154+
}
155+
156+
[DataContract]
157+
[Serializable]
158+
public class JSonPredictData
159+
{
160+
public JSonPredictData()
161+
{
162+
this._status = new status();
163+
this._head = new head();
164+
this._body = new body();
165+
}
166+
167+
[DataMember]
168+
public body _body { get; set; }
169+
170+
[DataMember]
171+
public head _head { get; set; }
172+
173+
[DataMember]
174+
public status _status { get; set; }
175+
176+
}
177+
178+
public static T ParseFromJson<T>(string szJson)
179+
{
180+
T obj = Activator.CreateInstance<T>();
181+
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(szJson)))
182+
{
183+
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
184+
return (T)serializer.ReadObject(ms);
185+
}
186+
}
187+
188+
public static string GetJson<T>(T obj)
189+
{
190+
DataContractJsonSerializer json = new DataContractJsonSerializer(obj.GetType());
191+
using (MemoryStream stream = new MemoryStream())
192+
{
193+
json.WriteObject(stream, obj);
194+
string szJson = Encoding.UTF8.GetString(stream.ToArray());
195+
return szJson;
196+
}
197+
}
198+
199+
private static T Serialization<T>(string obj) where T : class
200+
{
201+
using (var mStream = new MemoryStream(Encoding.UTF8.GetBytes(obj)))
202+
{
203+
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
204+
T entity = serializer.ReadObject(mStream) as T;
205+
return entity;
206+
}
207+
}
208+
209+
static void Main(string[] args)
210+
{
211+
string url = "http://123.56.191.136:8080/predict";
212+
string picUrl = "http://www.deepdetect.com/img/ambulance.jpg";
213+
string body = "{\"service\":\"imageserv\",\"parameters\":{\"input\":{\"width\":224,\"height\":224},\"output\":{\"best\":3}},\"data\":[\"" + picUrl + "\"]}";
214+
215+
string result = PostHttp(url, body, "application/x-www-form-urlencoded");
216+
217+
var jObject = JObject.Parse(result);
218+
219+
string predictResult = jObject["body"]["predictions"]["classes"][0].ToString();
220+
//this is the best result, you can also get other prediction result: ...["classes"][1].ToString()...
221+
222+
223+
}
224+
}
225+
}
Collapse file
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("csharpClient")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("csharpClient")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("2098a87e-3a5c-4984-8b7e-5acbdd1a33fb")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.
Binary file not shown.
Collapse file
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.