Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 86c29fc1

Přidáno uživatelem Eliška Mourycová před více než 3 roky(ů)

Re #8943. Prepared getting predictions from Model.

Zobrazit rozdíly:

Server/ServerApp/Connection/ConnectionListenerMulti.cs
232 232
					string requestXML = HttpUtility.UrlDecode(text);
233 233
					Console.WriteLine(requestXML);
234 234

  
235
					// prepare the type:
235 236
					Request newRequest = new Request();
236
					Request requestDeserialized = XmlCommunication.Deserialize(newRequest, requestXML);
237
					Request requestDeserialized = null;
238
					try
239
					{
240
						requestDeserialized = XmlCommunication.Deserialize(newRequest, requestXML);
241
					}
242
					catch
243
					{
244
						Console.WriteLine("wrong format of request!");
245

  
246
						// don't bother to send anything:
247
						continue;
248
					}
249
					
237 250

  
251
					// response headers:
238 252
					HttpListenerResponse response = context.Response;
239 253
					response.AddHeader("Access-Control-Allow-Credentials", "true");
240 254
					response.AddHeader("Access-Control-Expose-Headers", "ETag");
......
242 256
					response.AddHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
243 257
					response.AddHeader("Access-Control-Allow-Origin", "*");
244 258

  
245

  
259
					// get the prediction from the model:
246 260
					Response responsePrediction = predictionController.Predict(requestDeserialized);
247 261

  
248 262
					int rand = new Random().Next(1, 10);
249 263
					string msg = "OK " + rand;
250 264

  
265
					// build the xml from the prediction: - TODO mbe an exception can happen here as well? - it shouldnt
251 266
					msg = XmlCommunication.Serialize(responsePrediction);
252 267

  
253
					byte[] buffer = Encoding.UTF8.GetBytes(msg);
254 268

  
269
					// send the response:
270
					byte[] buffer = Encoding.UTF8.GetBytes(msg);
255 271
					response.ContentLength64 = buffer.Length;
256 272
					Stream st = response.OutputStream;
257 273
					st.Write(buffer, 0, buffer.Length);
258 274

  
259

  
275
					// close
260 276
					context.Response.Close(); // ?? Works better with this, if this line is absent, the client gets 'stuck' after approximately 6 messages
261 277
				}
262 278
				else
Server/ServerApp/Program.cs
58 58
			DataDownloader dd = DataDownloadAndRetrievalTest(config);
59 59

  
60 60
			// xml building test
61
			//XMLTest();
61
			XMLTest();
62 62

  
63 63

  
64 64

  
......
132 132
		{
133 133
			Response response = Response.Randomize();
134 134
			var xml = XmlCommunication.Serialize(response);
135
			//xml = "haha";
136
			Response response1 = new Response();
135 137
			Console.WriteLine(xml);
136
			Response responseDeserialized = XmlCommunication.Deserialize(response, xml);
138
			try
139
			{
140
				Response responseDeserialized = XmlCommunication.Deserialize(response1, xml);
141
			}
142
			catch(Exception e)
143
			{
144
				Console.WriteLine("bad format");
145
			}
146
			
137 147

  
138 148
			Console.WriteLine("------");
139 149

  

Také k dispozici: Unified diff