protected static StorageBox GetBoxFromStorage() { Bucket bucket = BucketStorage.GetRootBucket(); Assert.IsNotNull(bucket, "Returned bucket cannot be null"); return(new StorageBox(bucket, ForceSave)); }
protected static bool PerformSave() { if (rootBox == null) { return(true); } try { ModificationsSyncRoot.EnterWriteLock(); return(BucketStorage.SaveRootBucket(rootBox.UnderlyingBucket)); } finally { ModificationsSyncRoot.ExitWriteLock(); } }
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!"); }