Exemple #1
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}");
            }
        }