} // Name public override void Execute() { switch (m_nWorkMode) { case WorkMode.LoadFull: Result = ExperianLtd.Load(m_nServiceLogID, DB, Log); break; case WorkMode.CheckCache: Result = ExperianLtd.Load(m_sCompanyRefNum, DB, Log); break; default: Log.Alert("Unsupported work mode: {0}", m_nWorkMode.ToString()); return; } // switch if (Result != null && !string.IsNullOrEmpty(Result.RegisteredNumber)) { var scoreHistory = DB.Fill <ScoreAtDate>( "GetCompanyHistory", CommandSpecies.StoredProcedure, new QueryParameter("RefNumber", Result.RegisteredNumber) ); History = scoreHistory; } //Load companies house data var companyRef = string.IsNullOrEmpty(this.m_sCompanyRefNum) && Result != null ? Result.RegisteredNumber : this.m_sCompanyRefNum; GetCompaniesHouseData getCompaniesHouseData = new GetCompaniesHouseData(null, companyRef, false); getCompaniesHouseData.Execute(); CompaniesHouseResult = getCompaniesHouseData.Result; } // Execute
} // GetConsumerCaisBalance public static decimal?GetLimitedCaisBalance(ExperianLtd oExperianLtd) { if (oExperianLtd == null) { return(null); } int nFoundCount = 0; decimal balance = 0; foreach (var oRow in oExperianLtd.Children) { if (oRow.GetType() != typeof(ExperianLtdDL97)) { continue; } nFoundCount++; var dl97 = (ExperianLtdDL97)oRow; if ((dl97.AccountState != null) && (dl97.AccountState != "S")) { balance += dl97.CurrentBalance ?? 0; } } // for each return(nFoundCount == 0 ? (decimal?)null : balance); } // GetLimitedCaisBalance
public void Add(SafeReader oRow, AConnection oDB) { DateTime oInsertDate = oRow["InsertDate"]; switch ((string)oRow["ServiceType"]) { case "Consumer Request": if (DateFits(ref m_oNdspciiDataDate, oInsertDate)) { ExperianConsumerData data = ExperianConsumerData.Load((long)oRow["ServiceLogID"], oDB, m_oLog); if (data != null && data.ServiceLogId != null) { AddNdspciiData(data.CII); } } // if break; case "E-SeriesLimitedData": if (DateFits(ref m_oCompanyDataDate, oInsertDate)) { AddLtdData(ExperianLtd.Load((long)oRow["ServiceLogID"], oDB, m_oLog)); } break; case "E-SeriesNonLimitedData": if (DateFits(ref m_oCompanyDataDate, oInsertDate)) { AddCompanyData(oDB); } break; } // switch } // Add
} // AddNdspciiDAta private void AddLtdData(ExperianLtd oExperianLtd) { if (m_sCompanyNumber == null) { m_sCompanyNumber = oExperianLtd.RegisteredNumber; } m_sCompanyName = oExperianLtd.CompanyName; if (!m_oIncorporationDate.HasValue) { m_oIncorporationDate = oExperianLtd.IncorporationDate; } if (!m_oIncorporationDate.HasValue) { m_oLog.Warn("Failed to parse Experian output (incorporation date) for customer {0}", CustomerID); } m_nCompanyScore = oExperianLtd.CommercialDelphiScore; if (ReferenceEquals(m_sCreditLimit, null)) { m_sCreditLimit = oExperianLtd.CommercialDelphiCreditLimit.HasValue ? oExperianLtd.CommercialDelphiCreditLimit.Value.ToString() : null; } // if } // AddLtdData
public LoadExperianLtd(string sCompanyRefNum, long nServiceLogID) { Result = new ExperianLtd(); m_nWorkMode = string.IsNullOrWhiteSpace(sCompanyRefNum) ? WorkMode.LoadFull : WorkMode.CheckCache; m_sCompanyRefNum = sCompanyRefNum; m_nServiceLogID = nServiceLogID; } // constructor
} // Load private ExperianLtd Parse(Tuple <XmlDocument, DateTime, string> oDoc) { if (oDoc == null) { return(null); } if ((oDoc.Item1 == null) || (oDoc.Item1.DocumentElement == null)) { return(null); } Log.Info("Parsing Experian company data..."); ExperianLtd oMainTable = new ExperianLtd(Log) { ServiceLogID = m_nServiceLogID, }; oMainTable.LoadFromXml(oDoc.Item1.DocumentElement); if (!oMainTable.ShouldBeSaved()) { Log.Warn( "Parsing Experian company data failed: no main company data loaded for service log entry {0}, using requested company ref num '{1}'.", m_nServiceLogID, oDoc.Item3 ); oMainTable.RegisteredNumber = oDoc.Item3; } // if if (!oMainTable.ShouldBeSaved()) { Log.Warn( "Parsing Experian company data failed: no main company data loaded for service log entry {0}.", m_nServiceLogID ); return(null); } // if Log.Info("Parsing Experian company data complete."); oMainTable.ReceivedTime = oDoc.Item2; return(oMainTable); } // Parse
} // constructor public bool IsDirector(ExperianLtd oExperianLtd, string sFirstName, string sLastName) { sFirstName = sFirstName.Trim().ToLowerInvariant(); sLastName = sLastName.Trim().ToLowerInvariant(); var lst = oExperianLtd.GetChildren <ExperianLtdDL72>(); foreach (var oDir in lst) { if ( (oDir.FirstName.Trim().ToLowerInvariant() == sFirstName) && (oDir.LastName.Trim().ToLowerInvariant() == sLastName) ) { return(true); } } // for each return(false); } // IsDirector
} // Add public void LoadLastScore(AConnection oDB) { if (!ReferenceEquals(m_sCompanyName, null) && !ReferenceEquals(m_sCompanyNumber, null) && m_oIncorporationDate.HasValue && m_nCompanyScore.HasValue && !ReferenceEquals(m_sCreditLimit, null)) { return; } if (string.IsNullOrWhiteSpace(m_sCompanyRefNum)) { return; } ExperianLtd oExperianLtd = ExperianLtd.Load(m_sCompanyRefNum, oDB, m_oLog); if (oExperianLtd.RegisteredNumber == m_sCompanyRefNum) { AddLtdData(oExperianLtd); } AddCompanyData(oDB); } // LoadLastScore
} // Parse private ExperianLtd Save(ExperianLtd oMainTable) { if (oMainTable == null) { return(null); } Log.Info("Saving Experian company data into DB..."); ConnectionWrapper oPersistent = DB.GetPersistent(); oPersistent.BeginTransaction(); if (!oMainTable.Save(DB, oPersistent)) { oPersistent.Rollback(); Log.Warn("Saving Experian company data into DB failed."); return(null); } // if oPersistent.Commit(); Log.Info("Saving Experian company data into DB complete."); return(oMainTable); } // Save
} // IsDirector public void DetectTangibleEquity(ExperianLtd oExperianLtd, out decimal nResultTangibleEquity, out decimal nResultTotalCurrentAssets) { nResultTangibleEquity = -1; nResultTotalCurrentAssets = 0; IEnumerable <ExperianLtdDL99> lst = oExperianLtd.GetChildren <ExperianLtdDL99>(); ExperianLtdDL99 oCurNode = null; foreach (var oNode in lst) { if (!oNode.Date.HasValue) { continue; } if (oCurNode == null) { oCurNode = oNode; continue; } // if // ReSharper disable PossibleInvalidOperationException if (oCurNode.Date.Value < oNode.Date.Value) { oCurNode = oNode; } // ReSharper restore PossibleInvalidOperationException } // for each if (oCurNode == null) { return; } // ReSharper disable PossibleInvalidOperationException Log.Debug("Calculating tangible equity from data for {0}.", oCurNode.Date.Value.ToString("MMMM d yyyy", CultureInfo.InvariantCulture)); // ReSharper restore PossibleInvalidOperationException decimal nTangibleEquity = 0; decimal nTotalCurrentAssets = 0; Action <decimal?> oPlus = x => nTangibleEquity += x ?? 0; Action <decimal?> oMinus = x => nTangibleEquity -= x ?? 0; Action <decimal?> oSet = x => nTotalCurrentAssets = x ?? 0; var oTags = new List <Tuple <decimal?, Action <decimal?> > > { new Tuple <decimal?, Action <decimal?> >(oCurNode.TotalShareFund, oPlus), new Tuple <decimal?, Action <decimal?> >(oCurNode.InTngblAssets, oMinus), new Tuple <decimal?, Action <decimal?> >(oCurNode.FinDirLoans, oPlus), new Tuple <decimal?, Action <decimal?> >(oCurNode.CredDirLoans, oPlus), new Tuple <decimal?, Action <decimal?> >(oCurNode.FinLbltsDirLoans, oPlus), new Tuple <decimal?, Action <decimal?> >(oCurNode.DebtorsDirLoans, oMinus), new Tuple <decimal?, Action <decimal?> >(oCurNode.OnClDirLoans, oPlus), new Tuple <decimal?, Action <decimal?> >(oCurNode.CurrDirLoans, oMinus), new Tuple <decimal?, Action <decimal?> >(oCurNode.TotalCurrAssets, oSet), }; foreach (var oTag in oTags) { oTag.Item2(oTag.Item1); } var ci = new CultureInfo("en-GB", false); Log.Debug("Tangible equity is {0}.", nTangibleEquity.ToString("C2", ci)); Log.Debug("Total current assets is {0}.", nTotalCurrentAssets.ToString("C2", ci)); nResultTangibleEquity = nTangibleEquity; nResultTotalCurrentAssets = nTotalCurrentAssets; } // DetectTangibleEquity
public LimitedResults(ExperianLtd oExperianLtd, bool bCacheHit) : base(oExperianLtd.ServiceLogID, oExperianLtd.ReceivedTime, bCacheHit) { Owners = new SortedSet <string>(); RawExperianLtd = oExperianLtd; Parse(); } // constructor
public ParseExperianLtd(long nServiceLogID) { Result = new ExperianLtd(); m_nServiceLogID = nServiceLogID; } // constructor
} // TargetCache private LimitedResults GetOneLimitedBusinessData( string regNumber, int customerId, bool checkInCacheOnly, bool forceCheck ) { if (string.IsNullOrWhiteSpace(regNumber)) { return(null); } try { ExperianLtd oExperianLtd = null; bool bCacheHit = false; if (forceCheck) { oExperianLtd = DownloadOneLimitedFromExperian(regNumber, customerId); } if (oExperianLtd == null) { oExperianLtd = ObjectFactory.GetInstance <IEzServiceAccessor>().CheckLtdCompanyCache(1, regNumber); if ((oExperianLtd == null) || (oExperianLtd.ID == 0)) { oExperianLtd = null; log.Debug( "GetOneLimitedBusinessData({0}, {1}, {2}, {3}): no data found in cache.", regNumber, customerId, checkInCacheOnly, forceCheck ); if (!checkInCacheOnly) { oExperianLtd = DownloadOneLimitedFromExperian(regNumber, customerId); } } else { bool cacheExpired = (DateTime.UtcNow - oExperianLtd.ReceivedTime).TotalDays > CurrentValues.Instance.UpdateCompanyDataPeriodDays; if (cacheExpired) { oExperianLtd = DownloadOneLimitedFromExperian(regNumber, customerId); if ((oExperianLtd == null) || (oExperianLtd.ID == 0)) { oExperianLtd = null; log.Debug( "GetOneLimitedBusinessData({0}, {1}, {2}, {3}): " + "no data downloaded nor data found in cache.", regNumber, customerId, checkInCacheOnly, forceCheck ); } // if } else { bCacheHit = true; } } // if } // if log.Debug( "GetOneLimitedBusinessData({0}, {1}, {2}, {3}) = (cache hit: {4}):\n{5}", regNumber, customerId, checkInCacheOnly, forceCheck, bCacheHit, oExperianLtd == null ? "-- null --" : oExperianLtd.StringifyAll() ); return(oExperianLtd == null ? null : new LimitedResults(oExperianLtd, bCacheHit)); } catch (Exception e) { log.Error(e, "Failed to get limited results for a company {0} and customer {1} (cache only: {2}, force: {3}).", regNumber, customerId, checkInCacheOnly ? "yes" : "no", forceCheck ? "yes" : "no" ); return(new LimitedResults(e)); } // try } // GetOneLimitedBusinessData