public async Task <IActionResult> Bot(int id) { try { appsettingsModel appsettings = JsonConvert.DeserializeAnonymousType(ServerFileManager.FileReader(GetPathes.Get_SolutionMainPath() + "/Alduin.Web/appsettings.json"), new appsettingsModel()); var query = new GetBotByIdQuery { Id = id }; GetImgJsonModel ImagesJsonModel = JsonConvert.DeserializeAnonymousType(await _getBotImagesJsonServices.GetAllImg(id), new GetImgJsonModel()); var bot = await _mediator.Send(query); DateTime DateNowUTC = DateTime.UtcNow.AddMinutes(-5); var status = _localizer["Offline"]; if (bot.LastLoggedInUTC >= DateNowUTC) { status = _localizer["Online"]; } var botInquiryDeatils = new BotDeatilsInquiryModel { Name = bot.UserName, Domain = bot.Domain, LastIPAddress = bot.LastIPAddress, LastLoggedInUTC = bot.LastLoggedInUTC, Status = status, KeyCertified = bot.KeyCertified, KeyUnique = appsettings.Stump.KeyCertified }; var botmodel = new BotModel { newImagesJsonModel = ImagesJsonModel, newBotDeatilsInquiryModel = botInquiryDeatils }; return(View(botmodel)); } catch { return(RedirectToAction(nameof(List))); }; }
public async Task <IActionResult> Bot(int id) { try { var getImagesStatus = ""; #if (!DEBUG) // Release appsettingsModel appsettings = JsonConvert.DeserializeAnonymousType(ServerFileManager.FileReader(GetPathes.Get_SolutionMainPath() + "/appsettings.json"), new appsettingsModel()); #else // Debug appsettingsModel appsettings = JsonConvert.DeserializeAnonymousType(ServerFileManager.FileReader(GetPathes.Get_SolutionMainPath() + "/Alduin.Web/appsettings.json"), new appsettingsModel()); #endif GetImgJsonModel ImagesJsonModel; var query = new GetBotByIdQuery { Id = id }; var bot = await _mediator.Send(query); if (_env.WebRootFileProvider.GetDirectoryContents("img/Bots/" + bot.UserName + "_" + id).Exists) { var fullpath = _env.WebRootFileProvider.GetFileInfo("img/Bots")?.PhysicalPath + "/" + bot.UserName + "_" + id; var files = Directory.GetFiles(fullpath);//Wait to test List <string> images = new List <string>(files); ImagesJsonModel = new GetImgJsonModel() { Images = images }; getImagesStatus = "local"; } else { try { ImagesJsonModel = JsonConvert.DeserializeAnonymousType(await _getBotImagesJsonServices.GetAllImg(id), new GetImgJsonModel()); if (ImagesJsonModel.Images.Count == 0) { getImagesStatus = "nothing"; } else { getImagesStatus = "network"; } } catch { ImagesJsonModel = JsonConvert.DeserializeAnonymousType("{'Images':[]}", new GetImgJsonModel()); getImagesStatus = "nothing"; }; } DateTime DateNowUTC = DateTime.UtcNow.AddMinutes(-5); var status = _localizer["Offline"]; if (bot.LastLoggedInUTC >= DateNowUTC) { status = _localizer["Online"]; } var botInquiryDeatils = new BotDeatilsInquiryModel { Name = bot.UserName, Domain = bot.Domain, LastIPAddress = bot.LastIPAddress, LastLoggedInUTC = bot.LastLoggedInUTC, Status = status, KeyCertified = bot.KeyCertified, KeyUnique = appsettings.Stump.KeyCertified }; var botmodel = new BotModel { newImagesJsonModel = ImagesJsonModel, newBotDeatilsInquiryModel = botInquiryDeatils, getImagesStatus = getImagesStatus }; ViewData["ID"] = id; return(View(botmodel)); } catch (Exception e) { return(Content(e.ToString())); }; }