Пример #1
0
        private async Task <string> ParsDocument(string filePath, LogFile logFile)
        {
            try
            {
                await Task.Run(() =>
                {
                    DateTime dateStart = DateTime.MinValue;
                    DateTime dateEnd   = DateTime.MinValue;
                    var countFileLine  = File.ReadAllLines(filePath).Length;
                    using (var read = new StreamReader(filePath, Encoding.UTF8))
                    {
                        string value;
                        int index = 0;
                        while (!string.IsNullOrEmpty(value = read.ReadLine()))
                        {
                            /*-------------------getDate from log file-----------------*/
                            var startDate = Regex.Match(value, RegStart, RegexOptions.IgnoreCase);
                            if (startDate.Success)
                            {
                                var time = Regex.Match(value, RegDate, RegexOptions.IgnoreCase);
                                if (time.Success)
                                {
                                    dateStart = ConverterToDateTime(time.Value);
                                }
                            }

                            var endDate = Regex.Match(value, RegEnd, RegexOptions.IgnoreCase);
                            if (endDate.Success)
                            {
                                var time = Regex.Match(value, RegDate, RegexOptions.IgnoreCase);
                                if (time.Success)
                                {
                                    dateEnd = ConverterToDateTime(time.Value);
                                }
                            }
                            /*--------------------------------------------------------------*/


                            /*-----------------getRequestAndResponse------------------------*/
                            var input = Regex.Match(value, RegInput, RegexOptions.IgnoreCase);
                            if (input.Success)
                            {
                                var binarydata = Regex.Match(input.Value, RegBinData, RegexOptions.IgnoreCase);
                                var rezult     = binarydata.Success ? input.Value.Replace(binarydata.Value, "\"binary_data\":\"true\"") : input.Value;
                                var rez        = rezult.Remove(0, 8);
                                var id         = rez != "" ? GetmessageId(rez) : "notFoundInput_" + index;
                                var rezId      = id != "" ? id : "idIsNull_" + index;
                                DataProcessor.CreateLog(rezId, dateStart, rez, DateTime.MinValue, "", logFile);
                            }
                            var output = Regex.Match(value, RegOutput, RegexOptions.IgnoreCase);
                            if (output.Success)
                            {
                                var rez   = output.Value.Remove(0, 8);
                                var error = GetError(rez);
                                var id    = rez != "" ? GetmessageId(rez) : "notFoundOutput_" + index;
                                var rezId = id != "" ? id : "idIsNull_" + index;
                                DataProcessor.CreateLog(rezId, DateTime.MinValue, "", dateEnd, rez, logFile);
                            }
                            /*--------------------------------------------------------------*/
                            index++;
                            UpdateProgBarFile((int)((index * 100.0) / countFileLine));
                        }
                    }
                });

                return("\r\nDocument " + filePath + ". completed successful! \r\nCount objetcs: " + LogsList.Count);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return("Error!!! " + filePath);
        }