Subscribe to Random Programs I've created/altered.        RSS Feed
-----

Client XML Processing Engine

Icon Leave Comment
So for the past month or so I've been working on a Framework that is database driven and can take in any XML file and based on the client, choose a dynamic object mapper, and based on the keys in each item in the XML file choose a Parser, then it uses the parser to export information from the file to a CSV. It's not completely finished, but I hvae the foundation done and am pretty happy with it.

First thing I needed was the database (It's very simple right now).
Posted Image

So I figured out the program flow show go something like this
1. User chooses folder and populates a list of files.
2. User chooses files to Process.
3. Based on the folder location Go to the database and get the client associated with it.
4. Create an ObjectMapper based off the client.
5. Create a List<Parsers> based off the ObjectMapper
4. read in the file and serialize it to a List of json lines
5. loop through the lines of json and use the ObjectMapper to map the dynamic json to an InstanceList (InstanceList is the child of the root node and contains member and correspondenceItem nodes
6. When the Object Mapper is initialized A parser gets assigned to an instancelist.
7. loop through the instance lists and "Parse" it using it's assigned Parser.

Below is the code at how I achieved this.

frmMain
XmlDocument doc = new XmlDocument();
			StreamReader sr = new StreamReader(filePath);
			sr.ReadLine();
			doc.LoadXml(sr.ReadToEnd());
			XmlNodeList xmlNodeList = doc.ChildNodes[0].ChildNodes;
			List<string> jsonList = (from XmlNode xmlnode in xmlNodeList select JsonConvert.SerializeXmlNode(xmlnode)).ToList();
			ClientXMLProcessingEngineEntities engine = new ClientXMLProcessingEngineEntities();
			List<Client> clients = engine.Clients.ToList();
			List<IInstanceList> instanceLists = new List<IInstanceList>();
			List<Total> TotalCounts = new List<Total>();
			IObjectMapper mapper;
			Client currentClient = clients.Find(x => x.ClientName == "ClientName");
			ObjectMapper currentMapper = currentClient.ObjectMappers.ToList()[0];
			mapper = ObjectFactory.GetInstance(currentMapper);
			mapper.Initialize();
			jsonList.ForEach(x =>
			{
				instanceLists.Add(mapper.MapObject(JObject.Parse(x), true, ref TotalCounts));
			});
			instanceLists.ForEach(x =>
			{
				IParser parser = x.Parser;
				parser.ExportToCSV(x);
			});



Will Update after work, suddenly got busy.

Attached image(s)

  • Attached Image

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526 27 2829

Recent Entries

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)