Skip to content

Commit

Permalink
1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
melancn committed Jun 12, 2020
1 parent 4673d48 commit c5862c3
Show file tree
Hide file tree
Showing 13 changed files with 693 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Watching.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Watching", "Watching\Watching.csproj", "{6F88B1EC-2857-4A1E-9F02-F22CFFBC1557}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6F88B1EC-2857-4A1E-9F02-F22CFFBC1557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F88B1EC-2857-4A1E-9F02-F22CFFBC1557}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F88B1EC-2857-4A1E-9F02-F22CFFBC1557}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F88B1EC-2857-4A1E-9F02-F22CFFBC1557}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {711CCFD4-D6AB-4EDE-A7AC-BC8525744AC5}
EndGlobalSection
EndGlobal
Binary file added Watching/20200610043023979_easyicon_net_512.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions Watching/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
9 changes: 9 additions & 0 deletions Watching/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="Watching.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Watching"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions Watching/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace Watching
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
}
}
28 changes: 28 additions & 0 deletions Watching/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Window x:Class="Watching.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Watching"
mc:Ignorable="d"
Title="监控" Height="350" Width="525" Icon="20200610043023979_easyicon_net_512.ico" ResizeMode="CanMinimize" StateChanged="Window_StateChanged" Closed="Window_Closed" Closing="Window_Closing">
<Grid>
<TextBox x:Name="title" HorizontalAlignment="Left" Height="23" Margin="106,10,0,0" TextWrapping="Wrap" Text="DIY卡免还款签账额20元" VerticalAlignment="Top" Width="377" VerticalContentAlignment="Center"/>
<TextBox x:Name="content" HorizontalAlignment="Left" Height="23" Margin="106,44,0,0" TextWrapping="Wrap" Text="有货" VerticalAlignment="Top" Width="377" VerticalContentAlignment="Center"/>
<TextBox x:Name="alert_times" HorizontalAlignment="Left" Height="23" Margin="106,79,0,0" TextWrapping="Wrap" Text="10" VerticalAlignment="Top" Width="377" VerticalContentAlignment="Center"/>
<TextBox x:Name="interval_time" HorizontalAlignment="Left" Height="23" Margin="106,115,0,0" TextWrapping="Wrap" Text="35000" VerticalAlignment="Top" Width="377" VerticalContentAlignment="Center"/>
<TextBox x:Name="url" HorizontalAlignment="Left" Height="50" Margin="106,156,0,0" TextWrapping="Wrap" Text="https://shop.cgbchina.com.cn/mall/goods/03140714143403208122?itemCode=03140714143403208122" VerticalAlignment="Top" Width="377"/>
<Button x:Name="start" Content="开始" HorizontalAlignment="Left" Margin="19,280,0,0" VerticalAlignment="Top" Width="92" Height="24" Click="start_Click"/>
<TextBox x:Name="url_pattern" HorizontalAlignment="Left" Height="50" Margin="106,211,0,0" TextWrapping="Wrap" Text="stock-zero" VerticalAlignment="Top" Width="377"/>
<CheckBox x:Name="is_include" Content="是否包含" HorizontalAlignment="Left" Margin="10,241,0,0" VerticalAlignment="Top"/>
<Button x:Name="stop_btn" Content="停止" HorizontalAlignment="Left" Margin="147,280,0,0" VerticalAlignment="Top" Width="86" Height="24" Click="stop_btn_Click"/>
<TextBlock x:Name="status" HorizontalAlignment="Left" Margin="428,289,0,0" TextWrapping="Wrap" Text="已停止" VerticalAlignment="Top"/>
<Label Content="提示标题" HorizontalAlignment="Left" Margin="19,10,0,0" VerticalAlignment="Top"/>
<Label Content="提示内容" HorizontalAlignment="Left" Margin="19,44,0,0" VerticalAlignment="Top"/>
<Label Content="提示次数" HorizontalAlignment="Left" Margin="19,79,0,0" VerticalAlignment="Top"/>
<Label Content="轮询间隔(ms)" HorizontalAlignment="Left" Margin="7,115,0,0" VerticalAlignment="Top"/>
<Label Content="轮询地址" HorizontalAlignment="Left" Margin="19,156,0,0" VerticalAlignment="Top"/>
<Label Content="页面正则" HorizontalAlignment="Left" Margin="19,211,0,0" VerticalAlignment="Top"/>

