private void button_StartPublshing_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; String password = textBox_Password.Text; String rootDirectoryPath = textBox_RootDirectory.Text; String dataFilename = textBox_DataFilename.Text; if (!new DirectoryInfo(rootDirectoryPath).Exists) { Scraper.Print($"Root Folder \"{rootDirectoryPath}\" does not exist.", ConsoleColor.Red); } else if (!new FileInfo(dataFilename).Exists) { Scraper.Print($"Data File \"{dataFilename}\" does not exist.", ConsoleColor.Red); } else { Config.Write(Config.KEY_PASSWORD, password); Config.Write(Config.KEY_DIRECTORY, rootDirectoryPath); Config.Write(Config.KEY_DATA, dataFilename); Init(); scraper.StartPublishingThread(password, rootDirectoryPath, dataFilename); } }
public static Car[] ReadDataFromTxt(String excelFilename) { List <Car> list = new List <Car>(); String[] lines = File.ReadAllLines(excelFilename, Encoding.UTF8); int lineCount = lines.Length; String name = null, value = null; Car car = null; for (int i = 0; i < lineCount; i++) { String line = lines[i]; if (line.StartsWith("#") || line.StartsWith("//")) { continue; } try { String[] array = line.Split(new Char[] { '=' }, 2); if (name != null && value != null) { int quoteCount = line.Split('\"').Length; if (quoteCount > 1) { value += "\r\n" + line.Replace("\"", ""); } else { value += "\r\n" + line; continue; } } else if (String.IsNullOrWhiteSpace(line)) { continue; } else { name = array[0].Trim().ToLower(); value = array.Length > 1 ? array[1].Trim() : null; if (String.IsNullOrWhiteSpace(value)) { value = null; } if (value != null) { int quoteCount = value.Split('\"').Length; if (quoteCount == 2) { value = value.Replace("\"", ""); continue; } else if (quoteCount == 3) { value = value.Replace("\"", ""); } } } if (value != null) { value = value.Trim(); } if (name == "folder") { car = new Car(); car.DirectoryName = value; } else if (name == "make") { car.Make = value; } else if (name == "model") { car.Model = value; } else if (name == "type") { car.Type = value; } else if (name == "month") { car.Month = value; } else if (name == "year") { car.Year = value; } else if (name == "kw") { car.KW = value; } else if (name == "fuel") { car.Fuel = value; } else if (name == "color") { car.Color = value; } else if (name == "mileage") { car.Mileage = value; } else if (name == "price") { car.PriceInEuro = value; } else if (name == "description") { car.Description = value; } else if (name == "pictures") { car.Pictures = value; } else if (name == "firstname") { car.FirstName = value; } else if (name == "lastname") { car.LastName = value; } else if (name == "street") { car.Street = value; } else if (name == "zip") { car.ZIP = value; } else if (name == "city") { car.City = value; } else if (name == "area") { car.Area = value; } else if (name == "tel") { car.Tel = value; } else if (name == "end") { if (car != null) { list.Add(car); } } else { Scraper.Print($"\tUnknown KEY : {name} on line {i + 1} = {line}"); } name = null; value = null; } catch { Scraper.Print($"\tError on line {i + 1} = {line}"); } } return(list.ToArray()); }