INFO-3137 – Project 1
Your Task
You are to create an Abstract Factory for creating HTML and Markdown documents. Each concrete implementation of the Abstract Factory is to be implemented as a Singleton. As well, the document factory is to use a Factory Method to create elements in the document.
Details
The Factories:
· Need to have one concrete implementation each for both Html and Markdown documents
o Html documents are created using the HTML5 standard
o Markdown documents are created in the github format
§ See Markdown Cheatsheet for details
· Need to be implemented as Singletons
· Need to be able to create a concrete document implementation
· Need to be able to create multiple element types from the Factory Method “CreateElement.”
The types you need to be able to create are:
o Header (h1 to h3 at least)
o Image (including alt text and title text)
o List (ordered and unordered)
o Table (including table header and table rows)
The Documents
· Need to be able to add elements through a single AddElement method
· Need to be able to run the document
o This entails saving the document text to a file
o It also entails running a browser to display them. Some details for one way to do this are outlined later in this document.
· Accordingly, you’ll need to create an interface for HTML or Markdown Documents. It should contain the following methods:
o void AddElement(IElement element);
§ When implemented in concrete HTML and Markdown Document classes, this should add elements to a current list of elements.
o void RunDocument();
§ When implemented in concrete HTML and Markdown Document classes, this should generate either an HTML document or a Markdown Document and open it in chrome.
The Elements
· Need to store properties and be able to output the appropriate text for their own type to be properly added to the document.
· Accordingly, you’ll need an interface for HTML or Markdown Elements. This interface doesn’t actually need any instance variables or methods, but will instead be implemented by individual concrete HTML and Markdown Element classes (ex. HTMLHeader, MarkdownHeader, HTMLTable, MarkdownTable, and so on)
· These concrete element classes
o Should contain a constructor that takes and assigns the properties of the specific element
§ Note that these properties will vary depending on the element. To see what they would look like, take a look at docs/CreateDocumentScript.txt. For example, an HtmlImage would have properties that look like “img/csharp.png;Alt Text;Title Text”, as specified in the .txt file.
o Should contain a toString method that outputs a formatted string version of the properties, specific to the given document and element.
§ For example, in a concrete html image class, given the properties specified above, toString should return “<img alt='Alt Text' title='Title Text' src='img/csharp.png' /><br />”
§ Take a look at Parsing_Tutorial.pdf, for some ideas on how to parse the properties
o In the RunDocument() method, implemented in your concrete Document classes, you’ll ultimately end up calling these toString() methods. If you’ve implemented everything correctly, you should only have to call toString() once in each RunDocument() method (if you’re not sure how, feel free to ask!)
What you are provided with
Use the INFO3137-Project1 solution as a starting point. It is currently not able to compile and run, due to missing important interface types. It is your task to create the rest of the code. The solution contains:
· A project called Director
o This project will script your document creation
o dIt contains a reference to the DLL you’ll use to create your factory
o The project is also set to output to the appropriate directory to run the project
· A project called DocumentFactory
o This is where your factory implementation will go
o You are provided with the IDocumentFactory interface to get you started
o You are to create all other interfaces and implementations in this project
· A folder called “docs” (not visible in Visual Studio)
o It contains a file called CreateDocumentScript.txt. This will be used to test your factories.
§ The details of the syntax of this file will be outlined later in this document.
o Lastly, it contains an image subfolder, where there is a demo image that is to be used in your documents.
Things you’ll need
· The demo project is implemented using Chrome, which means you’ll need chrome installed to
run it
· To run Chrome from the command line, opening to a given page, you can use the following line of code
o You’ll still need to get the absolute local file path for the file you intend to open.
· To view the Markdown document formatted properly in the browser, you’ll need this extension
o To allow the extension to read local markdown files, you’ll need to go in to the
extension settings and set “Allow access to file URLs” to true
The CreateDocumentScript.txt Format
Some of the processing of this file is already handled for you, but you’ll still need to do some string
processing to get the various properties out of the file.
· Each “line” of the file is considered to end when the character ‘#’ is read
· The first part of each “line” is one of the following, and is delimited by a ‘:’
o Document
o Element
o Run
· The Document line contains two sub parts, deliminted by the ‘;’ character
o The type
o The file name
o You’ll use these to create a factory and a document
· The Element line contains:
o The element type, followed by a ‘:’
o This properties for the element
· The Table Element has some special syntax
o Each “line” of the table is delimited by a ‘;’
o Each of the parts of the table is delimited by a ‘$’
o The first item in each “line” is the type of the table row you’re creating, either head or row
· The Run line contains only the word run. This will create and run the actual document on disk