Beispiel #1
0
        public DefaultRunConfiguration ConvertGenericGetterOption(ConfigType type, CommandApi command, Options.IGetOptions option)
        {
            DefaultRunConfiguration config = new DefaultRunConfiguration(type, command);

            config = SetDefaultRunConfigurationOption(config, type, command, option);
            return(config);
        }
Beispiel #2
0
        public DefaultRunConfiguration ConvertAllGetterOption(ConfigType type, Options.AllObjectsOptions option)
        {
            ConfigGetGlobalOptions(option);
            CommandApi command = CommandApi.List;

            if (option.Delete)
            {
                command = CommandApi.Delete;
            }
            else if (option.Abort)
            {
                command = CommandApi.Abort;
            }
            else if (option.List)
            {
                command = CommandApi.List;
            }

            DefaultRunConfiguration config = new DefaultRunConfiguration(type, command);

            GetDefaultOptions(config, option);

            ConfigPrintInformation(option, type, Enum.GetName(typeof(CommandApi), command));
            return(config);
        }
Beispiel #3
0
        private ICommandLauncher CreateBucketCommandLauncher(CommandApi command)
        {
            switch (command)
            {
            case CommandApi.Create:
                return(new CreateCommandLauncher(new ApiObjectCreator.BucketCreator(new CreateHelper()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.List:
                return(new CommandGeneric <QBucket, BucketCommandValue>(new QBucketsRetriever(), new BucketListResumeCommand(new BytesFormatter()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.InfoBucket:
                return(new CommandGenericOneElem <QBucket, BucketInfoCommandValue>(new QBucketRetriever(), new ListBucketEntriesCommand(new BytesFormatter()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Delete:
                return(new CommandGeneric <QBucket, GenericInfoCommandValue>(new QBucketsRetriever(), new DeleteBucketCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.SyncFrom:
                return(new CommandGeneric <QBucket, GenericInfoCommandValue>(new QBucketsRetriever(), new SynchronizeLocalFolderFromBucketCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.SyncTo:
                return(new CommandGeneric <QBucket, GenericInfoCommandValue>(new QBucketsRetriever(), new SynchronizeLocalFolderToBucketCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Upload:
                return(new CommandGeneric <QBucket, GenericInfoCommandValue>(new QBucketsRetriever(), new UploadBucketCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Download:
                return(new CommandGeneric <QBucket, GenericInfoCommandValue>(new QBucketsRetriever(), new DownloadBucketCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Remove:
                return(new CommandGeneric <QBucket, GenericInfoCommandValue>(new QBucketsRetriever(), new RemoveEntityBucketCommand(), this.Formatter, this.ConnectionWrapper));

            default:
                throw new NotImplementedException("Not implemented command for Bucket");
            }
        }
Beispiel #4
0
        public BucketConfiguration ConvertBucketOption(ConfigType type, CommandApi command, Options.IBucketGetOptions option)
        {
            if (command == CommandApi.List && !string.IsNullOrEmpty(option.Name))
            {
                command = CommandApi.InfoBucket;
            }

            BucketConfiguration config = new BucketConfiguration(type, command);

            GetDefaultOptions(config, option);

            ConfigGetGlobalOptions(option);
            ConfigPrintInformation(option, type, Enum.GetName(typeof(CommandApi), command));
            config.Name = option.Name;

            if (option is Options.TerminateBucketOptions bucketDelete)
            {
                if (bucketDelete.BucketPath.Count() > 0)
                {
                    config.Command             = CommandApi.Remove;
                    config.RemoteRelativePaths = bucketDelete.BucketPath.ToList();
                }
            }
            else if (option is Options.CreateBucketOptions bucketCreate)
            {
                config.LocalPathFolders = bucketCreate.FolderList.ToList();
                config.LocalPathFiles   = bucketCreate.FileList.ToList();
            }
            else if (option is Options.SetBucketOptions bucketSet)
            {
                config.LocalPathFolders   = bucketSet.LocalFoldersPath.ToList();
                config.LocalPathFiles     = bucketSet.LocalFilesPath.ToList();
                config.RemoteRelativePath = bucketSet.RemoteFolderPath;
                config.StringPath         = bucketSet.RemoteFolderPath;
                config.String             = bucketSet.String;
            }
            else if (option is Options.GetBucketOptions bucketGet)
            {
                config.LocalPathGet = bucketGet.LocalPath;
                config.RemoteRelativePathFolders = bucketGet.RemoteFoldersPath.ToList();
                config.RemoteRelativePathFiles   = bucketGet.RemoteFilesPath.ToList();
                config.StringPath = bucketGet.String;
            }
            else if (option is Options.ListBucketOptions bucketInfo)
            {
                config.RemoteRelativePath = bucketInfo.RemoteFolderPath;
            }
            else if (option is Options.SyncFromBucketOptions bucketFrom)
            {
                config.LocalPathGet       = bucketFrom.LocalPath;
                config.RemoteRelativePath = bucketFrom?.RemoteFolderPath ?? string.Empty;
            }
            else if (option is Options.SyncToBucketOptions bucketTo)
            {
                config.LocalPathGet       = bucketTo.LocalPath;
                config.RemoteRelativePath = bucketTo?.RemoteFolderPath ?? string.Empty;
            }

            return(config);
        }
Beispiel #5
0
        private ICommandLauncher CreatePoolCommandLauncher(CommandApi command)
        {
            switch (command)
            {
            case CommandApi.Create:
                return(new CreateCommandLauncher(new ApiObjectCreator.CreateNewPool(new CreateHelper()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Info:
                return(new CommandGeneric <QPool, QPool>(new QPoolsRetriever(), new GenericCommand <QPool, QPool>(new ConnectionTransformer()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.List:
                return(new CommandGeneric <QPool, PoolCommandValue>(new QPoolsRetriever(), new GenericCollectionCommand <QPool, PoolCommandValue>(new PoolModelMapper()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Delete:
                return(new CommandGeneric <QPool, GenericInfoCommandValue>(new QPoolsRetriever(), new DeletePoolCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.UpdateResources:
                return(new CommandGeneric <QPool, GenericInfoCommandValue>(new QPoolsRetriever(), new UpdatePoolResourcesCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.UpdateConstant:
                return(new CommandGeneric <QPool, GenericInfoCommandValue>(new QPoolsRetriever(), new UpdatePoolConstantCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Set:
                return(new CommandGeneric <QPool, GenericInfoCommandValue>(new QPoolsRetriever(), new SetPoolElasticSettingsCommand(), this.Formatter, this.ConnectionWrapper));

            default:
                throw new NotImplementedException("Not implemented command for Pool");
            }
        }
Beispiel #6
0
        public ICommandLauncher CreateLauncher(ConfigType type, CommandApi command)
        {
            switch (type)
            {
            case ConfigType.Pool:
                return(this.CreatePoolCommandLauncher(command));

            case ConfigType.Task:
                return(this.CreateTaskCommandLauncher(command));

            case ConfigType.Job:
                return(this.CreateJobCommandLauncher(command));

            case ConfigType.Bucket:
                return(this.CreateBucketCommandLauncher(command));

            case ConfigType.All:
                return(this.CreateAllCommandLauncher(command));

            case ConfigType.Config:
                return(this.CreateConfigurationCommandLauncher(command));

            case ConfigType.Account:
                return(this.CreateAccountCommandLauncher(command));

            default:
                throw new NotImplementedException("Not implemented command : " + Enum.GetName(typeof(ConfigType), type));
            }
        }
Beispiel #7
0
        /// <summary>
        /// upgrade of the ConvertGenericGetterOption
        /// to have the snap options
        /// </summary>
        /// <param name="type">object type</param>
        /// <param name="command">object command to launch</param>
        /// <param name="option">object options and values</param>
        /// <returns>a new object command to be launch</returns>
        public SnapshotConfiguration ConvertSnapshotOption(ConfigType type, CommandApi command, Options.SnapshotTaskOptions option)
        {
            SnapshotConfiguration config = new SnapshotConfiguration(type, command);

            SetDefaultRunConfigurationOption(config, type, command, option);
            HydrateSnapOption(config, option);
            return(config);
        }
Beispiel #8
0
        public T ReadConfigurationFile <T>(string filePath, ConfigType type, CommandApi command) where T : IConfiguration
        {
            T   config    = ConfigReadFile <T>(filePath);
            var setconfig = config as IConfiguration;

            setconfig.Type    = type;
            setconfig.Command = command;
            return(config);
        }
Beispiel #9
0
        /// <summary>
        /// upgrade of the ConvertGenericGetterOption
        /// to have the options for constant update.
        /// </summary>
        /// <param name="type">object type.</param>
        /// <param name="command">object command to launch.</param>
        /// <param name="option">constant update options and values.</param>
        /// <returns>a new object command to be launch.</returns>
        public ConstantUpdateConfiguration ConvertConstantOption(ConfigType type, CommandApi command, Options.IConstantOptions option)
        {
            var config = new ConstantUpdateConfiguration(type, command);

            SetDefaultRunConfigurationOption(config, type, command, option);
            config.ConstantName  = option.ConstantName;
            config.ConstantValue = option.ConstantValue;

            return(config);
        }
 private static void CommandSendMessage(string json, CommandApi commandsApi)
 {
     if (JsonConvert.DeserializeObject <SendMessageCommand>(json) is SendMessageCommand commands)
     {
         foreach (var client in clients.Where(w => w.Id == commands.Data.From))
         {
             client.MessageNotify(new MessageViewModel(commands.Data));
         }
     }
 }
Beispiel #11
0
        /// <summary>
        /// upgrade of the ConvertGenericGetterOption
        /// to have the stdout and error options.
        /// </summary>
        /// <param name="type">object type.</param>
        /// <param name="command">object command to launch.</param>
        /// <param name="option">object options and values.</param>
        /// <returns>a new object command to be launch.</returns>
        public StdConfiguration ConvertStdOption(ConfigType type, CommandApi command, Options.AStdOptions option)
        {
            StdConfiguration config = new StdConfiguration(type, command);

            SetDefaultRunConfigurationOption(config, type, command, option);
            config.Stdout = option.Stdout;
            config.Stderr = option.Stderr;
            config.Fresh  = option.Fresh;

            return(config);
        }
Beispiel #12
0
        private ICommandLauncher CreateAccountCommandLauncher(CommandApi command)
        {
            switch (command)
            {
            case CommandApi.Info:
                return(new CommandGenericOneElem <UserInformation, UserInformationCommandValue>(new UserInformationRetriever(), new GetAccountInformationCommand(new UserInformationModelMapper(), new BytesFormatter()), this.Formatter, this.ConnectionWrapper));

            default:
                throw new NotImplementedException("Not implemented command for Account");
            }
        }
Beispiel #13
0
        private ICommandLauncher CreateConfigurationCommandLauncher(CommandApi command)
        {
            switch (command)
            {
            case CommandApi.Set:
                throw new NotImplementedException("Set Configuration don't call the SDK");

            default:
                throw new NotImplementedException("Not implemented command for Config ");
            }
        }
 private static void CommandClientDisconnected(string json, CommandApi commandsApi)
 {
     if (JsonConvert.DeserializeObject <ClientDisconnectedCommand>(json) is ClientDisconnectedCommand commands)
     {
         var clientVm = clients.Where(w => w.Id == commands.Data).FirstOrDefault();
         System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
         {
             clients.Remove(clientVm);
         }));
     }
 }
Beispiel #15
0
        public void TestBasicCommandOnBucketNotFoundReturnTheNotFoundErrorMessage(CommandApi commandType)
        {
            QBucket bucket = null; // symbolize the null return from sdk retrieve bucket method if the bucket doses not exist
            ICommand <QBucket, CommandValues.GenericInfoCommandValue> command;
            Task commandAsync    = null;
            CancellationToken ct = default(CancellationToken);
            var config           = new BucketConfiguration()
            {
                Name                = "NonExistingBucket",
                LocalPathGet        = "a",
                RemoteRelativePaths = new List <string> {
                    "b"
                },
            };

            switch (commandType)
            {
            case CommandApi.Delete:
                command      = new DeleteBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.SyncFrom:
                command      = new SynchronizeLocalFolderFromBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.SyncTo:
                command      = new SynchronizeLocalFolderToBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.Upload:
                command      = new UploadBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.Download:
                command      = new DownloadBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.Remove:
                command      = new RemoveEntityBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;
            }

            var    cliException = Assert.ThrowsAsync <Exception>(async() => await commandAsync, "Bucket not found should throw an error");
            string expected1    = "Bucket not found";

            StringAssert.Contains(expected1, cliException.Message);
        }
Beispiel #16
0
        public string DeviceCommands(int appId, string deviceId, string serviceId, string method, string paras, int expireTime = 1200, int maxRetransmit = 3)
        {
            var rst = new ReturnResult <DeviceCommandResp>();

            var api = new CommandApi();

            rst = api.DeviceCommands(new SendCommandRequest
            {
                deviceId = deviceId,
                command  = new CommandDetail
                {
                    serviceId = serviceId,
                    method    = method,
                    paras     = JsonHelper.Instance.Deserialize <object>(paras)
                },
                callbackUrl   = "http://120.76.164.210:9999/commandRsp",
                expireTime    = expireTime,
                maxRetransmit = maxRetransmit
            }, appId);

            if (rst.Result)
            {
                var data = rst.Data;
                var bll  = new CommandInfoBll();

                var addRst = bll.Add(new CommandInfo()
                {
                    CommandId          = data.commandId,
                    AppId              = data.appId,
                    DeviceId           = data.deviceId,
                    Command            = JsonHelper.Instance.Serialize(data.command),
                    CallbackUrl        = data.callbackUrl,
                    ExpireTime         = data.expireTime,
                    Status             = data.status,
                    Result             = JsonHelper.Instance.Serialize(data.result),
                    CreationTime       = FunHelper.UTCToDateTime(data.creationTime),
                    ExecuteTime        = FunHelper.UTCToDateTime(data.executeTime),
                    PlatformIssUedTime = FunHelper.UTCToDateTime(data.platformIssuedTime),
                    DeliveredTime      = FunHelper.UTCToDateTime(data.deliveredTime),
                    IssuedTimes        = data.issuedTimes,
                    MaxRetransMit      = data.maxRetransmit,
                });
                if (!addRst.Result)
                {
                    rst.Result  = false;
                    rst.Message = addRst.Message;
                }
            }

            return(JsonHelper.Instance.Serialize(rst));
        }
Beispiel #17
0
        private static void gpio_devices()
        {
//GPIO inicijalizacija
            GPIODevices.initRaspberry();
            GPIODevices.lightControll(true);
            int i = 0;

            while (true)
            {
                MyHelper.pauziraj(1000);
                ApiResult <CommandVM> command = CommandApi.GetOne();
                i++;
                System.Console.Write(i + ". ");
                if (!command.isException)
                {
                    if (command.value == null)
                    {
                        System.Console.WriteLine("Nema komande ");
                        continue;
                    }
                    System.Console.WriteLine("Preuzeta komanda " + command.value.Id + ": " +
                                             command.value.CommandType.MyDescription());
                    switch (command.value.CommandType)
                    {
                    case CommandType.LIGHT_ON:
                        GPIODevices.lightControll(true);

                        break;

                    case CommandType.LIGHT_OF:
                        GPIODevices.lightControll(false);
                        break;

                    case CommandType.DOOR_OPEN:
                        break;

                    default:
                        break;
                    }
                    CommandApi.CommandExecuted(command.value.Id);
                }

                double temp = GPIODevices.readTemperature();

                if (temp != -1)
                {
                    System.Console.Write("Temperatura je: " + temp.ToString());
                }
            }
        }
Beispiel #18
0
        public PoolSetConfiguration ConvertElasticPoolSetterOption(ConfigType type, CommandApi command, Options.SetPoolOptions option)
        {
            PoolSetConfiguration config = new PoolSetConfiguration(type, CommandApi.Set);

            SetDefaultRunConfigurationOption(config, type, command, option);

            config.ElasticMinimumTotalNodes  = option.ElasticMinimumTotalNodes;
            config.ElasticMaximumTotalNodes  = option.ElasticMaximumTotalNodes;
            config.ElasticMinimumIdlingNodes = option.ElasticMinimumIdlingNodes;
            config.ElasticResizePeriod       = option.ElasticResizePeriod;
            config.ElasticResizeFactor       = option.ElasticResizeFactor;
            config.ElasticMinimumIdlingTime  = option.ElasticMinimumIdlingTime;
            return(config);
        }
 private static void CommandClientConnected(string json, CommandApi commandsApi)
 {
     if (JsonConvert.DeserializeObject <ClientConnectedCommand>(json) is ClientConnectedCommand commands)
     {
         Task.Factory.StartNew(async() =>
         {
             HttpResponseMessage response = await httpClient.GetAsync($"api/Chat/{commands.Data}");
             if (response != null && response.IsSuccessStatusCode)
             {
                 var c = await response.Content.ReadAsAsync <IEnumerable <ClientViewModel> >();
                 System.Windows.Application.Current.Dispatcher.Invoke(() => { c.ToList().ForEach(f => clients.Add(f)); });
             }
         });
     }
 }
Beispiel #20
0
        public async Task UpdatePoolResourcesFromFakeHandlerReturnTheGoodUuid()
        {
            FakeHTTP.ReturnMessage = HttpPoolObject.PoolsListBodiesWithPaging;
            ConfigType type    = ConfigType.Pool;
            CommandApi command = CommandApi.UpdateResources;

            var commandLauncher = LaunchFactory.CreateLauncher(type, command);

            string returnString = await commandLauncher.RunAndPrintCommandAsync(
                new DefaultRunConfiguration(type, command),
                FalsePrinter);

            string expected1 = "796a5321-0001-4a5c-2f42-54cce169dff8";

            StringAssert.Contains(expected1, returnString);
        }
Beispiel #21
0
        public async Task SnapTaskFromFakeHandlerReturnTheGoodReturnTheGoodUuid()
        {
            FakeHTTP.ReturnMessage = HttpTaskObject.TasksListBodiesWithPaging;
            ConfigType type    = ConfigType.Task;
            CommandApi command = CommandApi.Snapshot;

            var commandLauncher = LaunchFactory.CreateLauncher(type, command);

            string returnString = await commandLauncher.RunAndPrintCommandAsync(
                new SnapshotConfiguration(type, command),
                FalsePrinter);

            string expected1 = "f78fdff8-7081-46e1-bb2f-d9cd4e185ece";

            StringAssert.Contains(expected1, returnString);
        }
Beispiel #22
0
        public async Task TestForCommandAll()
        {
            FakeHTTP.ReturnMessage = HttpTaskObject.TasksListBodiesWithPaging;
            ConfigType type    = ConfigType.All;
            CommandApi command = CommandApi.List;

            Dictionary <string, ICommandLauncher> dict = new Dictionary <string, ICommandLauncher>()
            {
                { "first", LaunchFactory.CreateLauncher(ConfigType.Task, command) },
                { "second", LaunchFactory.CreateLauncher(ConfigType.Pool, command) },
            };

            var allConfig = new DefaultRunConfiguration(type, command);
            var all       = new CommandAll(dict);
            await all.RunAndPrintCommandAsync(allConfig, FalsePrinter);
        }
Beispiel #23
0
        public async Task InfoPoolFromFakeHandlerReturnTheGoodUuid()
        {
            FakeHTTP.ReturnMessage = HttpPoolObject.PoolsListBodiesWithPaging;
            ConfigType type    = ConfigType.Pool;
            CommandApi command = CommandApi.Info;

            var commandLauncher = LaunchFactory.CreateLauncher(type, command);

            string returnString = await commandLauncher.RunAndPrintCommandAsync(
                new DefaultRunConfiguration(type, command) { Name = "Pool Name Test List1" },
                FalsePrinter);

            string expected1 = "796a5321-0001-4a5c-2f42-54cce169dff8";
            string expected2 = "CreationDate\": \"2019-11-08T10:54:11Z";

            StringAssert.Contains(expected1, returnString);
            StringAssert.Contains(expected2, returnString);
        }
Beispiel #24
0
        public async Task DeletePoolFromFakeHandlerReturnTheGoodUuid()
        {
            FakeHTTP.ReturnMessage = HttpPoolObject.PoolResponseBody;
            ConfigType type    = ConfigType.Pool;
            CommandApi command = CommandApi.Delete;

            var commandLauncher = LaunchFactory.CreateLauncher(type, command);

            string returnString = await commandLauncher.RunAndPrintCommandAsync(
                new DefaultRunConfiguration(type, command) { Id = "PoolId" },
                FalsePrinter);

            string expected1 = "f78fdff8-7081-46e1-bb2f-d9cd4e185ece";
            string expected2 = "Pool delete";

            StringAssert.Contains(expected1, returnString);
            StringAssert.Contains(expected2, returnString);
        }
Beispiel #25
0
        public async Task InfoJobFromFakeHandlerReturnTheGoodUuid()
        {
            FakeHTTP.ReturnMessage = HttpJobObject.JobsListBodies;
            ConfigType type    = ConfigType.Job;
            CommandApi command = CommandApi.Info;

            var commandLauncher = LaunchFactory.CreateLauncher(type, command);

            string returnString = await commandLauncher.RunAndPrintCommandAsync(
                new DefaultRunConfiguration(type, command),
                FalsePrinter);

            string expected1 = "f78fdff8-7081-46e1-bb2f-d9cd4e185ece";
            string expected2 = "2019-11-08T10:54:11Z";

            StringAssert.Contains(expected1, returnString);
            StringAssert.Contains(expected2, returnString);
        }
Beispiel #26
0
        public async Task InfoPoolFromFakeHandlerReturnTheGoodUuid()
        {
            FakeHTTP.ReturnMessage = HttpPoolObject.PoolResponseBody;
            ConfigType type    = ConfigType.Pool;
            CommandApi command = CommandApi.Info;

            var commandLauncher = LaunchFactory.CreateLauncher(type, command);

            string returnString = await commandLauncher.RunAndPrintCommandAsync(
                new DefaultRunConfiguration(type, command) { Name = "pool_name" },
                FalsePrinter);

            string expected1 = "f78fdff8-7081-46e1-bb2f-d9cd4e185ece";
            string expected2 = "CreationDate\": \"2019-11-08T10:54:11Z";

            StringAssert.Contains(expected1, returnString);
            StringAssert.Contains(expected2, returnString);
        }
Beispiel #27
0
        public void PoolBasicSubverbCanHaveAllTheBasicFlags(string subverb, CommandApi commandEnum)
        {
            string poolUuid = "PoolUUID";
            string name     = "NAME";
            string tags     = "TAG1,TAG2";

            string[]          argv = null;
            var               commandLineParser = new CommandLine.Parser();
            CommandLineParser parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration    iConfSet          = null;

            argv     = new string[] { "pool", subverb, "--name", name, "--id", poolUuid, "--tags", tags };
            iConfSet = parser.Parse(argv);
            if (!(iConfSet is DefaultRunConfiguration))
            {
                throw new Exception("return value is not DefaultRunConfiguration ");
            }

            DefaultRunConfiguration confset = (DefaultRunConfiguration)iConfSet;

            Assert.AreEqual(confset.Type, ConfigType.Pool);
            Assert.AreEqual(confset.Command, commandEnum);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Id, poolUuid);
            Assert.IsFalse(confset.TagsIntersect);
            CollectionAssert.Contains(confset.Tags, tags);

            argv     = new string[] { "pool", subverb, "--name", name, "--id", poolUuid, "--exclusive-tags", tags };
            iConfSet = parser.Parse(argv);
            if (!(iConfSet is DefaultRunConfiguration))
            {
                throw new Exception("return value is not DefaultRunConfiguration ");
            }

            confset = (DefaultRunConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Pool);
            Assert.AreEqual(confset.Command, commandEnum);
            Assert.AreEqual(confset.Name, name);
            Assert.AreEqual(confset.Id, poolUuid);
            Assert.IsTrue(confset.TagsIntersect);
            CollectionAssert.Contains(confset.Tags, tags);
        }
Beispiel #28
0
        public async Task <bool> SendCommand()
        {
            if (string.IsNullOrEmpty(_sasToken))
            {
                var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(Config.EventHub.KeyName, Config.EventHub.SharedAccessKey, TimeSpan.FromMinutes(30));
                _sasToken = (await tokenProvider.GetTokenAsync(Config.EventHub.Url, TimeSpan.FromMinutes(30))).TokenValue;
            }

            try
            {
                await CommandApi.SendCommand("body", _sasToken);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(false);
            }

            return(true);
        }
Beispiel #29
0
        public void TestBasicCommandOnPoolNotFoundReturnTheErrorMessage(CommandApi command)
        {
            FakeHTTP.ReturnStatusCode = System.Net.HttpStatusCode.NotFound;
            FakeHTTP.ReturnMessage    = "{\"Message\": \"No such pool\"}";
            ConfigType type = ConfigType.Pool;

            var commandManager = new CommandManager(LaunchFactory, FalsePrinter);

            var exception = Assert.ThrowsAsync <CommandManager.ErrorPrintException>(
                async() => await commandManager.StartAsync(
                    new DefaultRunConfiguration(type, command)
            {
                Name = "Invalid pool", TagsIntersect = true
            }),
                "Pool not found should throw from sdk");

            string expectedMessage = "No such pool";

            Assert.True(CLILogsCheckValues.Messages[CLILogs.LogsLevel.Error].Contains(expectedMessage));
        }
Beispiel #30
0
        private ICommandLauncher CreateTaskCommandLauncher(CommandApi command)
        {
            switch (command)
            {
            case CommandApi.Create:
                return(new CreateCommandLauncher(new ApiObjectCreator.CreateNewTask(new CreateHelper()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Info:
                return(new CommandGeneric <QTask, QTask>(new QTasksRetriever(), new GenericCommand <QTask, QTask>(new ConnectionTransformer()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Wait:
                return(new CommandGeneric <QTask, GenericInfoCommandValue>(new QTasksRetriever(), new WaitTaskCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.List:
                return(new CommandGeneric <QTask, TaskCommandValue>(new QTasksRetriever(), new GenericCollectionCommand <QTask, TaskCommandValue>(new TaskModelMapper()), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Abort:
                return(new CommandGeneric <QTask, GenericInfoCommandValue>(new QTasksRetriever(), new AbortTaskCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Delete:
                return(new CommandGeneric <QTask, GenericInfoCommandValue>(new QTasksRetriever(), new DeleteTaskCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.UpdateResources:
                return(new CommandGeneric <QTask, GenericInfoCommandValue>(new QTasksRetriever(), new UpdateTaskResourcesCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.UpdateConstant:
                return(new CommandGeneric <QTask, GenericInfoCommandValue>(new QTasksRetriever(), new UpdateTaskConstantCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.GetStdout:
                return(new CommandGeneric <QTask, string>(new QTasksRetriever(), new StdoutTaskCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.GetStderr:
                return(new CommandGeneric <QTask, string>(new QTasksRetriever(), new StderrTaskCommand(), this.Formatter, this.ConnectionWrapper));

            case CommandApi.Snapshot:
                return(new CommandGeneric <QTask, GenericInfoCommandValue>(new QTasksRetriever(), new SnapshotTaskCommand(), this.Formatter, this.ConnectionWrapper));

            default:
                throw new NotImplementedException("Not implemented command for Task");
            }
        }