public async Task <bool> Update(SystemCategories.Category category) { ILabSystemService service = new LabSystemService(new LabSystemsContextFactory()); string hostName = GetHostName(); LabSystem existingEntity = await service.Get(hostName); LabSystem entity = new LabSystem() { Ipaddress = GetIPAddress(), HostName = hostName, Osversion = GetOSVersion(), Timestamp = GetTimestamp(), Category = category, }; if (existingEntity != null) { entity.Id = existingEntity.Id; if (category == SystemCategories.Category.Unknown) { entity.Category = existingEntity.Category; } } entity.DiskDrives?.Clear(); entity.DiskDrives = await(new UpdateDiskDriveInfo()).Update(); Task <LabSystem> task = service.CreateOrUpdate(hostName, entity); task.Wait(); return(task.IsCompleted); }
static void Main(string[] args) { string keys = string.Join(",", new List <string>(SystemCategories.Categories.Keys)); CommandLineApplication cli = new CommandLineApplication(); CommandOption arg1 = cli.Option("-c | --category <value>", $"The category of the system. Options: {keys}", CommandOptionType.SingleValue); cli.HelpOption("-? | -h | --help"); cli.OnExecute(() => { SystemCategories.Category category = SystemCategories.Category.Unknown; Console.WriteLine("Heartbeating..."); if (arg1.HasValue() && SystemCategories.Categories.ContainsKey(arg1.Value())) { if (SystemCategories.Categories.ContainsKey(arg1.Value())) { category = SystemCategories.Categories[arg1.Value()]; } else { Console.WriteLine("Incorrect category specified!"); return(-1); } } UpdateSystemInfo update = new UpdateSystemInfo(); Task <bool> updateTask = update.Update(category); updateTask.Wait(); if (updateTask.Result) { Console.WriteLine("Success!"); return(0); } else { Console.WriteLine("Fail..."); return(-1); } }); Stopwatch watch = new Stopwatch(); watch.Start(); cli.Execute(args); watch.Stop(); Console.WriteLine("Time Taken to Heartbeat (seconds): " + (watch.ElapsedMilliseconds / 1000).ToString()); }