Exemplo n.º 1
0
        public async Task AddCalendarEntry(Guid server, DateTime firstRun, Periodicity periodicity, IEnumerable <string> items)
        {
            var entry = new DBCalendarEntry {
                Server = server, FirstRun = firstRun, Periodicity = periodicity, Values = new int[] { }, Items = items
            };

            entry.UpdateNextRun();
            await dataBase.AddCalendarEntry(entry);
        }
Exemplo n.º 2
0
        private static async Task WakeUp(CancellationToken ctoken)
        {
            ctoken.ThrowIfCancellationRequested();

            try
            {
                var tasks = ((await database.GetNextCalendarEntries()).Select(calEntry =>
                {
                    Console.WriteLine();
                    Console.WriteLine("-------------------");
                    Console.WriteLine();
                    Console.WriteLine(calEntry.NextRun + " - " + calEntry.Id);

                    calEntry.UpdateNextRun();
                    return(Task.Run(async() =>
                    {
                        ctoken.ThrowIfCancellationRequested();

                        await database.AddCalendarEntry(calEntry);
                        switch (await database.GetServerType(calEntry.Server))
                        {
                        case ServerType.Windows:
                            {
                                using (var backup = new AgentBackup(database))
                                {
                                    await backup.Run(calEntry.Server, calEntry.Items.ToArray(), ctoken);
                                }
                            }
                            break;

                        case ServerType.VMware:
                            {
                                await Task.WhenAll(calEntry.Items.Select(vm =>
                                {
                                    var backup = new VMwareBackup(database);
                                    return backup.Run(calEntry.Server, vm, ctoken);
                                }).ToArray());
                            }
                            break;
                        }
                    }, ctoken));
                }));

                await Task.WhenAll(tasks.ToArray());
            }
            catch (Exception e)
            {
                Console.WriteLine($"Database error: {e.Message}");
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] DBCalendarEntry calEntry)
        {
            calEntry.Id = await metaDB.AddCalendarEntry(calEntry);

            return(Ok(calEntry));
        }