Hi I have got a requirement to extract various reports from our project management system into tables. Around 28 reports.
So initially I thought about extracting it in different blocks based on the report IDs like this
switch (reportId)
{
case 737://project static
KipReport<ApiProjectStatic> rptPS = JsonConvert.DeserializeObject<KipReport<ApiProjectStatic>>(responseBody,dateTimeConverter);
List<ApiProjectStatic> jsonPS = (List<ApiProjectStatic>)rptPS.Data;
//jsonPS = JsonConvert.DeserializeObject<List<ProjectStaticMain>>(rpt.Data);
List<KipProjectStatic> PM = new List<KipProjectStatic>();
PM = _mapper.Map<List<KipProjectStatic>>(jsonPS);
PM.Select(p => { p.LogId = log.LogId; return p; }).ToList();
_context.KipProjectStatics.AddRange(PM);
_context.SaveChanges();
if (rptPS.TotalPages > 1 && rptPS.PageNumber != rptPS.TotalPages)
{
GetKeyedinReport(reportId, rptPS.PageNumber + 1,log);
}
break;
case 740:
.....
.....
For every reports what changes here is the classnames and Context objects. So my question is, is there any way to switch those classes from string names coming from tables
For example I have a table like this
Report ID ReportName ModelClass JSONClass Context
--------------------------------------------------------------------------------------------------
737 Project Details KipProjectStatic ApiProjectStatic KipProjectStatics
738 Program rreport KipProgramme ApiProgramme KipProgrammes
.....
...
.
---------------------------------------------------------------------------------------------------
So we are looping through these data and switches the functions and classes based on the string values coming from different columns. Hope its clear
Also here GetKeyedinReport function is always the same for all reports.. It just returns the json based on the ID we pass
Please share a solution
Aucun commentaire:
Enregistrer un commentaire