示例#1
0
        static void Main(string[] args)
        {
            string[] commands;
            var      list = File.ReadAllText("CreateDocumentScript.txt");

            commands = list.Split('#');

            foreach (var command in commands)
            {
                var strippedCommand = Regex.Replace(command, @"\t|\n|\r", "");
                var commandList     = strippedCommand.Split(':');
                switch (commandList[0])
                {
                case "Document":
                    CreateDocument(commandList[1].Split(';'));
                    break;

                case "Element":
                    _document.AddElement(_factory.CreateElement(commandList[1], commandList[2]));
                    break;

                case "Run":
                    RunDocument();
                    break;

                default:
                    break;
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            string[] commands;
            var      list = File.ReadAllText("CreateDocumentScript.txt");

            commands = list.Split('#');
            IDocumentFactory currentFactory  = null;
            IDocument        currentDocument = null;
            IElement         currentElement  = null;

            foreach (var command in commands)
            {
                var strippedCommand = Regex.Replace(command, @"\t|\n|\r", "");
                var commandList     = strippedCommand.Split(':');

                switch (commandList[0])
                {
                case "Document":
                {
                    var temp = commandList[1].Split(';');
                    switch (temp[0])
                    {
                    case "Html":
                        currentFactory  = HTMLFactory.GetInstance();
                        currentDocument = currentFactory.CreateDocument(temp[1]);
                        break;

                    case "Markdown":
                        currentFactory  = MDFactory.GetInstance();
                        currentDocument = currentFactory.CreateDocument(temp[1]);
                        break;

                    default:
                        break;
                    }
                }
                    // Your document creation code goes here
                    break;

                case "Element":
                {
                    currentElement = currentFactory.CreateElement(commandList[1], commandList[2]);
                    currentDocument.AddElement(currentElement);
                }

                    // Your element creation code goes here
                    break;

                case "Run":
                    currentDocument.RunDocument();
                    break;

                default:
                    break;
                }
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            string[] commands;
            var      list = File.ReadAllText("CreateDocumentScript.txt");

            commands = list.Split('#');

            foreach (var command in commands)
            {
                var strippedCommand = Regex.Replace(command, @"\t|\n|\r", "");
                var commandList     = strippedCommand.Split(':');
                switch (commandList[0])
                {
                case "Document":
                    // Your document creation code goes here
                    string[] fileName = commandList[1].Split(';');
                    if (fileName[0] == "Markdown")
                    {
                        //fileNameArray[1] == fileName
                        factory  = MarkdownFactory.CreateInstance();
                        document = factory.CreateDocument(fileName[1]);
                        Console.WriteLine(fileName[1]);
                    }
                    else if (fileName[0] == "Html")
                    {
                        factory  = HTMLFactory.CreateInstance();
                        document = factory.CreateDocument(fileName[1]);
                        Console.WriteLine(fileName[1]);
                    }
                    break;

                case "Element":
                    // Your element creation code goes here
                    document.AddElement(factory.CreateElement(commandList[1], commandList[2]));
                    break;

                case "Run":
                    // Your document running code goes here
                    document.RunDocument();
                    Console.WriteLine("Running Document");
                    break;

                default:
                    break;
                }
            }
            Console.WriteLine("Thanks for using...done");
            System.Environment.Exit(0);
        }
        static void Main(string[] args)
        {
            string[] commands;
            string   list = "";

            try
            {
                list = File.ReadAllText("CreateDocumentScript.txt");
            } catch (FileNotFoundException e)
            {
                Console.WriteLine("Input file not found (be sure CreateDocumentScript.txt is in the right directory: \"" + e.FileName + "\").");
                System.Environment.Exit(1);
            }

            commands = list.Split('#');

            // to be assigned below

            //string factoryType; // 'html' or 'markdown'

            foreach (var command in commands)
            {
                string   strippedCommand = Regex.Replace(command, @"\t|\n|\r", ""); // this cleans up the text a bit
                string[] commandList     = strippedCommand.Split(':');

                switch (commandList[0])
                {
                //[0] - Either Document or Element
                //[1] - Either filename if Document or ElementType if Element
                //[2]- props
                case "Document":
                    // Your document creation code goes here
                    // maybe create a concrete document and set the value of the `document` variable?
                    // commandList might look like: ["Document", "Markdown;index.md"]
                    //
                    string[] fileNameArray = commandList[1].Split(';');
                    if (fileNameArray[0] == "Markdown")
                    {
                        //fileNameArray[1] == fileName
                        factory  = MarkdownFactory.Get();
                        document = factory.CreateDocument(fileNameArray[1]);
                        Console.WriteLine(fileNameArray[1]);
                    }
                    else if (fileNameArray[0] == "Html")
                    {
                        factory  = HTMLFactory.Get();
                        document = factory.CreateDocument(fileNameArray[1]);
                        Console.WriteLine(fileNameArray[1]);
                    }

                    break;

                case "Element":
                    //[0] Element/Document
                    //[1] ElementType
                    //[2] props
                    // Your element creation code goes here
                    // maybe have the factory append a new element to the document?
                    // commandList might look like: ["Element", "Header", "1;The Header"]
                    // take a look at CreateDocumentScript.txt for all of them
                    // Console.Write(commandList[1] + "    ");
                    // Console.WriteLine(commandList[2]);
                    document.AddElement(factory.CreateElement(commandList[1], commandList[2]));

                    break;

                case "Run":
                    string name = document.GetFilename();
                    using (File.Create(name)){};
                    using (var writer = new StreamWriter(name, true)){
                        writer.WriteLine(document.Run());
                    };


                    //File.Create(RelativeToAbsolutePath(document.GetFilename()));
                    Console.WriteLine(document.Run());
                    // File.WriteAllText(RelativeToAbsolutePath(document.GetFilename()), document.Run());
                    // Console.WriteLine();
                    break;

                default:
                    break;
                }
            }
        }