Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

Commit e73d394

Browse files
committed
Add project files.
1 parent 195803e commit e73d394

15 files changed

+924
-0
lines changed

App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>

ILMerge.props

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<!-- -->
5+
<!-- ILMerge project-specific settings. Almost never need to be set explicitly. -->
6+
<!-- for details, see http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx -->
7+
<!-- -->
8+
<!-- *** set this file to Type=None, CopyToOutput=Never *** -->
9+
10+
<!-- If True, all copy local dependencies will also be merged from referenced projects whether they are referenced in the current project explicitly or not -->
11+
<ILMergeTransitive>true</ILMergeTransitive>
12+
13+
<!-- Extra ILMerge library paths (semicolon-separated). Dont put your package dependencies here, they will be added automagically -->
14+
<ILMergeLibraryPath></ILMergeLibraryPath>
15+
16+
<!-- The solution NuGet package directory if not standard 'SOLUTION\packages' -->
17+
<ILMergePackagesPath></ILMergePackagesPath>
18+
19+
<!-- The merge order file name if differs from standard 'ILMergeOrder.txt' -->
20+
<ILMergeOrderFile></ILMergeOrderFile>
21+
22+
<!-- The strong key file name if not specified in the project -->
23+
<ILMergeKeyFile></ILMergeKeyFile>
24+
25+
<!-- The assembly version if differs for the version of the main assembly -->
26+
<ILMergeAssemblyVersion></ILMergeAssemblyVersion>
27+
28+
<!-- added in Version 1.0.4 -->
29+
<ILMergeFileAlignment></ILMergeFileAlignment>
30+
31+
<!-- added in Version 1.0.4, default=none -->
32+
<ILMergeAllowDuplicateType></ILMergeAllowDuplicateType>
33+
34+
<!-- If the <see cref="CopyAttributes"/> is also set, any assembly-level attributes names that have the same type are copied over into the target assembly -->
35+
<ILMergeAllowMultipleAssemblyLevelAttributes></ILMergeAllowMultipleAssemblyLevelAttributes>
36+
37+
<!-- See ILMerge documentation -->
38+
<ILMergeAllowZeroPeKind></ILMergeAllowZeroPeKind>
39+
40+
<!-- The assembly level attributes of each input assembly are copied over into the target assembly -->
41+
<ILMergeCopyAttributes></ILMergeCopyAttributes>
42+
43+
<!-- Creates a .pdb file for the output assembly and merges into it any .pdb files found for input assemblies, default=true -->
44+
<ILMergeDebugInfo></ILMergeDebugInfo>
45+
46+
<!-- Target assembly will be delay signed -->
47+
<ILMergeDelaySign></ILMergeDelaySign>
48+
49+
<!-- Types in assemblies other than the primary assembly have their visibility modified -->
50+
<ILMergeInternalize></ILMergeInternalize>
51+
52+
<!-- The path name of the file that will be used to identify types that are not to have their visibility modified -->
53+
<ILMergeInternalizeExcludeFile></ILMergeInternalizeExcludeFile>
54+
55+
<!-- XML documentation files are merged to produce an XML documentation file for the target assembly -->
56+
<ILMergeXmlDocumentation></ILMergeXmlDocumentation>
57+
58+
<!-- External assembly references in the manifest of the target assembly will use full public keys (false) or public key tokens (true, default value) -->
59+
<ILMergePublicKeyTokens></ILMergePublicKeyTokens>
60+
61+
<!-- Types with the same name are all merged into a single type in the target assembly -->
62+
<ILMergeUnionMerge></ILMergeUnionMerge>
63+
64+
<!-- The version of the target framework, default 40 (works for 45 too) -->
65+
<ILTargetPlatform></ILTargetPlatform>
66+
</PropertyGroup>
67+
</Project>

ILMergeOrder.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# this file contains the partial list of the merged assemblies in the merge order
2+
# you can fill it from the obj\CONFIG\PROJECT.ilmerge generated on every build
3+
# and finetune merge order to your satisfaction
4+

