public async Task Delete(WordlistEntity entity, bool deleteFile = true) { if (deleteFile && File.Exists(entity.FileName)) { File.Delete(entity.FileName); } context.Remove(entity); await context.SaveChangesAsync(); }
public async void AddWordlist(WordlistEntity wordlist) { try { await vm.Add(wordlist); } catch (Exception ex) { Alert.Exception(ex); } }
/// <summary> /// Adds a wordlist and writes its content to disk. /// </summary> public async Task Add(WordlistEntity entity, MemoryStream stream) { // Generate a unique filename entity.FileName = Path.Combine(baseFolder, $"{Guid.NewGuid()}.txt").Replace('\\', '/'); // Create the file on disk await File.WriteAllBytesAsync(entity.FileName, stream.ToArray()); // Count the amount of lines entity.Total = File.ReadLines(entity.FileName).Count(); await Add(entity); }
public Wordlist FromEntity(WordlistEntity entity) { var wordlistType = ruriLibSettings.Environment.WordlistTypes .First(w => w.Name == entity.Type); var wordlist = new Wordlist(entity.Name, entity.FileName, wordlistType, entity.Purpose, false) { Id = entity.Id, Total = entity.Total }; return(wordlist); }
public WordlistDataPoolOptionsViewModel(WordlistDataPoolOptions options) : base(options) { wordlistRepo = SP.GetService <IWordlistRepository>(); if (options.WordlistId != -1) { wordlist = wordlistRepo.Get(options.WordlistId).Result; } // If the wordlist was not found (e.g. deleted) if (wordlist is null) { options.WordlistId = -1; } }
/// <inheritdoc/> public async Task Add(WordlistEntity entity, MemoryStream stream) { // Generate a unique filename var path = Path.Combine(baseFolder, $"{Guid.NewGuid()}.txt"); entity.FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? path.Replace('/', '\\') : path.Replace('\\', '/'); // Create the file on disk await File.WriteAllBytesAsync(entity.FileName, stream.ToArray()); // Count the amount of lines entity.Total = File.ReadLines(entity.FileName).Count(); await Add(entity); }
/// <summary> /// Creates a <see cref="Wordlist"/> from a <see cref="WordlistEntity"/>. /// </summary> public Wordlist FromEntity(WordlistEntity entity) { var wordlistType = ruriLibSettings.Environment.WordlistTypes .FirstOrDefault(w => w.Name == entity.Type); if (wordlistType == null) { throw new InvalidWordlistTypeException(entity.Type); } var wordlist = new Wordlist(entity.Name, entity.FileName, wordlistType, entity.Purpose, false) { Id = entity.Id, Total = entity.Total }; return(wordlist); }
public async Task Update(WordlistEntity entity) { context.Update(entity); await context.SaveChangesAsync(); }
/// <summary> /// Adds a wordlist that already exists on disk. /// </summary> public async Task Add(WordlistEntity entity) { // Save it to the DB context.Add(entity); await context.SaveChangesAsync(); }
/// <inheritdoc/> public async Task Update(WordlistEntity entity) { context.Entry(entity).State = EntityState.Modified; context.Update(entity); await context.SaveChangesAsync(); }
public async void AddWordlist(WordlistEntity entity) => await vm.AddWordlist(entity);
public async void SelectWordlist(WordlistEntity entity) { (vm.DataPoolOptions as WordlistDataPoolOptionsViewModel).SelectWordlist(entity); await vm.TrySetRecord(); }
public void SelectWordlist(WordlistEntity wordlist) { this.wordlist = wordlist; WordlistOptions.WordlistId = wordlist.Id; OnPropertyChanged(nameof(Info)); }