public dynamic GetResult(string xml) { var xDocument = ProcessingData(xml); dynamic root = new ExpandoObject(); XmlToDynamic.Parse(root, xDocument.Elements().First()); return(root); }
ICollection <string> GetDprojFiles(string dprojFileName) { var dir = Directory.GetCurrentDirectory(); var path = GetFilePath(dprojFileName, dir); var files = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); if (File.Exists(path)) { try { var rootDir = Path.GetDirectoryName(path); Directory.SetCurrentDirectory(rootDir); var x = XmlToDynamic.Parse(File.ReadAllText(path)); try { var references = x.ItemGroup.DCCReference; foreach (var reference in references) { var fpath = GetFilePath(reference.Include, dir); if (File.Exists(fpath)) { files.Add(fpath); fpath = Path.ChangeExtension(fpath, ".dfm"); if (File.Exists(fpath)) { files.Add(fpath); } } } } catch { } try { var project = GetFilePath(x?.ItemGroup?.DelphiCompile.Include, dir); if (File.Exists(project)) { files.Add(project); foreach (var f in GetProjFiles(project, dir)) { files.Add(f); } } } catch { } } finally { Directory.SetCurrentDirectory(dir); } } return(files); }
public Applicant ParseApplicant(string xmlRequest) { Applicant applicant; try { var xDoc = XDocument.Load(new StringReader(xmlRequest)); dynamic root = new ExpandoObject(); var primaryNode = xDoc.Descendants().FirstOrDefault(x => x.Name.LocalName == "primary"); XmlToDynamic.Parse(root, primaryNode); // Applicant personal information var title = root.primary.name.title; var foreName = root.primary.name.forename; var middleName = XmlToDynamic.HasProperty(root.primary.name, "middlename") ? root.primary.name.middlename : null; var surName = root.primary.name.surname; var dateOfBirth = root.primary.dob; // Current address var number = XmlToDynamic.HasProperty(root.primary.currentAddress.address, "number") ? root.primary.currentAddress.address.number : null; var postCode = root.primary.currentAddress.address.postcode; var postTown = root.primary.currentAddress.address.postTown; var street1 = root.primary.currentAddress.address.street1; applicant = new Applicant { Title = title, ForeName = foreName, MiddleName = middleName, Surname = surName, DateOfBirth = dateOfBirth, CurrentAddress = new Address { Number = number, PostCode = postCode, PostTown = postTown, Street1 = street1 } }; } catch (Exception e) { throw new Exception($"Unable to parse applicant information from Equifax request: {e.Message}"); } return(applicant); }
private void syncUploadedPortfolios() { DirectoryInfo directoryInfo = new DirectoryInfo(@Path.Combine(_hostingEnvironment.WebRootPath, _config.Value.PortfolioUploadPath)); FileInfo[] files = directoryInfo.GetFiles("*.xml"); using (var context = new PortfolioUploadContext(_serviceProvider.GetRequiredService <DbContextOptions <PortfolioUploadContext> >())) { // Clear out existing portfolios var itemsToDelete = context.Set <PortfolioUpload>(); context.PortfolioUpload.RemoveRange(itemsToDelete); //Populate db foreach (var file in files) { //fileter out non-portfolios using (var streamReader = new StreamReader(file.FullName)) { //read from file var xDoc = XDocument.Load(streamReader); dynamic portfolio = new ExpandoObject(); XmlToDynamic.Parse(portfolio, xDoc.Elements().First()); //dynamic portfolio = DynamicXml.Parse(streamReader.ReadToEnd()); try { context.PortfolioUpload.AddRange( new PortfolioUpload { Name = file.Name, TradeCount = portfolio.Portfolio.Trade.Count, Agreements = "N", UploadTime = file.LastWriteTime, FileName = file.Name, LastRunTime = file.LastAccessTime }); } catch { } } } context.SaveChanges(); } }
public IHttpActionResult Get(Guid Id) { try { var record = _emailRepository.Get(Id); if (record == null) { return(new CustomResponse(HttpStatusCode.OK, null)); } var xDocument = ProcessingData(record.Data); dynamic root = new ExpandoObject(); XmlToDynamic.Parse(root, xDocument.Elements().First()); return(new CustomResponse(HttpStatusCode.OK, root.root)); } catch (Exception ex) { return(new CustomResponse(HttpStatusCode.BadRequest, ex.Message)); } }
ICollection <string> GetGroupProjFiles(string groupProjFileName) { var files = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); var x = XmlToDynamic.Parse(File.ReadAllText(groupProjFileName)); try { var projects = x.ItemGroup.Projects; foreach (var proj in projects) { foreach (var f in GetDprojFiles(Path.GetFullPath(proj.Include))) { files.Add(f); } } } catch { } return(files); }
public IHttpActionResult Get() { try { var list = new List <dynamic>(); var records = _emailRepository.Get(); foreach (var record in records) { var xDocument = ProcessingData(record.Data); dynamic root = new ExpandoObject(); XmlToDynamic.Parse(root, xDocument.Elements().First()); list.Add(root.root); } return(new CustomResponse(HttpStatusCode.OK, list)); } catch (Exception ex) { return(new CustomResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public async Task <IActionResult> ViewXmlPortfolio(int?id) { if (id == null) { return(NotFound()); } var portfolioUpload = await _context.PortfolioUpload.FindAsync(id); if (portfolioUpload == null) { return(NotFound()); } else { //Make nicer storing full path? DirectoryInfo directoryInfo = new DirectoryInfo(@Path.Combine(_hostingEnvironment.WebRootPath, _config.Value.PortfolioUploadPath)); FileInfo file = directoryInfo.GetFiles(portfolioUpload.FileName).FirstOrDefault(); using (var streamReader = new StreamReader(file.FullName)) { //read from file var xDoc = XDocument.Load(streamReader); dynamic root = new ExpandoObject(); XmlToDynamic.Parse(root, xDoc.Elements().First()); try { return(View(root)); } catch { return(NotFound()); } } } }
public void TestMethod1() { //read from text //var xDoc = XDocument.Parse(txt); //read from url //var request = WebRequest.Create(@"http://...") as HttpWebRequest; //request.Credentials = CredentialCache.DefaultNetworkCredentials; //var xDoc = XDocument.Load(request.GetResponse().GetResponseStream()); //read from file var xDoc = XDocument.Parse(xml);//XDocument.Load(../xml.xml) dynamic root = new ExpandoObject(); XmlToDynamic.Parse(root, xDoc.Elements().First()); Console.WriteLine(root.contacts.contact.Count); Console.WriteLine(root.contacts.contact[0].firstName); Console.WriteLine(root.contacts.contact[0].id); }