Class ImportApi

Provides methods to upload, download, and delete import data from the Transit Azure Exchange API.

Inheritance
object
ImportApi
Namespace: Transit.Shared.Communication.Azure.Exchange
Assembly: Transit.Shared.dll
Syntax
public class ImportApi
Examples
// Upload a tour from a file
ImportApi api = new ImportApi("your-upload-scope");
await api.UploadAsync(ImportDataType.Tour, @"C:\Data\tour.xml");
// Upload a tour from a stream
ImportApi api = new ImportApi("your-upload-scope");
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
{
    await api.UploadAsync(ImportDataType.Tour, stream, "application/xml");
}
// Download tours
ImportApi api = new ImportApi("your-download-scope");
while (await api.DownloadAsync(ImportDataType.Tour) is { } file)
{
  await using (file)
  {
    if (file.FileName is not null)
    {
      string id = Path.GetFileNameWithoutExtension(file.FileName);
      using (Stream fs = File.OpenWrite(Path.Combine(targetDir, file.FileName)))
      {
        await file.Content.CopyToAsync(fs);
        file.Content.Close();
      }

      await api.DeleteAsync(ImportDataType.Tour, id);
    }
  }
}

Constructors

ImportApi(string)

Initializes a new instance of the ImportApi class.

Declaration
public ImportApi(string scope)
Parameters
Type Name Description
string scope

The scope value for authentication.

Methods

DeleteAsync(ImportDataType, string)

Deletes a file from the Transit Azure Exchange API.

Declaration
public Task DeleteAsync(ImportDataType dataType, string id)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

string id

The unique identifier of the file to delete (GUID format, the filename without extension).

Returns
Type Description
Task

A task representing the asynchronous delete operation.

Exceptions
Type Condition
ArgumentException

Thrown when the id is not a valid GUID.

DeleteAsync(ImportDataType, string, CancellationToken)

Deletes a file from the Transit Azure Exchange API with cancellation support.

Declaration
public Task DeleteAsync(ImportDataType dataType, string id, CancellationToken cancellationToken)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

string id

The unique identifier of the file to delete (GUID format, the filename without extension).

CancellationToken cancellationToken

A token to cancel the operation.

Returns
Type Description
Task

A task representing the asynchronous delete operation.

Exceptions
Type Condition
ArgumentException

Thrown when the id is not a valid GUID.

OperationCanceledException

Thrown when the operation is canceled.

DeleteAsync(ImportDataType, string, TimeSpan)

Deletes a file from the Transit Azure Exchange API with a timeout.

Declaration
public Task DeleteAsync(ImportDataType dataType, string id, TimeSpan timeout)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

string id

The unique identifier of the file to delete (GUID format, the filename without extension).

TimeSpan timeout

The maximum time to wait for the operation to complete.

Returns
Type Description
Task

A task representing the asynchronous delete operation.

Exceptions
Type Condition
ArgumentException

Thrown when the id is not a valid GUID.

OperationCanceledException

Thrown when the operation times out.

DownloadAsync(ImportDataType)

Downloads the next available file from the Transit Azure Exchange API.

Declaration
public Task<FileDownloadResult> DownloadAsync(ImportDataType dataType)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

Returns
Type Description
Task<FileDownloadResult>

A CH.Shared.Communication.FileDownloadResult containing the file content and metadata. If no file is available, the result's CH.Shared.Communication.FileDownloadResult.FileName is null.

Remarks

The returned CH.Shared.Communication.FileDownloadResult must be disposed after use. Use a while loop to download all available files until the returned CH.Shared.Communication.FileDownloadResult is null. After processing each file, call DeleteAsync(ImportDataType, string) to remove it from the server.

DownloadAsync(ImportDataType, CancellationToken)

Downloads the next available file from the Transit Azure Exchange API with cancellation support.

Declaration
public Task<FileDownloadResult> DownloadAsync(ImportDataType dataType, CancellationToken cancellationToken)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

CancellationToken cancellationToken

A token to cancel the operation.

Returns
Type Description
Task<FileDownloadResult>

A CH.Shared.Communication.FileDownloadResult containing the file content and metadata. If no file is available, the result's CH.Shared.Communication.FileDownloadResult.FileName is null.

Remarks

The returned CH.Shared.Communication.FileDownloadResult must be disposed after use. Use a while loop to download all available files until the returned CH.Shared.Communication.FileDownloadResult is null. After processing each file, call DeleteAsync(ImportDataType, string) to remove it from the server.

