public bool DownloadNewCases(bool GeoCodeAddresses) { //ceck if we've established conection and queried for the data bool _status = false; //we may be calling Downloadnewcases without the intermediate prompt that QueryCases allows.\ //if so call it first. if (_result == null) { _status = QueryNewCases(); } if (_status == true || _result != null) { try { string _rawData = _bankruptcyParser.PurchaseCases(_result); if (_rawData == null || _rawData.Length == 0) { _importStatus = "NO DATA"; return(false); } //_transaction.RawData = "text"; //string _rawData = "text"; //create the filepath string newPath = System.IO.Path.Combine(ConfigurationManager.AppSettings.Get("PACERFilePath"), _court.FilePrefix); System.IO.Directory.CreateDirectory(newPath); _filePath = newPath + @"\" + _court.FilePrefix + _startDate.ToString("MMddyyyy") + "_" + _endDate.ToString("MMddyyyy") + ".txt"; System.IO.File.WriteAllText(_filePath, _rawData); PacerImportTransactionService.Save(this); //if (_court == null) //{ // _court = CourtService.GetByID(this.CourtID); //} // ZipGeoCodeService.UpdateStatsForState(_court.StateCode); //execute the dts package //Load DTSX //Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application(); //Package package = app.LoadPackage(System.Configuration.ConfigurationManager.AppSettings.Get("PACERImportDTSXFile"), null); ////Specify Excel Connection From DTSX Connection Manager //Debug.WriteLine(package.Connections["SourceConnectionFlatFile"].ConnectionString); //package.Connections["SourceConnectionFlatFile"].ConnectionString = _filePath; //Debug.WriteLine(package.Connections["DestinationConnectionOLEDB"].ConnectionString); //package.Connections["DestinationConnectionOLEDB"].ConnectionString = ConfigurationManager.AppSettings["DTSConnectionString"]; //// //Execute DTSX. //Microsoft.SqlServer.Dts.Runtime.DTSExecResult results = package.Execute(); //if (results == DTSExecResult.Success) //{ // //yay! // BRGCaseMailServer.PacerImportTransactionService.ProcessImportTransaction(this); //} //else //{ // string _message = string.Empty; // foreach (DtsError _err in package.Errors) // { // _message += _err.Description + ". "; // } // _message += "Please see you system adminstrator. "; // //dts did not work so load the file and parse manually // _importMessage = "SSIS Import Failed with the error:" + _message + ". Trying Manaul import..."; if (BRGCaseMailServer.PacerImportTransactionService.ProcessManualImportTransaction(this) == true) { //process imported lines int rows = PacerImportTransactionService.ProcessImportedLineItems(this, GeoCodeAddresses); if (_court == null) { _court = CourtService.GetByID(this.CourtID); } if (this._dischargedCases == true) { _court.LastPacerLoadDischargeDate = this.EndDate; } else { _court.LastPacerLoadFileDate = this.EndDate; } CourtService.Save((Court)_court); return(true); } else { return(false); } } catch (Exception ex) { _importMessage = ex.Message; _importStatus = "FAILURE"; PacerImportTransactionService.Save(this); return(false); } } else { PacerImportTransactionService.Save(this); return(false); //end if (_status == true || _result != null) } }
public bool QueryNewCases() { o = new CaseSearchOptions(); string user = System.Configuration.ConfigurationManager.AppSettings.Get("PACERuser"); string pass = System.Configuration.ConfigurationManager.AppSettings.Get("PACERPassword"); _court = CourtService.GetByID(_courtID); _bankruptcyParser = new BankruptcyParser(_court.URLAbbrv, user, pass); // Login to the system if (!_bankruptcyParser.Login()) { _importMessage = "Could Not Login: "******"FAILURE"; _court = CourtService.GetByID(_courtID); _bankruptcyParser = new BankruptcyParser(_court.URLAbbrv, user, pass); if (!_bankruptcyParser.NextGenLogin()) { return(false); } else { return(true); } } // setup the search paramters o.open_cases = true; o.closed_cases = true; o.party_information = true; //set the chapters and discharged/filed o.chapter = new List <CaseSearchOptions.chapters>(); if (_dischargedCases == true) { o.date_type = CaseSearchOptions.date_types.discharged; o.chapter.Add(CaseSearchOptions.chapters.seven); o.chapter.Add(CaseSearchOptions.chapters.thirteen); } else { o.date_type = CaseSearchOptions.date_types.filed; o.chapter.Add(CaseSearchOptions.chapters.seven); } //set the case type o.case_type = new List <CaseSearchOptions.case_types>(); o.case_type.Add(CaseSearchOptions.case_types.bk); //Set the start and end dates. o.start = DateTime.Parse(_startDate.ToString()); o.end = DateTime.Parse(_endDate.ToString()); _result = _bankruptcyParser.FindCases(o); if (_result == null) { _importMessage = "Could Not Find Cases:" + _bankruptcyParser.lastError; _importStatus = "FAILURE"; PacerImportTransactionService.Save(this); return(false); } else { this.BillablePages = _result.billable_pages; this.Cost = Decimal.Parse(_result.cost.ToString()); SearchCriteria = _result.criteria; DownloadTimeStamp = DateTime.Now; PacerImportTransactionService.Save(this); //don't set the status and message yet as we still have to import... return(true); } }
public bool Reprocess(bool GeoCodeAddresses) { //ceck if we've established conection and queried for the data if (this.FilePath.Length > 0) { try { // Read the file as one string. System.IO.StreamReader myFile = new System.IO.StreamReader(this.FilePath); string _rawData = myFile.ReadToEnd(); myFile.Close(); if (_rawData == null || _rawData.Length == 0) { _importStatus = "NO DATA"; return(false); } //delete all imported data but don;t bother deleting bankruptcy case data as it will get written over //if already exists PacerImportDataService.DeleteForTransaction(this.ID); //get the court //Court _court = CourtService.GetByID(this.CourtID); //this.PacerFileFormatID = _format.ID; PacerFileFormat _format = PacerFileFormatService.GetByID(this.PacerFileFormatID); //on a reprocess we use the current format for the court if (BRGCaseMailServer.PacerImportTransactionService.ProcessManualImportTransaction(this, _format) == true) { //process imported lines int rows = PacerImportTransactionService.ProcessImportedLineItems(this, GeoCodeAddresses); if (_court == null) { _court = CourtService.GetByID(this.CourtID); } if (this._dischargedCases == true) { _court.LastPacerLoadDischargeDate = this.EndDate; } else { _court.LastPacerLoadFileDate = this.EndDate; } CourtService.Save((Court)_court); return(true); } else { return(false); } } catch (Exception ex) { this.ImportMessage = ex.Message; this.ImportStatus = "FAILURE"; PacerImportTransactionService.Save(this); return(false); } } else { PacerImportTransactionService.Save(this); return(false); //end if (_status == true || _result != null) } }
static public int ProcessImportedLineItems(PacerImportTransaction objPacerImportTransaction, bool GeocodeLocations) { List <PacerImportData> _data = PacerImportDataService.GetForImportTransaction(objPacerImportTransaction.ID); PacerImportData _previousRow = null; int insertedRowCount = 0; int updatedRowCount = 0; int formatErrors = 0; string StateCode = null; foreach (PacerImportData _row in _data) { if (_previousRow == null) { //first row - is this row a debtor - if this row fails we just exit with failure because the //file format is most likely incorrect. if (((_row.PartyCaseRole.ToUpper() == "DEBTOR") || (_row.PartyCaseRole.ToUpper() == "CO-DEBTOR") || (_row.PartyCaseRole.ToUpper() == "JOINT DEBTOR")) && _row.CareOfOK) { _row.Imported = true; PacerImportDataService.Save(_row); try { BankruptcyCase _case = new BankruptcyCase(_row); Debug.WriteLine(_case.CaseNumber4Digit); if (GeocodeLocations) { YahooGeoCoder.GeocodeCase(_case); } _case.IsModified = true; int returnvalue = BankruptcyCaseService.Save(_case, true); if (returnvalue == 1) { insertedRowCount++; } else if (returnvalue == 2) { updatedRowCount++; } } catch (Exception ex) { formatErrors++; } } _previousRow = _row; } else //previousrow != null if this row fails we do not exit with failure because the // it's just a bad row. { if (_row.PartyAddressLine1 != _previousRow.PartyAddressLine1 && ((_row.PartyCaseRole.ToUpper() == "DEBTOR") || (_row.PartyCaseRole.ToUpper() == "CO-DEBTOR") || (_row.PartyCaseRole.ToUpper() == "JOINT DEBTOR")) && _row.CareOfOK) { try { //debtor at different address _row.Imported = true; PacerImportDataService.Save(_row); BankruptcyCase _case = new BankruptcyCase(_row); if (GeocodeLocations) { YahooGeoCoder.GeocodeCase(_case); } if (insertedRowCount == 318) { Debug.WriteLine(_case.CaseNumber4Digit); } if (_case.LastName == "Babakatis") { Debug.WriteLine(_case.CaseNumber4Digit); } _case.IsModified = true; int returnvalue = BankruptcyCaseService.Save(_case, true); if (returnvalue == 1) { insertedRowCount++; if (insertedRowCount == 1654) { Debug.WriteLine(insertedRowCount); } } else if (returnvalue == 2) { updatedRowCount++; } } catch (Exception e) { formatErrors++; } } _previousRow = _row; } } // update counts for objPacerImportTransaction.InsertedCases = insertedRowCount; objPacerImportTransaction.LineCount = _data.Count; objPacerImportTransaction.TotalCases = insertedRowCount + updatedRowCount; if (objPacerImportTransaction.ImportMessage.Length > 0) { //we already have an import string - parse the result to add the previous total try { if (objPacerImportTransaction.ImportMessage.IndexOf("Unique Cases Added") > 0) { int previoustotal = Int32.Parse(objPacerImportTransaction.ImportMessage.Substring(0, objPacerImportTransaction.ImportMessage.IndexOf("Unique Cases Added") - 1)); objPacerImportTransaction.ImportMessage = previoustotal + insertedRowCount + " Unique Cases Added! " + updatedRowCount + " Cases Updated! " + formatErrors + " format Errors."; } else { objPacerImportTransaction.ImportMessage = insertedRowCount + " Unique Cases Added! " + updatedRowCount + " Cases Updated! " + formatErrors + " format Errors."; } } catch { } } else { objPacerImportTransaction.ImportMessage = insertedRowCount + " Unique Cases Added! " + updatedRowCount + " Cases Updated! " + formatErrors + " format Errors."; } objPacerImportTransaction.ImportStatus = "SUCCESS"; Save(objPacerImportTransaction); Court _court = CourtService.GetByID(objPacerImportTransaction.CourtID); ZipGeoCodeService.UpdateStatsForState(_court.StateCode); return(insertedRowCount); }