</Grid>
</Window>
192 changes: 192 additions & 0 deletions Watching/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.Http;
using System.Text.RegularExpressions;

namespace Watching
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private NotifyIcon notifyIcon;
private int run_id = 0;
private Boolean is_stop = false;

public MainWindow()
{
InitializeComponent();

this.notifyIcon = new NotifyIcon();
this.notifyIcon.BalloonTipText = "系统监控中... ...";
this.notifyIcon.ShowBalloonTip(2000);
this.notifyIcon.Text = "系统监控中... ...";
this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
this.notifyIcon.Visible = true;


//this.notifyIcon.MouseClick += NotifyIcon_MouseClick;
this.notifyIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler((o, e) =>
{
if (e.Button == MouseButtons.Left)
{
if (this.Visibility == System.Windows.Visibility.Visible) { this.HideWindow(); }
else this.ShowWindow();
}
});

addIconMenu();
}

private void NotifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
//addIconMenu();
}
}

private void addIconMenu()
{
System.Windows.Forms.ContextMenu menu = new System.Windows.Forms.ContextMenu();
System.Windows.Forms.MenuItem closeItem = new System.Windows.Forms.MenuItem();
closeItem.Text = "退出";
closeItem.Click += new EventHandler(delegate { this.Close(); });

menu.MenuItems.Add(closeItem);
notifyIcon.ContextMenu = menu;
}

private void ShowWindow()
{
this.Visibility = System.Windows.Visibility.Visible;
this.Activate();
}

private void HideWindow()
{
this.Visibility = System.Windows.Visibility.Hidden;
notifyIcon.ShowBalloonTip(3000, "监控", "监控最小化到托盘", ToolTipIcon.Info);
}

private void CloseWindow()
{
notifyIcon.Visible = false;
notifyIcon.Dispose();
notifyIcon = null;
}

private void Window_StateChanged(object sender, EventArgs e)
{
if (WindowState == WindowState.Minimized) { this.HideWindow(); } else this.ShowWindow();

}

private void start_Click(object sender, RoutedEventArgs e)
{
if (run_id > 0)
{
return;
}
status.Text = "运行中";
processWatching(url.Text, url_pattern.Text, title.Text, content.Text);
}

private void Window_Closed(object sender, EventArgs e)
{
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.CloseWindow();
}

private async void processWatching(string url, string url_pattern, string title, string content)
{
Boolean is_match = this.is_include.IsChecked == true ? true : false;
HttpClient u = new HttpClient();
int time_out = int.Parse(interval_time.Text);
int times = int.Parse(alert_times.Text);
int count = 0;
await System.Threading.Tasks.Task.Run(() =>
{
run_id = System.Threading.Thread.CurrentThread.ManagedThreadId;
string html;
while (true)
{
Console.WriteLine(is_stop);
if (is_stop || count >= times)
{
run_id = 0;
is_stop = false;
break;
}

try
{
html = u.GetStringAsync(url).Result;
}
catch (HttpRequestException e)
{
ShowDialog(e.Message);
run_id = 0;
is_stop = false;
break;
}

Match match = Regex.Match(html, url_pattern);
if (is_match)
{
if (match.Success)
{
count++;
notifyIcon.ShowBalloonTip(time_out, title, content, ToolTipIcon.Info);
}
}
else
{
if (!match.Success)
{
count++;
notifyIcon.ShowBalloonTip(time_out, title, content, ToolTipIcon.Info);
}
}
Thread.Sleep(time_out);
}
});
status.Text = "已停止";
}

private void ShowDialog(string message)
{
throw new NotImplementedException();
}

private void startHttp()
{
}

private void stop_btn_Click(object sender, RoutedEventArgs e)
{
if (run_id > 0)
{
status.Text = "正在停止...";
is_stop = true;
}
}
}
}
55 changes: 55 additions & 0 deletions Watching/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Watching")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("melanQ")]
[assembly: AssemblyProduct("Watching")]
[assembly: AssemblyCopyright("Copyright © melanQ 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

//若要开始生成可本地化的应用程序,请设置
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
//例如,如果您在源文件中使用的是美国英语,
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
//对以下 NeutralResourceLanguage 特性的注释。 更新
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
//或应用程序资源字典中找到时使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(未在页面中找到资源时使用,
//、应用程序或任何主题专用资源字典中找到时使用)
)]


// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit c5862c3

Please sign in to comment.