Exceptions
Type Condition
OperationCanceledException

Thrown when the operation is canceled.

DownloadAsync(ImportDataType, TimeSpan)

Downloads the next available file from the Transit Azure Exchange API with a timeout.

Declaration
public Task<FileDownloadResult> DownloadAsync(ImportDataType dataType, TimeSpan timeout)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

TimeSpan timeout

The maximum time to wait for the operation to complete.

Returns
Type Description
Task<FileDownloadResult>

A CH.Shared.Communication.FileDownloadResult containing the file content and metadata. If no file is available, the result's CH.Shared.Communication.FileDownloadResult.FileName is null.

Remarks

The returned CH.Shared.Communication.FileDownloadResult must be disposed after use. Use a while loop to download all available files until the returned CH.Shared.Communication.FileDownloadResult is null. After processing each file, call DeleteAsync(ImportDataType, string) to remove it from the server.

Exceptions
Type Condition
OperationCanceledException

Thrown when the operation times out.

UploadAsync(ImportDataType, Stream, string)

Uploads data from a stream to the Transit Azure Exchange API. See ImportMapper forsupported Types

Declaration
public Task UploadAsync(ImportDataType dataType, Stream input, string contentType)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

Stream input

The stream containing the data to upload.

string contentType

The MIME content type of the data (e.g., "application/xml", "text/csv").

Returns
Type Description
Task

A task representing the asynchronous upload operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the content type is not supported.

UploadAsync(ImportDataType, Stream, string, CancellationToken)

Uploads data from a stream to the Transit Azure Exchange API with cancellation support. See ImportMapper forsupported Types

Declaration
public Task UploadAsync(ImportDataType dataType, Stream input, string contentType, CancellationToken cancellationToken)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

Stream input

The stream containing the data to upload.

string contentType

The MIME content type of the data (e.g., "application/xml", "text/csv").

CancellationToken cancellationToken

A token to cancel the operation.

Returns
Type Description
Task

A task representing the asynchronous upload operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the content type is not supported.

OperationCanceledException

Thrown when the operation is canceled.

UploadAsync(ImportDataType, Stream, string, TimeSpan)

Uploads data from a stream to the Transit Azure Exchange API with a timeout. See ImportMapper forsupported Types

Declaration
public Task UploadAsync(ImportDataType dataType, Stream input, string contentType, TimeSpan timeout)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

Stream input

The stream containing the data to upload.

string contentType

The MIME content type of the data (e.g., "application/xml", "text/csv").

TimeSpan timeout

The maximum time to wait for the operation to complete.

Returns
Type Description
Task

A task representing the asynchronous upload operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the content type is not supported.

OperationCanceledException

Thrown when the operation times out.

UploadAsync(ImportDataType, string)

Uploads a file to the Transit Azure Exchange API. See ImportMapper forsupported Types

Declaration
public Task UploadAsync(ImportDataType dataType, string file)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

string file

The full path to the file to upload. The file extension determines the content type.

Returns
Type Description
Task

A task representing the asynchronous upload operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the file extension is not supported.

UploadAsync(ImportDataType, string, CancellationToken)

Uploads a file to the Transit Azure Exchange API with cancellation support. See ImportMapper forsupported Types

Declaration
public Task UploadAsync(ImportDataType dataType, string file, CancellationToken cancellationToken)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

string file

The full path to the file to upload. The file extension determines the content type.

CancellationToken cancellationToken

A token to cancel the operation.

Returns
Type Description
Task

A task representing the asynchronous upload operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the file extension is not supported.

OperationCanceledException

Thrown when the operation is canceled.

UploadAsync(ImportDataType, string, TimeSpan)

Uploads a file to the Transit Azure Exchange API with a timeout. See ImportMapper forsupported Types

Declaration
public Task UploadAsync(ImportDataType dataType, string file, TimeSpan timeout)
Parameters
Type Name Description
ImportDataType dataType

The import data type (Order, Tour, Message, or Data).

string file

The full path to the file to upload. The file extension determines the content type.

TimeSpan timeout

The maximum time to wait for the operation to complete.

Returns
Type Description
Task

A task representing the asynchronous upload operation.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the file extension is not supported.

OperationCanceledException

Thrown when the operation times out.

In this article
Back to top Generated by DocFX