Example #1
0
        public async Task <HttpStatusCode> DeployQuestionnaire(string url, string instrumentFile)
        {
            var model = new InstrumentPackageDto
            {
                InstrumentFile = instrumentFile
            };

            var stringContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
            var response      = await _httpClient.PostAsync(url, stringContent);

            return(response.StatusCode);
        }
        public async Task <string> InstallInstrumentAsync(string serverParkName, InstrumentPackageDto instrumentPackageDto, string tempFilePath)
        {
            serverParkName.ThrowExceptionIfNullOrEmpty("serverParkName");
            instrumentPackageDto.InstrumentFile.ThrowExceptionIfNullOrEmpty("instrumentPackageDto.InstrumentFile");
            tempFilePath.ThrowExceptionIfNullOrEmpty("tempFilePath");

            var instrumentFile = await _storageService.DownloadPackageFromInstrumentBucketAsync(instrumentPackageDto.InstrumentFile, tempFilePath);

            _fileService.UpdateInstrumentFileWithSqlConnection(instrumentFile);

            var instrumentName = _fileService.GetInstrumentNameFromFile(instrumentPackageDto.InstrumentFile);

            _blaiseSurveyApi.InstallSurvey(
                instrumentName,
                serverParkName,
                instrumentFile,
                SurveyInterviewType.Cati);

            return(instrumentName);
        }
        public void SetUpTests()
        {
            _blaiseSurveyApiMock = new Mock <IBlaiseSurveyApi>(MockBehavior.Strict);
            _fileServiceMock     = new Mock <IFileService>(MockBehavior.Strict);
            _storageServiceMock  = new Mock <ICloudStorageService>(MockBehavior.Strict);
            _mockSequence        = new MockSequence();

            _instrumentFile = "OPN2010A.zip";
            _serverParkName = "ServerParkA";
            _instrumentName = "OPN2010A";
            _tempPath       = @"c:\temp\GUID";

            _instrumentPackageDto = new InstrumentPackageDto
            {
                InstrumentFile = _instrumentFile
            };

            _sut = new InstrumentInstallerService(
                _blaiseSurveyApiMock.Object,
                _fileServiceMock.Object,
                _storageServiceMock.Object);
        }
        public async Task <IHttpActionResult> InstallInstrument([FromUri] string serverParkName, [FromBody] InstrumentPackageDto instrumentPackageDto)
        {
            var tempPath = _configurationProvider.TempPath;

            try
            {
                _loggingService.LogInfo($"Attempting to install instrument '{instrumentPackageDto.InstrumentFile}' on server park '{serverParkName}'");

                var instrumentName = await _installInstrumentService.InstallInstrumentAsync(serverParkName, instrumentPackageDto, tempPath);

                _loggingService.LogInfo($"Instrument '{instrumentPackageDto.InstrumentFile}' installed on server park '{serverParkName}'");

                return(Created($"{Request.RequestUri}/{instrumentName}", instrumentPackageDto));
            }
            finally
            {
                tempPath.CleanUpTempFiles();
                _loggingService.LogInfo($"Removed temporary files and folder '{tempPath}'");
            }
        }