This MVP release provides a complete full-stack solution for managing action mappings in Geutebruck's GeViScope and GeViSoft video surveillance systems. ## Features ### Flutter Web Application (Port 8081) - Modern, responsive UI for managing action mappings - Action picker dialog with full parameter configuration - Support for both GSC (GeViScope) and G-Core server actions - Consistent UI for input and output actions with edit/delete capabilities - Real-time action mapping creation, editing, and deletion - Server categorization (GSC: prefix for GeViScope, G-Core: prefix for G-Core servers) ### FastAPI REST Backend (Port 8000) - RESTful API for action mapping CRUD operations - Action template service with comprehensive action catalog (247 actions) - Server management (G-Core and GeViScope servers) - Configuration tree reading and writing - JWT authentication with role-based access control - PostgreSQL database integration ### C# SDK Bridge (gRPC, Port 50051) - Native integration with GeViSoft SDK (GeViProcAPINET_4_0.dll) - Action mapping creation with correct binary format - Support for GSC and G-Core action types - Proper Camera parameter inclusion in action strings (fixes CrossSwitch bug) - Action ID lookup table with server-specific action IDs - Configuration reading/writing via SetupClient ## Bug Fixes - **CrossSwitch Bug**: GSC and G-Core actions now correctly display camera/PTZ head parameters in GeViSet - Action strings now include Camera parameter: `@ PanLeft (Comment: "", Camera: 101028)` - Proper filter flags and VideoInput=0 for action mappings - Correct action ID assignment (4198 for GSC, 9294 for G-Core PanLeft) ## Technical Stack - **Frontend**: Flutter Web, Dart, Dio HTTP client - **Backend**: Python FastAPI, PostgreSQL, Redis - **SDK Bridge**: C# .NET 8.0, gRPC, GeViSoft SDK - **Authentication**: JWT tokens - **Configuration**: GeViSoft .set files (binary format) ## Credentials - GeViSoft/GeViScope: username=sysadmin, password=masterkey - Default admin: username=admin, password=admin123 ## Deployment All services run on localhost: - Flutter Web: http://localhost:8081 - FastAPI: http://localhost:8000 - SDK Bridge gRPC: localhost:50051 - GeViServer: localhost (default port) Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
234 lines
7.7 KiB
Dart
234 lines
7.7 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import '../../core/errors/exceptions.dart';
|
|
import '../../core/errors/failures.dart';
|
|
import '../data_sources/local/server_local_data_source.dart';
|
|
import '../data_sources/remote/server_remote_data_source.dart';
|
|
import '../data_sources/local/action_mapping_local_data_source.dart';
|
|
import '../data_sources/remote/action_mapping_remote_data_source.dart';
|
|
|
|
enum SyncStatus {
|
|
idle,
|
|
syncing,
|
|
success,
|
|
error,
|
|
}
|
|
|
|
class SyncResult {
|
|
final SyncStatus status;
|
|
final String? message;
|
|
final int? syncedCount;
|
|
final List<String>? errors;
|
|
|
|
SyncResult({
|
|
required this.status,
|
|
this.message,
|
|
this.syncedCount,
|
|
this.errors,
|
|
});
|
|
|
|
factory SyncResult.idle() => SyncResult(status: SyncStatus.idle);
|
|
|
|
factory SyncResult.syncing() => SyncResult(
|
|
status: SyncStatus.syncing,
|
|
message: 'Syncing changes...',
|
|
);
|
|
|
|
factory SyncResult.success(int count) => SyncResult(
|
|
status: SyncStatus.success,
|
|
message: 'Successfully synced $count change${count != 1 ? 's' : ''}',
|
|
syncedCount: count,
|
|
);
|
|
|
|
factory SyncResult.error(List<String> errors) => SyncResult(
|
|
status: SyncStatus.error,
|
|
message: 'Sync failed: ${errors.length} error${errors.length != 1 ? 's' : ''}',
|
|
errors: errors,
|
|
);
|
|
}
|
|
|
|
abstract class SyncService {
|
|
/// Sync all dirty servers with the remote API
|
|
Future<Either<Failure, SyncResult>> syncServers();
|
|
|
|
/// Download fresh data from server and update local storage
|
|
Future<Either<Failure, int>> downloadServers();
|
|
|
|
/// Sync all dirty action mappings with the remote API
|
|
Future<Either<Failure, SyncResult>> syncActionMappings();
|
|
|
|
/// Download fresh action mappings from server and update local storage
|
|
Future<Either<Failure, int>> downloadActionMappings();
|
|
}
|
|
|
|
class SyncServiceImpl implements SyncService {
|
|
final ServerLocalDataSource localDataSource;
|
|
final ServerRemoteDataSource remoteDataSource;
|
|
final ActionMappingLocalDataSource actionMappingLocalDataSource;
|
|
final ActionMappingRemoteDataSource actionMappingRemoteDataSource;
|
|
|
|
SyncServiceImpl({
|
|
required this.localDataSource,
|
|
required this.remoteDataSource,
|
|
required this.actionMappingLocalDataSource,
|
|
required this.actionMappingRemoteDataSource,
|
|
});
|
|
|
|
@override
|
|
Future<Either<Failure, SyncResult>> syncServers() async {
|
|
try {
|
|
// Get all dirty servers
|
|
final dirtyServers = await localDataSource.getDirtyServers();
|
|
|
|
if (dirtyServers.isEmpty) {
|
|
return Right(SyncResult.success(0));
|
|
}
|
|
|
|
final errors = <String>[];
|
|
int successCount = 0;
|
|
|
|
// Process each dirty server
|
|
for (final server in dirtyServers) {
|
|
try {
|
|
final operation = server.syncOperation;
|
|
final serverModel = server.toServerModel();
|
|
|
|
if (operation == 'create') {
|
|
await remoteDataSource.createServer(serverModel);
|
|
await localDataSource.markServerAsSynced(server.id, server.serverType);
|
|
successCount++;
|
|
} else if (operation == 'update') {
|
|
await remoteDataSource.updateServer(serverModel);
|
|
await localDataSource.markServerAsSynced(server.id, server.serverType);
|
|
successCount++;
|
|
} else if (operation == 'delete') {
|
|
await remoteDataSource.deleteServer(server.id, server.serverType);
|
|
await localDataSource.markServerAsSynced(server.id, server.serverType);
|
|
successCount++;
|
|
}
|
|
} catch (e) {
|
|
errors.add('Failed to sync ${server.alias}: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
if (errors.isEmpty) {
|
|
return Right(SyncResult.success(successCount));
|
|
} else if (successCount > 0) {
|
|
// Partial success
|
|
return Right(SyncResult(
|
|
status: SyncStatus.success,
|
|
message: 'Synced $successCount/${dirtyServers.length} changes',
|
|
syncedCount: successCount,
|
|
errors: errors,
|
|
));
|
|
} else {
|
|
// Complete failure
|
|
return Right(SyncResult.error(errors));
|
|
}
|
|
} on ServerException catch (e) {
|
|
return Left(ServerFailure(e.message));
|
|
} on NetworkException catch (e) {
|
|
return Left(NetworkFailure(e.message));
|
|
} catch (e) {
|
|
return Left(ServerFailure('Unexpected error during sync: ${e.toString()}'));
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<Either<Failure, int>> downloadServers() async {
|
|
try {
|
|
// Fetch all servers from API
|
|
final servers = await remoteDataSource.getAllServers();
|
|
|
|
// Replace local storage (preserving dirty servers)
|
|
await localDataSource.replaceAllServers(servers);
|
|
|
|
return Right(servers.length);
|
|
} on ServerException catch (e) {
|
|
return Left(ServerFailure(e.message));
|
|
} on NetworkException catch (e) {
|
|
return Left(NetworkFailure(e.message));
|
|
} catch (e) {
|
|
return Left(ServerFailure('Unexpected error during download: ${e.toString()}'));
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<Either<Failure, SyncResult>> syncActionMappings() async {
|
|
try {
|
|
// Get all dirty action mappings
|
|
final dirtyMappings = await actionMappingLocalDataSource.getDirtyActionMappings();
|
|
|
|
if (dirtyMappings.isEmpty) {
|
|
return Right(SyncResult.success(0));
|
|
}
|
|
|
|
final errors = <String>[];
|
|
int successCount = 0;
|
|
|
|
// Process each dirty action mapping
|
|
for (final mapping in dirtyMappings) {
|
|
try {
|
|
final operation = mapping.syncOperation;
|
|
final mappingModel = mapping.toActionMappingModel();
|
|
|
|
if (operation == 'create') {
|
|
await actionMappingRemoteDataSource.createActionMapping(mappingModel);
|
|
await actionMappingLocalDataSource.markActionMappingAsSynced(mapping.id);
|
|
successCount++;
|
|
} else if (operation == 'update') {
|
|
await actionMappingRemoteDataSource.updateActionMapping(mapping.id, mappingModel);
|
|
await actionMappingLocalDataSource.markActionMappingAsSynced(mapping.id);
|
|
successCount++;
|
|
} else if (operation == 'delete') {
|
|
await actionMappingRemoteDataSource.deleteActionMapping(mapping.id);
|
|
await actionMappingLocalDataSource.markActionMappingAsSynced(mapping.id);
|
|
successCount++;
|
|
}
|
|
} catch (e) {
|
|
errors.add('Failed to sync ${mapping.name}: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
if (errors.isEmpty) {
|
|
return Right(SyncResult.success(successCount));
|
|
} else if (successCount > 0) {
|
|
// Partial success
|
|
return Right(SyncResult(
|
|
status: SyncStatus.success,
|
|
message: 'Synced $successCount/${dirtyMappings.length} changes',
|
|
syncedCount: successCount,
|
|
errors: errors,
|
|
));
|
|
} else {
|
|
// Complete failure
|
|
return Right(SyncResult.error(errors));
|
|
}
|
|
} on ActionMappingException catch (e) {
|
|
return Left(ActionMappingFailure(e.message));
|
|
} on NetworkException catch (e) {
|
|
return Left(NetworkFailure(e.message));
|
|
} catch (e) {
|
|
return Left(ActionMappingFailure('Unexpected error during sync: ${e.toString()}'));
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<Either<Failure, int>> downloadActionMappings() async {
|
|
try {
|
|
// Fetch all action mappings from API
|
|
final mappings = await actionMappingRemoteDataSource.getAllActionMappings();
|
|
|
|
// Replace local storage with force=true to discard local changes and get fresh server data
|
|
await actionMappingLocalDataSource.replaceAllActionMappings(mappings, force: true);
|
|
|
|
return Right(mappings.length);
|
|
} on ActionMappingException catch (e) {
|
|
return Left(ActionMappingFailure(e.message));
|
|
} on NetworkException catch (e) {
|
|
return Left(NetworkFailure(e.message));
|
|
} catch (e) {
|
|
return Left(ActionMappingFailure('Unexpected error during download: ${e.toString()}'));
|
|
}
|
|
}
|
|
}
|