Esempio n. 1
0
        public void TestCommands()
        {
            var test = @"<?xml version=""1.0"" encoding=""utf-8""?>
<task>
    <metadata>
        <name>Hello World</name>
        <id>0d852117-6adf-4af7-8c8b-f52300ccae15</id>
    </metadata>
     <commands>
        <Command name=""Maze.WakeOnLan"" modules=""SystemUtilities;TaskManager"" hash=""12"">
            asdasdadsdas
        </Command>
    </commands>
</task>";

            var resolverMock = new Mock <ITaskComponentResolver>();

            resolverMock.Setup(x => x.ResolveCommand("Maze.WakeOnLan")).Returns(typeof(WakeOnLanCommand));

            var reader   = new MazeTaskReader(XDocument.Parse(test), resolverMock.Object, _serializerCache);
            var elements = reader.GetCommands().ToList();

            Assert.Collection(elements, command =>
            {
                var wolCmd = Assert.IsType <WakeOnLanCommand>(command);
                Assert.Equal("asdasdadsdas", wolCmd.Content);
            });
        }
Esempio n. 2
0
        public void TestAudienceClientsIncludingServer()
        {
            var test = @"<?xml version=""1.0"" encoding=""utf-8""?>
<task>
    <metadata>
        <name>Hello World</name>
        <id>0d852117-6adf-4af7-8c8b-f52300ccae15</id>
    </metadata>
    <audience>
        <Clients id=""C1-10,G5"" />
        <Server />
    </audience>
</task>";


            var reader = new MazeTaskReader(XDocument.Parse(test), null, _serializerCache);

            var audienceCollection = reader.GetAudience();

            Assert.False(audienceCollection.IsAll);
            Assert.True(audienceCollection.IncludesServer);
            Assert.Collection(audienceCollection, target =>
            {
                Assert.Equal(CommandTargetType.Client, target.Type);
                Assert.Equal(1, target.From);
                Assert.Equal(10, target.To);
            }, target =>
            {
                Assert.Equal(CommandTargetType.Group, target.Type);
                Assert.Equal(5, target.From);
                Assert.Equal(5, target.To);
            });
        }
Esempio n. 3
0
        public void TestCommandMetadata()
        {
            var test = @"<?xml version=""1.0"" encoding=""utf-8""?>
<task>
    <metadata>
        <name>Hello World</name>
        <id>0d852117-6adf-4af7-8c8b-f52300ccae15</id>
    </metadata>
     <commands>
        <Command name=""Maze.WakeOnLan"" modules=""SystemUtilities;TaskManager"" hash=""12"">
            asdasdadsdas
        </Command>
    </commands>
</task>";


            var reader   = new MazeTaskReader(XDocument.Parse(test), null, _serializerCache);
            var elements = reader.GetCommandMetadata().ToList();

            Assert.Collection(elements, command =>
            {
                Assert.Equal("Maze.WakeOnLan", command.Name);
                Assert.Collection(command.Modules, s => Assert.Equal("SystemUtilities", s), s => Assert.Equal("TaskManager", s));
            });
        }
Esempio n. 4
0
        public async Task <IActionResult> ExecuteTask([FromServices] ITaskComponentResolver taskComponentResolver,
                                                      [FromServices] IXmlSerializerCache serializerCache, [FromServices] IExecuteTaskAction executeTaskAction)
        {
            var reader = new MazeTaskReader(Request.Body, taskComponentResolver, serializerCache);
            var task   = reader.ReadTask();

            var result = await executeTaskAction.BizActionAsync(task);

            return(BizActionStatus(executeTaskAction, () => Ok(result)));
        }
Esempio n. 5
0
        public async Task <IActionResult> CreateOrUpdateTask([FromServices] ITaskComponentResolver taskComponentResolver,
                                                             [FromServices] IXmlSerializerCache serializerCache)
        {
            var mazeTask = new MazeTaskReader(Request.Body, taskComponentResolver, serializerCache);
            var task     = mazeTask.ReadTask();

            await _clientTaskManager.AddOrUpdateTask(task);

            return(Ok());
        }
Esempio n. 6
0
 public static async Task <MazeTask> FetchTaskAsync(Guid taskId, ITaskComponentResolver taskComponentResolver,
                                                    IXmlSerializerCache xmlSerializerCache, IRestClient restClient)
 {
     using (var response = await CreateRequest(HttpVerb.Get, taskId.ToString("N")).Execute(restClient))
         using (var stream = await response.Content.ReadAsStreamAsync())
         {
             var taskReader = new MazeTaskReader(stream, taskComponentResolver, xmlSerializerCache);
             return(taskReader.ReadTask());
         }
 }
Esempio n. 7
0
        public async Task <IActionResult> CreateTask([FromServices] ITaskComponentResolver taskComponentResolver,
                                                     [FromServices] IXmlSerializerCache serializerCache, [FromServices] ICreateTaskAction createTaskAction, [FromServices] IHubContext <AdministrationHub> hubContext)
        {
            var reader = new MazeTaskReader(Request.Body, taskComponentResolver, serializerCache);
            var task   = reader.ReadTask();

            await createTaskAction.BizActionAsync(task);

            return(await BizActionStatus(createTaskAction, async() =>
            {
                await hubContext.Clients.All.SendAsync(HubEventNames.TaskCreated, task.Id);
                return Ok();
            }));
        }
