Пример #1
0
        /// <summary>
        ///     This method gets the data or current status for a request
        /// </summary>
        /// <param name="dataRequestLogObj"></param>
        /// <returns></returns>
        public static NoticeOfPropertyValueResult ReRun(DataRequestLog dataRequestLogObj)
        {
            NoticeOfPropertyValueResult resultObj = new NoticeOfPropertyValueResult();

            resultObj.BBL                 = dataRequestLogObj.BBL;
            resultObj.requestId           = dataRequestLogObj.RequestId;
            resultObj.externalReferenceId = dataRequestLogObj.ExternalReferenceId;
            resultObj.status              = ((RequestStatus)dataRequestLogObj.RequestStatusTypeId).ToString();

            try
            {
                using (WebDataEntities webDBEntities = new WebDataEntities())
                {
                    if (dataRequestLogObj.RequestStatusTypeId == (int)RequestStatus.Success)
                    {
                        Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters);
                        //check if data available
                        WebDataDB.NoticeOfProperyValue noticeOfPropetyValueObj = webDBEntities.NoticeOfProperyValues.FirstOrDefault(i => i.BBL == parameters.BBL);

                        if (noticeOfPropetyValueObj != null && DateTime.UtcNow.Subtract(noticeOfPropetyValueObj.LastUpdated).Days <= 30)
                        {
                            resultObj.noticeOfPropertyValue = noticeOfPropetyValueObj;
                        }
                        else
                        {
                            resultObj.status = RequestStatus.Error.ToString();
                        }
                    }
                }
                return(resultObj);
            }
            catch (Exception e)
            {
                Common.Logs.log().Error(string.Format("Exception encountered processing request log for {0} with externalRefId {1}{2}",
                                                      dataRequestLogObj.BBL, dataRequestLogObj.ExternalReferenceId, Common.Logs.FormatException(e)));
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        ///     This method deals with all the details associated with either returning the Notice Of Property Value details or creating the
        ///     request for getting the data from the web
        /// </summary>
        /// <param name="propertyBBL"></param>
        /// <param name="externalReferenceId"></param>
        /// <param name="jobId"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public static NoticeOfPropertyValueResult GetDetails(string propertyBBL, string externalReferenceId, int priority, string jobId)
        {
            NoticeOfPropertyValueResult NPOVResultObj = new NoticeOfPropertyValueResult();

            NPOVResultObj.BBL = propertyBBL;
            NPOVResultObj.externalReferenceId = externalReferenceId;
            NPOVResultObj.status = RequestStatus.Pending.ToString();

            string parameters = ParametersToJSON(propertyBBL);

            using (WebDataEntities webDBEntities = new WebDataEntities())
            {
                using (var webDBEntitiestransaction = webDBEntities.Database.BeginTransaction())
                {
                    try
                    {
                        string jsonBillParams = ParametersToJSON(propertyBBL);

                        //check if data available
                        var noticeOfPropertyValueObj = webDBEntities.NoticeOfProperyValues.FirstOrDefault(i => i.BBL == propertyBBL);

                        // record in database and data is not stale
                        if (noticeOfPropertyValueObj != null && DateTime.UtcNow.Subtract(noticeOfPropertyValueObj.LastUpdated).Days <= 30)
                        {
                            NPOVResultObj.noticeOfPropertyValue = noticeOfPropertyValueObj;
                            NPOVResultObj.status = RequestStatus.Success.ToString();

                            DAL.DataRequestLog.InsertForCacheAccess(webDBEntities, propertyBBL, RequestTypeId, externalReferenceId, jobId, jsonBillParams);
                        }
                        else
                        {   //check if pending request in queue
                            DataRequestLog dataRequestLogObj = DAL.DataRequestLog.GetPendingRequest(webDBEntities, propertyBBL, RequestTypeId, jsonBillParams);

                            if (dataRequestLogObj == null) //No Pending Request Create New Request
                            {
                                string requestStr = RequestResponseBuilder.RequestObjects.RequestData.NoticeOfPropertyValue(propertyBBL);

                                Request requestObj = DAL.Request.Insert(webDBEntities, requestStr, RequestTypeId, priority, jobId);

                                dataRequestLogObj = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId, requestObj.RequestId,
                                                                                               externalReferenceId, jobId, jsonBillParams);

                                NPOVResultObj.status    = RequestStatus.Pending.ToString();
                                NPOVResultObj.requestId = requestObj.RequestId;
                            }
                            else //Pending request in queue
                            {
                                //Update Priority if need
                                Request requestObj = DAL.Request.Update(webDBEntities, dataRequestLogObj.RequestId.GetValueOrDefault(), priority, jobId);

                                NPOVResultObj.status = RequestStatus.Pending.ToString();
                                //Send the RequestId for the pending request back
                                NPOVResultObj.requestId = dataRequestLogObj.RequestId;
                                dataRequestLogObj       = DAL.DataRequestLog.InsertForWebDataRequest(webDBEntities, propertyBBL, RequestTypeId,
                                                                                                     dataRequestLogObj.RequestId.GetValueOrDefault(), externalReferenceId, jobId, jsonBillParams);
                            }
                        }
                        webDBEntitiestransaction.Commit();
                    }
                    catch (Exception e)
                    {
                        webDBEntitiestransaction.Rollback();
                        NPOVResultObj.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(NPOVResultObj);
        }