Class ApiConnectorContext
- Namespace
- MES.MQC.DataSourceLibrary.Adapters
- Assembly
- MES.MQC.DataSourceLibrary.dll
public class ApiConnectorContext : AdapterContextBase
- Inheritance
-
ApiConnectorContext
- Inherited Members
Constructors
ApiConnectorContext(ApiConnectorConfiguration, string, DateTime?, DateTime?, DateTime?, Action, Action<long>, Action<string, Action>, Func<string, int, string, IDisposable>)
public ApiConnectorContext(ApiConnectorConfiguration configuration, string appDataPath, DateTime? projectStartDate = null, DateTime? projectEndDate = null, DateTime? lastImportDate = null, Action progressCheckCancel = null, Action<long> progressTryReport = null, Action<string, Action> progressExecuteSubtask = null, Func<string, int, string, IDisposable> progressBeginSubtask = null)
Parameters
configurationApiConnectorConfigurationappDataPathstringprojectStartDateDateTime?projectEndDateDateTime?lastImportDateDateTime?progressCheckCancelActionprogressTryReportAction<long>progressExecuteSubtaskAction<string, Action>progressBeginSubtaskFunc<string, int, string, IDisposable>
Properties
Configuration
Configuration of the API DataSource. Has to be cast to the specific Configuration class of the Adapter:
Configuration is AdapterConfiguration configuration.
public ApiConnectorConfiguration Configuration { get; }
Property Value
DownloadPath
The DownloadPath is a cache-directory, where files have to be saved into in the Download-method.
public string DownloadPath { get; }
Property Value
LastImportDate
Date of the last import, if there was any. Set by the last execution in AdapterReadResult.DateTime and/or AdapterDownloadResult.DateTime. The Adapter should only read data / download files that are newer than the last import date.
public DateTime? LastImportDate { get; }
Property Value
ProjectEndDate
Configured end date of the project. Can be used to filter out data / files.
public DateTime? ProjectEndDate { get; }
Property Value
ProjectStartDate
Configured start date of the project. Can be used to filter out data / files.
public DateTime? ProjectStartDate { get; }
Property Value
Methods
BeginTask(string, int, string)
BeginTask is a Utility method. Create a task that reports it's steps. A task shows up in the dialog of the frontend. If the total number is not known, the counter can be set to a arbitrary number and only {0} used in the description.
Example:
// {0} = current item number, {1} = total number of items
using (context.BeginSubtask("Title", items.Length, "{0} of {1}"))
{
foreach (var item in items)
{
// increase the task counter {0}
context.ReportProgressForTask();
// do something
}
}
public IDisposable BeginTask(string title, int counter, string description)
Parameters
titlestringTitle of the task.
counterintTotal number to be counted.
descriptionstringDescription with {0} and/or {1} to show the steps/total.
Returns
- IDisposable
IDisposable, as long as it is not disposed the tasks runs
CheckCancel()
CheckCancel is a Utility method. Should be used in loops of long running operations. If the import was cancelled by the user, this method stops the execution.
public void CheckCancel()
ExecuteTask(string, Action)
ExecuteTask is a Utility method. Create a task that executes a action. A task shows up in the dialog of the frontend.
public void ExecuteTask(string title, Action action)
Parameters
ReportProgressForTask(long)
ReportProgressForTask is a Utility method. Increase the progress counter {0}
public void ReportProgressForTask(long amount = 1)
Parameters
amountlongAmount to report progress for the task