示例#1
0
        public static Validation <Error, ICentralinoLine> Of(string line)
        {
            return(LineDto.Of(line).ToValidation().Bind(lineDto =>
            {
                var internalNumber = new InternalNumber(lineDto.InternalNumberStr);
                var externalNumber = ExternalNumber.Of(lineDto.ExternalNumberStr);
                var coCode = new CoCode(lineDto.CoCodeStr);
                var cdCode = string.IsNullOrWhiteSpace(lineDto.CdCodeStr) ? None : Some(new CdCode(lineDto.CdCodeStr));

                Validation <Error, DateTime> dateTimeValue = ReadDate(lineDto.DateTimeStr).MapFail(error => EnrichError(error, line));
                Validation <Error, Cost> costValue = ReadCost(lineDto.CostStr).MapFail(error => EnrichError(error, line));;
                Validation <Error, Duration> durationValue = ReadDuration(lineDto.DurationStr).MapFail(error => EnrichError(error, line));;

                return (dateTimeValue, costValue, durationValue).Apply((dateTime, cost, duration) =>
                                                                       (ICentralinoLine)externalNumber
                                                                       .CreateCall(new CallData(
                                                                                       line,
                                                                                       dateTime,
                                                                                       internalNumber,
                                                                                       coCode,
                                                                                       cdCode,
                                                                                       duration,
                                                                                       cost)));
            }));
        }
示例#2
0
        public static Either <Error, LineDto> Of(string line)
        {
            var minimumLength = 70;

            if (line.Length < minimumLength)
            {
                return(Prelude.Left(Error.New($"line ${line} should be at least ${minimumLength} characters long")));
            }

            var lineDto = new LineDto
                          (
                dateTimeStr: ReadLineToken(line, 0, 14),
                internalNumberStr: ReadLineToken(line, 14, 7),
                coCodeStr: ReadLineToken(line, 21, 3),
                externalNumberStr: ReadLineToken(line, 24, 21),
                durationStr: ReadLineToken(line, 45, 9),
                costStr: ReadLineToken(line, 54, 11),
                cdCodeStr: ReadLineToken(line, 65, 15)
                          );

            return(Prelude.Right(lineDto));
        }