private async void Select_Executed(object arg) { try { var authors = _document.Document.Package.Info.Authors; var newDocument = SIDocument.Create(_document.Document.Package.Name, authors.Count > 0 ? authors[0] : Resources.Empty); var mainRound = newDocument.Package.CreateRound(RoundTypes.Standart, Resources.ThemesCollection); var allthemes = new List <Theme>(); _document.Document.Package.Rounds.ForEach(round => round.Themes.ForEach(allthemes.Add)); for (var index = _from; index <= _to; index++) { var newTheme = allthemes[index - 1].Clone(); mainRound.Themes.Add(newTheme); // Выгрузим с собой необходимые коллекции await _document.Document.CopyCollections(newDocument, allthemes[index - 1]); } OnNewItem(new QDocument(newDocument, _document.StorageContext) { FileName = newDocument.Package.Name }); } catch (Exception exc) { _document.OnError(exc); } }
private async void Select2_Executed(object arg) { try { var authors = _document.Document.Package.Info.Authors; var newDocument = SIDocument.Create(_document.Document.Package.Name, authors.Count > 0 ? authors[0] : Resources.Empty); var mainRound = newDocument.Package.CreateRound(RoundTypes.Standart, Resources.ThemesCollection); var allthemes = Themes.Where(st => st.IsSelected).Select(st => st.Theme); foreach (var theme in allthemes) { var newTheme = theme.Clone(); mainRound.Themes.Add(newTheme); // Выгрузим с собой необходимые коллекции await _document.Document.CopyCollections(newDocument, theme); } OnNewItem(new QDocument(newDocument, _document.StorageContext) { FileName = newDocument.Package.Name }); } catch (Exception exc) { _document.OnError(exc); } }
private static SIDocument CreateDocument() { var document = SIDocument.Create("test", "author", new PackageMock()); var round = new Round(); document.Package.Rounds.Add(round); var theme = new Theme(); round.Themes.Add(theme); var question = new Question(); theme.Questions.Add(question); question.Scenario.Add(new Atom { Type = AtomTypes.Text, Text = "question" }); question.Scenario.Add(new Atom { Type = AtomTypes.Marker }); question.Scenario.Add(new Atom { Type = AtomTypes.Audio, Text = "audio.mp3", AtomTime = 10 }); var question2 = new Question(); theme.Questions.Add(question2); question2.Scenario.Add(new Atom { Type = AtomTypes.Text, Text = "question" }); question2.Right.Add("right"); var question3 = new Question(); theme.Questions.Add(question3); question3.Scenario.Add(new Atom { Type = AtomTypes.Text, Text = "question" }); question3.Scenario.Add(new Atom { Type = AtomTypes.Marker }); question3.Scenario.Add(new Atom { Type = AtomTypes.Audio, Text = "audio.mp3", AtomTime = 10 }); question3.Scenario.Add(new Atom { Type = AtomTypes.Text, Text = "answer" }); return(document); }
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)); }
internal async Task <SIDocument> SelectAsync(DBNode item) { var doc = await Utils.GetXml(item.Key); var manager = new XmlNamespaceManager(doc.NameTable); var siDoc = SIDocument.Create(doc.SelectNodes(@"/tournament/Title", manager)[0].InnerText.GrowFirstLetter().ClearPoints(), Resources.EmptyValue); siDoc.Package.Info.Comments.Text += string.Format(Resources.DBStorageComment, doc["tournament"]["FileName"].InnerText); string s = doc["tournament"]["Info"].InnerText; if (s.Length > 0) { siDoc.Package.Info.Comments.Text += string.Format("\r\nИнфо: {0}", s); } s = doc["tournament"]["URL"].InnerText; if (s.Length > 0) { siDoc.Package.Info.Comments.Text += string.Format("\r\nURL: {0}", s); } s = doc["tournament"]["PlayedAt"].InnerText; if (s.Length > 0) { siDoc.Package.Info.Comments.Text += string.Format("\r\nИграно: {0}", s); } s = doc["tournament"]["Editors"].InnerText; if (s.Length > 0) { siDoc.Package.Info.Authors[0] = $"{Resources.Editors}: {s}"; } var round = siDoc.Package.CreateRound(RoundTypes.Standart, Resources.EmptyValue); var nodeList2 = doc.SelectNodes(@"/tournament/question", manager); foreach (XmlNode node2 in nodeList2) { var text = node2["Question"].InnerText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); var ans = node2["Answer"].InnerText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); var sour = node2["Sources"].InnerText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); int i = 0, j = 0; var themeName = new StringBuilder(); while (i < text.Length && !(text[i].Length > 3 && text[i].Substring(0, 3) == " ")) { if (themeName.Length > 0) { themeName.Append(' '); } themeName.Append(text[i++]); } var theme = round.CreateTheme(themeName.ToString().GrowFirstLetter().ClearPoints()); var authorsText = node2["Authors"].InnerText; if (!string.IsNullOrWhiteSpace(authorsText)) { theme.Info.Authors.Add(authorsText); } var themeComments = new StringBuilder(node2["Comments"].InnerText); while (i < text.Length && text[i].Length > 4 && text[i].Substring(0, 3) == " " && !char.IsDigit(text[i][3])) { if (themeComments.Length > 0) { themeComments.Append(' '); } themeComments.Append(text[i++]); } theme.Info.Comments.Text = themeComments.ToString(); bool final = true; Question quest = null; var qText = new StringBuilder(); i--; #region questionsReading while (++i < text.Length) { text[i] = text[i].Trim(); string js = (j + 1).ToString(); if (text[i].Substring(0, js.Length) == js && (text[i].Length > 3 && text[i].Substring(js.Length, 2) == ". " || text[i].Length > 4 && text[i].Substring(js.Length, 3) == "0. ")) { j++; final = false; if (qText.Length > 0) { quest = theme.CreateQuestion(10 * (j - 1)); quest.Type.Name = QuestionTypes.Simple; quest.Scenario.Clear(); quest.Scenario.Add(qText.ToString().GrowFirstLetter().ClearPoints()); } int add = 3; if (text[i].Substring(js.Length, 2) == ". ") { add = 2; } qText = new StringBuilder(text[i].Substring(js.Length + add)); } else { if (qText.Length > 0) { qText.Append(' '); } qText.Append(text[i]); } } if (final) { quest = theme.CreateQuestion(0); quest.Right[0] = node2["Answer"].InnerText.Trim().GrowFirstLetter().ClearPoints(); } else { quest = theme.CreateQuestion(10 * j); } quest.Scenario.Clear(); quest.Scenario.Add(qText.ToString().GrowFirstLetter().ClearPoints()); quest.Type.Name = QuestionTypes.Simple; #endregion #region answersReading int number = 0, number2 = -1, multiplier = 1; if (!final) { i = -1; qText = new StringBuilder(); while (++i < ans.Length) { ans[i] = ans[i].Trim(); number = 0; int k = 0; while (char.IsDigit(ans[i][k])) { number = number * 10 + int.Parse(ans[i][k++].ToString()); } if (!((ans[i].Length > k + 2 && ans[i].Substring(k, 2) == ". " || ans[i].Length > 3 + k && ans[i].Substring(k, 3) == "0. "))) { number = -1; } if (number >= 0) { if (qText.Length > 0 && theme.Questions.Count > number2) { theme.Questions[number2].Right[0] = qText.ToString().GrowFirstLetter().ClearPoints(); } if (number2 == -1) { multiplier = number; } number2 = number / multiplier - 1; int add = 3; if (ans[i].Substring(k, 2) == ". ") { add = 2; } qText = new StringBuilder(ans[i].Substring(k + add)); } else { if (qText.Length > 0) { qText.Append(' '); } qText.Append(ans[i]); } } if (theme.Questions.Count > number2) { theme.Questions[number2].Right[0] = qText.ToString().GrowFirstLetter().ClearPoints(); } } #endregion #region sourcesReading i = -1; qText = new StringBuilder(); number = 0; number2 = 0; while (++i < sour.Length) { sour[i] = sour[i].Trim(); number = 0; int k = 0; while (char.IsDigit(sour[i][k])) { number = number * 10 + int.Parse(sour[i][k++].ToString()); } number--; if (!((sour[i].Length > k + 2 && sour[i].Substring(k, 2) == ". " || sour[i].Length > 3 + k && sour[i].Substring(k, 3) == "0. "))) { number = -1; } if (number >= 0) { if (qText.Length > 0 && theme.Questions.Count > number2) { theme.Questions[number2].Info.Sources.Add(qText.ToString().GrowFirstLetter().ClearPoints()); } number2 = number; int add = 3; if (sour[i].Substring(k, 2) == ". ") { add = 2; } qText = new StringBuilder(sour[i].Substring(k + add)); } else { if (qText.Length > 0) { qText.Append(' '); } qText.Append(sour[i]); } } if (theme.Questions.Count > number2 && qText.Length > 0) { theme.Questions[number2].Info.Sources.Add(qText.ToString().GrowFirstLetter().ClearPoints()); } if (number2 == -1) { theme.Info.Sources.Add(node2["Sources"].InnerText); } #endregion } return(siDoc); }
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)); }
private void Create_Executed(object arg) { try { var doc = SIDocument.Create(_packageName, _packageAuthor); switch (_packageType) { case PackageType.Classic: { for (int i = 0; i < 3; i++) { var round = doc.Package.CreateRound(RoundTypes.Standart, null); for (int j = 0; j < 6; j++) { var theme = round.CreateTheme(null); for (int k = 0; k < 5; k++) { theme.CreateQuestion(100 * (i + 1) * (k + 1)); } } } var final = doc.Package.CreateRound(RoundTypes.Final, Resources.FinalName); for (int j = 0; j < 7; j++) { final.CreateTheme(null).CreateQuestion(0); } } break; case PackageType.Special: { var param = PackageParams; for (int i = 0; i < param.NumOfRounds; i++) { var round = doc.Package.CreateRound(RoundTypes.Standart, null); for (int j = 0; j < param.NumOfThemes; j++) { var theme = round.CreateTheme(null); for (int k = 0; k < param.NumOfQuestions; k++) { theme.CreateQuestion(param.NumOfPoints * (i + 1) * (k + 1)); } } } if (param.HasFinal) { var final = doc.Package.CreateRound(RoundTypes.Final, Resources.FinalName); for (int j = 0; j < param.NumOfFinalThemes; j++) { final.CreateTheme(null).CreateQuestion(0); } } } break; case PackageType.ThemesCollection: doc.Package.CreateRound(RoundTypes.Standart, Resources.ThemesCollection); break; case PackageType.Empty: default: break; } OnNewItem(new QDocument(doc, _storageContextViewModel) { FileName = doc.Package.Name }); OnClosed(); } catch (Exception exc) { OnError(exc); } }