public async Task <List <LawDto> > GetLaw(LawType lawType) { return(await _context.Laws .Where(s => s.Type == lawType) .Select(s => new LawDto { Id = s.Id, Content = s.Content, Punishment = s.Punishment, Type = s.Type }).ToListAsync()); }
public static LawStrategy GetStrategy(LawType type) { switch (type) { case LawType.Alo: return(new AloLaw()); case LawType.Conway: return(new ConwayLaw()); case LawType.Prof: return(new ProfLaw()); case LawType.Intervenant: return(new IntervenantLaw()); default: return(new ConwayLaw()); } }
private async Task UploadFiles(Region region, LawType lawType, string ftpDirectory, string folderName) { var token = new CancellationToken(); var lawOptions = lawType == LawType.FZ_44 ? _options.FZ_44 : _options.FZ_223; using var ftp = new FtpClient(_options.Server, lawOptions.User, lawOptions.Password); try { await ftp.ConnectAsync(token); } catch (Exception) { ClearTempDirectories(); } var items = await ftp.GetListingAsync(ftpDirectory, token); items = items .Where(i => i.Modified >= DateTime.Now.Date) .ToArray(); var tempPath = Path.GetTempPath() + folderName; if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } foreach (var item in items) { switch (item.Type) { case FtpFileSystemObjectType.Link: break; case FtpFileSystemObjectType.Directory: break; case FtpFileSystemObjectType.File: try { var itemName = Guid.NewGuid().ToString() + item.Name; var status = await ftp.DownloadFileAsync(tempPath + itemName, item.FullName, FtpLocalExists.Append); if (status.IsSuccess()) { string zipPath = tempPath + itemName; string extractPath = tempPath + region.Name; using ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Read); if (archive.Entries.Count > 0) { archive.ExtractToDirectory(extractPath, true); } } } catch (Exception e) { throw e; } break; } } await ftp.DisconnectAsync(); }