public void ReadTextFile(string path) { var textFile = new TxtFile(path, string.Empty); var readStr = _dataRepo.Read(textFile); Invoke(() => _view.ShowDataContent(readStr)); }
private void LvwResult_SelectedIndexChanged(object sender, EventArgs e) { if (LvwResult.SelectedItems.Count == 0) { return; } var sFile = Path.Combine(LvwResult.SelectedItems[0].SubItems[1].Text, LvwResult.SelectedItems[0].Text); // Open file and hightlight var lang = Language.Custom; var ext = Path.GetExtension(sFile).ToLower(); switch (ext) { case ".sql": lang = Language.SQL; break; case ".xml": case ".jrxml": lang = Language.XML; break; case ".php": lang = Language.PHP; break; default: lang = Language.Custom; break; } TxtFile.Language = lang; TxtFile.OpenFile(sFile); }
public void CreatingNewTxtObj_GivenRegularTxtFile_ReadsInTheWordsCorrectly() { // Arrange/Act var file = new TxtFile(Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt")); // Assert Assert.IsTrue(file.WordsUnsorted.Contains("hi")); Assert.IsTrue(file.WordsUnsorted.Contains("my")); Assert.IsTrue(file.WordsUnsorted.Contains("name")); Assert.IsTrue(file.WordsUnsorted.Contains("is")); Assert.IsTrue(file.WordsUnsorted.Contains("baloo")); Assert.IsTrue(file.WordsUnsorted.Contains("and")); Assert.IsTrue(file.WordsUnsorted.Contains("i")); Assert.IsTrue(file.WordsUnsorted.Contains("live")); Assert.IsTrue(file.WordsUnsorted.Contains("in")); Assert.IsTrue(file.WordsUnsorted.Contains("the")); Assert.IsTrue(file.WordsUnsorted.Contains("djungle")); Assert.IsTrue(file.WordsUnsorted.Contains("yesterday")); Assert.IsTrue(file.WordsUnsorted.Contains("met")); Assert.IsTrue(file.WordsUnsorted.Contains("a")); Assert.IsTrue(file.WordsUnsorted.Contains("new")); Assert.IsTrue(file.WordsUnsorted.Contains("friend")); Assert.IsTrue(file.WordsUnsorted.Contains("his")); Assert.IsTrue(file.WordsUnsorted.Contains("is")); Assert.IsTrue(file.WordsUnsorted.Contains("mowgli")); Assert.IsFalse(file.WordsUnsorted.Contains(".")); Assert.IsFalse(file.WordsUnsorted.Contains(",")); }
public static void EventMonsters(string path) { //Split information lines TxtFile.ReadFromFile(path, '\t'); //Set string info string Stringinformation = null; //Repeat for each line in the file for (int CurrentItem = 0; CurrentItem <= TxtFile.amountLine - 1; CurrentItem++) { //Create full string Stringinformation = TxtFile.lines[CurrentItem].ToString(); //Split string TxtFile.commands = Stringinformation.Split('\t'); //Read id from first row int id = Convert.ToInt32(TxtFile.commands[0]); //Add item to database Data.EventDataBase.ID.Add(id); } //Set definition for console name drop string monsters = "Monster"; //If there are more then 1 event drops if (TxtFile.amountLine > 1) { //Set string to DROPS monsters = "Monsters"; } //Write information to the console Console.WriteLine("[INFO] Loaded " + TxtFile.amountLine + " Event " + monsters + ""); }
protected void RecordCSTData(string key, List <double> list) { TxtFile t_I = new TxtFile(); try { string root = ParPathRoot.PathRoot + "软件运行记录\\RecordData\\" + key + "\\"; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } string pathDir = Log.CreateAllTimeFile(root); string path = pathDir + DateTime.Now.Hour.ToString() + "_" + DateTime.Now.Minute.ToString() + ".txt"; string name = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString(); t_I.WriteText(path, key);//写入 for (int i = 0; i < list.Count; ++i) { t_I.WriteText(path, i.ToString() + "=" + list[i].ToString());//写入 } } catch (Exception ex) { Log.L_I.WriteError(NameClass, ex); } }
private void LoadScr_Click(object sender, EventArgs e) { var Fol = new FolderBrowserDialog(); Fol.Description = @"选择脚本目录"; Fol.ShowNewFolderButton = false; Fol.ShowDialog(); if (Fol.SelectedPath != "") { Scr.Clear(); foreach (var VARIABLE in new DirectoryInfo(Fol.SelectedPath).GetFiles("*.txt")) { var cap = Name2Page(VARIABLE.Name); if (cap == -1) { continue; } var temp = new TxtFile(); temp.Name = VARIABLE.Name; temp.Cap = cap; temp.Ori = File.ReadAllLines(VARIABLE.FullName); Scr.Add(temp); } CountS.Text = Scr.Count.ToString(); } }
public void Test_SortedTextFile() { string dir = Directory.GetCurrentDirectory(); var fullpath = Path.Combine(dir, @"ExampleFiles\ValidTxtFile.txt"); //Hi my name is Baloo and i live in the djungle. Yesterday I met a new friend, his name is Mowgli. List <string> expected = new List <string> { "a", "and", "baloo", "djungle", "friend", "hi", "his", "i", "i", "in", "is", "is", "live", "met", "mowgli", "my", "name", "name", "new", "the", "yesterday" }; var actual = new TxtFile(fullpath); actual.SortWords(); Assert.AreEqual(expected, actual.WordsSorted); }
public void EqualsTest() { var relativePath = @"..\..\MockUserFiles\Draft_Environmental_Assessment.docx"; InputFile target = new DocXFile(relativePath); object obj = null; var expected = false; bool actual; actual = target.Equals(obj); Check.That(actual).IsEqualTo(expected); obj = new DocXFile(relativePath); expected = true; actual = target.Equals(obj); Check.That(actual).IsEqualTo(expected); var other = new TxtFile(@"..\..\MockUserFiles\Draft_Environmental_Assessment.txt"); expected = false; actual = target.Equals(other); InputFile other1 = new DocXFile(@"..\..\MockUserFiles\Draft_Environmental_Assessment.docx"); expected = true; actual = target.Equals(other1); var other2 = new DocXFile(@"..\..\MockUserFiles\Draft_Environmental_Assessment.docx"); expected = true; actual = target.Equals(other2); Check.That(actual).IsEqualTo(expected); }
//calcula resultado ano internal void CalculaResAno(List <PFResults> lstResultadoFluxo, string alim, string arquivo, MainWindow jan) { // obtem 1mês PFResults res1 = lstResultadoFluxo.First(); //usa variavel da classe para armazenar a soma _energyMeter = res1._energyMeter; //remove lstResultadoFluxo.Remove(res1); // obtem medidores do 2mes em diante e soma com o 1mes foreach (PFResults res in lstResultadoFluxo) { //medidor MyEnergyMeter emMes = res._energyMeter; //soma _energyMeter.Soma(emMes); } // cria string com o formato de saida das perdas string conteudo = _energyMeter.FormataResultado(alim); // grava perdas alimentador em arquivo TxtFile.GravaEmArquivo(conteudo, arquivo, jan); }
// verifica saida e grava perdas em arquivo OU alimentador que nao tenha convergido public void GravaPerdasArquivo() { //Se modo otmiza não grava arquivo if (_paramGerais._parAvan._otimizaPUSaidaSE || _paramGerais._parGUI._otmPorEnergia || _paramGerais._parGUI._otmPorDemMax) { return; } // Se alim Nao Convergiu if (!_resFluxo._convergiuBool) { //Grava a lista de alimentadores não convergentes em um txt TxtFile.GravaLstAlimNaoConvergiram(_paramGerais, _janela); } // Grava Perdas de acordo com o tipo de fluxo else { string nomeAlim = _paramGerais.GetNomeAlimAtual(); // obtem o nome do arquivo de perdas, conforme o tipo do fluxo string arquivo = _paramGerais.GetNomeArquivoPerdas(); // Grava Perdas TxtFile.GravaPerdas(_resFluxo, nomeAlim, arquivo, _janela); } }
//Plota niveis tensao nas barras dos trafos public void PlotaCargasIsoladasArq(MainWindow janela) { // se convergiu if (_circuit.Solution.Converged) { // nome alim string nomeAlim = _param.GetNomeAlimAtual(); // linha String linha = ""; // para cada key value foreach (string carga in _lstCargasIsoladas) { // evita plotagem do null em _lstCargasIsoladas if (carga == null) { break; } // TODO tratar retirada \n ultima linha linha += nomeAlim + "\t" + carga + "\n"; } TxtFile.GravaEmArquivo2(linha, _param.GetNomeArqBarraTrafoLocal(), janela); } }
public void CreatingNewTxtObj_GivenMessyTxtFile_ReadsInTheWordsCorrectly() { // Arrange/Act var file = new TxtFile(Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\MessyTxtFile.txt")); // Assert Assert.IsTrue(file.WordsUnsorted.Contains("all")); Assert.IsTrue(file.WordsUnsorted.Contains("an")); Assert.IsTrue(file.WordsUnsorted.Contains("and")); Assert.IsTrue(file.WordsUnsorted.Contains("awefull")); Assert.IsTrue(file.WordsUnsorted.Contains("be")); Assert.IsTrue(file.WordsUnsorted.Contains("crap")); Assert.IsTrue(file.WordsUnsorted.Contains("crappy")); Assert.IsTrue(file.WordsUnsorted.Contains("gonna")); Assert.IsTrue(file.WordsUnsorted.Contains("is")); Assert.IsTrue(file.WordsUnsorted.Contains("lots")); Assert.IsTrue(file.WordsUnsorted.Contains("mohahahaha")); Assert.IsTrue(file.WordsUnsorted.Contains("of")); Assert.IsTrue(file.WordsUnsorted.Contains("over")); Assert.IsTrue(file.WordsUnsorted.Contains("place")); Assert.IsTrue(file.WordsUnsorted.Contains("spaces")); Assert.IsTrue(file.WordsUnsorted.Contains("tabs")); Assert.IsTrue(file.WordsUnsorted.Contains("text")); Assert.IsTrue(file.WordsUnsorted.Contains("the")); Assert.IsTrue(file.WordsUnsorted.Contains("this")); Assert.IsTrue(file.WordsUnsorted.Contains("with")); }
public void SetupTest() { var databaseOperations = new DatabaseOperationsRepository(DbFile.GetConnectionString("testdb.db")); databaseOperations.CreateAndInitialize(DbFile.GetPath("testdb.db"), TxtFile.ReadText("RebuildDatabase.txt")); }
public void LoadTextTest() { var target = new TxtFile(ValidTxtFilePath); var expected = new StreamReader(ValidTxtFilePath).ReadToEnd(); var actual = target.LoadText(); Check.That(actual).IsEqualTo(expected); }
public async Task LoadTextAsyncTest() { var target = new TxtFile(ValidTxtFilePath); var expected = await new StreamReader(target.FullPath).ReadToEndAsync(); var actual = await target.LoadTextAsync(); Check.That(actual).IsEqualTo(expected); }
public void Search_WordIsNotInFile_ReturnsRightOccurance() { // Arrange var file = new TxtFile(Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt")); // Assert Assert.AreEqual(0, file.Search("kuckeliku")); }
public void TestSaveASSorted() { string dir = Directory.GetCurrentDirectory(); var fullpath = Path.Combine(dir, @"ExampleFiles\ValidTxtFile.txt"); var result = new TxtFile(fullpath); result.SortWords(); result.SaveSortedFile(); }
public void TextFileConstructorTest() { var target = new TxtFile(ValidTxtFilePath); var fileInfo = new FileInfo(ValidTxtFilePath); Check.That(fileInfo.FullName).IsEqualTo(target.FullPath); Check.That(fileInfo.Name).IsEqualTo(target.FileName); Check.That(fileInfo.Extension).IsEqualTo(target.Extension); }
public void SaveTxtFile(string path, string content) { var textFile = new TxtFile(path, content); var updateOK = _dataRepo.Upadate(textFile); if (updateOK) { Invoke(() => _view.ShowMessageBox("Update Success")); } }
public void NameSansExtTest() { var relativePath = @"..\..\MockUserFiles\Draft_Environmental_Assessment.txt"; InputFile target = new TxtFile(relativePath); var expected = "Draft_Environmental_Assessment"; string actual; actual = target.Name; Check.That(actual).IsEqualTo(expected); }
public void btnCreateFilesSync() { Stopwatch Timer = new Stopwatch(); Timer.Start(); TxtFile.CreateFilesSync(7000); this.AdicionarMensagemStatus(Timer.ElapsedMilliseconds.ToString()); Timer.Stop(); }
public void SaveSortedFile_DoesSaveFile() { var fullpath = Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt"); var result = new TxtFile(fullpath); result.SortWords(); result.SaveSortedFile(); bool fileExist = File.Exists(Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile_SortedWords.txt")); Assert.IsTrue(fileExist); }
public void ScriptExamples_OptionInput_Parsed_IsNotAPlaceholder() { string scriptText = TxtFile.ReadText("OptionBox.txt"); ICompiler compiler = new Compiler(); compiler.Compile(scriptText); IInputField inputField = compiler.InputFields[0]; Assert.IsFalse(inputField.IsPlaceholder); }
public void ScriptExamples_CreateMultilineScriptInExpression_OutputsCorrectly() { ICompiler compiler = new Compiler(); compiler.Compile(TxtFile.ReadText("MultiLine.txt")); IGenerator generator = new Generator(); string output = generator.Generate(compiler, TxtFile.ReadText("MultiLine.tpl")); Assert.AreEqual(TxtFile.ReadText("MultiLine.out"), output); }
public void NewTextFile(string path, string content) { TryFlow(() => { var textFile = new TxtFile(path, content); var createOK = _dataRepo.Create(textFile); if (createOK) { Invoke(() => _view.ShowMessageBox("Create Success")); } }); }
// Cria arquivo texto cabecalho DRP DRC public static void CriaArqCabecalho(GeneralParameters paramGerais, MainWindow janela) { // string nomeArq = paramGerais.GetNomeComp_arquivoDRPDRC(); //Grava cabecalho string linha = "Alim\tF.A.\tDRP:\tDRC:\tTotal:"; //Grava em arquivo TxtFile.GravaEmArquivo(linha, nomeArq, janela); }
private static void Main() { var name = "Test"; var folder = "C:/Temp"; using (var file = new TxtFile(name, folder)) { Console.WriteLine(file.FullPath); } Console.ReadKey(); }
public void CreatingNewTxtObj_GivenRegularTxtFile_ReadsInTheCorrectNumOfWords() { //Arrange var fullpath = Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt"); int numWords = 21; //Act var sut = new TxtFile(fullpath); //Assert Assert.AreEqual(numWords, sut.WordsUnsorted.Count); }
public void SortWords__SameNumberOfWordsInSortedWordsAndUnsortedWords() { //Arrange var fullpath = Path.Combine(Directory.GetCurrentDirectory(), @"ExampleFiles\ValidTxtFile.txt"); var sut = new TxtFile(fullpath); //Act sut.SortWords(); //Assert Assert.AreEqual(sut.WordsSorted.Count, sut.WordsUnsorted.Count); }
// TODO refactory private void QueryLineCode(Circuit dssCircuit) { List <string> lstCabos = new List <string> { "CAB102", "CAB103", "CAB104", "CAB107", "CAB108", "CAB202", "CAB203", "CAB204", "CAB207", "CAB208", "CABA06", "CABA08", "CAB2021", "CAB1031", "CAB1021", "CAB2031", "CABA061", "CABBT106", "CABBT107", "CABBT108", "CABBT803", "CABBT805", "CABBT809", "CABBT810", "CABBT801", "CABBT807", "CABBT808" }; Text textDSS = _oDSS._DSSObj.Text; List <string> resRmatrix = new List <string>(); List <string> resXmatrix = new List <string>(); foreach (string lineCode in lstCabos) { textDSS.Command = "? LineCode." + lineCode + ".Rmatrix"; resRmatrix.Add(lineCode + "\tRmatrix=" + textDSS.Result); textDSS.Command = "? LineCode." + lineCode + ".Xmatrix"; resXmatrix.Add("\tXmatrix=" + textDSS.Result); } TxtFile.GravaListArquivoTXT(resRmatrix, _paramGerais.GetArqRmatrix(), _janela); TxtFile.GravaListArquivoTXT(resXmatrix, _paramGerais.GetArqXmatrix(), _janela); }