Overview
The UI application is a .NET MAUI (Multi-platform App UI) application that provides a graphical interface for managing APM. It runs on both Windows and Android, with platform-specific features and services. Location:source/UI/
Platforms: Windows, Android
Framework: .NET MAUI with .NET 10.0
Entry Point: source/UI/MauiProgram.cs
Purpose
The MAUI application provides:- Printer Management - Configure thermal and dot matrix printers
- Scale Management - Configure and monitor serial scales
- Template Editor - Create and edit print templates visually
- System Logs - View application logs and debugging information
- Settings - Configure application behavior
- Service Control (Windows) - Start/stop WorkerService
- Print Testing - Test print jobs and preview output
Architecture Pattern
The UI follows the MVVM (Model-View-ViewModel) pattern:MVVM Benefits
- Separation of Concerns - UI logic separate from business logic
- Testability - ViewModels can be unit tested
- Data Binding - Automatic UI updates when data changes
- Platform Abstraction - Platform-specific code isolated
MauiProgram.cs - Application Bootstrap
Location:source/UI/MauiProgram.cs
Builder Configuration
.UseMauiApp<App>()- Sets the main application class.UseMauiCommunityToolkit()- Adds community toolkit components.ConfigureFonts()- Registers custom fonts- Debug logging enabled in development
Core Service Registration
Location: source/UI/MauiProgram.cs:32Platform-Specific Services
Location: source/UI/MauiProgram.cs:50Windows Platform
- IWorkerServiceManager - Control Windows Service (start/stop/status)
- ITrayAppService - System tray interaction
- WindowsPlatformService - Windows-specific file operations
- WebSocketServerService - Can act as server if needed
- SerialScaleService - Direct serial port access
Android Platform
- AndroidPlatformService - Android file system operations
- AndroidWebSocketService - Runs WebSocket server in-app (no separate service)
ViewModel Registration
Location: source/UI/MauiProgram.cs:68Transient - New instance created each time the page is navigated to
View Registration
Location: source/UI/MauiProgram.cs:77- Pages:
Transient- New instance per navigation - AppShell:
Singleton- Single shell for app lifetime
Value Converters
Location: source/UI/MauiProgram.cs:86Service Provider Exposure
Location: source/UI/MauiProgram.cs:90Application Structure
Folder Organization
Key ViewModels
HomeViewModel
Purpose: Dashboard with system status overview Features:- Service status (Windows only)
- Quick stats (printer count, scale count)
- Recent logs
- Quick actions
PrintersViewModel
Purpose: Manage printer configurations Features:- List all configured printers
- Add new printer
- Edit existing printer
- Delete printer
- Test print
IPrintService- Printer operationsISettingsRepository- Load/save settingsILoggingService- Logging
PrinterDetailViewModel
Purpose: Configure individual printer settings Properties:- Printer ID, Name
- Connection Type (TCP, USB, IPP)
- IP Address, Port (for TCP)
- Local Printer Name (for USB)
- URI (for IPP)
- Paper Width
- Character Set
- Copy-to Printers
- Save configuration
- Test print
- Delete printer
ScalesViewModel
Purpose: Manage scale configurations Features:- List all configured scales
- Add new scale
- Edit existing scale
- Delete scale
- Start/stop monitoring
IScaleRepository- Scale configurationIScaleService- Scale communication
ScaleDetailViewModel
Purpose: Configure individual scale settings Properties:- Scale ID, Name
- COM Port
- Baud Rate
- Data Bits, Parity, Stop Bits
- Protocol settings
- Current weight
- Stability indicator
- Connection status
- Save configuration
- Start/stop listening
- Tare scale
TemplateEditorViewModel
Purpose: Edit print templates Features:- Load template by document type
- Visual template editor
- Section management (header, items, footer)
- Element properties (text, alignment, font)
- Save template
- Preview rendering
ITemplateRepository- Template storageITicketRenderer- Preview rendering
LogsViewModel
Purpose: View system logs Features:- Live log streaming
- Filter by level (Info, Warning, Error)
- Search logs
- Clear logs
- Export logs
ILoggingService- Log access
SettingsViewModel
Purpose: Application settings Features:- Default paper width
- Default encoding
- Log level
- Auto-start settings (Windows)
- Data directory
Platform-Specific Services
Windows Platform Services
WindowsWorkerServiceManager
Purpose: Control the WorkerService Windows Service Interface:- Uses
System.ServiceProcess.ServiceController - Queries service status
- Sends start/stop commands
- Requires appropriate permissions
WindowsTrayAppService
Purpose: Interact with TrayApp Features:- Launch TrayApp
- Check if TrayApp is running
- Send messages to TrayApp
WindowsPlatformService
Purpose: Windows-specific operations Features:- File system access with Windows paths
- Registry access
- Process management
Android Platform Services
AndroidPlatformService
Purpose: Android-specific operations Features:- Android file system access
- Storage permissions
- Intent handling
AndroidWebSocketService
Purpose: Run WebSocket server within the Android app Differences from Windows:- No separate service process
- Runs in app’s background
- Lifecycle tied to app (can be killed by OS)
- Requires background service permissions
Navigation
APM uses Shell Navigation for routing:AppShell.xaml
Data Binding
Example: Printer List Binding
ViewModel:Dependency Injection in Views
Constructor Injection
Community Toolkit Components
APM uses MAUI Community Toolkit for enhanced functionality:Converters
InverseBoolConverter- Invert boolean valuesIsNotNullOrEmptyConverter- Check for null/empty strings
Behaviors
EventToCommandBehavior- Convert events to commandsValidationBehavior- Input validation
Markup Extensions
TranslateExtension- Localization support
Platform Differences
Windows
Features:- Full access to WorkerService control
- System tray integration
- All printer connection types (TCP, USB, IPP)
- Direct serial port access
- Full file system access
- Desktop only (no mobile)
Android
Features:- Mobile-friendly UI
- TCP printer support
- Built-in WebSocket server
- Background service
- No USB printer support (without OTG adapter)
- Limited serial port access
- No Windows Service control
- File system restrictions
- Background service limitations (can be killed by OS)
Deployment
Windows Deployment
Output:UI.exe (self-contained or framework-dependent)
Distribution:
- MSIX installer (Microsoft Store)
- Traditional installer (Inno Setup, WiX)
- Portable executable
- .NET 10.0 Runtime (if framework-dependent)
- Windows 10/11
Android Deployment
Output:com.appsiel.printmanager.apk (or AAB for Play Store)
Distribution:
- Google Play Store
- Direct APK installation (sideloading)
- Android 7.0+ (API 24+)
- Storage permissions
- Network permissions
- Background service permissions
Testing
Unit Testing ViewModels
UI Testing
MAUI supports UI testing with:- Appium - Cross-platform UI automation
- Platform-specific: UITest (iOS), Espresso (Android), WinAppDriver (Windows)
Performance Optimization
- Lazy Loading - ViewModels created on-demand
- CollectionView - Virtualized list rendering
- Async Operations - Non-blocking UI
- Image Caching - Reuse loaded images
- Compiled Bindings - Faster data binding (when possible)
Next Steps
- Worker Service - Background service integration
- Core Components - Services and interfaces
- System Overview - Complete system architecture