protected internal override void EmitRecord(string contextName, string recordName , OutputRecord outRec) { // Setup so that the records have the proper leader names so they are // unambiguous at the ganglia level, and this prevents a lot of rework StringBuilder sb = new StringBuilder(); sb.Append(contextName); sb.Append('.'); if (contextName.Equals("jvm") && outRec.GetTag("processName") != null) { sb.Append(outRec.GetTag("processName")); sb.Append('.'); } sb.Append(recordName); sb.Append('.'); int sbBaseLen = sb.Length; // emit each metric in turn foreach (string metricName in outRec.GetMetricNames()) { object metric = outRec.GetMetric(metricName); string type = typeTable[metric.GetType()]; if (type != null) { sb.Append(metricName); EmitMetric(sb.ToString(), type, metric.ToString()); sb.Length = sbBaseLen; } else { Log.Warn("Unknown metrics type: " + metric.GetType()); } } }
public virtual Stream <OutputRecord> Hello() { OutputRecord t = new OutputRecord(); t.Result = Service.hello(); return(Stream.of(t)); }
// List containing nc1 and nc2. /// <summary> /// Initializes, for testing, two NoEmitMetricsContext's, and adds one value /// to the first of them. /// </summary> /// <exception cref="System.IO.IOException"/> protected override void SetUp() { nc1 = new NoEmitMetricsContext(); nc1.Init("test1", ContextFactory.GetFactory()); nc2 = new NoEmitMetricsContext(); nc2.Init("test2", ContextFactory.GetFactory()); contexts = new AList <MetricsContext>(); contexts.AddItem(nc1); contexts.AddItem(nc2); MetricsRecord r = nc1.CreateRecord("testRecord"); r.SetTag("testTag1", "testTagValue1"); r.SetTag("testTag2", "testTagValue2"); r.SetMetric("testMetric1", 1); r.SetMetric("testMetric2", 33); r.Update(); IDictionary <string, ICollection <OutputRecord> > m = nc1.GetAllRecords(); Assert.Equal(1, m.Count); Assert.Equal(1, m.Values.Count); ICollection <OutputRecord> outputRecords = m.Values.GetEnumerator().Next(); Assert.Equal(1, outputRecords.Count); outputRecord = outputRecords.GetEnumerator().Next(); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext executionContext) { string skillName = executionContext.FunctionName; log.LogInformation("Object detection function: C# HTTP trigger function processed a request."); var response = new WebApiResponse(); response.values = new List <OutputRecord>(); string requestBody = new StreamReader(req.Body).ReadToEnd(); var data = JsonConvert.DeserializeObject <WebApiRequest>(requestBody); // Do some schema validation if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } if (data.Values == null) { return(new BadRequestObjectResult("The request schema does not match expected schema. Could not find values array.")); } // Calculate the response for each value. foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord(); responseRecord.RecordId = record.RecordId; try { responseRecord.Data = GetObjects(record.Data.Url).Result; } catch (Exception e) { // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; responseRecord.Errors = new List <OutputRecord.OutputRecordMessage>(); responseRecord.Errors.Add(error); } finally { response.values.Add(responseRecord); } } return((ActionResult) new OkObjectResult(response)); }
/// <summary> /// Prints output in console /// </summary> /// <param name="output"></param> public void GenerateOutput(OutputRecord output) { Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine($" Processing File - {output.Filename}"); Console.WriteLine("-----------------------------------------------------------"); foreach (var record in output.Records) { Console.WriteLine($"{output.Filename} {record.DateAndTime} {record.BaseValue.ToString("N6")} {output.Median.ToString("N6")}"); } Console.WriteLine("\n\n"); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Custom skill: C# HTTP trigger function processed a request."); // Read input, deserialize it and validate it. var data = GetStructuredInput(req.Body); if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } // Calculate the response for each value. var response = new WebApiResponse(); foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord(); responseRecord.RecordId = record.RecordId; try { responseRecord.Data = DoWork(record.Data).Result; } catch (Exception e) { // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; } finally { response.values.Add(responseRecord); } } return(new OkObjectResult(response)); }
public static IActionResult EntitySearch( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Entity Search function: C# HTTP trigger function processed a request."); var response = new WebApiResponse { Values = new List <OutputRecord>() }; string requestBody = new StreamReader(req.Body).ReadToEnd(); var data = JsonConvert.DeserializeObject <WebApiRequest>(requestBody); if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } if (data.Values == null) { return(new BadRequestObjectResult("The request schema does not match expected schema. Could not find values array.")); } foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord { RecordId = record.RecordId }; try { responseRecord.Data = new OutputRecord.OutputRecordContainer(FetchEntityMetadata(record.Data.Name).Result); } catch (Exception e) { log.LogError(e.Message); } finally { response.Values.Add(responseRecord); } } return(new OkObjectResult(response)); }
void consoleFlush() { outputBuffer.Length = 0; Regex filter = null; string pat = filterPattern.Trim(); if (!string.IsNullOrEmpty(pat) && pat != "*") { try { filter = new Regex(pat); } catch { } } for (int i = 0; i < recordList.Count; ++i) { OutputRecord record = recordList[i]; if (record.type == OutputRecord.OutputType.Log && !toggleLog) { continue; } else if (record.type == OutputRecord.OutputType.Err && !toggleErr) { continue; } if (filter != null && !filter.IsMatch(record.text)) { continue; } outputBuffer.AppendLine(record.text); } outputText_ = outputBuffer.ToString(); scrollPosition_.y = float.MaxValue; Repaint(); }
void ConsoleFlush() { outputBuffer.Length = 0; string keyword = filterText.Trim(); for (int i = 0; i < recordList.Count; ++i) { OutputRecord record = recordList[i]; if (record.type == OutputRecord.OutputType.Log && !toggleLog) { continue; } else if (record.type == OutputRecord.OutputType.Err && !toggleErr) { continue; } if (!string.IsNullOrEmpty(keyword)) { if (record.text.IndexOf(keyword) >= 0) { string highlightText = string.Format("<color=#ffff00ff>{0}</color>", keyword); string displayText = record.text.Replace(keyword, highlightText); outputBuffer.AppendLine(displayText); } } else { outputBuffer.AppendLine(record.text); } } outputText = outputBuffer.ToString(); scrollPosition.y = float.MaxValue; Repaint(); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Custom skill: C# HTTP trigger function processed a request."); // Read input, deserialize it and validate it. var data = GetStructuredInput(req.Body); if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } var storageConnectionString = Environment.GetEnvironmentVariable("StorageContainerString"); var modelTable = Environment.GetEnvironmentVariable("ModelTableName"); var entityTable = Environment.GetEnvironmentVariable("EntityTableName"); // Calculate the response for each value. var response = new WebApiResponse(); foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord { RecordId = record.RecordId }; var rootObject = new OutputRecord.OutputRecordData { FormEntitiesv2 = new Dictionary <string, string>() }; try { // Read Azure Table and find all entries where mlmodel = "Form" // Read information about the storage account and storage key from App Settings var storageAccount = CreateStorageAccountFromConnectionString(storageConnectionString); var sourceBlob = new CloudBlob(new Uri(record.Data.Url), storageAccount.Credentials); var sourceContainer = sourceBlob.Container.Name; // Since we are storing the file into format "container/formtype/attachmenttype/files" var formType = sourceBlob.Parent.Parent.Prefix.Replace("/", ""); var sourceFilePath = sourceBlob.Name; var sourceFileName = sourceFilePath.Replace(sourceBlob.Parent.Prefix, "").Replace(".pdf", ""); log.LogInformation("Form Recognizer Skill function: Url : {0}", record.Data.Url); var sortedModel = GetModelInfo(storageConnectionString, modelTable, formType).Result; // Loop through all the results once it's sorted by Page Number foreach (var model in sortedModel) { var folder = sourceBlob.Parent.Prefix; var file = sourceFileName + "_" + model.Page.PadLeft(3, '0') + ".jpg"; var blob = GetBlobReference(folder + file, sourceContainer, storageConnectionString); Stream myBlob = new MemoryStream(); blob.DownloadToStreamAsync(myBlob).Wait(); myBlob.Position = 0; var entities = AnalyzeForm(model.ModelId, model.EndPoint, model.SubscriptionKey, myBlob, rootObject.FormEntitiesv2, entityTable, storageConnectionString, file, model.Page, formType, folder, sourceContainer).Result; log.LogInformation("Form Recognizer Skill : C# HTTP output : {0}", responseRecord.Data); } responseRecord.Data = rootObject; } catch (Exception e) { // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; log.LogInformation("Custom skill: C# Exception : {0}", e.Message); responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; } finally { response.values.Add(responseRecord); } } return(new OkObjectResult(response)); }
/// <summary> /// Write result in excel sheet /// </summary> /// <param name="output"></param> public void GenerateOutput(OutputRecord output) { throw new NotImplementedException(); }
public async Task <ActionResult <string> > MergeSharePointMetadatav2() { System.Diagnostics.Trace.WriteLine("Starting call"); var response = new WebApiResponse() { Values = new List <OutputRecord>() }; string requestBody = new StreamReader(Request.Body).ReadToEnd(); //dynamic data = JsonConvert.DeserializeObject(requestBody); var data = JsonConvert.DeserializeObject <CustomSkillApiRequest>(requestBody); // Do some schema validation if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } if (data.Values == null) { return(new BadRequestObjectResult("The request schema does not match expected schema. Could not find values array.")); } // Calculate the response for each value. foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord { RecordId = record.RecordId, }; try { System.Diagnostics.Trace.WriteLine("Record Metadata URL Details: {0}", record.Data.Metadataurl); responseRecord.Data = new OutputRecord.OutputRecordData(); var metadata = await svc.GetMetadata(new Uri(record.Data.Metadataurl)); responseRecord.Data.ACLS = ""; responseRecord.Data.SPWebUrl = metadata.SPWebUrl; responseRecord.Data.CreatedAuthorDisplayName = metadata.CreatedAuthorDisplayName; //responseRecord.Data.DocumentType = metadata.DocumentType; //responseRecord.Data.Region = metadata.Region; //responseRecord.Data.Country = metadata.Country; //responseRecord.Data.AustraliaState = metadata.AustraliaState; //responseRecord.Data.Asset = metadata.Asset; responseRecord.Data.LinkFilename = metadata.LinkFilename; } catch (Exception e) { // Something bad happened, log the issue. System.Diagnostics.Trace.TraceInformation("Something [info] bad happened {0}", e.Message.ToString()); System.Diagnostics.Trace.TraceError("Something [error] bad happened {0}", e.Message.ToString()); System.Diagnostics.Trace.WriteLine("Something [error] bad happened {0}", e.Message.ToString()); var error = new OutputRecord.OutputRecordMessage { Message = e.InnerException.Message }; responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; } finally { response.Values.Add(responseRecord); } } return((ActionResult) new OkObjectResult(response)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Custom Search function: C# HTTP trigger function processed a request."); var response = new WebApiResponse { Values = new List <OutputRecord>() }; string requestBody = new StreamReader(req.Body).ReadToEnd(); var data = JsonConvert.DeserializeObject <WebApiRequest>(requestBody); log.LogInformation("Custom Search function: Request is validated." + data); // Do some schema validation if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } if (data.Values == null) { return(new BadRequestObjectResult("The request schema does not match expected schema. Could not find values array.")); } log.LogInformation("Custom Search function: Starting the record ."); // Calculate the response for each value. foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord { RecordId = record.RecordId }; try { responseRecord.Data = GetEntityMetadata(record.Data.Name, log).Result; log.LogInformation("Custom Search function: Response record." + responseRecord.Data.ToString()); } catch (Exception e) { // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; log.LogError("Custom Search function: Error message." + error.Message); } finally { response.Values.Add(responseRecord); } } return((ActionResult) new OkObjectResult(response)); }
/// <summary> /// Prints the result in Console /// </summary> /// <param name="output"></param> public void PrintResult(OutputRecord output) { _outputService.GenerateOutput(output); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("LuisSkill function: C# HTTP trigger function processed a request."); var response = new WebApiResponse { Values = new List <OutputRecord>() }; string requestBody = new StreamReader(req.Body).ReadToEnd(); var data = JsonConvert.DeserializeObject <WebApiRequest>(requestBody); // Do some schema validation if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } if (data.Values == null) { return(new BadRequestObjectResult("The request schema does not match expected schema. Could not find values array.")); } var storageConnectionString = Environment.GetEnvironmentVariable("StorageContainerString"); var modelTable = Environment.GetEnvironmentVariable("ModelTableName"); var entityTable = Environment.GetEnvironmentVariable("EntityTableName"); log.LogInformation("LuisSkill function: Model Name : {0}", modelTable); foreach (var record in data.Values) { OutputRecord responseRecord = new OutputRecord { RecordId = record.RecordId }; // Read Azure Table and find all entries where mlmodel = "luis" // Read information about the storage account and storage key from App Settings var storageAccount = CreateStorageAccountFromConnectionString(storageConnectionString); var sourceBlob = new CloudBlob(new Uri(record.Data.Url), storageAccount.Credentials); var sourceContainer = sourceBlob.Container.Name; var sourceFilePath = sourceBlob.Name; // Since we are storing the file into format "container/formtype/attachmenttype/files" var formType = sourceBlob.Parent.Parent.Prefix.Replace("/", ""); var sourceFileName = sourceFilePath.Replace(sourceBlob.Parent.Prefix, "").Replace(".pdf", ""); log.LogInformation("LuisSkill function: Url : {0}", record.Data.Url); log.LogInformation("LuisSkill function: Text : {0}", record.Data.OcrText); var sortedModel = GetModelInfo(storageConnectionString, modelTable, formType, log).Result; // Construct object for results var rootObject = new OutputRecord.OutputRecordData { LuisEntities = new Dictionary <string, string>() }; var duplicatePair = new ListWithDuplicates(); // Loop through all the results once it's sorted by Page Number foreach (var model in sortedModel) { var folder = sourceBlob.Parent.Prefix; var file = sourceFileName + "_" + model.Page.PadLeft(3, '0') + ".jpg"; log.LogInformation("LuisSkill function: Model : {0}, {1}", model.PartitionKey, model.Page); var convertedText = record.Data.OcrText[Convert.ToInt32(model.Page) - 1]; if (model.StartIndex > 0 && convertedText.Substring(model.StartIndex).Length > 500) { convertedText = convertedText.Substring(model.StartIndex, 500); } else if (model.StartIndex > 0) { convertedText = convertedText.Substring(model.StartIndex); } if (model.StartIndex == 0 && convertedText.Length > 500) { convertedText = convertedText.Substring(model.StartIndex, 500); } var entities = GetEntities(convertedText, model.ModelId, model.EndPoint, model.SubscriptionKey, rootObject.LuisEntities, formType, entityTable, storageConnectionString, file, model.Page, log, duplicatePair).Result; } responseRecord.Data = rootObject; response.Values.Add(responseRecord); } return((ActionResult) new OkObjectResult(response)); }
public static IActionResult RunHeaderExtraction([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext executionContext) { string skillName = executionContext.FunctionName; log.LogInformation($"{skillName}: C# HTTP trigger function processed a request."); // Read input, deserialize it and validate it. var data = GetStructuredInput(req.Body); if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } if (data.Values.Count() != 1) { return(new BadRequestObjectResult($"{skillName} - Invalid request record array: Skill requires exactly 1 image per request.")); } var response = new WebApiResponse(); foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord(); responseRecord.RecordId = record.RecordId; try { var fileLocation = string.Format("{0}?{1}", record.Data["path"], record.Data["token"].ToString().StartsWith("?") ? record.Data["token"].ToString().Substring(1) : record.Data["token"]); using (WebClient webConnection = new WebClient()) { using (var mStream = new MemoryStream(webConnection.DownloadData(fileLocation))) { if (record.Data["contentType"].ToString() == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { using (var doc = WordprocessingDocument.Open(mStream, false)) { var paragraphs = doc.MainDocumentPart.Document.Body .OfType <Paragraph>() .Where(p => p.ParagraphProperties != null && p.ParagraphProperties.ParagraphStyleId != null && p.ParagraphProperties.ParagraphStyleId.Val.Value.Contains("Heading")).ToList(); //var allStyles = DocumentFormat.OpenXml.Wordprocessing. responseRecord.Data["headings"] = paragraphs.Select(a => a.InnerText).ToList(); } } responseRecord.Data["headings"] = null; } } } catch (Exception e) { log.LogInformation($"{skillName}: Error {e.Message}"); // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; } finally { response.values.Add(responseRecord); } } return(new OkObjectResult(response)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Data Processor skill: C# HTTP trigger function processed a request."); // Read input, deserialize it and validate it. var data = GetStructuredInput(req.Body); if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } var storageConnectionString = Environment.GetEnvironmentVariable("StorageContainerString"); var entityTable = Environment.GetEnvironmentVariable("EntityTableName"); var cosmosUri = Environment.GetEnvironmentVariable("CosmosUri"); var cosmosKey = Environment.GetEnvironmentVariable("CosmosKey"); var cosmosDbId = Environment.GetEnvironmentVariable("CosmosDbId"); var cosmosContainer = Environment.GetEnvironmentVariable("CosmosContainer"); var response = new WebApiResponse(); foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord { RecordId = record.RecordId }; var rootObject = new OutputRecord.OutputRecordData { FormDoc = new List <FormDoc>() }; try { log.LogInformation("Data Processor skill: Process record : {0}", record.Data.Url); var storageAccount = CreateStorageAccountFromConnectionString(storageConnectionString); var sourceBlob = new CloudBlob(new Uri(record.Data.Url), storageAccount.Credentials); var sourceContainer = sourceBlob.Container.Name; var sourceFilePath = sourceBlob.Name; var sourceFileName = sourceFilePath.Replace(sourceBlob.Parent.Prefix, "").Replace(".pdf", ""); var json = string.Empty; var formDoc = await ProcessData(storageConnectionString, entityTable, sourceFileName, sourceContainer, log); rootObject.FormDoc = formDoc; json = JsonConvert.SerializeObject(formDoc, Formatting.Indented); log.LogInformation("Json Value : " + json); WriteToCosmos(formDoc, cosmosUri, cosmosDbId, cosmosContainer, cosmosKey); rootObject.FormDocJson = json; responseRecord.Data = rootObject; } catch (Exception e) { // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; log.LogInformation("Data Processor skill: C# Exception : {0}", e.Message); responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; } finally { response.values.Add(responseRecord); } } log.LogInformation($"Completed"); return(new OkObjectResult(response)); }
public static IActionResult RunHocrGenerator([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext executionContext) { string skillName = executionContext.FunctionName; log.LogInformation($"{skillName}: C# HTTP trigger function processed a request."); // Read input, deserialize it and validate it. var data = GetStructuredInput(req.Body); if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } if (data.Values.Count() != 1) { return(new BadRequestObjectResult($"{skillName} - Invalid request record array: Skill requires exactly 1 image per request.")); } var response = new WebApiResponse(); foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord(); responseRecord.RecordId = record.RecordId; try { log.LogInformation($"{skillName}: List was received {record.Data["ocrImageMetadataList"]}."); List <OcrImageMetadata> imageMetadataList = JsonConvert.DeserializeObject <List <OcrImageMetadata> >(JsonConvert.SerializeObject(record.Data["ocrImageMetadataList"])); List <HocrPage> pages = new List <HocrPage>(); for (int i = 0; i < imageMetadataList.Count; i++) { pages.Add(new HocrPage(imageMetadataList[i], i)); } HocrDocument hocrDocument = new HocrDocument(pages); responseRecord.Data["hocrDocument"] = hocrDocument; } catch (Exception e) { log.LogInformation($"{skillName}: Error {e.Message}."); // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; } finally { response.values.Add(responseRecord); } } return(new OkObjectResult(response)); }
public static async Task <IActionResult> RunImageStore( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext executionContext) { string skillName = executionContext.FunctionName; log.LogInformation($"{skillName}: C# HTTP trigger function processed a request."); // Read input, deserialize it and validate it. var data = GetStructuredInput(req.Body); if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } if (data.Values.Count() != 1) { return(new BadRequestObjectResult($"{skillName} - Invalid request record array: Skill requires exactly 1 image per request.")); } string blobStorageConnectionString = Environment.GetEnvironmentVariable("BlobStorageAccountConnectionString", EnvironmentVariableTarget.Process); string blobContainerName = Environment.GetEnvironmentVariable("BlobContainerName", EnvironmentVariableTarget.Process); if (String.IsNullOrEmpty(blobStorageConnectionString) || String.IsNullOrEmpty(blobContainerName)) { return(new BadRequestObjectResult($"{skillName} - Information for the blob storage account is missing")); } CloudStorageAccount storageAccount = CloudStorageAccount.Parse(blobStorageConnectionString); var blobClient = storageAccount.CreateCloudBlobClient(); var libraryContainer = blobClient.GetContainerReference(blobContainerName); // Calculate the response for each value. var response = new WebApiResponse(); foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord(); responseRecord.RecordId = record.RecordId; try { var blockBlob = libraryContainer.GetBlockBlobReference(Guid.NewGuid().ToString()); if (!await blockBlob.ExistsAsync()) { using (var stream = new MemoryStream(Convert.FromBase64String(record.Data["imageData"].ToString()))) { await blockBlob.UploadFromStreamAsync(stream); blockBlob.Properties.ContentType = "image/jpg"; await blockBlob.SetPropertiesAsync(); } } log.LogInformation($"{skillName}: Saving image to {blockBlob.Uri.ToString()}."); responseRecord.Data["imageStoreUri"] = blockBlob.Uri.ToString(); } catch (Exception e) { log.LogInformation($"{skillName}: Error {e.Message}."); // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; } finally { response.values.Add(responseRecord); } } return(new OkObjectResult(response)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext executionContext) { string skillName = executionContext.FunctionName; log.LogInformation("Custom skill: C# HTTP trigger function processed a request."); // Read input, deserialize it and validate it. var data = GetStructuredInput(req.Body); if (data == null) { return(new BadRequestObjectResult("The request schema does not match expected schema.")); } // Calculate the response for each value. var response = new WebApiResponse(); foreach (var record in data.Values) { if (record == null || record.RecordId == null) { continue; } OutputRecord responseRecord = new OutputRecord(); responseRecord.RecordId = record.RecordId; try { responseRecord.Data = GetPosition(record.Data).Result; if (responseRecord.Data != null && responseRecord.Data.Results != null && responseRecord.Data.Results.Count > 0) { var firstPoint = responseRecord.Data.Results[0]; if (firstPoint.Position != null) { responseRecord.Data.MainGeoPoint = new OutputRecord.EdmGeographPoint( Convert.ToDouble(firstPoint.Position.lat), Convert.ToDouble(firstPoint.Position.lon)); } } } catch (Exception e) { log.LogInformation($"{skillName}: Error {e.Message}."); // Something bad happened, log the issue. var error = new OutputRecord.OutputRecordMessage { Message = e.Message }; responseRecord.Errors = new List <OutputRecord.OutputRecordMessage> { error }; } finally { response.values.Add(responseRecord); } } return(new OkObjectResult(response)); }
private static string Record(OutputRecord record) { return($"{record.Trader},{record.Symbol},{record.Quantity}"); }