Running LINQPad scripts from command prompt and PUB XML OPF file creation
Is there a way to run scripts you create in LINQpad as command scripts from windows? Are there simple ways of compiling them through .NET somehow without opening VS? I've looked into this in the past and have never found a simple solution.
The ability to call .NET functions from LINQpad is awesome. Below is a script I created in LINQpad that creates an EPUB OPF file.
So THANK YOU JOE!
' Get files
Dim dFiles As New Dictionary(Of Integer, String)
dim sPath as string = "C:\Files2012_Test\2012-03-07"
Dim dirInfo As New IO.DirectoryInfo(sPath)
Dim cnt As Integer = 0
For Each file As FileInfo In dirInfo.GetFiles("*.html", SearchOption.TopDirectoryOnly)
cnt += 1
dFiles.Add(cnt, file.Name)
Next
Dim pair As KeyValuePair(Of Integer, String)
For Each pair In dFiles
Debug.Print("{0}, {1}", pair.Key, pair.Value)
Next
' end get files
Dim ns As XNamespace = "http://www.idpf.org/2007/opf"
Dim dc As XNamespace = "http://purl.org/dc/elements/1.1/"
Dim opf As XNamespace = "http://www.idpf.org/2007/opf"
Dim BookTitle As String = "Anatomy and Physiology"
Dim BookId As String = "123"
Dim TocTitle As String = "Chapters"
Dim BookAuthorName As String = "Smith"
Dim tocHtmlFilename As String = "htmlfilename"
Dim textGuide As String = "study"
Dim PathGetFileNameFilename As String = ""
'TODO : setup all metadata
Dim metadata As New XElement(ns + "metadata", _
New XAttribute(XNamespace.Xmlns + "dc", dc), _
New XAttribute(XNamespace.Xmlns + "opf", opf), _
New XElement(dc + "title", BookTitle), _
New XElement(dc + "language", "en-us"), _
New XElement("meta", _
New XAttribute("name", "cover"), _
New XAttribute("content", "My_Cover")), _
New XElement(dc + "identifier", _
New XAttribute("id", BookId), _
New XAttribute(opf + "scheme", "ISBN"), "123456789"), _
New XElement(dc + "creator", BookAuthorName), _
New XElement(dc + "publisher", "McGraw Hill"), _
New XElement(dc + "subject", "McGraw Hill"), _
New XElement(dc + "date", DateTime.Today))
Dim manifest as new XElement(ns + "manifest")
For Each pair In dFiles
manifest.Add(new XElement(ns + "item", _
New XAttribute("id",pair.Key), _
New XAttribute("href",pair.Value)))
Next
Dim spine As New XElement(ns + "spine", _
New XAttribute("toc", "My_Table_of_Contents"), _
New XElement(ns + "itemref", _
New XAttribute("idref", "item1")), _
New XElement(ns + "itemref", _
New XAttribute("idref", "item2")))
Dim guide As New XElement(ns + "guide", New XElement(ns + "reference", New XAttribute("type", "toc"), New XAttribute("title", TocTitle), New XAttribute("href", tocHtmlFilename)), New XElement(ns + "reference", New XAttribute("type", "text"), New XAttribute("title", TocTitle), New XAttribute("href", PathGetFileNameFilename + (If((textGuide Is Nothing), "", "#" + textGuide)))))
Dim package As New XElement(ns + "package", New XAttribute("version", "2.0"), New XAttribute("unique-identifier", BookId), metadata, manifest, spine, _
guide)
Dim opfDoc As New XDocument(package)
opfDoc.Save(Path.ChangeExtension(sPath + "\aTestfromvb", ".opf"))
' Console.WriteLine(Path.ChangeExtension(filename, ".opf" + ": file created."));
The ability to call .NET functions from LINQpad is awesome. Below is a script I created in LINQpad that creates an EPUB OPF file.
So THANK YOU JOE!
' Get files
Dim dFiles As New Dictionary(Of Integer, String)
dim sPath as string = "C:\Files2012_Test\2012-03-07"
Dim dirInfo As New IO.DirectoryInfo(sPath)
Dim cnt As Integer = 0
For Each file As FileInfo In dirInfo.GetFiles("*.html", SearchOption.TopDirectoryOnly)
cnt += 1
dFiles.Add(cnt, file.Name)
Next
Dim pair As KeyValuePair(Of Integer, String)
For Each pair In dFiles
Debug.Print("{0}, {1}", pair.Key, pair.Value)
Next
' end get files
Dim ns As XNamespace = "http://www.idpf.org/2007/opf"
Dim dc As XNamespace = "http://purl.org/dc/elements/1.1/"
Dim opf As XNamespace = "http://www.idpf.org/2007/opf"
Dim BookTitle As String = "Anatomy and Physiology"
Dim BookId As String = "123"
Dim TocTitle As String = "Chapters"
Dim BookAuthorName As String = "Smith"
Dim tocHtmlFilename As String = "htmlfilename"
Dim textGuide As String = "study"
Dim PathGetFileNameFilename As String = ""
'TODO : setup all metadata
Dim metadata As New XElement(ns + "metadata", _
New XAttribute(XNamespace.Xmlns + "dc", dc), _
New XAttribute(XNamespace.Xmlns + "opf", opf), _
New XElement(dc + "title", BookTitle), _
New XElement(dc + "language", "en-us"), _
New XElement("meta", _
New XAttribute("name", "cover"), _
New XAttribute("content", "My_Cover")), _
New XElement(dc + "identifier", _
New XAttribute("id", BookId), _
New XAttribute(opf + "scheme", "ISBN"), "123456789"), _
New XElement(dc + "creator", BookAuthorName), _
New XElement(dc + "publisher", "McGraw Hill"), _
New XElement(dc + "subject", "McGraw Hill"), _
New XElement(dc + "date", DateTime.Today))
Dim manifest as new XElement(ns + "manifest")
For Each pair In dFiles
manifest.Add(new XElement(ns + "item", _
New XAttribute("id",pair.Key), _
New XAttribute("href",pair.Value)))
Next
Dim spine As New XElement(ns + "spine", _
New XAttribute("toc", "My_Table_of_Contents"), _
New XElement(ns + "itemref", _
New XAttribute("idref", "item1")), _
New XElement(ns + "itemref", _
New XAttribute("idref", "item2")))
Dim guide As New XElement(ns + "guide", New XElement(ns + "reference", New XAttribute("type", "toc"), New XAttribute("title", TocTitle), New XAttribute("href", tocHtmlFilename)), New XElement(ns + "reference", New XAttribute("type", "text"), New XAttribute("title", TocTitle), New XAttribute("href", PathGetFileNameFilename + (If((textGuide Is Nothing), "", "#" + textGuide)))))
Dim package As New XElement(ns + "package", New XAttribute("version", "2.0"), New XAttribute("unique-identifier", BookId), metadata, manifest, spine, _
guide)
Dim opfDoc As New XDocument(package)
opfDoc.Save(Path.ChangeExtension(sPath + "\aTestfromvb", ".opf"))
' Console.WriteLine(Path.ChangeExtension(filename, ".opf" + ": file created."));
Comments
You could also vote here. Joe started a thread in the old forum here.