1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Collections;
|
---|
6 | using LoggingTool.models;
|
---|
7 | using System.Text.RegularExpressions;
|
---|
8 |
|
---|
9 | namespace LoggingTool.interfaces
|
---|
10 | {
|
---|
11 | class TeamUpLogic : ILoggerLogic
|
---|
12 | {
|
---|
13 | List<TeamUpQuestionnaire> questionnaires;
|
---|
14 | List<TeamUpEvent> events;
|
---|
15 | List<String> rawInput;
|
---|
16 |
|
---|
17 | /* ****************************************************************
|
---|
18 | * constructor TeamUpLogic
|
---|
19 | * @description: Creates a TeamUpLogic object to act as the mediator
|
---|
20 | * between Input and Output
|
---|
21 | * ****************************************************************/
|
---|
22 | public TeamUpLogic()
|
---|
23 | {
|
---|
24 | questionnaires = new List<TeamUpQuestionnaire>();
|
---|
25 | events = new List<TeamUpEvent>();
|
---|
26 | rawInput = new List<String>();
|
---|
27 | }
|
---|
28 |
|
---|
29 | /* ****************************************************************
|
---|
30 | * function addInput
|
---|
31 | * @param input : String
|
---|
32 | * @description : Appends the input into the raw string array
|
---|
33 | * ****************************************************************/
|
---|
34 | public void addInput(String input)
|
---|
35 | {
|
---|
36 | rawInput.Add(input);
|
---|
37 | }
|
---|
38 |
|
---|
39 | /* *********************************************************************
|
---|
40 | * function createModels
|
---|
41 | * @description: Parses all the raw input and creates objects out of it.
|
---|
42 | * *********************************************************************/
|
---|
43 | public void createModels()
|
---|
44 | {
|
---|
45 | //Loop through all the inputs
|
---|
46 | foreach (String input in rawInput)
|
---|
47 | {
|
---|
48 | //If there are more than 4 |'s, this is a questionnaire.
|
---|
49 | if ((input.Split('|').Count() - 1) > 4)
|
---|
50 | questionnaires.Add(new TeamUpQuestionnaire(input));
|
---|
51 |
|
---|
52 | //Else, this is an TeamUpEvent
|
---|
53 | else
|
---|
54 | events.Add(new TeamUpEvent(input));
|
---|
55 | }
|
---|
56 | rawInput = new List<String>();
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* **********************************************************************
|
---|
60 | * function formatModels
|
---|
61 | * @return: List<LoggerMessage>
|
---|
62 | * @description: Takes the models in the lists (attributes) and formats
|
---|
63 | * them into messages.
|
---|
64 | * **********************************************************************/
|
---|
65 | public List<LoggerMessage> formatModels()
|
---|
66 | {
|
---|
67 | List<LoggerMessage> resultSet = new List<LoggerMessage>();
|
---|
68 | foreach (TeamUpQuestionnaire questionnaire in questionnaires)
|
---|
69 | {
|
---|
70 | TeamUpSpreadsheetMessage message = new TeamUpSpreadsheetMessage(TeamUpSpreadsheetMessage.QUESTIONNAIRE, questionnaire.toStringArray());
|
---|
71 | resultSet.Add(message);
|
---|
72 | }
|
---|
73 |
|
---|
74 | foreach (TeamUpEvent e in events)
|
---|
75 | {
|
---|
76 | TeamUpSpreadsheetMessage message = new TeamUpSpreadsheetMessage(TeamUpSpreadsheetMessage.EVENT, e.toStringArray());
|
---|
77 | resultSet.Add(message);
|
---|
78 | }
|
---|
79 |
|
---|
80 | return resultSet;
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|
84 | }
|
---|