tryDeployment method

  1. @mustCallSuper
Future<StudyStatus> tryDeployment(
  1. String studyDeploymentId,
  2. String deviceRoleName
)

Verifies whether the device is ready for deployment of the study runtime identified by studyDeploymentId and deviceRoleName, and in case it is, deploys. In case already deployed, nothing happens and the status of the deployment is returned.

Throws NotConfiguredException if the client has not yet been configured. Throws IllegalArgumentException if a study with the given studyDeploymentId and deviceRoleName does not exist or if deployment failed because of unexpected study deployment ID, device role name, or device registration.

Implementation

@mustCallSuper
Future<StudyStatus> tryDeployment(
  String studyDeploymentId,
  String deviceRoleName,
) async {
  _checkConfiguration();

  var study = getStudy(studyDeploymentId, deviceRoleName);

  if (study == null) {
    throw IllegalArgumentException(
      "A study with the study deployment ID '$studyDeploymentId' "
      "and device role name '$deviceRoleName' was not found. "
      "Has this study been added using the addStudy method?",
    );
  }
  var status = study.status;

  // Early out in case this study has already received and validated
  // deployment information and is running.
  // if (study.status == StudyStatus.Running) return study.status;
  // TODO: Should not check for this? Allow for re-deployment?
  // if (study.isDeployed) return study.status;

  // Try to deploy the study.
  await proxy?.tryDeployment(study, registration);

  var newStatus = study.status;
  if (status != newStatus) repository.updateStudy(study);
  return newStatus;
}