Beispiel #1
0
        private void DeployPackageFromPackage()
        {
            int fileExtractedCount = 0;
            int totalFileCount     = 0;

            using Timer timer = new Timer(
                      x => _logger.LogInformation($"Extracting {fileExtractedCount} of {totalFileCount} files from package"),
                      null,
                      TimeSpan.FromSeconds(5),
                      TimeSpan.FromSeconds(5));

            try
            {
                switch (_option.PackageFile.ToNullIfEmpty() != null)
                {
                case true:
                    _logger.LogInformation($"Deploying from {_option.PackageFile} to {_executionContext.DeploymentFolder}");
                    ZipArchiveTools.ExtractFromZipFile(
                        _option.PackageFile !,
                        _executionContext.DeploymentFolder !,
                        _executionContext.TokenSource.Token,
                        x =>
                    {
                        fileExtractedCount = x.Count;
                        totalFileCount     = x.Total;
                    });
                    break;

                default:
                    _logger.LogInformation($"Deploying from resource to {_executionContext.DeploymentFolder}");
                    ZipArchiveTools.ExtractZipFileFromResource(
                        typeof(MlHostedService),
                        "MlHost.MlPackage.RunModel.mlPackage",
                        _executionContext.DeploymentFolder !,
                        _executionContext.TokenSource.Token,
                        x =>
                    {
                        fileExtractedCount = x.Count;
                        totalFileCount     = x.Total;
                    });
                    break;
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to deploy package, ex={ex}");
                throw;
            }
        }
        public async Task GivenFiles_CreateMlPackage()
        {
            // Create files to package
            var    builder           = new BuildTestMlPackage();
            string mlPackageFilePath = await builder.Build();

            // Act
            mlPackageFilePath.VerifyAssert(x => File.Exists(x), $"File {mlPackageFilePath} does not exit");

            string extractToFolder = Path.Combine(Path.GetTempPath(), $"{nameof(MlPackageActivityTests)}_extract_{Guid.NewGuid()}");

            ZipArchiveTools.ExtractFromZipFile(mlPackageFilePath, extractToFolder, CancellationToken.None);

            // Assert
            builder.GetExportedFileList()
            .Select(x => Path.Combine(extractToFolder, x))
            .ForEach(x => x.VerifyAssert(y => File.Exists(x), $"File {x} does not exist after ML package was extract"));

            FileTools.DeleteDirectory(Path.GetDirectoryName(mlPackageFilePath) !);
        }