public override async Task <int> RunAsync(string[] args) { if (!Node.IsSet && !Authorization.IsSet) { throw new ArgumentNullException("You must provide the target bot (node) for this action. Use '-n' [--node] (or '-a' [--authorization]) parameters"); } string authorization = Authorization.Value; if (Node.IsSet) { authorization = _settingsFile.GetNodeCredentials(Lime.Protocol.Node.Parse(Node.Value)).Authorization; } _blipAIClient = new BlipHttpClientAsync(authorization); var intents = new List <Intention>(); if (IntentsFilePath.IsSet) { Console.WriteLine("Starting intents import task..."); intents = await ImportIntentions(); Console.WriteLine("Intents imported with success..."); } if (AnswersFilePath.IsSet && intents != null && intents.Count > 0) { Console.WriteLine("Starting answers import task..."); await ImportAnswers(intents); Console.WriteLine("Answers imported with success..."); } if (EntitiesFilePath.IsSet) { Console.WriteLine("Starting entities import task..."); await ImportEntities(); Console.WriteLine("Entities imported with success..."); } return(0); }
public async override Task <int> RunAsync(string[] args) { if ((!From.IsSet && !FromAuthorization.IsSet) || (!To.IsSet && !ToAuthorization.IsSet)) { throw new ArgumentNullException("You must provide from and to parameters for this action. Use '-f' [--from] (or '-fa' [--fromAuthorization]) and '-t' [--to] (or '-ta' [--toAuthorization]) parameters"); } string fromAuthorization = FromAuthorization.Value; string toAuthorization = ToAuthorization.Value; if (From.IsSet && string.IsNullOrEmpty(fromAuthorization)) { fromAuthorization = _settingsFile.GetNodeCredentials(Node.Parse(From.Value)).Authorization; } if (To.IsSet && string.IsNullOrEmpty(toAuthorization)) { toAuthorization = _settingsFile.GetNodeCredentials(Node.Parse(To.Value)).Authorization; } IBlipBucketClient sourceBlipBucketClient = new BlipHttpClientAsync(fromAuthorization); IBlipBucketClient targetBlipBucketClient = new BlipHttpClientAsync(toAuthorization); IBlipAIClient sourceBlipAIClient = new BlipHttpClientAsync(fromAuthorization); IBlipAIClient targetBlipAIClient = new BlipHttpClientAsync(toAuthorization); try { foreach (var content in Contents.Value) { //if IAModel handle in a different way if (content.Equals(BucketNamespace.AIModel)) { LogVerboseLine($"COPY AIMODEL: {From.Value} to {To.Value}"); if (Force.IsSet) { LogVerboseLine("FORCE mode"); LogVerboseLine("\t> Deleting all entities and intents from target"); var targetEntities = await targetBlipAIClient.GetAllEntities(Verbose.IsSet); LogVerbose($"\t>>> Entities: {targetEntities.Count} - "); foreach (var entity in targetEntities) { await targetBlipAIClient.DeleteEntity(entity.Id); LogVerbose("*"); } LogVerboseLine("|"); var targetIntents = await targetBlipAIClient.GetAllIntents(Verbose.IsSet); LogVerbose($"\t>>> Intent: {targetIntents.Count} - "); foreach (var intent in targetIntents) { await targetBlipAIClient.DeleteIntent(intent.Id); LogVerbose("*"); } LogVerboseLine("|"); } LogVerboseLine("COPY: "); LogVerboseLine("\t> Getting AI Model from source: "); LogVerbose("\t>>> "); var entities = await sourceBlipAIClient.GetAllEntities(Verbose.IsSet); LogVerbose("\t>>> "); var intents = await sourceBlipAIClient.GetAllIntents(Verbose.IsSet); LogVerboseLine("\t> Copying AI Model to target: "); LogVerbose($"\t>>> Entities: {entities.Count} - "); foreach (var entity in entities) { await targetBlipAIClient.AddEntity(entity); LogVerbose("*"); } LogVerboseLine("|"); LogVerbose($"\t>>> Intents: {intents.Count} - "); foreach (var intent in intents) { intent.Name = intent.Name.RemoveDiacritics().RemoveSpecialCharacters(); var id = await targetBlipAIClient.AddIntent(intent.Name, verbose : Verbose.IsSet); if (!string.IsNullOrEmpty(id)) { if (intent.Questions != null) { await targetBlipAIClient.AddQuestions(id, intent.Questions); } if (intent.Answers != null) { await targetBlipAIClient.AddAnswers(id, intent.Answers); } } LogVerbose("*"); } LogVerboseLine("|"); } else { var documentKeysToCopy = await sourceBlipBucketClient.GetAllDocumentKeysAsync(content) ?? new DocumentCollection(); var documentPairsToCopy = await sourceBlipBucketClient.GetAllDocumentsAsync(documentKeysToCopy, content); if (documentPairsToCopy != null) { foreach (var resourcePair in documentPairsToCopy) { await targetBlipBucketClient.AddDocumentAsync(resourcePair.Key, resourcePair.Value, content); } } } } return(0); } catch (Exception e) { Console.WriteLine("\n>> Failed!"); Console.WriteLine(e); return(1); } }