Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/01-basic/report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 01-basic 问答题报告

## Q1.1

**(1)** CsvReader 自动按逗号拆解 CSV,LogRecordMap 里的 Index(0)-Index(3)
指定了第 0 列到第 3 列分别对应 LineNo、Timestamp、PodName、Message。

**(2)** 在 LineParser.ParseLine 方法中,先用 JsonDocument.Parse 解析 JSON,
然后通过 root.TryGetProperty("event", ...) 取出 event 字段,
再用 switch 表达式匹配 "call"、"request"、"internal" 来判断日志种类。

**(3)** 使用 JsonSerializer.Deserialize<XxxMessage>() 解析 JSON。
通过 [JsonRequired] 特性防止字段缺失,缺字段时自动抛 JsonException。
通过 JsonNamingPolicy.KebabCaseLower 将烤串命名自动转换为大驼峰命名。
## Q1.2
第一步: KeyValueVisitor.Dump(LogEntry entry) 被调用,里面只有一行:

return entry.Accept(this); // this 是 KeyValueVisitor 自己

第二步: entry 实际是 CallLogEntry,所以走 CallLogEntry.Accept:

return visitor.Visit(this); // this 是 CallLogEntry,visitor 是
KeyValueVisitor

第三步: this 是 CallLogEntry,C# 自动匹配到
KeyValueVisitor.Visit(CallLogEntry entry),在里面构建字典并返回。
## Q1.3
使用了GLM5.2帮助我理解JSON与C#的转换。
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions docs/02-multithreading/report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 多线程实验报告

## 1. 功能介绍
本项目实现了一个多线程日志解析器和简易交互界面:
- **InputDirectory**: 输入目录路径,加载日志文件。
- **ShowLogFiles**: 查看当前目录下所有 .log 文件。
- **AnalyzeFiles**: 使用多线程并行分析指定的日志文件。
- **AnalyzeAll**: 一键分析目录下的所有文件。
- **GetAnalysisResult**: 查看特定文件的分析结果,支持状态分类显示。
- **异常处理**: 程序实现了完善的 try-catch 机制,即使输入非法路径或文件名,程序依然稳定运行。

## 2. 运行截图

![功能截图](assets/ScreenShot_2026-08-21_154541_552.png)
![鲁棒性测试](assets/ScreenShot_2026-08-21_154638_202.png)

## 3. 问答题

### Q2.1 临界区理解
**① 共享变量及保护:**
- WorkQueue: _items (Queue) 和 _isCompleted (bool),通过 `lock(_items)` 保护。
- LogFileAnalyzer: _currentDirectory, _isAnalyzing, _logFiles, _analysisResults,通过 `lock(_syncRoot)` 保护。

**② 为什么用 while 而不是 if:**
因为“虚假唤醒”和“多线程竞争”。被唤醒后,可能货物已经被其他线程抢走。使用 while 循环可以确保线程在醒来后再次检查仓库是否真的有货,从而避免从空仓库取货引发崩溃。

### Q2.2 代码框架
**① 如何扫描文件:**
在 `ChangeDirectory` 方法中使用 `Directory.EnumerateFiles` 扫描。

**② 如何递归扫描:**
将 `SearchOption.TopDirectoryOnly` 修改为 `SearchOption.AllDirectories` 即可。

### Q2.3 AI 使用情况
我使用了 AI 辅助编程。AI 主要帮助我理解了多线程中 `Monitor.Wait` 和 `Pulse` 的协同工作逻辑,并协助我修复了 NuGet 包还原和 C# 语法兼容性问题。

---
283 changes: 283 additions & 0 deletions docs/03-async-grpc/report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
# 异步与 gRPC 实验报告

## 1. 功能介绍

本项目实现了一个基于 gRPC 的远程日志分析系统,包含:
- **LogAnalyzerAgent**:常驻运行的服务端,对外提供 gRPC 服务(Ping、GetAgentStatus、ChangeDirectory、GetLogFiles、AnalyzeAll、AnalyzeFiles、GetAnalysisResult 流式返回)
- **RemoteCli**:远程控制台客户端,全部使用 `async/await` 异步调用 gRPC 接口
- **GrpcTypeConverter / GrpcLogEntryVisitor**:内部 C# 类型与 Protobuf 消息类型的双向转换,访问者模式 + 单例模式

## 2. 运行截图

### 完整功能


Dell@DESKTOP-0GJFVEM MINGW64 ~
$ cd /d/dotnet-workshop && dotnet run --project src/RemoteCli
Connecting to agent at http://localhost:5000...

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 5
Please input directory containing log files:
D:\dotnet-workshop\src\dataset

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 1
Log files:
- basic-fail.log
- basic-multiple.log
- basic.log

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 1
Log files:
- basic-fail.log
- basic-multiple.log
- basic.log

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 1
Log files:
- basic-fail.log
- basic-multiple.log
- basic.log

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 1
Log files:
- basic-fail.log
- basic-multiple.log
- basic.log

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>>
Invalid input, please try again.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>>
Invalid input, please try again.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>>
Invalid input, please try again.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>>
Invalid input, please try again.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>>
Invalid input, please try again.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>>
Invalid input, please try again.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> D:\dotnet-workshop\src\dataset
Invalid input, please try again.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 1
Log files:
- basic-fail.log
- basic-multiple.log
- basic.log

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 2
Please input degree of parallelism (0 for processor count):
4
Please input file names separated by comma (e.g. log1.log,log2.log):
basic.log
Analysis finished.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 4
Please input file name:
basic.log
File: basic.log
State: Succeeded
LineNo: 0
Timestamp: 2026-06-05T16:00:29.0450000+00:00
PodName: userservice-0
Severity: Info
EventType: Call
RequestId: 3a013a08-6853-49fc-8f06-50daeb5c1e51
TargetService: authservice
DurationMs: 18

LineNo: 1
Timestamp: 2026-06-05T16:00:31.0860000+00:00
PodName: userservice-1
Severity: Info
EventType: Request
RequestId: 1177c344-115e-4f85-b8ec-c9164d132b79
Method: GET
Path: /api/user/john
StatusCode: 404

LineNo: 2
Timestamp: 2026-06-05T16:05:45.3220000+00:00
PodName: gateway-0
Severity: Error
EventType: Internal
ExceptionName: System.InvalidOperationException
ExceptionMessage: Failed to load gateway routing configuration.


Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 3
Please input degree of parallelism (0 for processor count):
4
All files analysis finished.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 4
Please input file name:
basic-fail.log
File: basic-fail.log
State: Failed
Analysis failed: JSON deserialization for type 'LogParser.Parser.LineParser+RequestMessage' was missing required properties including: 'method'.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>>


### 鲁棒性测试

>>> abc
Invalid input, please try again.

Please choose:
1. Show log files.
2. Analyze specified log files.
3. Analyze all log files.
4. Get log file analysis result.
5. Change directory.
6. Exit.
>>> 5
Please input directory containing log files:
C:\nope
Error: DirectoryNotFound: Directory not found: C:\nope, please try again:
Please input directory containing log files:



## 3. 问答题

### Q3.1 网络应用开发与非网络应用的区别

网络应用开发需要注意用户端的请求,可以关注到,和以往的并行开发应用不同,这一部分需要使用到异步开发来解放CPU的性能,充分发挥所有功能的

### Q3.2 AI 使用情况


Loading
Loading