Ejemplo n.º 1
0
        public override async Task <int> RunAsync(string[] args)
        {
            bool success;
            var  watch = System.Diagnostics.Stopwatch.StartNew();

            var client = new BlipHttpClientAsync(VALID_AUTHORIZATION);

            using (var spinner = CLI.Spinner("Sending..."))
            {
                success = await client.PingAsync(Node.Value);
            }

            watch.Stop();
            var elapsedMilli = watch.ElapsedMilliseconds;

            if (success)
            {
                Console.WriteLine($"Response from [{Node.Value}]: time={elapsedMilli}ms");
            }
            else
            {
                using (CLI.WithForeground(ConsoleColor.Red))
                {
                    Console.WriteLine($"Without response from [{Node.Value}]: time={elapsedMilli}ms");
                }
            }

            return(0);
        }
Ejemplo n.º 2
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 = _blipAIClientFactory.GetInstanceForAI(fromAuthorization);
            IBlipAIClient targetBlipAIClient = _blipAIClientFactory.GetInstanceForAI(toAuthorization);

            foreach (var content in Contents.Value)
            {
                //if IAModel handle in a different way
                if (content.Equals(BucketNamespace.AIModel))
                {
                    await CopyAIModelAsync(fromAuthorization, toAuthorization, sourceBlipAIClient, targetBlipAIClient);
                }
                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);
        }
Ejemplo n.º 3
0
        public override async Task <int> RunAsync(string[] args)
        {
            var client = new BlipHttpClientAsync(AccessKey.Value);
            var result = await client.AnalyseForMetrics(Text.Value);

            using (CLI.WithForeground(ConsoleColor.Red))
            {
                Console.WriteLine("This text will be written in RED font on default background");

                using (CLI.WithForeground(ConsoleColor.White))
                {
                    using (CLI.WithBackground(ConsoleColor.Red))
                    {
                        Console.WriteLine("This text will be written in WHITE font on RED background");
                    }

                    Console.WriteLine("And this text will be written in WHITE font on default background");
                }
            }

            return(0);
        }
Ejemplo n.º 4
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);
            }
        }