public LibraryReport(Library library, StaticImage drawing, string directory) : base(library.Details.Name) { this.library = library; staticImage = drawing; this.directory = directory; }
protected override Library ImportImplementation(string FileName) { Library lib = new Library(Guid.NewGuid()); lib.Details.Name = Path.GetFileNameWithoutExtension(FileName); lib.Details.Description = "Imported sokoban library."; lib.Details.Date = new FileInfo(FileName).CreationTime; lib.Details.DateSpecified = true; lib.Details.License = "Unknown"; if (Details != null) { lib.Details = Details; } if (string.IsNullOrEmpty(lib.Details.Name)) { lib.Details.Name = Path.GetFileNameWithoutExtension(FileName); } List<string> block = new List<string>(); using (StreamReader reader = File.OpenText(FileName)) { while (!reader.EndOfStream) { string current = reader.ReadLine(); if (IsBlockBreak(current, block)) { ProcessBlock(lib, block); block.Clear(); block.Add(current); } else { block.Add(current); } } // Process last item ProcessBlock(lib, block); } return lib; }
private void ProcessBlock(Library lib, List<string> block) { if (block.Count < 3) return;// Skip int order = 0; try { order = int.Parse(block[0].Remove(0, 2).Trim()); } catch(Exception) { // Nothing } string name = block[1].Trim(); if (name.Length == 0) name = namer.MakeName(); Puzzle puz = new Puzzle(lib); puz.Details.Name = name; puz.Details.Description = ""; puz.Category = lib.CategoryTree.Root.Data; puz.Order = lib.Puzzles.Count + 1; puz.PuzzleID = lib.IdProvider.GetNextIDString("P{0}"); block.RemoveAt(0); block.RemoveAt(0); puz.MasterMap = new PuzzleMap(puz); puz.MasterMap.MapID = puz.Library.IdProvider.GetNextIDString("M{0}"); puz.MasterMap.Map = new SokobanMap(); puz.MasterMap.Map.SetFromStrings(block.ToArray(), "v# $.*@+"); puz.Rating = PuzzleAnalysis.CalcRating(puz.MasterMap.Map).ToString("0.0"); // Cleanup puz.MasterMap.Map.ApplyVoidCells(); lib.Puzzles.Add(puz); }
protected override Library ImportImplementation(string FileName) { SokoSolve.Core.Model.Library lib = new SokoSolve.Core.Model.Library(Guid.NewGuid()); XmlDocument import = new XmlDocument(); import.Load(FileName); lib.Details = new GenericDescription(); if (import.DocumentElement.LocalName != "SokobanLevels") throw new Exception("Expected node 'SokobanLevels'"); if (import.DocumentElement["Title"] != null) { lib.Details.Name = import.DocumentElement["Title"].InnerText; } if (import.DocumentElement["Description"] != null) { lib.Details.Description = import.DocumentElement["Description"].InnerText; } if (import.DocumentElement["Email"] != null) { if (lib.Details.Author == null) lib.Details.Author = new GenericDescriptionAuthor(); lib.Details.Author.Email = import.DocumentElement["Email"].InnerText; } if (import.DocumentElement["Url"] != null) { if (lib.Details.Author == null) lib.Details.Author = new GenericDescriptionAuthor(); lib.Details.Author.Homepage = import.DocumentElement["Url"].InnerText; } lib.Categories.Root.Data.Details = new GenericDescription(lib.Details); if (import.DocumentElement["LevelCollection"] != null) { lib.Details.License = import.DocumentElement["LevelCollection"].GetAttribute("Copyright"); XmlElement xmlLevelCollection = (XmlElement)import.DocumentElement["LevelCollection"]; int levelcount = 1; foreach (XmlElement xmlLevel in xmlLevelCollection.ChildNodes) { if (xmlLevel.LocalName == "Level") { Puzzle newPuzzle = new Puzzle(lib); newPuzzle.PuzzleID = lib.IdProvider.GetNextIDString("P{0}"); newPuzzle.Details = new GenericDescription(); newPuzzle.Details.Name = string.Format("Puzzle No. {0}", lib.Puzzles.Count); newPuzzle.Details.Description = string.Format("Imported SLV puzzle"); newPuzzle.Category = lib.Categories.Root.Data; newPuzzle.Order = levelcount++; PuzzleMap newMap = new PuzzleMap(newPuzzle); newMap.MapID = lib.IdProvider.GetNextIDString("M{0}"); newPuzzle.Maps.Add(newMap); List<string> rows = new List<string>(); foreach (XmlElement xmlRow in xmlLevel.ChildNodes) { rows.Add(xmlRow.InnerText); } newMap.Map = new SokobanMap(); newMap.Map.setFromStrings(rows.ToArray(), "?# $.*@+"); newMap.Map.ApplyVoidCells(); lib.Puzzles.Add(newPuzzle); } } } return lib; }
public static HtmlBuilder Report(Category category, Library helpLib) { HtmlBuilder report = Report(category.Details); List<Puzzle> puz = category.GetPuzzles(); report.AddLabel("Puzzles", puz.Count.ToString()); int puzPerLine = 4; int counter = 1; report.AddLine("<table class=\"tableformat\"><tr><td>"); foreach (Puzzle puzzle in puz) { report.Add(puzzle.Details.Name); report.Add("<br/>"); report.Add("<a href=\"app://puzzle/{0}\">", puzzle.PuzzleID); report.Add(puzzle.MasterMap, DrawingHelper.DrawPuzzle(puzzle.MasterMap), "width:100px; height:80px"); report.Add("</a>"); if (counter % puzPerLine == 0) { // Row break report.AddLine("</td></tr><tr><td>"); } else { // Next cell report.AddLine("</td><td>"); } counter++; } report.AddLine("</td></tr></table>"); return report; }
public static HtmlBuilder Report(Library library) { HtmlBuilder report = Report(library.Details); report.AddLabel("Rating", library.Rating); report.AddLabel("Puzzles", library.Puzzles.Count.ToString()); foreach (Category category in library.Categories) { report.Add(Report(category, library)); } return report; }
private void buttonOK_Click(object sender, EventArgs e) { richTextBoxImportResults.Text = ""; string fileLocation = null; if (!string.IsNullOrEmpty(tbFileName.Text)) { // Use local file fileLocation = tbFileName.Text; // Store the new directory in profile ProfileController.Current.LibraryCurrentImportDir = Path.GetDirectoryName(openF.FileName); } else if (!string.IsNullOrEmpty(tbClipboard.Text)) { // Use clipboard fileLocation = Path.GetTempFileName(); File.WriteAllText(fileLocation, tbClipboard.Text); } else { if (htmlView1.WebBrowser.DocumentType == "TXT File" || htmlView1.WebBrowser.DocumentType == "text\\xml") { // Use internet fileLocation = Path.GetTempFileName(); htmlView1.SaveToFile(fileLocation); } else { richTextBoxImportResults.Text = string.Format("Internet import from '{0}' is not supported.", htmlView1.WebBrowser.DocumentType); tabControlImport.SelectTab(tabPageFeedback); return; } } Importer.Details = ucGenericDescription1.Data; Library newLib = Importer.Import(fileLocation); if (newLib != null && Importer.LastError == null) { if (rbNewLibrary.Checked) { library = newLib; } else if (rbAddCurrent.Checked) { // Add to current foreach (Puzzle puzzle in newLib.Puzzles) { puzzle.Category = library.Categories[library.Categories.Count -1]; puzzle.Library = library; puzzle.Order = library.Puzzles.Count + 1; puzzle.PuzzleID = library.IdProvider.GetNextIDString("P{0}"); library.Puzzles.Add(puzzle); } } FindForm().DialogResult = DialogResult.OK; FindForm().Close(); } else { richTextBoxImportResults.Text = string.Format("{0}\n\n\nTechnical Error Message (For advanced users or bug reports):\n{1}", Importer.LastError.Message, StringHelper.Report(Importer.LastError)); tabControlImport.SelectTab(tabPageFeedback); } }
/// <summary> /// Default Constructor /// </summary> /// <param name="myLibrary"></param> public Puzzle(Library myLibrary) { maps = new List<PuzzleMap>(); details = new GenericDescription(); library = myLibrary; }