private DataBlock CheckResponse(DataBlock dataBlock) { var item = dataBlock.NLPAnalysisResponse; if (item == null) { _logger.LogError($"Error when analysing: \"{dataBlock.Input}\""); return(dataBlock); } return(dataBlock); }
private void Consumer() { _logger?.LogInformation($"Start {Name}."); _status = true; while (!_cancellationTokenSource.IsCancellationRequested) { ProcessQueue(); try { _eventSlim.Wait(_cancellationTokenSource.Token); _eventSlim.Reset(); } catch (OperationCanceledException ex) { // expected _logger?.LogError("AsyncQueueDispatcher exception.", ex); break; } } ProcessQueue(); // one last time for the remaining messages }
public void Error(string message, Exception ex) { CheckLoggerCreated(); _inner.LogError(message, ex); if (ex?.InnerException != null) { Error("Inner Exception", ex.InnerException); } }
private async Task FlushCallback(object obj) { var utcNow = DateTime.UtcNow; var oldPointStates = _pointMap.Keys.Where(x => x.UtcTimeStamp < utcNow && x.Status == PointStatus.Untreated).ToList(); oldPointStates.ForEach(state => state.Status = PointStatus.Sending); foreach (var chunkedStates in Chunked(oldPointStates)) { var measurementStates = chunkedStates.GroupBy(x => x.LineProtocolPoint.Measurement); foreach (var currentStates in measurementStates) { var states = currentStates.Select(x => x).ToList(); var lineProtocolPayload = new LineProtocolPayload(); foreach (var state in states.OrderByDescending(x => x.UtcTimeStamp)) { lineProtocolPayload.Add(state.LineProtocolPoint); } try { await _lineProtocolClient.WriteAsync(lineProtocolPayload); } catch (Exception ex) { _logger?.LogError(currentStates.Key + "__" + currentStates.Count() + "__" + ex.Message, ex); } finally { foreach (var state in states) { _pointMap.TryRemove(state, out _); } } } } }
public async Task <AnalysisResponse> AnalyseForMetrics(string analysisRequest) { if (analysisRequest == null) { throw new ArgumentNullException(nameof(analysisRequest)); } try { var command = new Command { Id = EnvelopeId.NewId(), To = Node.Parse("*****@*****.**"), Uri = new LimeUri("/analysis"), Method = CommandMethod.Set, Resource = new AnalysisRequest { TestingRequest = true, Text = analysisRequest } }; var envelopeResult = await RunCommandAsync(command); return(envelopeResult.Resource as AnalysisResponse); } catch (HttpRequestException e) { _logger.LogError(e, "\nException Caught!"); _logger.LogError(e, "Message :{0} ", e.Message); return(null); } }
public void Error(string message, Exception ex) { CheckLoggerCreated(); _inner.LogError(message, ex); }
public async Task AnalyseAsync(string authorization, string inputSource, string reportOutput, bool doContentCheck = false) { if (string.IsNullOrEmpty(authorization)) { throw new ArgumentNullException("You must provide the target bot (node) for this action."); } if (string.IsNullOrEmpty(inputSource)) { throw new ArgumentNullException("You must provide the input source (phrase or file) for this action."); } if (string.IsNullOrEmpty(reportOutput)) { throw new ArgumentNullException("You must provide the full output's report file name for this action."); } _logger.LogDebug("COMEÇOU!"); _fileService.CreateDirectoryIfNotExists(reportOutput); var bucketStorage = new BucketStorage("Key " + authorization); var contentProvider = new Take.ContentProvider.ContentProvider(bucketStorage, 5); var client = _blipClientFactory.GetInstanceForAI(authorization); var allIntents = new List <Intention>(); if (doContentCheck) { _logger.LogDebug("\tCarregando intencoes..."); allIntents = await client.GetAllIntentsAsync(); _logger.LogDebug("\tCarregadas!"); } bool isPhrase = false; var isDirectory = _fileService.IsDirectory(inputSource); var isFile = _fileService.IsFile(inputSource); if (isFile) { _logger.LogDebug("\tA entrada é um arquivo"); isPhrase = false; } else if (isDirectory) { _logger.LogError("\tA entrada é um diretório"); throw new ArgumentNullException("You must provide the input source (phrase or file) for this action. Your input was a direcory."); } else { _logger.LogDebug("\tA entrada é uma frase"); isPhrase = true; } var options = new ExecutionDataflowBlockOptions { BoundedCapacity = DataflowBlockOptions.Unbounded, MaxDegreeOfParallelism = 20, }; var analyseBlock = new TransformBlock <NLPAnalyseDataBlock, NLPAnalyseDataBlock>((Func <NLPAnalyseDataBlock, Task <NLPAnalyseDataBlock> >)AnalyseForMetrics, options); var checkBlock = new TransformBlock <NLPAnalyseDataBlock, NLPAnalyseDataBlock>((Func <NLPAnalyseDataBlock, NLPAnalyseDataBlock>)CheckResponse, options); var contentBlock = new TransformBlock <NLPAnalyseDataBlock, NLPAnalyseDataBlock>((Func <NLPAnalyseDataBlock, Task <NLPAnalyseDataBlock> >)GetContent, options); var showResultBlock = new ActionBlock <NLPAnalyseDataBlock>(BuildResult, new ExecutionDataflowBlockOptions { BoundedCapacity = DataflowBlockOptions.Unbounded, MaxMessagesPerTask = 1 }); analyseBlock.LinkTo(checkBlock, new DataflowLinkOptions { PropagateCompletion = true }); checkBlock.LinkTo(contentBlock, new DataflowLinkOptions { PropagateCompletion = true }); contentBlock.LinkTo(showResultBlock, new DataflowLinkOptions { PropagateCompletion = true }); _count = 0; var inputList = await GetInputList(isPhrase, inputSource, client, reportOutput, allIntents, contentProvider, doContentCheck); _total = inputList.Count; foreach (var input in inputList) { await analyseBlock.SendAsync(input); } analyseBlock.Complete(); await showResultBlock.Completion; _logger.LogDebug("TERMINOU!"); }