private async Task <DBServer> GetServer(Guid id, bool withcreds = false) { var servertype = await metaDB.GetServerType(id); DBServer server = null; switch (servertype) { case ServerType.Windows: server = await metaDB.GetWindowsServer(id, withcreds); break; case ServerType.VMware: server = await metaDB.GetVMWareServer(id, withcreds); break; } return(server); }
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}"); } }
public async Task Details(Guid serverId) { var servertype = await metaDB.GetServerType(serverId); switch (servertype) { case ServerType.Windows: await PrintWindowsServer(await metaDB.GetWindowsServer(serverId)); break; case ServerType.VMware: await PrintVMwareServer(await metaDB.GetVMWareServer(serverId)); break; } }