public static void AddOrUpdateDB(DBWords database) { if (database == null) { Console.WriteLine("Database does not exist, entering input mode..."); return; } while (true) { Console.Write("Enter file name: "); var fileName = Console.ReadLine(); var fullFileName = Directory.GetCurrentDirectory() + "\\" + fileName; if (!Directory.EnumerateFiles(Directory.GetCurrentDirectory()).Contains(fullFileName)) { Console.WriteLine("Invalid file name, try again..."); continue; } var EncodeChecker = new Utf8Checker(); if (EncodeChecker.Check(fileName)) { var a = FileController.ParseFile(File.ReadAllLines(fileName)); var e = FileController.GenerateWordList(a); var result = Requests.GenerateUpdateRequestWithGlobalOptions(e); DBController.AddOrUpdateEntity(database, result); return; } else { Console.WriteLine("File is not in UTF-8 encoding"); } } }
public DebugStreamReader(byte[] data, Encoding encoding, bool auto) : base(new MemoryStream(data), encoding) { if (ToClientEncoding) { _isUtf8 = Utf8Checker.IsUtf8(data, data.Length); } else { _isUtf8 = Utf8Checker.IsUtf8(data, data.Length > 20000 ? 20000 : data.Length); } _auto = auto; }
public void Main() { String fileToCheck, logFileName; bool OK_UTF8; IUtf8Checker fileCheckerUtf8 = new Utf8Checker(); List <IErrorUtf8Checker> errorsList; System.IO.StreamWriter logFile; try { fileToCheck = Dts.Variables["User::InputFile"].Value.ToString(); logFileName = fileToCheck + "_utf8check.log"; if (File.Exists(fileToCheck)) { OK_UTF8 = fileCheckerUtf8.Check(fileToCheck); if (OK_UTF8 == false) { errorsList = fileCheckerUtf8.GetErrorList(); logFile = new StreamWriter(logFileName); int i = 0; foreach (ErrorUtf8Checker e in errorsList) { logFile.WriteLine(++i + ") " + e.ToString()); } logFile.Close(); } } //exit always with success. It writes a log file if any warning occurs Dts.TaskResult = (int)ScriptResults.Success; } catch (DecoderFallbackException eUTF) { Console.Write(eUTF.ToString()); Dts.TaskResult = (int)ScriptResults.Failure; } catch (Exception e) { Console.Write(e.ToString()); Dts.TaskResult = (int)ScriptResults.Failure; } }
//--------------------------------------------------------------------------- public ImportClass(FormMain f) { f1 = f; utf8Checker = new Utf8Checker(); }