Example #1
0
        private async void tmrEditNotify_Tick(object sender, EventArgs e)
        {
            if (!_logDirty)
            {
                return;
            }

            _log.Info(_sbLog.ToString());
            _logDirty = false;

            string hash;

            using (var md5 = MD5.Create())
            {
                using (var stream = File.OpenRead(_filePath))
                {
                    hash = BitConverter.ToString(md5.ComputeHash(stream))
                           .Replace("-", "")
                           .ToLowerInvariant();
                }
            }

            _log.Info($"Hash of {_filePath}: {hash}");
            if (_storage.IsExists(hash))
            {
                _log.Info($"Файл {_filePath} уже обработан");
                return;
            }

            try
            {
                var parser = ParserSelector.Select(_filePath);
                await Task.Run(() => parser.Load());

                var tokenSource = new CancellationTokenSource();
                foreach (var node in parser.Data)
                {
                    _log.Debug($"Parsing current row: {node.Name}, {node.Sum}");
                    _taskQueue.Enqueue(() =>
                                       ExecuteTask(node.Name, string.Empty, node.Sum, _filePath, node.Source, tokenSource));
                }

                if (!tmrQueue.Enabled)
                {
                    tmrQueue.Start();
                }
            }
            catch
            {
                _log.Error($"Не удалось открыть файл: {_filePath}");
            }
        }
Example #2
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _log.Debug($"{nameof(OpenToolStripMenuItem)} clicked");

            var result = openFileDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            _log.Info($"Выбран файл: {openFileDialog.FileName}");
            var dt = new DataTable();

            gridSource.DataSource = dt;

            try
            {
                var parser = ParserSelector.Select(openFileDialog.FileName);
                _openedFileParser = parser;
                parser.Load();
                Text = $@"{openFileDialog.FileName} - {_appname}";
                _log.Debug($"Добавление колонок в {nameof(gridSource)}");
                foreach (var caption in parser.Captions)
                {
                    dt.Columns.Add(caption, typeof(string));
                }

                gridSource.Update();

                foreach (DataGridViewColumn column in gridSource.Columns)
                {
                    column.SortMode = DataGridViewColumnSortMode.NotSortable;
                }

                gridSource.Update();

                _log.Debug($"Добавление данных в {nameof(gridSource)}");
                foreach (var node in parser.Data)
                {
                    dt.LoadDataRow(node.AsArray(), LoadOption.Upsert);
                }

                gridSource.Update();
            }
            catch
            {
                _log.Error($"Не удалось открыть файл: {openFileDialog.FileName}");
                Text = _appname;
            }
        }
Example #3
0
        private async void ScanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (var file in Directory.EnumerateFiles(_appSettings.FolderPath, "*.*", SearchOption.AllDirectories))
            {
                _log.Info($"Select file: {file}");
                string hash;
                using (var md5 = MD5.Create())
                {
                    using (var stream = File.OpenRead(file))
                    {
                        hash = BitConverter.ToString(md5.ComputeHash(stream))
                               .Replace("-", "")
                               .ToLowerInvariant();
                    }
                }

                _log.Info($"Hash of {file}: {hash}");
                if (_storage.IsExists(hash))
                {
                    _log.Info($"Файл {file} уже обработан");
                    continue;
                }

                try
                {
                    var parser = ParserSelector.Select(file);
                    await Task.Run(() => parser.Load());

                    foreach (var node in parser.Data)
                    {
                        _log.Debug($"Parsing current row: {node.Name}, {node.Sum}");
                        _taskQueue.Enqueue(() => ExecuteTask(node.Name, string.Empty, node.Sum, file));
                    }

                    if (!tmrQueue.Enabled)
                    {
                        tmrQueue.Start();
                    }

                    _storage.AddNode(hash);
                }
                catch
                {
                    Log.Error($"Не удалось открыть файл: {_filePath}");
                }
            }
        }
Example #4
0
        private static void ProccesSave(string[] parts)
        {
            if (ParserSelector == null)
            {
                ParserSelector = new ParserSelector();
            }

            if (parts.Length == 1)
            {
                var message = ParserSelector.ParseToFile(Formats.xml, Cache.GetInstance().GetGroups(), Cache.GetInstance().GetParseErrors());
                Program.PrintMessage(message);
                return;
            }
            else if (Enum.TryParse(parts[1], out Formats action))
            {
                var message = ParserSelector.ParseToFile(action, Cache.GetInstance().GetGroups(), Cache.GetInstance().GetParseErrors());
                Program.PrintMessage(message);
            }
            else
            {
                Console.WriteLine($"Format:{parts[1]} unknown, supported formats:{GetEnumValues<Formats>()}");
            }
        }
Example #5
0
        private async void ScanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(_appSettings.FolderPath))
            {
                _log.Error($"Папка {_appSettings.FolderPath} не найдена");
                return;
            }

            LogManager.ReconfigExistingLoggers();

            foreach (var file in Directory.EnumerateFiles(_appSettings.FolderPath, "*.*", SearchOption.AllDirectories))
            {
                _log.Info($"Select file: {file}");

                if (!File.Exists(file))
                {
                    _log.Error($"Файд {file} не найден");
                    continue;
                }

                string hash;
                using (var md5 = MD5.Create())
                {
                    using (var stream = File.OpenRead(file))
                    {
                        hash = BitConverter.ToString(md5.ComputeHash(stream))
                               .Replace("-", "")
                               .ToLowerInvariant();
                    }
                }

                _log.Info($"Hash of {file}: {hash}");
                if (_storage.IsExists(hash))
                {
                    _log.Info($"Файл {file} уже обработан");
                    continue;
                }

                try
                {
                    var parser = ParserSelector.Select(file);
                    await Task.Run(() => parser.Load());

                    var tokenSource = new CancellationTokenSource();
                    foreach (var node in parser.Data)
                    {
                        _log.Debug($"Parsing current row: {node.Name}, {node.Sum}");
                        _taskQueue.Enqueue(() =>
                                           ExecuteTask(node.Name, string.Empty, node.Sum, file, node.Source, tokenSource));
                    }

                    if (!tmrQueue.Enabled)
                    {
                        tmrQueue.Start();
                    }

                    _storage.AddNode(hash);
                }
                catch
                {
                    _log.Error($"Не удалось открыть файл: {file}");
                }
            }

            var target = (FileTarget)LogManager.Configuration.FindTargetByName("errfile_parsed");

            target.Flush(exception => { });
            target.Dispose();
        }