//saves Design Doc into Text file public void SaveTxt(DesignDocument DDSaveTxt) { try { StringBuilder QueAns = new StringBuilder(); QueAns.AppendLine(DDSaveTxt.DesignDocTitle + "\n"); QueAns.AppendLine("----------------------------------"); QueAns.AppendLine("----------------------------------"); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\code\designnotes\SavedDD\" + DDSaveTxt.DesignDocTitle + ".txt")) { //Add Design Doc Title foreach (Question q in DDSaveTxt.Questions) { //If the line doesn't contain the word 'Second', write the line to the file. QueAns.AppendLine(q.QuestionToAsk + "\n"); QueAns.AppendLine("----------------------------------"); QueAns.AppendLine(q.QuestionAnswer + "\n"); } //Write String buffer to text file file.WriteLine(QueAns); } } catch (System.IO.DirectoryNotFoundException e) { System.Console.WriteLine(e.Message); } }
private void AddUserQuestion(ConsoleKeyInfo userInput, DesignDocument designDocument) { if (userInput.Key == ConsoleKey.Y) { Console.WriteLine(ConsoleMessages.EnterQuestionDescription); String QuestionDescription = Console.ReadLine(); Console.WriteLine(ConsoleMessages.EnterAnswerDescription); String UserAnswer = Console.ReadLine(); ; designDocument.AddUserQuestion(QuestionDescription, UserAnswer); Console.WriteLine(ConsoleMessages.QASaveSuccessfully); } }
//saves data from Questionaire to XML file public void SaveXml(DesignDocument DDSaveXml) { try { System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(DesignDocument)); var wfile = new System.IO.StreamWriter(@"C:\code\designnotes\SavedDD\" + DDSaveXml.DesignDocTitle + ".xml"); writer.Serialize(wfile, DDSaveXml); wfile.Close(); } catch (System.IO.DirectoryNotFoundException e) { System.Console.WriteLine(e.Message); } }
private void CreateDesignDocument() { Console.WriteLine(ConsoleMessages.CreatingDesignDocument); DesignDocument designDocument = new DesignDocument(); Console.WriteLine("What would you like to call your design document? \n \n"); designDocument.DesignDocTitle = Console.ReadLine(); foreach (Question q in designDocument.Questions) { Console.WriteLine(q.QuestionToAsk); string answer = Console.ReadLine(); designDocument.AddUserNameToQuestion(q.QuestionIndex, answer); } Console.WriteLine(ConsoleMessages.AddAdditionalQuestion); ConsoleKeyInfo userinput = Console.ReadKey(); AddUserQuestion(userinput, designDocument); SaveFacade SF = new SaveFacade(); SF.SaveXml(designDocument); SF.SaveTxt(designDocument); }
/*Loads single XML document into designdoc Object*/ public DesignDocument MakeDesignDocObj(String path) { DesignDocument LoadedDesignDoc = new DesignDocument(); System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(path); XmlDocument LoadedDoc = new XmlDocument(); LoadedDoc.Load(path); XmlNode DesignDocTitle = LoadedDoc.DocumentElement.SelectSingleNode("DesignDocTitle"); LoadedDesignDoc.DesignDocTitle = DesignDocTitle.InnerText; List<Question> ques = new List<Question>(); while (reader.Read()) { Question LoadedQuestion = new Question(); reader.MoveToContent(); if (reader.NodeType == System.Xml.XmlNodeType.Entity) LoadedQuestion.QuestionToAsk = reader.Name + "\n"; if (reader.NodeType == System.Xml.XmlNodeType.Text) LoadedQuestion.QuestionAnswer = reader.Value + "\n"; ques.Add(LoadedQuestion); } LoadedDesignDoc.Questions = ques; return LoadedDesignDoc; }