Esempio n. 1
0
        /// <summary>
        ///     This method gets the data or current status for a request
        /// </summary>
        /// <param name="dataRequestLogObj"></param>
        /// <returns></returns>
        public static ZillowPropertyDetails ReRun(DataRequestLog dataRequestLogObj)
        {
            ZillowPropertyDetails zPropertyDetails = new ZillowPropertyDetails();

            zPropertyDetails.BBL                 = dataRequestLogObj.BBL;
            zPropertyDetails.requestId           = dataRequestLogObj.RequestId;
            zPropertyDetails.externalReferenceId = dataRequestLogObj.ExternalReferenceId;
            zPropertyDetails.status              = ((RequestStatus)dataRequestLogObj.RequestStatusTypeId).ToString();;
            zPropertyDetails.zEstimate           = null;
            try
            {
                using (WebDataEntities webDBEntities = new WebDataEntities())
                {
                    if (dataRequestLogObj.RequestStatusTypeId == (int)RequestStatus.Success)
                    {
                        Parameters parameters = JSONToParameters(dataRequestLogObj.RequestParameters);
                        //check if data available
                        WebDataDB.Zillow zillowObj = webDBEntities.Zillows.FirstOrDefault(i => i.BBL == parameters.BBL);

                        if (zillowObj != null && DateTime.UtcNow.Subtract(zillowObj.LastUpdated).Days <= 30)
                        {
                            zPropertyDetails.zEstimate = zillowObj.zEstimate;
                        }
                        else
                        {
                            zPropertyDetails.status = RequestStatus.Error.ToString();
                        }
                    }
                }
                return(zPropertyDetails);
            }
            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); }
        }
Esempio n. 2
0
        /// <summary>
        ///     This method deals with all the details associated with either returning the Zillow details or creating the
        ///     request for getting it scrapped from the web
        /// </summary>
        public static ZillowPropertyDetails Get(string propertyBBL, string address, string externalReferenceId, int priority, string jobId)
        {
            ZillowPropertyDetails zPropertyDetails = new ZillowPropertyDetails();

            zPropertyDetails.BBL = propertyBBL;
            zPropertyDetails.externalReferenceId = externalReferenceId;
            zPropertyDetails.status    = RequestStatus.Pending.ToString();
            zPropertyDetails.zEstimate = null;

            string parameters = ParametersToJSON(propertyBBL, address);

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

                        //check if data available
                        WebDataDB.Zillow zillowObj = webDBEntities.Zillows.FirstOrDefault(i => i.BBL == propertyBBL);

                        // record in database and data is not stale
                        if (zillowObj != null && DateTime.UtcNow.Subtract(zillowObj.LastUpdated).Days <= 30)
                        {
                            zPropertyDetails.zEstimate = zillowObj.zEstimate;
                            zPropertyDetails.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.ZillowZEstimate(address);

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

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

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