Revize 5cb4249a
Přidáno uživatelem Eliška Mourycová před téměř 4 roky(ů)
Server/ServerApp/Connection/ConnectionListener.cs | ||
---|---|---|
161 | 161 |
//return xml; |
162 | 162 |
|
163 | 163 |
|
164 |
Console.WriteLine("Constructiing a response for GET request.");
|
|
164 |
Console.WriteLine("Constructing a response for GET request."); |
|
165 | 165 |
Console.WriteLine("Request string: "); |
166 | 166 |
Console.WriteLine(requestString); |
167 | 167 |
|
... | ... | |
172 | 172 |
Request requestDeserialized = null; |
173 | 173 |
try |
174 | 174 |
{ |
175 |
requestDeserialized = XmlCommunication.Deserialize(newRequest, requestString); |
|
175 |
Console.WriteLine("Trying to deserialize xml request."); |
|
176 |
requestDeserialized = XmlCommunication.Deserialize<Request>(requestString); |
|
176 | 177 |
} |
177 | 178 |
catch |
178 | 179 |
{ |
... | ... | |
184 | 185 |
|
185 | 186 |
|
186 | 187 |
// get the prediction from the model: |
188 |
Console.WriteLine("Getting the prediction from the predictor."); |
|
189 |
Console.WriteLine("Deserialized request is null? : " + requestDeserialized == null); |
|
187 | 190 |
Response responsePrediction = predictionController.Predict(requestDeserialized); |
188 | 191 |
|
189 | 192 |
string constructedXml = XmlCommunication.Serialize(responsePrediction); |
... | ... | |
198 | 201 |
|
199 | 202 |
private string ConstructPOSTResponse(string requestString) |
200 | 203 |
{ |
201 |
Console.WriteLine("Constructiing a response for POST request.");
|
|
204 |
Console.WriteLine("Constructing a response for POST request."); |
|
202 | 205 |
Console.WriteLine("Request string: "); |
203 | 206 |
Console.WriteLine(requestString); |
204 | 207 |
|
... | ... | |
209 | 212 |
Request requestDeserialized = null; |
210 | 213 |
try |
211 | 214 |
{ |
212 |
requestDeserialized = XmlCommunication.Deserialize(newRequest, requestString); |
|
215 |
Console.WriteLine("Trying to deserialize xml request."); |
|
216 |
requestDeserialized = XmlCommunication.Deserialize<Request>(requestString); |
|
213 | 217 |
} |
214 | 218 |
catch |
215 | 219 |
{ |
... | ... | |
221 | 225 |
|
222 | 226 |
|
223 | 227 |
// get the prediction from the model: |
228 |
Console.WriteLine("Getting the prediction from the predictor."); |
|
229 |
Console.WriteLine("Deserialized request is null? : " + requestDeserialized == null); |
|
224 | 230 |
Response responsePrediction = predictionController.Predict(requestDeserialized); |
225 | 231 |
|
226 | 232 |
|
... | ... | |
365 | 371 |
Request requestDeserialized = null; |
366 | 372 |
try |
367 | 373 |
{ |
368 |
requestDeserialized = XmlCommunication.Deserialize(newRequest, requestXML);
|
|
374 |
requestDeserialized = XmlCommunication.Deserialize<Request>(requestXML);
|
|
369 | 375 |
} |
370 | 376 |
catch |
371 | 377 |
{ |
... | ... | |
630 | 636 |
Console.WriteLine(requestXML); |
631 | 637 |
|
632 | 638 |
Request newRequest = new Request(); |
633 |
Request requestDeserialized = XmlCommunication.Deserialize(newRequest, requestXML);
|
|
639 |
Request requestDeserialized = XmlCommunication.Deserialize<Request>(requestXML);
|
|
634 | 640 |
|
635 | 641 |
ClientService newService = new ClientService(); |
636 | 642 |
newService.UniqueID = GetNextID(); |
Server/ServerApp/Connection/XMLProtocolHandler/XmlCommunication.cs | ||
---|---|---|
21 | 21 |
} |
22 | 22 |
} |
23 | 23 |
|
24 |
public static T Deserialize<T>(T toDeserialize, string xmlString) |
|
24 |
//public static T Deserialize<T>(T toDeserialize, string xmlString) |
|
25 |
//{ |
|
26 |
// using (var stream = new StringReader(xmlString)) |
|
27 |
// { |
|
28 |
// var xml = new XmlSerializer(toDeserialize.GetType()); |
|
29 |
// T deserialized = (T)xml.Deserialize(stream); |
|
30 |
// return deserialized; |
|
31 |
// } |
|
32 |
//} |
|
33 |
|
|
34 |
public static T Deserialize<T>(string xmlString) |
|
25 | 35 |
{ |
26 | 36 |
using (var stream = new StringReader(xmlString)) |
27 | 37 |
{ |
28 |
var xml = new XmlSerializer(toDeserialize.GetType());
|
|
38 |
var xml = new XmlSerializer(typeof(T));
|
|
29 | 39 |
T deserialized = (T)xml.Deserialize(stream); |
30 | 40 |
return deserialized; |
31 | 41 |
} |
32 | 42 |
} |
43 |
|
|
33 | 44 |
} |
34 | 45 |
} |
Server/ServerApp/Program.cs | ||
---|---|---|
144 | 144 |
Console.WriteLine(xml); |
145 | 145 |
try |
146 | 146 |
{ |
147 |
Response responseDeserialized = XmlCommunication.Deserialize(response1, xml);
|
|
147 |
Response responseDeserialized = XmlCommunication.Deserialize<Response>(xml);
|
|
148 | 148 |
} |
149 | 149 |
catch(Exception e) |
150 | 150 |
{ |
... | ... | |
158 | 158 |
Request request = Request.Randomize(); |
159 | 159 |
xml = XmlCommunication.Serialize(request); |
160 | 160 |
Console.WriteLine(xml); |
161 |
Request requestDeserialized = XmlCommunication.Deserialize(request, xml);
|
|
161 |
Request requestDeserialized = XmlCommunication.Deserialize<Request>(xml);
|
|
162 | 162 |
} |
163 | 163 |
|
164 | 164 |
|
Server/ServerApp/Properties/launchSettings.json | ||
---|---|---|
2 | 2 |
"profiles": { |
3 | 3 |
"ServerApp": { |
4 | 4 |
"commandName": "Project", |
5 |
"commandLineArgs": "C:\\Users\\kalivoda\\Temp\\serverAppNetCore\\ServerAppNETCore\\ServerApp\\server_config"
|
|
5 |
"commandLineArgs": "C:\\Users\\elisk\\Documents\\aswi2021tri-musketyri\\Server\\ServerApp\\server_config"
|
|
6 | 6 |
} |
7 | 7 |
} |
8 | 8 |
} |
Server/ServerApp/User/CommandsAcceptor.cs | ||
---|---|---|
28 | 28 |
public void AcceptCommand() |
29 | 29 |
{ |
30 | 30 |
while (true) { |
31 |
Console.Write(">"); |
|
31 | 32 |
string command = Console.ReadLine(); |
32 |
Console.WriteLine("received admin command: " + command); |
|
33 |
Command c = ParseString(command); |
|
34 |
CheckCommand(c); |
|
35 |
//Program.NotifyUserMessage(command); |
|
33 |
if(command.Length > 0) |
|
34 |
{ |
|
35 |
Console.WriteLine("received admin command: " + command); |
|
36 |
Command c = ParseString(command); |
|
37 |
CheckCommand(c); |
|
38 |
//Program.NotifyUserMessage(command); |
|
39 |
} |
|
40 |
|
|
36 | 41 |
} |
37 | 42 |
} |
38 | 43 |
|
Také k dispozici: Unified diff
Modified XML deserialization + commands acceptor