Esempio n. 8
0
        public void TestStopEvent()
        {
            var test = @"<?xml version=""1.0"" encoding=""utf-8""?>
<task>
    <metadata>
        <name>Hello World</name>
        <id>0d852117-6adf-4af7-8c8b-f52300ccae15</id>
    </metadata>
     <stop>
        <Duration duration=""PT1M"" />
    </stop>
</task>";

            var resolverMock = new Mock <ITaskComponentResolver>();

            resolverMock.Setup(x => x.ResolveStopEvent("Duration")).Returns(typeof(DurationStopEvent));

            var reader   = new MazeTaskReader(XDocument.Parse(test), resolverMock.Object, _serializerCache);
            var elements = reader.GetStopEvents().ToList();

            Assert.Collection(elements, info => Assert.Equal(TimeSpan.FromSeconds(60), Assert.IsType <DurationStopEvent>(info).Duration));
        }
Esempio n. 9
0
        public void TestParseConditions()
        {
            var test = @"<?xml version=""1.0"" encoding=""utf-8""?>
<task>
    <metadata>
        <name>Hello World</name>
        <id>0d852117-6adf-4af7-8c8b-f52300ccae15</id>
    </metadata>
    <filters>
        <OperatingSystem min=""Windows7"" />
    </filters>
</task>";

            var resolverMock = new Mock <ITaskComponentResolver>();

            resolverMock.Setup(x => x.ResolveFilter("OperatingSystem")).Returns(typeof(OperatingSystemFilterInfo));

            var reader   = new MazeTaskReader(XDocument.Parse(test), resolverMock.Object, _serializerCache);
            var elements = reader.GetFilters().ToList();

            Assert.Collection(elements, info => Assert.Equal("Windows7", Assert.IsType <OperatingSystemFilterInfo>(info).Min));
        }
Esempio n. 10
0
        public void TestDeserializeAudienceAll()
        {
            var test = @"<?xml version=""1.0"" encoding=""utf-8""?>
<task>
    <metadata>
        <name>Hello World</name>
        <id>0d852117-6adf-4af7-8c8b-f52300ccae15</id>
    </metadata>
    <audience>
        <AllClients />
    </audience>
</task>";


            var reader = new MazeTaskReader(XDocument.Parse(test), null, _serializerCache);

            var audienceCollection = reader.GetAudience();

            Assert.True(audienceCollection.IsAll);
            Assert.False(audienceCollection.IncludesServer);
            Assert.Empty(audienceCollection);
        }
Esempio n. 11
0
        public void TestParseTransmissionEvents()
        {
            var test = @"<?xml version=""1.0"" encoding=""utf-8""?>
<task>
    <metadata>
        <name>Hello World</name>
        <id>0d852117-6adf-4af7-8c8b-f52300ccae15</id>
    </metadata>
    <triggers>
        <DateTime date=""2018-10-05T18:21:07.8601530Z"" />
    </triggers>
</task>";

            var resolverMock = new Mock <ITaskComponentResolver>();

            resolverMock.Setup(x => x.ResolveTrigger("DateTime")).Returns(typeof(DateTimeTriggerInfo));

            var reader   = new MazeTaskReader(XDocument.Parse(test), resolverMock.Object, _serializerCache);
            var elements = reader.GetTriggers().ToList();

            Assert.Collection(elements,
                              info => Assert.Equal(DateTimeOffset.Parse("2018-10-05T18:21:07.8601530Z"), Assert.IsType <DateTimeTriggerInfo>(info).Date));
        }
Esempio n. 12
0
        public async Task <IActionResult> ExecuteTask([FromServices] ITaskComponentResolver taskComponentResolver,
                                                      [FromServices] IXmlSerializerCache serializerCache)
        {
            var mazeTask = new MazeTaskReader(Request.Body, taskComponentResolver, serializerCache);
            var task     = mazeTask.ReadTask();

            var memoryStorage = new MemoryTaskStorage();
            await _clientTaskManager.TriggerNow(task, SessionKey.Create("Execute"), memoryStorage);

            return(Ok(new TaskSessionsInfo
            {
                Sessions = memoryStorage.Sessions.Select(x => new TaskSessionDto
                {
                    TaskReferenceId = x.TaskReferenceId,
                    TaskSessionId = x.TaskSessionId,
                    Description = x.Description,
                    CreatedOn = x.CreatedOn
                }).ToList(),
                Executions = memoryStorage.Executions.Select(x => new TaskExecutionDto
                {
                    TaskExecutionId = x.TaskExecutionId,
                    TaskReferenceId = x.TaskReferenceId,
                    TaskSessionId = x.TaskSessionId,
                    CreatedOn = x.CreatedOn
                }).ToList(),
                Results = memoryStorage.CommandResults.Select(x => new CommandResultDto
                {
                    CommandResultId = x.CommandResultId,
                    TaskExecutionId = x.TaskExecutionId,
                    CommandName = x.CommandName,
                    Result = x.Result,
                    Status = x.Status,
                    FinishedAt = x.FinishedAt
                }).ToList()
            }));
        }