initialize method
Future
initialize(
- DataEndPoint dataEndPoint,
- MasterDeviceDeployment deployment,
- Stream<
DataPoint> data
override
Initialize the data manager by specifying the dataEndPoint
, study
deployment
, and the stream of data
events to handle.
Implementation
Future initialize(
DataEndPoint dataEndPoint,
MasterDeviceDeployment deployment,
Stream<DataPoint> data,
) async {
super.initialize(dataEndPoint, deployment, data);
assert(dataEndPoint is CarpDataEndPoint);
carpEndPoint = dataEndPoint as CarpDataEndPoint;
if ((carpEndPoint.uploadMethod == CarpUploadMethod.FILE) ||
(carpEndPoint.uploadMethod == CarpUploadMethod.BATCH_DATA_POINT)) {
// make sure that files are not zipped if using batch upload
assert(
carpEndPoint.uploadMethod == CarpUploadMethod.BATCH_DATA_POINT
? carpEndPoint.zip == false
: true,
'Files uploaded to CARP must not be zipped.');
// Create a [FileDataManager] and wrap it.
fileDataManager = new FileDataManager();
// merge the file data manager's events into this CARP data manager's event stream
fileDataManager.events.listen((event) => addEvent(event));
// listen to data manager events, but only those from the file manager and only closing events
// on a close event, upload the file to CARP
fileDataManager.events
.where((event) => event.runtimeType == FileDataManagerEvent)
.where((event) => event.type == FileDataManagerEventTypes.FILE_CLOSED)
.listen((event) =>
_uploadDatumFileToCarp((event as FileDataManagerEvent).path));
// initialize the file data manager
fileDataManager.initialize(dataEndPoint, deployment, data);
}
_initialized = true;
await user; // This will trigger authentication to the CARP server
}