Exemplo n.º 1
0
        // get a reference to the sole instance of this class, creating it if necessary
        public static DocumentCreatorSingleton GetInstance()
        {
            if (instance == null)
            {
                instance = new DocumentCreatorSingleton();
            }

            return(instance);
        }
Exemplo n.º 2
0
        //
        // GET: /Clone/
        //
        // Home page for documents created using the Clone pattern
        //
        public IActionResult Index(string format)
        {
            // get a document that can be cloned (in a real program, this document would be passed to us by someone else)
            IDocument doc = DocumentCreatorSingleton.GetInstance().GetSampleDocument(format);

            // make a clone
            IDocument clone = doc.Clone();

            return(View("~/Views/Shared/Results.cshtml", clone.GetString()));
        }
Exemplo n.º 3
0
        //
        // GET: /AbstractFactory/Submit
        //
        // Process a submission.
        //
        public IActionResult Submit(string format, string headingText, string paragraphText)
        {
            // get the proper document factory for the output type
            IDocumentFactory factory = DocumentCreatorSingleton.GetInstance().GetDocumentFactory(format);

            // create the document parts
            IHeading   headingObj   = factory.CreateHeading(1, headingText);
            IParagraph paragraphObj = factory.CreateParagraph(paragraphText);

            return(View("~/Views/Shared/Results.cshtml", headingObj.GetString() + paragraphObj.GetString()));
        }
Exemplo n.º 4
0
        //
        // GET: /AbstractFactory/Submit
        //
        // Process a submission.
        //
        public IActionResult Submit(string format, string titleText, string authorText, string bodyText)
        {
            // get the proper document builder for the output type
            IDocumentBuilder builder = DocumentCreatorSingleton.GetInstance().GetDocumentBuilder(format);

            // start building
            builder.OpenDocument();

            // build the head with the title and author
            builder.BuildHead(titleText, authorText);

            // build the body
            builder.BuildBody(bodyText);

            // finished building
            builder.CloseDocument();

            return(View("~/Views/Shared/Results.cshtml", builder.GetDocument().GetString()));
        }