Skip to content

Commit

Permalink
Merge pull request #20 from NaroZeol/work
Browse files Browse the repository at this point in the history
修复服务器连接异常时会造成的诸多问题,优化程序逻辑,框架更新为.net8.0
  • Loading branch information
NaroZeol authored Jan 17, 2024
2 parents 5fc21d9 + 93f9c5a commit b839fd6
Show file tree
Hide file tree
Showing 20 changed files with 535 additions and 103 deletions.
497 changes: 484 additions & 13 deletions .gitignore

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
从西南交通大学官方网站获取通知,目前实现对教务网,计院官网,扬华素质网的支持。

目前主要维护.net 8.0版本,随缘更新Framework 4.8版本
11 changes: 0 additions & 11 deletions dotnet7.0/Program/Program.csproj.user

This file was deleted.

18 changes: 0 additions & 18 deletions dotnet7.0/Program/Properties/PublishProfiles/FolderProfile.pubxml

This file was deleted.

This file was deleted.

Binary file removed dotnet7.0/Program/Resources/icon/Normal.ico
Binary file not shown.
Binary file removed dotnet7.0/Program/Resources/icon/OnNotify.ico
Binary file not shown.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ private static string GetFileContent(string fileName)
FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
string ret = FileData.ReadFromFile(fileStream);
fileStream.Close();
ret = ret.Insert(0, "获取失败,请检查网络连接\n");
return ret;
}

public async static Task<string> GetNoticeFromJWCAsync()
public async static Task<(bool success, string text)> GetNoticeFromJWCAsync()
{
HtmlWeb web = new();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
HtmlAgilityPack.HtmlDocument doc;
try
{
doc = await web.LoadFromWebAsync("http://jwc.swjtu.edu.cn/vatuu/WebAction?setAction=newsList");
}
catch (Exception e) when (e is System.Net.Http.HttpRequestException || e is System.Net.Sockets.SocketException)
{
return GetFileContent("JWC.txt");
return (false, GetFileContent("JWC.txt"));
}
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@class='littleResultDiv']");

if (nodes == null){
return GetFileContent("JWC.txt");

if (nodes == null)
{
return (false, GetFileContent("JWC.txt"));
}

string baseUrl = "http://jwc.swjtu.edu.cn/";
Expand All @@ -38,44 +40,39 @@ public async static Task<string> GetNoticeFromJWCAsync()
string title = node.SelectSingleNode(".//a").InnerText;
result += "标题: " + title + "\n";
result += "链接: " + baseUrl + link[3..] + "\n";
result += "\n";
result += "\n";
}

return result;
return (true, result);
}
public async static Task<string> GetNoticeFromSCAIAsync()
public async static Task<(bool success, string text)> GetNoticeFromSCAIAsync()
{
HtmlWeb web = new();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
HtmlAgilityPack.HtmlDocument doc;
try
{
doc = await web.LoadFromWebAsync("https://scai.swjtu.edu.cn/web/page-module.html?mid=B730BEB095B31840&tid=350");
}
catch (Exception e) when (e is System.Net.Http.HttpRequestException || e is System.Net.Sockets.SocketException)
{
return GetFileContent("SCAI.txt");
return (false, GetFileContent("SCAI.txt"));
}
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@class='list-top-item fl']");
HtmlNodeCollection nodes1 = doc.DocumentNode.SelectNodes("//div[@class='list-top-item fr']");
nodes.Append(nodes1[0]);

HtmlNodeCollection normalNotice = doc.DocumentNode.SelectNodes("//div[@class='info-wrapper fl']");
HtmlNodeCollection? nodes = doc.DocumentNode.SelectNodes("//div[@class='list-top-item fl']");
HtmlNodeCollection? nodes1 = doc.DocumentNode.SelectNodes("//div[@class='list-top-item fr']");
HtmlNodeCollection? normalNotice = doc.DocumentNode.SelectNodes("//div[@class='info-wrapper fl']");

if (normalNotice == null)
if (nodes == null || nodes1 == null || normalNotice == null)
{
return GetFileContent("SCAI.txt");
return (false, GetFileContent("SCAI.txt"));
}

nodes.Append(nodes1[0]);

foreach (HtmlNode node in normalNotice)
{
nodes.Add(node);
}

if (nodes == null)
{
return GetFileContent("SCAI.txt");
}

string baseUrl = "https://scai.swjtu.edu.cn/";

string result = "";
Expand All @@ -89,30 +86,27 @@ public async static Task<string> GetNoticeFromSCAIAsync()
result += "\n";
}

return result;
return (true, result);
}

public async static Task<string> GetNoticeFromXGBAsync()
public async static Task<(bool success, string text)> GetNoticeFromXGBAsync()
{
HtmlWeb web = new();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
HtmlAgilityPack.HtmlDocument doc;
try
{
doc = await web.LoadFromWebAsync("http://xg.swjtu.edu.cn/web/Home/PushNewsList?Lmk7LJw34Jmu=010j.shtml");
}
catch (Exception e) when (e is System.Net.Http.HttpRequestException || e is System.Net.Sockets.SocketException)
{
FileStream fileStream = new FileStream("XGB.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
string ret = FileData.ReadFromFile(fileStream);
fileStream.Close();
return ret;
return (false, GetFileContent("XGB.txt"));
}

HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@class='right-side']//ul[@class='block-ctxlist']//li");

if (nodes == null)
{
return GetFileContent("XGB.txt");
return (false, GetFileContent("XGB.txt"));
}

string baseUrl = "http://xg.swjtu.edu.cn/";
Expand All @@ -127,7 +121,7 @@ public async static Task<string> GetNoticeFromXGBAsync()
result += "\n";
}

