private static async Task <bool> ExtractThemeAsync( IPackagesProvider provider, SIDocument doc, List <string> files, int roundIndex, Func <Round, bool> predicate, StringBuilder packageComments, int baseCost) { var fIndex = Rand.Next(files.Count); var doc2 = await provider.GetPackageAsync(files[fIndex]); if (doc2 == null) { throw new PackageNotFoundException(files[fIndex]); } using (doc2) { var normal = doc2.Package.Rounds.Where(predicate).ToList(); var count = normal.Count; if (count == 0) { files.RemoveAt(fIndex); return(false); } var rIndex = Rand.Next(count); var r = normal[rIndex]; var tIndex = Rand.Next(r.Themes.Count); var theme = r.Themes[tIndex]; // Исключим повторения имён тем if (doc.Package.Rounds.Any(round => round.Themes.Any(th => th.Name == theme.Name))) { return(false); } // Нужно перенести в пакет необходимых авторов, источники, медиаконтент InheritAuthors(doc2, r, theme); InheritSources(doc2, r, theme); for (int i = 0; i < theme.Questions.Count; i++) { theme.Questions[i].Price = (roundIndex + 1) * (i + 1) * baseCost; InheritAuthors(doc2, theme.Questions[i]); InheritSources(doc2, theme.Questions[i]); await InheritContentAsync(doc, doc2, theme.Questions[i]); } doc.Package.Rounds[roundIndex].Themes.Add(theme); packageComments.AppendFormat("{0}:{1}:{2};", files[fIndex], doc2.Package.Rounds.IndexOf(r), tIndex); return(true); } }
private static async Task <SIDocument> GenerateCore(IPackagesProvider provider, int roundsCount, int themesCount, int baseCost, SIDocument doc, string roundNameFormat) { var files = (await provider.GetPackages()).ToList(); var packageComments = new StringBuilder(RandomIndicator); // Информация для отчёта об игре for (var i = 0; i < roundsCount; i++) { doc.Package.Rounds.Add(new Round { Type = RoundTypes.Standart, Name = string.Format(roundNameFormat, i + 1) }); for (int j = 0; j < themesCount; j++) { if (files.Count == 0) { break; } if (!await ExtractTheme(provider, doc, files, i, round => round.Type == RoundTypes.Standart && round.Themes.Count > 0 /*, usedThemes*/, packageComments, baseCost)) { j--; continue; } } if (files.Count == 0) { break; } } doc.Package.Rounds.Add(new Round { Type = RoundTypes.Final, Name = "ФИНАЛ" }); for (var j = 0; j < 7; j++) { if (files.Count == 0) { break; } if (!await ExtractTheme(provider, doc, files, roundsCount, round => round.Type == RoundTypes.Final && round.Themes.Count > 0 /*, usedThemes*/, packageComments, 0)) { j--; continue; } } // В пакете могут быть и свои комментарии; допишем туда doc.Package.Info.Comments.Text += packageComments.ToString(); return(doc); }
public DbMigrator( IDbTransformationProvider dbTransformationProvider, IPackageInstaller installer, IPackagesProvider provider, ILog logger) { _dbTransformationProvider = dbTransformationProvider; _logger = logger; _installer = installer; _provider = provider; _maps = GetPackagesMap(); }
public static Task <SIDocument> GenerateRandomPackageAsync( IPackagesProvider provider, string folder, string name, string author, string roundNameFormat, string finalName, int roundsCount = 3, int themesCount = 6, int baseCost = 100) { var doc = SIDocument.Create(name, author, folder); return(GenerateCoreAsync(provider, roundsCount, themesCount, baseCost, doc, roundNameFormat, finalName)); }
public static async Task <SIDocument> GenerateRandomPackage(IPackagesProvider provider, string name, string author, string roundNameFormat, int roundsCount = 3, int themesCount = 6, int baseCost = 100, Stream stream = null) { var doc = SIDocument.Create(name, author, stream); return(await GenerateCore(provider, roundsCount, themesCount, baseCost, doc, roundNameFormat)); }