I have to read some data from xml file and then need to store the converted json in the database. The class DtoProcedureXml mapped with xml attributes.
public class ProcedureManager
{
#region Declaration
private DtoProcedureXml procedure;
private ProcedureDataManager procedureDataManager;
#endregion
public ProcedureManager()
{
this.procedureDataManager = new ProcedureDataManager();
}
public bool SaveProcedureData(long procedureID)
{
bool isSuccess = false;
try
{
SetProcedureXmlData();
isSuccess = SaveProcedureSummary(procedureID);
}
catch (Exception ex)
{
CommonLogger.LogException("Failed to save procedure data");
}
return isSuccess;
}
private bool SaveProcedureSummary(long procedureID)
{
//saving the data to db
return procedureDataManager.Save(new DtoProcedure { ProcedureID = procedureID, JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(this.procedure), CreatedOn = DateTime.Now });
}
private void SetProcedureXmlData()
{
this.procedure = new DtoProcedureXml();
XmlSerializer serializer = new XmlSerializer(typeof(DtoProcedureXml));
using (XmlTextReader reader = new XmlTextReader(FileShareUrlBuilder.GetPath(Constants.Structures.PathType.XMLFILEPATH)))
{
object obj = serializer.Deserialize(reader);
this.procedure = (DtoProcedureXml)obj;
reader.Close();
}
}
}
I have some concerns with the function SetSReportXmlData() When I was debugging the XmlSerializer code takes few milliseconds, is it right to move that code in the using section?
Also please let me know if there is any efficient solutions than this logic.