OregonBusinessService¶
Bulk-loads a CSV feed of Oregon (DCBS) business registry records into the OregonBusiness data table, parsing the file with FileReader<OregonBusinessCsvFile>, truncating over-length name fields to fit column limits, and running the whole load inside a single IUnitOfWork transaction; collaborates with IUserProfileService to stamp each created row with the current user and IErrorConditionHandler for error handling (injected but not exercised in the shown logic).*
Purpose¶
- Reads an Oregon business registry CSV file and loads each business row (with a state code shorter than 3 characters) into the
OregonBusinesstable. - Truncates
FirstName,MiddleName, andLastNamevalues to their respective column-length limits (20/30/50 characters) before insertion. - Stamps every created row with the current user's ID and creation timestamp.
- Wraps the entire file-load operation in a single transaction, committing only on success and rolling back (and re-throwing) on failure.
Context¶
- Namespace:
SAIF.Services.Policies.DcbsOregonBusiness - Assembly/package:
SAIF.Services(packaged inside theSAIF.SAIFCode.CoreNuGet package).
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| OregonBusinessService (constructor) | public OregonBusinessService(IUnitOfWork uow, IUserProfileService prof, IErrorConditionHandler errorConditionHandler) |
Wires the unit of work, user-profile service (also assigned to a shared static field), and error-condition handler used during file processing. |
| DataException | public Exception DataException { get; set; } |
Holds an exception captured during processing for inspection by the caller after the operation completes.* |
| ProcessOregonBusinessFile | public bool ProcessOregonBusinessFile(ILogWriter controlLog, string filepath) |
Reads the CSV at filepath, inserts a new OregonBusiness row for each record whose state code is under 3 characters, commits the transaction on success (logging the loaded count and current user), or rolls back and throws on failure; logs progress and the abort line number via controlLog. |
Behavioral notes¶
ProcessOregonBusinessFilebegins the transaction (_unitOfWork.Begin()) before parsing the file, so a parse failure leaves the transaction open until the surroundingcatchre-throws without an explicit rollback call in that branch.*- Only records whose
StateCodeis shorter than 3 characters are loaded; records with a state code of 3 or more characters are silently skipped and not counted inloadcount. CreateOregonBusinessRowis astaticprivate helper that truncatesFirstName(20 chars),MiddleName(30 chars), andLastName(curiously checked againstMiddleName.Length, then substringed fromLastName) (50 chars) before adding the row to theOregonBusinessrepository.- The user-profile service is assigned to a
private static IUserProfileService _profileServicefield in the constructor, meaning the last-constructed instance's profile service is shared across all instances of this type.* - On failure, the method logs the error, rolls back the transaction, and throws a plain
Exception("Error in Processing Oregon Businesses- review the log file"), discarding the original exception's type.
Constraints and usage notes¶
uowandprofare null-checked viaEnforce.ArgumentNotNull;errorConditionHandleris not.- The class carries a
CA1506:AvoidExcessiveClassCouplingsuppression. - Because
_profileServiceisstatic, this service should not be treated as safe for concurrent use by multiple users in the same process without further verification.*
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.
Sources¶
Services/SAIF.Services/Policies/DcbsOregonBusiness/OregonBusinessService.cs