public void Range() { var log = new[] { "2018-09-09 23:58:35,66023314,0", "2018-09-10 08:08:31,66023314,0", "2018-09-10 11:03:01,66024154,0" }; var processor = new LogProcessor(); Func <DateTime, DateTime, IEnumerable <string> > rangeProcessor = (from, to) => processor.Process(log, "戦果.csv", from, to, false); PAssert.That( () => rangeProcessor(DateTime.MinValue, DateTime.MaxValue).SequenceEqual(new[] { "[\"2018-09-09 23:58:35\",\"66023314\",\"0\"]", ",\n[\"2018-09-10 08:08:31\",\"66023314\",\"0\"]", ",\n[\"2018-09-10 11:03:01\",\"66024154\",\"0\"]" })); PAssert.That( () => rangeProcessor(DateTime.MinValue, new DateTime(2018, 9, 10)).SequenceEqual(new[] { "[\"2018-09-09 23:58:35\",\"66023314\",\"0\"]" } )); PAssert.That( () => rangeProcessor(new DateTime(2018, 9, 10), DateTime.MaxValue).SequenceEqual(new[] { "[\"2018-09-10 08:08:31\",\"66023314\",\"0\"]", ",\n[\"2018-09-10 11:03:01\",\"66024154\",\"0\"]" })); PAssert.That( () => rangeProcessor(new DateTime(2018, 9, 10), new DateTime(2018, 9, 10, 11, 0, 0)).SequenceEqual(new[] { "[\"2018-09-10 08:08:31\",\"66023314\",\"0\"]" })); }
public void ProcessFile() { int retries = 0; retryOpeningLogfile: retries++; if (retries > 1) { if (retries == 4) { if (!File.Exists(fileToProcess)) { ReportUserError("File doesn't exist."); } else if (new FileInfo(fileToProcess).Length == 0) { ReportUserError("File is empty."); } else { ReportUserError("Failed to open/read file."); } } Thread.Sleep(500); } var header = ReadHeader(fileToProcess); if (header == null) { goto retryOpeningLogfile; } TcpPort = header.Port; var cancellationToken = cts.Token; try { using (fileStream = new FileStream(fileToProcess, FileMode.Open, FileAccess.Read, FileShare.Read)) { var processor = new LogProcessor(fileStream, new KrofilerLogEventVisitor(this)); processor.Process(cancellation, runner != null); } if (cancellation.IsCancellationRequested) { completionSource.SetCanceled(); } else { completionSource.SetResult(true); } } catch (Exception e) { if (cancellation.IsCancellationRequested) { completionSource.SetCanceled(); } else { completionSource.SetException(e); } } Finished?.Invoke(this); }
private void ProcessFile() { try { //Give runtime 10 seconds to create .mlpd for (int i = 0; i < 100; i++) { if (File.Exists(Options.MlpdOutputPath)) { break; } Thread.Sleep(100); } using (var fs = new FileStream(Options.MlpdOutputPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var logStream = new NeverEndingLogStream(fs, cts.Token)) { processor = new LogProcessor(logStream, null, visitor); processor.Process(cts.Token); } } catch (OperationCanceledException) { } catch (Exception ex) { Console.WriteLine(ex); } }
public void MaterialLogInNumberType() { var processor = new LogProcessor(); var log = "2018-09-10 20:36:34,294892,296784,259518,294588,2484,2975,2550,3"; var result = processor.Process(new[] { log }, "資材ログ.csv", DateTime.MinValue, DateTime.MaxValue, true) .ToArray(); PAssert.That(() => result.Length == 1, "現在値の出力なし"); PAssert.That(() => result[0] == "[1536579394000,294892,296784,259518,294588,2484,2975,2550,3]"); }
public void EnseiLog() { var processor = new LogProcessor(); var log = new[] { "2018-09-10 17:45:09,大成功,北方鼠輸送作戦,589,498,0,0,0,0,0", "2018-09-10 17:53:34,成功,長距離練習航海,0,117,34,0,0,1,0" }; var result = processor.Process(log, "遠征報告書.csv", DateTime.MinValue, DateTime.MaxValue, false); PAssert.That(() => result.SequenceEqual(new[] { "[\"2018-09-10 17:45:09\",\"大成功\",\"北方鼠輸送作戦\",\"589\",\"498\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]", ",\n[\"2018-09-10 17:53:34\",\"成功\",\"長距離練習航海\",\"0\",\"117\",\"34\",\"0\",\"0\",\"1\",\"0\",\"0\"]" })); }
public void BattleLogWithComma() { var processor = new LogProcessor(); var log = new[] { "2020-09-27 19:49:04,ペナン島沖,4,,S,同航戦,単縦陣,梯形陣,深海5,500t級軽巡洋艦,駆逐艦,神風," + "羽黒改二(Lv159),64/64,足柄改二(Lv159),60/63,神風改(Lv99),23/23,島風改(Lv158),41/41,Gotland andra(Lv136),53/53,,," + "軽巡ホ級(flagship),0/53,駆逐ロ級後期型,0/37,駆逐ロ級後期型,0/37,,,,,,,9,0,制空権確保,7-3", }; var result = processor.Process(log, "海戦・ドロップ報告書.csv", DateTime.MinValue, DateTime.MaxValue, false); PAssert.That(() => result.First() == "[\"2020-09-27 19:49:04\",\"ペナン島沖\",\"4\",\"\",\"S\",\"同航戦\",\"単縦陣\",\"梯形陣\",\"深海5,500t級軽巡洋艦\",\"駆逐艦\",\"神風\"," + "\"羽黒改二(Lv159)\",\"64/64\",\"足柄改二(Lv159)\",\"60/63\",\"神風改(Lv99)\",\"23/23\",\"島風改(Lv158)\",\"41/41\",\"Gotland andra(Lv136)\",\"53/53\",\"\",\"\"," + "\"軽巡ホ級(flagship)\",\"0/53\",\"駆逐ロ級後期型\",\"0/37\",\"駆逐ロ級後期型\",\"0/37\",\"\",\"\",\"\",\"\",\"\",\"\",\"9\",\"0\",\"確保\",\"\",\"\",\"7-3\"]"); }
public void BattleLog() { var processor = new LogProcessor(null, new Dictionary <string, string> { { "鎮守府正面海域", "1-1" } }); var log = new[] { "2018-09-08 11:28:01,鎮守府正面海域,3,ボス,A,同航戦,単縦陣,単縦陣,敵主力艦隊,駆逐艦,雷,浜波改(Lv78),32/32,涼風(Lv10),3/16,,,,,,,,,軽巡ホ級,0/33,駆逐イ級,0/20,駆逐イ級,7/20,,,,,,,0,0," }; var result = processor.Process(log, "海戦・ドロップ報告書.csv", DateTime.MinValue, DateTime.MaxValue, false); PAssert.That(() => result.First() == "[\"2018-09-08 11:28:01\",\"鎮守府正面海域\",\"3\",\"ボス\",\"A\",\"同航戦\",\"単縦陣\",\"単縦陣\",\"敵主力艦隊\",\"駆逐艦\",\"雷\"," + "\"浜波改(Lv78)\",\"32/32\",\"涼風(Lv10)\",\"3/16\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"," + "\"軽巡ホ級\",\"0/33\",\"駆逐イ級\",\"0/20\",\"駆逐イ級\",\"7/20\",\"\",\"\",\"\",\"\",\"\",\"\",\"0\",\"0\",\"\",\"涼風(Lv10)\",\"\",\"1-1\"]"); }
public void TruncatedLog() { var processor = new LogProcessor(); var logs = new[] { "2014-12-15 23:10:34,29734,29855,28016,41440,1407,1529,2151,13", "2014-12-15 23:13:29,29709,29819,28019,41440,1407,1529,21", "2014-12-15 23:16:06,29710,29819,28018,41440,1407,1529,2151,13" }; var result = processor.Process(logs, "資材ログ", DateTime.MinValue, DateTime.MaxValue, true); PAssert.That(() => result.SequenceEqual(new[] { "[1418652634000,29734,29855,28016,41440,1407,1529,2151,13]", ",\n[1418652966000,29710,29819,28018,41440,1407,1529,2151,13]" })); }
static LogStreamHeader TryReadHeader(string mldpFilePath) { try { using (var s = File.OpenRead(mldpFilePath)) { var visitor = new HeadReaderLogEventVisitor(); var processor = new LogProcessor(s, visitor, null); try { processor.Process(visitor.TokenSource.Token); } catch { } return(processor.StreamHeader); } } catch { return(null); } }
public void DateFormat() { var processor = new LogProcessor(); var body = ",大型艦建造,まるゆ,潜水艦,1500,1500,2000,1000,1,0,瑞鶴改二甲(163),120"; var expected = ",\"大型艦建造\",\"まるゆ\",\"潜水艦\",\"1500\",\"1500\",\"2000\",\"1000\",\"1\",\"0\",\"瑞鶴改二甲(163)\",\"120\"]"; Func <string, string> dateProcessor = date => processor.Process(new[] { date + body }, "建造報告書", DateTime.MinValue, DateTime.MaxValue, false) .First(); var era = "30-09-10 20:13:39"; PAssert.That(() => "[\"2018-09-10 20:13:39\"" + expected == dateProcessor(era), "和暦を西暦に直す"); var excel = "2018/9/10 20:13"; PAssert.That(() => "[\"2018-09-10 20:13:00\"" + expected == dateProcessor(excel), "Excelの形式から変換する"); }
public void MaterialLogWithCurrentRecord() { var processor = new LogProcessor(new[] { new MaterialCount { Now = 2001 }, new MaterialCount { Now = 2002 }, new MaterialCount { Now = 2003 }, new MaterialCount { Now = 2004 }, new MaterialCount { Now = 201 }, new MaterialCount { Now = 202 }, new MaterialCount { Now = 203 }, new MaterialCount { Now = 100 } }); var now = new DateTime(2018, 1, 1); var log = "2018-09-10 20:36:34,294892,296784,259518,294588,2484,2975,2550,3"; var result = processor.Process(new[] { log }, "資材ログ.csv", DateTime.MinValue, DateTime.MaxValue, false, now) .ToArray(); PAssert.That(() => result[0] == "[\"2018-09-10 20:36:34\",\"294892\",\"296784\",\"259518\",\"294588\",\"2484\",\"2975\",\"2550\",\"3\"]"); var date = Logger.FormatDateTime(now); PAssert.That(() => result[1] == $",\n[\"{date}\",\"2001\",\"2002\",\"2003\",\"2004\",\"201\",\"202\",\"203\",\"100\"]", "現在値"); }