public Project Load(string filename)
        {
            Project project = new Project();

            using (var zipStream = new ZipInputStream(new FileStream(filename, FileMode.Open)))
            {
                ZipEntry entry;
                while ((entry = zipStream.GetNextEntry()) != null)
                {
                    if (entry.IsFile)
                    {
                        if (Path.GetFileName(entry.Name).Equals("book.xml"))
                        {
                            // TODO: validate file
                            project.Book = bookLoader.Load(zipStream);
                        }
                        else if (Util.Helpers.TextFileExtensions.Contains(Path.GetExtension(entry.Name)))
                        {
                            // text file
                            project.Files.Add(readTextSupportFile(zipStream, entry));
                        }
                        else
                        {
                            // binary file
                            project.Files.Add(readBinarySupportFile(zipStream, entry));
                        }
                    }
                }
            }

            return project;
        }
Exemplo n.º 2
0
 public virtual void Export(Project project, string outputFilename)
 {
     using (FileStream outfile = new FileStream(outputFilename, FileMode.Create))
     {
         Export(project, outfile);
     }
 }
Exemplo n.º 3
0
        public override void Export(Project project, Stream output)
        {
            using (XmlWriter writer = XmlWriter.Create(output))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("html");

                writer.WriteStartElement("head");
                writer.WriteElementString("title", project.Book.Title);
                foreach (string file in cssFiles)
                {
                    writer.WriteStartElement("link");
                    writer.WriteAttributeString("rel", "stylesheet");
                    writer.WriteAttributeString("type", "text/css");
                    writer.WriteAttributeString("href", file);
                    writer.WriteEndElement();  // link
                }
                writer.WriteEndElement();  // head

                writer.WriteStartElement("body");
                writer.WriteElementString("h1", project.Book.Title);

                foreach (Chapter c in project.Book.Chapters)
                {
                    writer.WriteElementString("h2", c.Title);

                    writer.WriteStartElement("div");
                    writer.WriteAttributeString("class", "intro");
                    writer.WriteString(c.Introduction);
                    writer.WriteEndElement();  // div

                    foreach (Post p in c.Posts)
                    {
                        writer.WriteElementString("h3", p.Title);

                        if (!string.IsNullOrWhiteSpace(p.Author))
                        {
                            writer.WriteStartElement("p");
                            writer.WriteAttributeString("class", "author");
                            writer.WriteString(string.Format("by {0}", p.Author));
                            writer.WriteEndElement();
                        }
                        writer.WriteStartElement("div");
                        writer.WriteAttributeString("class", "article");
                        writer.WriteRaw(p.Content);
                        writer.WriteEndElement();  // div
                    }
                }

                writer.WriteEndElement();  // body
                writer.WriteEndElement();  // html
            }
        }
 public void Save(Project project, string filename)
 {
     using (var zipStream = new ZipOutputStream(new FileStream(filename, FileMode.Create)))
     {
         zipStream.PutNextEntry(new ZipEntry("book.xml"));
         bookLoader.Save(project.Book, zipStream);
         zipStream.CloseEntry();
         foreach (var file in project.Files)
         {
             zipStream.PutNextEntry(new ZipEntry(file.Filename));
             fileController.WriteSupportFile(file, zipStream);
             zipStream.CloseEntry();
         }
     }
 }
Exemplo n.º 5
0
        public override void Export(Project project, Stream output)
        {
            using (var zipStream = new ZipOutputStream(output))
            {
                HtmlExportController htmlExport = new HtmlExportController(project.Files.Where(f => Path.GetExtension(f.Filename).Equals("css")).Select(f => f.Filename).ToArray());
                zipStream.PutNextEntry(new ZipEntry(htmlFilename));
                htmlExport.Export(project, zipStream);
                zipStream.CloseEntry();

                foreach (var file in project.Files)
                {
                    zipStream.PutNextEntry(new ZipEntry(file.Filename));
                    fileController.WriteSupportFile(file, zipStream);
                    zipStream.CloseEntry();
                }
            }
        }
Exemplo n.º 6
0
        public Project Import(string inputFilename)
        {
            Book book;
            using (Stream output = new MemoryStream())
            {
                // read WP XML file
                using (Stream wpFile = new FileStream(inputFilename, FileMode.Open))
                using (Stream xslt = Assembly.GetExecutingAssembly().GetManifestResourceStream("Medius.Controllers.wp2book.xsl"))
                {
                    // transform stream to stream
                    XmlTransformer.Transform(xslt, wpFile, output);
                }

                // rewind and validate
                output.Seek(0, SeekOrigin.Begin);
                using (Stream xsd = Assembly.GetExecutingAssembly().GetManifestResourceStream("Medius.Model.book.xsd"))
                {
                    XmlValidator validator = new XmlValidator();
                    if (!validator.Validate(xsd, output))
                    {
                        throw new InvalidDataException(
                        "Could not load book XML.\r\nCause(s):\r\n" +
                            string.Join("\r\n", validator.Errors.Select(
                                e => string.Format(
                                    "Line {0} Col {1}: {2}", e.Line, e.Column, e.Message
                                    )
                                )
                            )
                        );
                    }
                }

                // rewind again and deserialize
                output.Seek(0, SeekOrigin.Begin);
                book = books.Load(output);
            }

            Project project = new Project();
            project.Book = book;
            return project;
        }
Exemplo n.º 7
0
 public FileManagementDialog(Project project)
     : this()
 {
     this.project = project;
     this.actions = new UndoRedoController();
 }
Exemplo n.º 8
0
 public RemoveFilesAction(Project project, IList<ISupportFile> files)
     : base()
 {
     this.project = project;
     this.files = new List<ISupportFile>(files);
 }
Exemplo n.º 9
0
        private void wordPressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();
            d.AddExtension = true;
            d.DefaultExt = ".xml";
            d.Filter = "WordPress eXtended RSS (*.xml)|*.xml";
            d.Multiselect = false;
            d.Title = "Open WordPress export file";
            if (d.ShowDialog() != DialogResult.OK)
                return;

            if (modified && !confirmContinueOverwrite())
                return;

            disableUI();

            IImportController importer = new WordpressImportController(new XmlPersistenceController());
            actions.Clear();
            project = importer.Import(d.FileName);

            // fix any lingering order problems
            normalize(project.Book);

            // bookkeeping
            activeFilename = null;  // force "save as"
            modified = false;

            updateUI();
            enableUI();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Loads a model state from a file.
        /// </summary>
        /// <returns><c>true</c> if project was loaded successfully.</returns>
        private bool load()
        {
            // select file
            OpenFileDialog d = new OpenFileDialog();
            d.AddExtension = true;
            d.CheckFileExists = true;
            d.CheckPathExists = true;
            d.DefaultExt = ".medius";
            d.Filter = "Medius projects (*.medius)|*.medius";
            d.Multiselect = false;
            d.SupportMultiDottedExtensions = true;
            d.Title = "Open an existing project";
            d.ValidateNames = true;

            if (d.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return false;

            // load into memory
            project = projectLoader.Load(d.FileName);

            // fix up ordering constraints, etc
            normalize(project.Book);

            // bookkeeping
            activeFilename = d.FileName;
            modified = false;
            fileManager = new FileManagementDialog(project);

            return true;
        }
Exemplo n.º 11
0
 public AddFileAction(Project project, string filename, Stream stream = null)
 {
     this.project = project;
     this.stream = stream;
     this.filename = filename;
 }
Exemplo n.º 12
0
 public abstract void Export(Project project, Stream output);