Esempio n. 1
0
        /// <summary>
        /// This constructor takes the following string format as input:
        /// <code>"(id,created,employee(id,firstname,employeeType(id), lastname),location)"</code>
        /// I am assuming that ids are integers, and that created is a very simple
        /// 2019-01-31 style date string.
        /// </summary>
        /// <param name="inputString"></param>
        public EmployeeLocation(string inputString)
        {
            InnerAndOuterString inputWithoutParanthesis = ExtractFromParanthesis.fromDelimiter("", inputString);

            if (inputWithoutParanthesis == null)
            {
                // this would happen if there were no paranthesis or if the first character was not an opening paranthesis
                throw new ArgumentException("Employee location does not begin and end with paranthesis");
            }

            InnerAndOuterString employeeAndInputWithoutEmployee = ExtractFromParanthesis.fromDelimiter("employee", inputWithoutParanthesis.inner);

            List <string> employeeLocationParts = CSVLine.toListOfLength(employeeAndInputWithoutEmployee.outer, 4);

            this.id = GetId.getId(employeeLocationParts.ElementAt(0));

            try
            {
                this.created = DateTime.ParseExact(employeeLocationParts.ElementAt(1), "yyyy-MM-dd", CultureInfo.InvariantCulture);
            }
            catch (System.FormatException)
            {
                throw new ArgumentException("Date format not in proper format (yyyy-MM-dd)");
            }

            this.employee = new Employee(employeeAndInputWithoutEmployee.inner);
            this.location = employeeLocationParts.ElementAt(3);
        }
        /// <summary>
        /// This constructor takes the following string format as input:
        /// <code>"id,firstname,employeeType(id),lastname"</code>
        /// </summary>
        /// <param name="inputString"></param>
        public Employee(string inputString)
        {
            InnerAndOuterString employeeTypeAndEmployeeWithoutET = ExtractFromParanthesis.fromDelimiter("employeeType", inputString);

            if (employeeTypeAndEmployeeWithoutET == null)
            {
                throw new ArgumentException("employeeType missing or missing its following paranthesis");
            }

            List <string> employeeParts = CSVLine.toListOfLength(employeeTypeAndEmployeeWithoutET.outer, 4);

            this.id           = GetId.getId(employeeParts.ElementAt(0));
            this.firstname    = employeeParts.ElementAt(1);
            this.lastname     = employeeParts.ElementAt(3);
            this.employeeType = new EmployeeType(employeeTypeAndEmployeeWithoutET.inner);
        }