public static EmpDocument Create(MondaiDocument mondaiDocument) { var result = new FishDocument(); var documentElement = new FishElement("document"); documentElement.Items.Add(new FishElement("id", mondaiDocument.Id)); documentElement.Items.Add(new FishElement("title", mondaiDocument.Name)); result.Items.Add(documentElement); documentElement.Items.AddRange ( mondaiDocument.Items.Select(daimon => { var daimonElement = new FishElement("daimon"); daimonElement.Items.Add(new FishElement("id", daimon.Id)); daimonElement.Items.Add(new FishElement("title", daimon.Name)); daimonElement.Items.AddRange ( daimon.Items.Select(chumon => { var chumonElement = new FishElement("chumon"); chumonElement.Items.Add(new FishElement("id", chumon.Id)); chumonElement.Items.Add(new FishElement("title", chumon.Name)); if (chumon.IsShuffled) { chumonElement.Items.Add(new FishElement("shuffle", "true")); } if (chumon.IsOptional) { chumonElement.Items.Add(new FishElement("optional", "true")); } chumonElement.Items.AddRange(chumon.HelpIds.Select(helpId => new FishElement("helpId", helpId))); chumonElement.Items.AddRange ( chumon.Items.Select(mondai => { var shomon = mondai as Shomon; if (null != shomon) { return Create(shomon); } var ankimon = mondai as Ankimon; if (null != ankimon) { return Create(ankimon); } throw new ApplicationException(); }) ); return chumonElement; }) ); return daimonElement; }) ); var emp = new EmpDocument(); emp._fishDocument = result; return emp; }
public MondaiDocument GetMondaiDocument() { var mondaiDocument = new MondaiDocument(); var documentElement = GetElement("document"); mondaiDocument.Id = documentElement.GetElement("id").Value; mondaiDocument.Name = documentElement.GetElement("title").Value; var daimonItems = documentElement.GetElements("daimon").Select(daimonElement => { var daimon = new Daimon() { Id = daimonElement.GetElement("id").Value, Name = daimonElement.GetElement("title").Value, }; var chumonItems = daimonElement.Items.Where(xx => "chumon" == xx.Name).Select(chumonElement => { var chumon = new Chumon() { Id = chumonElement.GetElement("id").Value, Name = chumonElement.GetElement("title").Value, IsOptional = "true" == chumonElement.GetValue("optional"), IsShuffled = "true" == chumonElement.GetValue("shuffle"), }; // 入力ミスの検査 var optional = chumonElement.GetValue("optional"); var shuffle = chumonElement.GetValue("shuffle"); var flag = (null == optional || "true" == optional || "false" == optional) && (null == shuffle || "true" == shuffle || "false" == shuffle); if (!flag) throw new EmpException("optional, shuffleにはtrue, falseのみ指定できます"); chumon.HelpIds = chumonElement.GetValues("helpId").Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); var shomonItems = chumonElement.Items.Where(x => "shomon" == x.Name || "ankimon" == x.Name).Select ( shomonElement => { switch (shomonElement.Name) { case "shomon" : { return (EigoTestMondai)CreateShomon(shomonElement); } case "ankimon" : { return (EigoTestMondai)CreateAnkimon(shomonElement); } default : { throw new InvalidOperationException(); } } } ); chumon.Items = shomonItems.ToList(); // chumon.GetTimeLimit() = chumon.制限時間の計算(); return chumon; }).Cast<EigoTestMondai>(); daimon.Items = chumonItems.ToList(); return daimon; }).Cast<EigoTestMondai>(); mondaiDocument.Items = daimonItems.ToList(); return mondaiDocument; }
public void MoveTo(MondaiDocument mondaiDocument) { Window.EPuzzleData.CurrentMondaiDocument = mondaiDocument; Window.State = WindowState.FoFi(this, new DaimonState(Window, Window.EPuzzleData.GetDaimon(Window.EPuzzleData.CurrentMondaiDocument.Id))); }