Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
O SessionsPythonPlugin foi atualizado para usar a versão mais recente (2024-10-02-preview) da API de Sessões Dinâmicas do Interpretador de Código do Azure. A nova API introduziu alterações significativas, que são refletidas na superfície da API pública do plug-in.
Este guia de migração ajudará você a migrar seu código existente para a versão mais recente do plug-in.
A inicialização do plug-in
A assinatura do construtor do plug-in foi alterada para aceitar um argumento CancellationToken para a função authTokenProvider. Essa alteração permite cancelar o processo de geração de token, se necessário:
// Before
static async Task<string> GetAuthTokenAsync()
{
return tokenProvider.GetToken();
}
// After
static async Task<string> GetAuthTokenAsync(CancellationToken ct)
{
return tokenProvider.GetToken(ct);
}
var plugin = new SessionsPythonPlugin(settings, httpClientFactory, GetAuthTokenAsync);
O método UploadFileAsync
A UploadFileAsync assinatura do método foi alterada para representar melhor a finalidade dos parâmetros:
// Before
string remoteFilePath = "your_file.txt";
string? localFilePath = "C:\documents\your_file.txt";
await plugin.UploadFileAsync(remoteFilePath: remoteFilePath, localFilePath: localFilePath);
// After
string remoteFileName = "your_file.txt";
string localFilePath = "C:\documents\your_file.txt";
await plugin.UploadFileAsync(remoteFileName: remoteFileName, localFilePath: localFilePath);
O método DownloadFileAsync
Da mesma forma, a assinatura do DownloadFileAsync método foi alterada para representar melhor a finalidade dos parâmetros:
// Before
string remoteFilePath = "your_file.txt";
await plugin.DownloadFileAsync(remoteFilePath: remoteFilePath);
// After
string remoteFileName = "your_file.txt";
await plugin.DownloadFileAsync(remoteFileName: remoteFileName);
O método ExecuteCodeAsync
A ExecuteCodeAsync assinatura do método foi alterada para fornecer uma maneira estruturada de trabalhar com os resultados da execução:
// Before
string result = await plugin.ExecuteCodeAsync(code: "print('Hello, world!')");
// After
SessionsPythonCodeExecutionResult result = await plugin.ExecuteCodeAsync(code: "print('Hello, world!')");
string status = result.Status;
string? executionResult = result.Result?.ExecutionResult;
string? stdout = result.Result?.StdOut;
string? stderr = result.Result?.StdErr;
A classe SessionsRemoteFileMetadata
A SessionsRemoteFileMetadata classe de modelo, usada pelos métodos UploadFileAsync e ListFilesAsync, foi atualizada para representar melhor os metadados de arquivos e diretórios remotos.
// Before
SessionsRemoteFileMetadata file = await plugin.UploadFileAsync(...);
string fileName = file.Filename;
long fileSize = file.Size;
DateTime? lastModified = file.LastModifiedTime;
// After
SessionsRemoteFileMetadata file = await plugin.UploadFileAsync(...);
string name = file.Name;
long? size = file.SizeInBytes;
DateTime lastModified = file.LastModifiedAt;