MainForm.Designer.cs

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainForm.cs

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
using System.Net.Http.Headers;
11+
using System.Net.Http;
12+
using System.IO;
13+
using Newtonsoft.Json;
14+
using Newtonsoft.Json.Linq;
15+
16+
17+
namespace XqLineNotifier
18+
{
19+
public partial class MainForm : Form
20+
{
21+
public MainForm()
22+
{
23+
InitializeComponent();
24+
}
25+
26+
private string lineToken = "";
27+
private static string AppJsonFilePath = "./lineToken.json";
28+
private static string XqMonitorPath = "./";
29+
private static string XqLogFileExtension = "*.xqlog";
30+
31+
public void CreateFileWatcher(string path)
32+
{
33+
// Create a new FileSystemWatcher and set its properties.
34+
FileSystemWatcher watcher = new FileSystemWatcher();
35+
watcher.Path = path;
36+
/* Watch for changes in LastAccess and LastWrite times, and
37+
the renaming of files or directories. */
38+
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
39+
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
40+
41+
// Add event handlers.
42+
// Only watch *.xqlog files
43+
watcher.Filter = XqLogFileExtension;
44+
watcher.Changed += new FileSystemEventHandler(OnChanged);
45+
watcher.Created += new FileSystemEventHandler(OnCreatedAsync);
46+
watcher.Deleted += new FileSystemEventHandler(OnChanged);
47+
watcher.Renamed += new RenamedEventHandler(OnRenamed);
48+
49+
// Begin watching.
50+
watcher.EnableRaisingEvents = true;
51+
}
52+
53+
// Define the event handlers.
54+
private async void OnCreatedAsync(object source, FileSystemEventArgs e)
55+
{
56+
// Specify what is done when a file is changed, created, or deleted.
57+
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
58+
59+
try
60+
{
61+
if (this.lineToken.Trim() != "")
62+
{
63+
string message = File.ReadAllText(e.FullPath, Encoding.GetEncoding("Big5"));
64+
65+
HttpClient client = new HttpClient();
66+
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", this.lineToken);
67+
var form = new FormUrlEncodedContent(new[]
68+
{
69+
new KeyValuePair<string, string>("message", message)
70+
});
71+
HttpResponseMessage result = await client.PostAsync(new Uri("https://notify-api.line.me/api/notify"), form);
72+
}
73+
File.Delete(e.FullPath);
74+
}
75+
catch (Exception ex)
76+
{
77+
MessageBox.Show(ex.ToString());
78+
}
79+
80+
}
81+
82+
private static void OnChanged(object source, FileSystemEventArgs e)
83+
{
84+
// Specify what is done when a file is changed, created, or deleted.
85+
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
86+
}
87+
88+
private static void OnRenamed(object source, RenamedEventArgs e)
89+
{
90+
// Specify what is done when a file is renamed.
91+
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
92+
}
93+
94+
public class AppSettings
95+
{
96+
public string LineToken { get; set; }
97+
}
98+
99+
private AppSettings readAppSettings()
100+
{
101+
var jsonString = System.IO.File.ReadAllText(AppJsonFilePath);
102+
AppSettings appSettings = JsonConvert.DeserializeObject<AppSettings>(jsonString);
103+
return appSettings;
104+
}
105+
106+
private void checkXqLineNotifyPathExists()
107+
{
108+
if (!Directory.Exists(XqMonitorPath))
109+
{
110+
Directory.CreateDirectory(XqMonitorPath);
111+
}
112+
}
113+
private void createAppSettingsFile()
114+
{
115+
var appJsonObj = new AppSettings() { LineToken = "" };
116+
System.IO.File.WriteAllText(AppJsonFilePath, JsonConvert.SerializeObject(appJsonObj));
117+
}
118+
119+
private void initAppSettings()
120+
{
121+
122+
try
123+
{
124+
if (!System.IO.File.Exists(AppJsonFilePath))
125+
{
126+
this.createAppSettingsFile();
127+
}
128+
AppSettings appSettings = this.readAppSettings();
129+
lineToken = appSettings.LineToken;
130+
txtLineToken.Text = lineToken;
131+
}
132+
catch (Exception e)
133+
{
134+
this.createAppSettingsFile();
135+
}
136+
}
137+
138+
private void MainForm_Load(object sender, EventArgs e)
139+
{
140+
checkXqLineNotifyPathExists();
141+
initAppSettings();
142+
createXqMonitorPath();
143+
deleteAllXqLog();
144+
CreateFileWatcher(XqMonitorPath);
145+
}
146+
147+
private void createXqMonitorPath() {
148+
if (!System.IO.Directory.Exists(XqMonitorPath)) {
149+
System.IO.Directory.CreateDirectory(XqMonitorPath);
150+
}
151+
}
152+
153+
private void deleteAllXqLog() {
154+
foreach (string sFile in System.IO.Directory.GetFiles(XqMonitorPath, XqLogFileExtension))
155+
{
156+
System.IO.File.Delete(sFile);
157+
}
158+
}
159+
160+
private void btnSave_Click(object sender, EventArgs e)
161+
{
162+
txtLineToken.Text = txtLineToken.Text.Trim();
163+
AppSettings appSettings = this.readAppSettings();
164+
appSettings.LineToken = txtLineToken.Text;
165+
string jsonString = JsonConvert.SerializeObject(appSettings);
166+
System.IO.File.WriteAllText(AppJsonFilePath, jsonString);
167+
this.lineToken = txtLineToken.Text;
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)