Пример #1
0
        public async void Parse(WhoisParameters parametr)
        {
            _result  = new ConcurrentQueue <string>();
            _domains = new ConcurrentQueue <string>(_csvReaderWriter.ReadFile(parametr.FilePath));
            List <Task> tasks = new List <Task>();

            _pauseToken  = true;
            _cancelToken = true;
            _saver       = true;
            SetParams(parametr);
            StartParsing?.Invoke(_domains.Count, _streamsCount, _timeout);
            _result.Enqueue("Url" + _parser.BuildHeader());
            for (int i = 0; i < _streamsCount; i++)
            {
                tasks.Add(startTask());
            }
            await Task.WhenAll(tasks);

            if (_saver)
            {
                if (_csvReaderWriter.Write(_savefilepath, new TextFromListGetter(_result.ToList())))
                {
                    MessageBox.Show("Done");
                }
            }
            ParsingEnd?.Invoke();
            foreach (var item in tasks)
            {
                item.Dispose();
            }
        }
Пример #2
0
        public bool SyncData(string savefile, string examplefile, IEnumerable <ColumnSelector> parameters)
        {
            List <string> result         = new List <string>();
            List <string> savedstrings   = _csvReaderWriter.ReadFile(savefile);
            List <string> examplestrings = _csvReaderWriter.ReadFile(examplefile);

            foreach (var saved in savedstrings)
            {
                string synchstring = saved;
                string twin        = examplestrings.FirstOrDefault(s => s.Substring(0, s.IndexOf(';')).ToLower().Trim() == saved.ToLower().Trim());
                if (twin != null)
                {
                    string[] twinparams = twin.Split(';');
                    foreach (var par in parameters)
                    {
                        if (par.Index < twinparams.Length)
                        {
                            synchstring += ";" + twinparams[par.Index];
                        }
                    }
                }
                result.Add(synchstring);
            }
            return(_csvReaderWriter.Write(savefile, new TextFromListGetter(result)));
        }
Пример #3
0
        public static bool WriteServers()
        {
            List <string> list = new List <string>();

            foreach (var item in _servers)
            {
                list.Add(item.IPAdress + ";" + item.Port + ";" + item.User + ";" + item.Password + ";" + item.Limits);
            }
            return(_csvReaderWriter.Write(filepath, new TextFromListGetter(list)));
        }
        private void AssertWritesColumns(ICsvReaderWriter csvReaderWriter)
        {
            // Arrange
            const string dataFile = @"test_data\emptyFile.csv";

            csvReaderWriter.Open(dataFile, CSVReaderWriterForAnnotation.Mode.Write);

            // Act
            csvReaderWriter.Write("Column 1A", "Column 1B");
            csvReaderWriter.Write("Column 2A", "Column 2B");
            csvReaderWriter.Close();
            var linesAfterWrite = File.ReadAllLines(dataFile);

            // Assert

            // Check only correct number of lines have been written
            Assert.AreEqual(2, linesAfterWrite.Length);

            // Check line added is expected string
            Assert.AreEqual("Column 1A\tColumn 1B", linesAfterWrite[0]);
            Assert.AreEqual("Column 2A\tColumn 2B", linesAfterWrite[1]);
        }
Пример #5
0
 public void ShouldWriteColumnsProperly_OnWrite()
 {
     _csvReaderWriter.Write("1", "2", "3");
     _file.Received().WriteLine("1\t2\t3");
 }