return result;
return (true, result);
}

}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private async void Button1_Click(object sender, EventArgs e)
this.ActiveControl = null;
string LoadingSymbol = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
int i = 0;
Task<string> task = GetNotice.GetNoticeFromJWCAsync();
Task<(bool success, string text)> task = GetNotice.GetNoticeFromJWCAsync();

while (!task.IsCompleted)
{
Expand All @@ -38,15 +38,16 @@ private async void Button1_Click(object sender, EventArgs e)
FileStream file = new("JWC.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);

string oldText = FileData.ReadFromFile(file);
string diff = FileData.CheckDiff(task.Result, oldText);
string diff = FileData.CheckDiff(task.Result.text, oldText);

richTextBox1.Clear();
richTextBox1.AppendTextColorful(diff, Color.Red, 2);
richTextBox1.AppendTextColorful(oldText, Color.Black, 1);
richTextBox1.SelectionStart = 0;
richTextBox1.ScrollToCaret();

FileData.WriteToFile(task.Result, file);
if (task.Result.success == true)
FileData.WriteToFile(task.Result.text, file);
file.Close();

button1.Text = "教务处";
Expand All @@ -60,7 +61,7 @@ private async void Button2_Click(object sender, EventArgs e)
this.ActiveControl = null;
string LoadingSymbol = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
int i = 0;
Task<string> task = GetNotice.GetNoticeFromSCAIAsync();
Task<(bool success, string text)> task = GetNotice.GetNoticeFromSCAIAsync();

while (!task.IsCompleted)
{
Expand All @@ -70,15 +71,16 @@ private async void Button2_Click(object sender, EventArgs e)
FileStream file = new("SCAI.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);

string oldText = FileData.ReadFromFile(file);
string diff = FileData.CheckDiff(task.Result, oldText);
string diff = FileData.CheckDiff(task.Result.text, oldText);

richTextBox1.Clear();
richTextBox1.AppendTextColorful(diff, Color.Red, 2);
richTextBox1.AppendTextColorful(oldText, Color.Black, 1);
richTextBox1.SelectionStart = 0;
richTextBox1.ScrollToCaret();

FileData.WriteToFile(task.Result, file);
if (task.Result.success == true)
FileData.WriteToFile(task.Result.text, file);
file.Close();

button2.Text = "计院";
Expand All @@ -92,7 +94,7 @@ private async void button3_Click(object sender, EventArgs e)
this.ActiveControl = null;
string LoadingSymbol = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
int i = 0;
Task<string> task = GetNotice.GetNoticeFromXGBAsync();
Task<(bool success, string text)> task = GetNotice.GetNoticeFromXGBAsync();

while (!task.IsCompleted)
{
Expand All @@ -102,15 +104,16 @@ private async void button3_Click(object sender, EventArgs e)
FileStream file = new("XGB.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);

string oldText = FileData.ReadFromFile(file);
string diff = FileData.CheckDiff(task.Result, oldText);
string diff = FileData.CheckDiff(task.Result.text, oldText);

richTextBox1.Clear();
richTextBox1.AppendTextColorful(diff, Color.Red, 2);
richTextBox1.AppendTextColorful(oldText, Color.Black, 1);
richTextBox1.SelectionStart = 0;
richTextBox1.ScrollToCaret();

FileData.WriteToFile(task.Result, file);
if (task.Result.success == true)
FileData.WriteToFile(task.Result.text, file);
file.Close();

button3.Text = "学工部";
Expand Down Expand Up @@ -192,17 +195,18 @@ private void OpenWindowMenuBottom_Click(object sender, EventArgs e)

private async void TimerOfAutoRunning_Tick(object sender, EventArgs e)
{
if (global::Program.Utilities.CheckNetwork.IsNetworkConnected == false)
Task<(bool success, string text)> task1 = GetNotice.GetNoticeFromJWCAsync();
Task<(bool success, string text)> task2 = GetNotice.GetNoticeFromSCAIAsync();
Task<(bool success, string text)> task3 = GetNotice.GetNoticeFromXGBAsync();

await Task.WhenAll(task1, task2, task3);

if (task1.Result.success == false || task2.Result.success == false || task3.Result.success == false)
{
timerOfFlashingButton.Enabled = false;
NoticeIcon.Icon = icon1;
return;
}
Task<string> task1 = GetNotice.GetNoticeFromJWCAsync();
Task<string> task2 = GetNotice.GetNoticeFromSCAIAsync();
Task<string> task3 = GetNotice.GetNoticeFromXGBAsync();

await Task.WhenAll(task1, task2, task3);

FileStream file1 = new("JWC.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
FileStream file2 = new("SCAI.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
Expand All @@ -212,9 +216,9 @@ private async void TimerOfAutoRunning_Tick(object sender, EventArgs e)
string oldText2 = FileData.ReadFromFile(file2);
string oldText3 = FileData.ReadFromFile(file3);

string diff1 = FileData.CheckDiff(task1.Result, oldText1);
string diff2 = FileData.CheckDiff(task2.Result, oldText2);
string diff3 = FileData.CheckDiff(task3.Result, oldText3);
string diff1 = FileData.CheckDiff(task1.Result.text, oldText1);
string diff2 = FileData.CheckDiff(task2.Result.text, oldText2);
string diff3 = FileData.CheckDiff(task3.Result.text, oldText3);

if (diff1.Length > 0 || diff2.Length > 0 || diff3.Length > 0)
{
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit b839fd6

Please sign in to comment.