Beispiel #1
0
 // TODO: Possibly remove this depending on whether we can ensure proper entries intrinsically
 private static IEnumerable<string> Validate(Request request)
 {
     foreach (var requestData in request.Data.Where(requestData => !requestData.IsValid))
     {
         yield return string.Concat("Request of type ", requestData.Type, " with id: ", requestData.Id, " is missing data.", Environment.NewLine);
     }
 }
Beispiel #2
0
        public string Serialize(Request request)
        {
            var validationErrors = Validate(request);
            if (validationErrors.Any())
                throw new NWXClientException(string.Concat(validationErrors));
            var doc = new XElement("nwx",
                                   new XAttribute("version", request.Version.ToString()),
                                   request.Authenticator != null ? request.Authenticator.GenerateXml() : null,
                                   new XElement("Request",
                                                from d in request.Data
                                                select SerializeXml(d.Type, d)));
            //select d.GenerateXml()));
            return doc.ToString();

            //var doc = new XmlDocument();
            //doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null));

            //XmlElement nwx = doc.CreateElement("nwx");
            //nwx.SetAttribute("version", request.Version.ToString());

            //XmlElement req = doc.CreateElement("Request");

            //foreach(IRequestData data in request.Data)
            //{
            //    req.AppendChild(data.GenerateXml())
            //}

            //nwx.AppendChild(req);
            //doc.AppendChild(nwx);
            //return doc.InnerXml;
        }