Ejemplo n.º 1
0
        public string ProcessMsd2Records(GesmesHelpers gesmesHelpers, string filename, FlatFile fileInfo)
        {
            _fileInfo = fileInfo;
            string record = string.Empty;

            var allLines = File.ReadAllLines(filename);
            var lines    = allLines.Where(c => c.Contains("ARR")).ToList();

            for (int i = 0; i < lines.Count; i++)
            {
                string currentRecord = string.Empty;
                try
                {
                    if (!string.IsNullOrEmpty(lines[i]) && lines[i].Substring(0, 3) == "ARR")
                    {
                        string[] msd2Elements = gesmesHelpers.Split(":", lines[i].Replace("'", ""));

                        currentRecord = string.Join('|', msd2Elements, 0, 7);

                        string lastRecord = (i == 0) ? string.Empty : string.Join('|', gesmesHelpers.Split(":", lines[i - 1]), 0, 7);
                        string nextRecord = (i == (lines.Count - 1)) ? string.Empty : string.Join('|', gesmesHelpers.Split(":", lines[i + 1]), 0, 7);

                        ValidateAndPopulateMsd2DataFromFlatFile(msd2Elements);
                        if ((string.IsNullOrEmpty(recordErrors.ToString().Trim())))
                        {
                            if (!(currentRecord.Equals(nextRecord)))
                            {
                                AddMsd2DataToDatabase();
                            }
                        }

                        if (!(string.IsNullOrEmpty(recordErrors.ToString().Trim())))
                        {
                            bodyErrorMsg.AppendLine(" #Line from your file").AppendLine().AppendLine(lines[i])
                            .AppendLine(" #What is wrong and how to fix it").AppendLine().Append(recordErrors)
                            .AppendLine().Append(" ___").AppendLine();
                            recordErrors.Clear();
                        }
                    }
                }
                catch (Exception err)
                {
                    _logger.LogError("Gesmes Record error:", err.Message, err.InnerException != null ? err.InnerException.Message : string.Empty, err.StackTrace);

                    if (_fileInfo != null)
                    {
                        recordErrors.AppendLine(err.Message).Append(" Please correct it or contact the helpdesk for advice.");
                        bodyErrorMsg.AppendLine(" #Line from your file").AppendLine().AppendLine(lines[i])
                        .AppendLine(" #What is wrong and how to fix it").AppendLine().Append(recordErrors)
                        .AppendLine().Append(" ___").AppendLine();
                        recordErrors.Clear();
                    }
                }
            }
            return(bodyErrorMsg.ToString());
        }
Ejemplo n.º 2
0
 public Msd1FileProcess(Msd1Data msd1,
                        FlatFile fileInfo,
                        GesmesHelpers gesmesHelpers,
                        ValidateMsdData validateMsdData,
                        IMsd1DataService msd1DataService,
                        IFileProcessService fileProcessService,
                        IHelperService helperService,
                        ILogger <Msd1FileProcess> logger)
 {
     _msd1               = msd1;
     _fileInfo           = fileInfo;
     _gesmesHelpers      = gesmesHelpers;
     _helperService      = helperService;
     _msd1DataService    = msd1DataService;
     _validateMsdData    = validateMsdData;
     _fileProcessService = fileProcessService;
     _logger             = logger;
     recordErrors        = new StringBuilder();
     bodyErrorMsg        = new StringBuilder();
 }