/// <summary> /// This method gets the data or current status for a request /// </summary> /// <param name="dataRequestLogObj"></param> /// <returns></returns> public static WaterBillDetails ReRun(DataRequestLog dataRequestLogObj) { WaterBillDetails waterBill = new WaterBillDetails(); waterBill.BBL = dataRequestLogObj.BBL; waterBill.requestId = dataRequestLogObj.RequestId; waterBill.externalReferenceId = dataRequestLogObj.ExternalReferenceId; waterBill.status = ((RequestStatus)dataRequestLogObj.RequestStatusTypeId).ToString(); waterBill.billAmount = null; try { using (WebDataEntities webDBEntities = new WebDataEntities()) { if (dataRequestLogObj.RequestStatusTypeId == (int)RequestStatus.Success) { Parameters waterParams = JSONToParameters(dataRequestLogObj.RequestParameters); //check if data available WebDataDB.WaterBill waterBillObj = webDBEntities.WaterBills.FirstOrDefault(i => i.BBL == waterParams.BBL); if (waterBillObj != null && DateTime.UtcNow.Subtract(waterBillObj.LastUpdated).Days <= 30) { waterBill.billAmount = waterBillObj.BillAmount; } else { waterBill.status = RequestStatus.Error.ToString(); } } } return(waterBill); } catch (Exception e) { Common.Logs.log().Error(string.Format("Exception encountered precessing request log for {0} with externalRefId {1}{2}", dataRequestLogObj.BBL, dataRequestLogObj.ExternalReferenceId, Common.Logs.FormatException(e))); return(null); } }
/// <summary> /// This method deals with all the details associated with either returning the water bill details or creating the /// request for getting is scrapped from the web /// </summary> public static WaterBillDetails Get(string propertyBBL, string externalReferenceId, int priority, string jobId) { WaterBillDetails waterBill = new WaterBillDetails(); waterBill.externalReferenceId = externalReferenceId; waterBill.status = RequestStatus.Pending.ToString(); waterBill.BBL = propertyBBL; waterBill.billAmount = null; using (WebDataEntities webDBEntities = new WebDataEntities()) { using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction()) { string parameters = ParametersToJSON(propertyBBL); try { //check if data available WebDataDB.WaterBill waterBillObj = webDBEntities.WaterBills.FirstOrDefault(i => i.BBL == propertyBBL); // record in database and data is not stale if (waterBillObj != null && DateTime.UtcNow.Subtract(waterBillObj.LastUpdated).Days <= 30) { waterBill.billAmount = waterBillObj.BillAmount; waterBill.status = RequestStatus.Success.ToString(); DAL.DataRequestLog.InsertForCacheAccess(webDBEntities, propertyBBL, RequestTypeId, externalReferenceId, jobId, parameters); } else { //check if pending request in queue DataRequestLog dataRequestLogObj = DAL.DataRequestLog.GetPendingRequest(webDBEntities, propertyBBL, RequestTypeId, parameters); if (dataRequestLogObj == null) //No Pending Request Create New Request { string requestStr = RequestData.WaterBill(propertyBBL); Request requestObj = DAL.Request.Insert(webDBEntities, requestStr, RequestTypeId, priority, jobId); dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, requestObj.RequestId, externalReferenceId, jobId, parameters); waterBill.status = RequestStatus.Pending.ToString(); waterBill.requestId = requestObj.RequestId; } else //Pending request in queue { waterBill.status = RequestStatus.Pending.ToString(); //Send the RequestId for the pending request back waterBill.requestId = dataRequestLogObj.RequestId; dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, dataRequestLogObj.RequestId.GetValueOrDefault(), externalReferenceId, jobId, parameters); } } webDBEntitiestransaction.Commit(); } catch (Exception e) { webDBEntitiestransaction.Rollback(); waterBill.status = RequestStatus.Error.ToString(); DAL.DataRequestLog.InsertForFailure(propertyBBL, RequestTypeId, externalReferenceId, jobId, parameters); Common.Logs.log().Error(string.Format("Exception encountered processing {0} with externalRefId {1}: {2}", propertyBBL, externalReferenceId, Common.Logs.FormatException(e))); } } } return(waterBill); }