πΌ Commercial Project β part of a client-facing initiative.
A .NET 10 Worker Service application that automates bidirectional data synchronization between a route optimization system (RoutePlus) and the GoNet CRM system via SFTP.
RoutePlus Import Service is an enterprise-grade background service designed to streamline field service operations by:
- Exporting client visit schedules and address data to RoutePlus for route optimization
- Importing optimized routes back into the GoNet system
- Automatically updating planned visit dates based on actual route assignments
- Creating scheduled tasks in GoNet based on route optimization results
- Client Visits Export: Retrieves recent client visits from GoNet database
- Client Addresses Export: Exports client address information with visit priorities
- CSV Generation: Converts data to CSV format with customizable column mappings
- SFTP Upload: Securely uploads CSV files to RoutePlus SFTP server
- Route Points Download: Downloads optimized route files from SFTP (only today's files)
- CSV Parsing: Imports route points with visit dates, times, and sequences
- Task Creation: Automatically creates tasks in GoNet for each optimized visit
- Date Filtering: Only processes routes within a 2-week timeframe
- Planned Date Matching: Maps actual visits from route optimization to planned visit dates
- 1:1 Visit Assignment: Ensures each optimized visit is assigned to the nearest planned date
- Past Date Protection: Preserves historical planned dates
- Null Handling: Sets unmatched planned dates to null for clarity
- Time-Based Execution: Runs export at sending hour, import at download hour
- Once-Daily Processing: Prevents duplicate processing with date tracking
- Sequence-Based Timing: Automatically assigns hourly time slots (8 AM - 5 PM) based on visit sequence
RoutePlusImport/
βββ RoutePlusImport.Service/ # Worker Service (entry point)
β βββ Worker.cs # Background service orchestrator
β βββ Program.cs # Service configuration & DI
β βββ appsettings.json # Configuration
βββ RoutePlusImport.Contracts/ # Interfaces & DTOs
β βββ Models/ # Domain models
β β βββ ClientAddress.cs
β β βββ ClientVisit.cs
β β βββ ClientTask.cs
β β βββ PlannedVisitDate.cs
β βββ DTOs/ # Data transfer objects
β β βββ RoutePoint.cs
β βββ Services/ # Service interfaces
β β βββ IClientDataService.cs
β β βββ ICsvExportService.cs
β β βββ ICsvImportService.cs
β β βββ IFtpService.cs
β βββ Repositories/ # Repository interfaces
β β βββ IClientRepository.cs
β βββ Attributes/ # Custom attributes
β β βββ CsvColumnAttribute.cs
β βββ Settings/ # Configuration models
β βββ AppSettings.cs
β βββ FtpSettings.cs
βββ RoutePlusImport.Infrastructure/ # Implementations
βββ Data/ # Database access
β βββ DapperDbExecutor.cs
β βββ IDbExecutor.cs
βββ Repositories/ # Repository implementations
β βββ ClientRepository.cs
βββ Services/ # Business logic services
βββ ClientDataService.cs
βββ CsvExportService.cs
βββ CsvImportService.cs
βββ FtpService.cs
- Runs continuously as a Windows Service
- Executes tasks based on configured schedules
- Manages execution state to prevent duplicate runs
- Logs all operations for monitoring and troubleshooting
Core orchestration service handling:
- Client visits and addresses processing
- Route points import and task creation
- Planned visit date synchronization with intelligent matching algorithm
- CsvExportService: Generates CSV files with attribute-based column mapping using
[CsvColumn]attributes - CsvImportService: Parses CSV files with support for:
- Quoted fields and escaped characters
- Type conversion (string, int, DateTime, TimeSpan, etc.)
- Custom column name mapping via attributes
- SFTP client using SSH.NET for secure file transfer
- Upload/download with file modification date filtering
- Support for both input and output folder paths
- Connection management with proper dispose patterns
- ClientRepository: Database operations via stored procedures
- Uses Dapper for high-performance data access
- Supports complex multi-table queries and updates
- Handles nullable DateTime types for flexible date management
- .NET 10: Latest .NET framework with modern C# features
- C# 14: Modern language features (file-scoped namespaces, global usings, etc.)
- Dapper: Micro-ORM for high-performance database access
- SSH.NET: SFTP client library for secure file transfers
- Serilog: Structured logging with rolling file support
- Microsoft.Extensions.Hosting: Worker Service framework
- Microsoft.Data.SqlClient: SQL Server database connectivity
The service uses structured logging with Serilog:
- Console Output: Real-time monitoring during development
- Rolling File Logs: Daily log files with configurable retention
- Log Levels: Information, Warning, Error
- Contextual Logging: Includes operation details, client IDs, file paths, counts
- Separate Log Directory: Configurable via
AppSettings:LogsExpirationDays
Example Log Output:
[2026-03-06 15:00:00 INF] Worker running at: 06.03.2026 15:00:00 +01:00
[2026-03-06 15:00:01 INF] Processing route points...
[2026-03-06 15:00:02 INF] Downloaded file: C:\Temp\Exports\Downloads\route_20260306.csv
[2026-03-06 15:00:03 INF] Imported 156 route points from CSV
[2026-03-06 15:00:04 INF] Filtered to 89 route points within 2 weeks
[2026-03-06 15:00:05 INF] Updated planned dates for client 12345: D1=2026-05-26, D2=null, D3=2026-08-12
[2026-03-06 15:00:10 INF] Route points processing completed. Success: 89, Failed: 0
- Graceful Degradation: Continues processing on individual failures
- Try-Catch Blocks: Comprehensive error handling at all levels
- Detailed Error Logging: Full exception details with stack traces
- Transaction Safety: Database operations use stored procedures with proper error handling
- SFTP Resilience: Proper connection disposal and error recovery
- CSV Parsing: Handles malformed data with logging
- Async/Await: Fully asynchronous for optimal resource utilization
- Batch Processing: Efficient bulk operations for large datasets
- Connection Pooling: Reuses database connections via Dapper
- SFTP Streaming: Memory-efficient file transfers
- Date Filtering: Processes only relevant data (2-week window)
- Single Daily Execution: Prevents unnecessary resource usage
- SFTP Encryption: All file transfers use SSH protocol (port 22)
- Parameterized Queries: Protection against SQL injection via Dapper
- Credential Management: Stored in
appsettings.json(use secure config in production) - Connection Timeout: Prevents hung connections
- Input Validation: Date parsing with error handling
- Linked Server Access: Controlled via SQL Server OPENQUERY
The Worker Service executes on a configurable schedule:
Daily Schedule:
08:00 (SendingHour) β Export client visits and addresses to RoutePlus
15:00 (DownloadHour) β Import route points and update planned dates
Execution Control:
- Checks every
WorkingIntervalMinutes(configurable) - Tracks last execution date to prevent duplicate runs
- Only processes files modified today from SFTP
This project is proprietary and confidential.
It was developed for a client and is not permitted to be shared, redistributed, or used without explicit written permission from the owner.
See LICENSE for details.
Β© 2026-present calKU0