in SamplesV1/TwitterAnalysisSample-CustomC#Activity/CustomC#ActivityClass/SentimentAnalysis.cs [29:134]
public IDictionary<string, string> Execute(
IEnumerable<LinkedService> linkedServices,
IEnumerable<Dataset> datasets,
Activity activity,
IActivityLogger logger)
{
_logger = logger;
_logger.Write("######Execute Begin######");
// to get extended properties (for example: SliceStart)
DotNetActivity dotNetActivity = (DotNetActivity)activity.TypeProperties;
string sliceStartTime = dotNetActivity.ExtendedProperties["SliceStart"];
_logger.Write("Slice start time is : {0}", sliceStartTime);
_baseUrl = dotNetActivity.ExtendedProperties["baseUrl"];
if (String.IsNullOrEmpty(_baseUrl))
{
_logger.Write("Null or Empty Base URL for ML Model: {0}", _baseUrl);
throw new Exception(string.Format("Null or Empty Base URL for ML Model: {0}", _baseUrl));
}
_logger.Write("Base ML Azure Website url is : {0}", _baseUrl);
_apiKey = dotNetActivity.ExtendedProperties["apiKey"];
if (String.IsNullOrEmpty(_apiKey))
{
_logger.Write("Null or Empty API Key for ML Model: {0}", _apiKey);
throw new Exception(string.Format("Null or Empty API Key for ML Model: {0}", _apiKey));
}
// declare dataset types
CustomDataset inputLocation;
CustomDataset outputLocation;
AzureStorageLinkedService inputLinkedService;
AzureStorageLinkedService outputLinkedService;
// Get the ADF Input Tables
Dataset inputDataset = datasets.Single(dataset => dataset.Name == activity.Inputs.Single().Name);
inputLocation = inputDataset.Properties.TypeProperties as CustomDataset;
inputLinkedService = linkedServices.Single(
linkedService =>
linkedService.Name ==
inputDataset.Properties.LinkedServiceName).Properties.TypeProperties
as AzureStorageLinkedService;
_storageConnectionString = inputLinkedService.ConnectionString;
if (String.IsNullOrEmpty(_storageConnectionString))
{
_logger.Write("Null or Empty Connection string for input table: {0}", inputDataset.Name);
throw new Exception(string.Format("Null or Empty Connection string for input table: {0}", inputDataset.Name));
}
string folderPath = GetFolderPath(inputDataset);
if (String.IsNullOrEmpty(folderPath))
{
_logger.Write("Null or Empty folderpath for input table: {0}", inputDataset.Name);
throw new Exception(string.Format("Null or Empty folder path for input table: {0}", inputDataset.Name));
}
_storageContainerName = folderPath.Split('/')[0];
_inputBlobName = folderPath.Substring(folderPath.IndexOf('/') + 1) ;
_logger.Write("Folder Path for Input Table {0}: {1}", inputDataset.Name, folderPath);
// Get the ADF Output Tables
Dataset outputDataset = datasets.Single(dataset => dataset.Name == activity.Outputs.Single().Name);
outputLocation = outputDataset.Properties.TypeProperties as CustomDataset;
outputLinkedService = linkedServices.Single(
linkedService =>
linkedService.Name ==
outputDataset.Properties.LinkedServiceName).Properties.TypeProperties
as AzureStorageLinkedService;
_storageConnectionString = outputLinkedService.ConnectionString;
folderPath = GetFolderPath(outputDataset);
if (String.IsNullOrEmpty(_storageConnectionString))
{
_logger.Write("Null or Empty Connection string for output table: {0}", outputDataset.Name);
throw new Exception(string.Format("Null or Empty Connection string for output table: {0}", outputDataset.Name));
}
if (String.IsNullOrEmpty(folderPath))
{
_logger.Write("Null or Empty folderpath for output table: {0}", outputDataset.Name);
throw new Exception(string.Format("Null or Empty folder path for output table: {0}", outputDataset.Name));
}
_outputBlobName = folderPath.Substring(folderPath.IndexOf('/') + 1) ;
_logger.Write("Folder Path for Ouput Table {0}: {1}", outputDataset.Name, folderPath);
try
{
// Invoke ML Batch Execution Service
InvokeBatchExecutionService().Wait();
}
catch (Exception ex)
{
_logger.Write("ML Model Call failed with error : {0}", ex.ToString());
throw;
}
return new Dictionary<string, string>();
}