public ImagicianPageViewModel() { _logService = DependencyService.Get <ILogService>(); _fileService = DependencyService.Get <IFileService>(); _imageService = DependencyService.Get <IImageService>(); _folderService = DependencyService.Get <IFolderService>(); _settingsService = DependencyService.Get <ISettingsService>(); _service = DependencyService.Get <IDatabaseService>(); PropertyChanged += (sender, e) => { if (e.PropertyName == "IsBusy") { GetImagesCommand.ChangeCanExecute(); } }; }
public async Task <IActionResult> DownloadAllImg(int id) { var query = new GetBotByIdQuery { Id = id }; var bot = await _mediator.Send(query); var log = new LogModel(); GetImgJsonModel ImagesJsonModel; try { var fullpath = ""; if (!_env.WebRootFileProvider.GetDirectoryContents("img/Bots/" + bot.UserName + "_" + id).Exists) { var path = _env.WebRootFileProvider.GetFileInfo("img/Bots")?.PhysicalPath; Directory.CreateDirectory(path + "/" + bot.UserName + "_" + id); } else { fullpath = _env.WebRootFileProvider.GetFileInfo("img/Bots")?.PhysicalPath + "/" + bot.UserName + "_" + id; } ImagesJsonModel = JsonConvert.DeserializeAnonymousType(await _getBotImagesJsonServices.GetAllImg(id), new GetImgJsonModel()); for (var i = 0; i < ImagesJsonModel.Images.Count; i++) { StringBuilder FileName = new StringBuilder(); for (var j = ImagesJsonModel.Images[i].LastIndexOf(@"\") + 1; j < ImagesJsonModel.Images[i].Length; j++) { FileName.Append(ImagesJsonModel.Images[i][j]); } GetImagesVariables variables = new GetImagesVariables { imagePath = ImagesJsonModel.Images[i] }; BaseCommands command = new BaseCommands { Method = "GetImg" }; GetImagesCommand model = new GetImagesCommand { newBaseCommand = command, newVariables = variables }; _client.DownLoadFileByWebRequest(bot.Domain, fullpath + "/" + FileName.ToString(), JsonConvert.SerializeObject(model)); } log = new LogModel() { KeyUnique = bot.KeyUnique, Message = "Download Sucess", Type = "Sucess" }; } catch { log = new LogModel() { KeyUnique = bot.KeyUnique, Message = "Download Failed", Type = "Error" }; }; return(Json(log)); }