public override bool Init(FtpServer server, IServerConfig config) { if (!base.Init(server, config)) { return(false); } var userSettingFile = config.Options.GetValue("userSetting"); if (string.IsNullOrEmpty(userSettingFile)) { server.Logger.Error("No user setting file defined!"); return(false); } List <FtpUser> users; try { users = XmlSerializerUtil.Deserialize <List <FtpUser> >(server.GetFilePath(userSettingFile)); } catch (Exception e) { AppServer.Logger.Error("Failed to deserialize FtpUser list file!", e); return(false); } m_UserDict = users.ToDictionary(u => u.UserName, u => u, StringComparer.OrdinalIgnoreCase); return(true); }
/// <summary> /// Parses the response, parses body elements. /// </summary> /// <typeparam name="TRes"></typeparam> /// <param name="message"></param> public static void ParseResponse <TRes>(SoapMessage message) { Logger.Instance.LogFunctionEntry("TouricoMessageHelper", "ParseResponse"); var touricoMessage = message as TouricoMessage; if (touricoMessage == null) { throw new InvalidCastException("Expected SabreMessage"); } var doc = new XmlDocument(); doc.LoadXml(message.RawResponseText); var nsMgr = new XmlNamespaceManager(doc.NameTable); nsMgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/"); //Body var bodyNode = doc.SelectSingleNode("//soap:Body", nsMgr); if (bodyNode != null) { //Try catch here to know if body is actual response or Fault XmlReader bodyReader = XmlReader.Create(new StringReader(bodyNode.InnerXml)); Message msg = Message.CreateMessage(MessageVersion.Soap11, null, bodyReader); var converter = TypedMessageConverter.Create(typeof(TRes), null, new XmlSerializerFormatAttribute()); touricoMessage.ResponseBodyPayload = (TRes)converter.FromMessage(msg); touricoMessage.ResponseBodyText = bodyNode.InnerXml; if (touricoMessage.ResponseBodyPayload == null) { var fault = XmlSerializerUtil <WSFault> .Deserialize(touricoMessage.ResponseBodyText); if (fault != null) { throw new TouricoProviderException(fault); } throw new Exception("ResponseBodyPayload is null."); } } Logger.Instance.LogFunctionExit("TouricoMessageHelper", "ParseResponse"); }
private void ReadUserConfigFile() { if (!File.Exists(m_UserConfigFile)) { return; } var lastFileWriteTime = File.GetLastWriteTime(m_UserConfigFile); if (lastFileWriteTime <= m_LastUserFileLoadTime) { return; } var users = XmlSerializerUtil.Deserialize <List <FtpUser> >(m_UserConfigFile); m_UserDict = users.ToDictionary(u => u.UserName, u => u, StringComparer.OrdinalIgnoreCase); m_LastUserFileLoadTime = lastFileWriteTime; }
private static async Task Låge4(ParticipateResponse participateResponse, string xmlUrl, HttpClient httpClient) { Console.WriteLine("Parsing XML..."); XDocument xmlDocument = XDocument.Load(xmlUrl); ToyDistributionProblem parsedXml = XmlSerializerUtil.Deserialize <ToyDistributionProblem>(xmlDocument); Console.WriteLine($"Xml parsed to object...{parsedXml.Children.Count} children and {parsedXml.Toys.Count} toys..."); Console.WriteLine("Starting to distribute toys to children..."); Queue <Child> remainingChilren = new Queue <Child>(parsedXml.Children); int counter = 0; ToyDistributorHelper toyDistributor = new ToyDistributorHelper(parsedXml.Toys); //ToyDistributionResult result = new ToyDistributionResult(); List <ToyDistribution> distributionResult = new List <ToyDistribution>(); try { while (remainingChilren.Count > 0) { Console.WriteLine($"Iteration: {counter}"); Child currentChild = remainingChilren.Dequeue(); Toy foundToy; bool resolved = toyDistributor.TryResolve(currentChild, out foundToy); if (resolved) { distributionResult.Add(new ToyDistribution() { ChildName = currentChild.Name, ToyName = foundToy.Name }); toyDistributor.RemoveToy(foundToy); } else { remainingChilren.Enqueue(currentChild); } counter++; if (counter > 50) { break; } } //Console.WriteLine($"Toy distribution result: {result.ToString()}"); //List<ToyDistribution> distributionResult = new List<ToyDistribution>(); //foreach (var res in result.ToyDistribution) //{ // distributionResult.Add(new ToyDistribution() { ChildName = res.Key, ToyName = res.Value }); //} HttpResponseMessage toyDistributionResponse = await httpClient.PostAsJsonAsync("/api/toydistribution", new { id = participateResponse.Id, toyDistribution = distributionResult }); if (!toyDistributionResponse.IsSuccessStatusCode) { string reason = await toyDistributionResponse.Content.ReadAsStringAsync(); throw new ChristmasException($"{toyDistributionResponse.StatusCode}: {(await toyDistributionResponse.Content.ReadAsStringAsync())}"); } Console.WriteLine("##############################################################################"); string apiResult = await toyDistributionResponse.Content.ReadAsStringAsync(); Console.WriteLine(apiResult); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }