mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-22 09:29:50 +00:00
DnsServerSystemTrayApp added with testing
This commit is contained in:
239
DnsServerSystemTrayApp/AboutForm.Designer.cs
generated
Normal file
239
DnsServerSystemTrayApp/AboutForm.Designer.cs
generated
Normal file
@@ -0,0 +1,239 @@
|
||||
namespace DnsServerSystemTrayApp
|
||||
{
|
||||
partial class AboutForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm));
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.lnkTerms = new System.Windows.Forms.LinkLabel();
|
||||
this.btnClose = new System.Windows.Forms.Button();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.lnkWebsite = new System.Windows.Forms.LinkLabel();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.lnkContactEmail = new System.Windows.Forms.LinkLabel();
|
||||
this.labVersion = new System.Windows.Forms.Label();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255)))));
|
||||
this.panel1.Controls.Add(this.pictureBox1);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(56, 261);
|
||||
this.panel1.TabIndex = 21;
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255)))));
|
||||
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
|
||||
this.pictureBox1.Location = new System.Drawing.Point(0, 205);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Padding = new System.Windows.Forms.Padding(4);
|
||||
this.pictureBox1.Size = new System.Drawing.Size(56, 56);
|
||||
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBox1.TabIndex = 12;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Font = new System.Drawing.Font("Arial", 30F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69)))));
|
||||
this.label2.Location = new System.Drawing.Point(75, 24);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(456, 46);
|
||||
this.label2.TabIndex = 24;
|
||||
this.label2.Text = "Technitium DNS Server";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.label4.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69)))));
|
||||
this.label4.Location = new System.Drawing.Point(62, 193);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(436, 44);
|
||||
this.label4.TabIndex = 33;
|
||||
this.label4.Text = resources.GetString("label4.Text");
|
||||
//
|
||||
// lnkTerms
|
||||
//
|
||||
this.lnkTerms.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.lnkTerms.AutoSize = true;
|
||||
this.lnkTerms.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lnkTerms.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255)))));
|
||||
this.lnkTerms.Location = new System.Drawing.Point(62, 237);
|
||||
this.lnkTerms.Name = "lnkTerms";
|
||||
this.lnkTerms.Size = new System.Drawing.Size(116, 15);
|
||||
this.lnkTerms.TabIndex = 32;
|
||||
this.lnkTerms.TabStop = true;
|
||||
this.lnkTerms.Text = "Terms && Conditions";
|
||||
this.lnkTerms.VisitedLinkColor = System.Drawing.Color.White;
|
||||
this.lnkTerms.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkTerms_LinkClicked);
|
||||
//
|
||||
// btnClose
|
||||
//
|
||||
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.btnClose.Location = new System.Drawing.Point(565, 229);
|
||||
this.btnClose.Name = "btnClose";
|
||||
this.btnClose.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnClose.TabIndex = 31;
|
||||
this.btnClose.Text = "&Close";
|
||||
this.btnClose.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69)))));
|
||||
this.label3.Location = new System.Drawing.Point(476, 144);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(59, 16);
|
||||
this.label3.TabIndex = 37;
|
||||
this.label3.Text = "Website";
|
||||
//
|
||||
// lnkWebsite
|
||||
//
|
||||
this.lnkWebsite.AutoSize = true;
|
||||
this.lnkWebsite.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lnkWebsite.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255)))));
|
||||
this.lnkWebsite.Location = new System.Drawing.Point(476, 160);
|
||||
this.lnkWebsite.Name = "lnkWebsite";
|
||||
this.lnkWebsite.Size = new System.Drawing.Size(129, 16);
|
||||
this.lnkWebsite.TabIndex = 36;
|
||||
this.lnkWebsite.TabStop = true;
|
||||
this.lnkWebsite.Text = "technitium.com/dns";
|
||||
this.lnkWebsite.VisitedLinkColor = System.Drawing.Color.White;
|
||||
this.lnkWebsite.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkWebsite_LinkClicked);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69)))));
|
||||
this.label1.Location = new System.Drawing.Point(476, 99);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(57, 16);
|
||||
this.label1.TabIndex = 35;
|
||||
this.label1.Text = "Contact";
|
||||
//
|
||||
// lnkContactEmail
|
||||
//
|
||||
this.lnkContactEmail.AutoSize = true;
|
||||
this.lnkContactEmail.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lnkContactEmail.LinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(153)))), ((int)(((byte)(255)))));
|
||||
this.lnkContactEmail.Location = new System.Drawing.Point(476, 115);
|
||||
this.lnkContactEmail.Name = "lnkContactEmail";
|
||||
this.lnkContactEmail.Size = new System.Drawing.Size(164, 16);
|
||||
this.lnkContactEmail.TabIndex = 34;
|
||||
this.lnkContactEmail.TabStop = true;
|
||||
this.lnkContactEmail.Text = "support@technitium.com";
|
||||
this.lnkContactEmail.VisitedLinkColor = System.Drawing.Color.White;
|
||||
this.lnkContactEmail.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkContactEmail_LinkClicked);
|
||||
//
|
||||
// labVersion
|
||||
//
|
||||
this.labVersion.AutoSize = true;
|
||||
this.labVersion.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.labVersion.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69)))));
|
||||
this.labVersion.Location = new System.Drawing.Point(86, 132);
|
||||
this.labVersion.Name = "labVersion";
|
||||
this.labVersion.Size = new System.Drawing.Size(147, 18);
|
||||
this.labVersion.TabIndex = 38;
|
||||
this.labVersion.Text = "version x.x.x.x (beta)";
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Font = new System.Drawing.Font("Arial", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(57)))), ((int)(((byte)(69)))));
|
||||
this.label5.Location = new System.Drawing.Point(84, 103);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(206, 29);
|
||||
this.label5.TabIndex = 39;
|
||||
this.label5.Text = "System Tray App";
|
||||
//
|
||||
// AboutForm
|
||||
//
|
||||
this.AcceptButton = this.btnClose;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(250)))), ((int)(((byte)(250)))));
|
||||
this.CancelButton = this.btnClose;
|
||||
this.ClientSize = new System.Drawing.Size(652, 261);
|
||||
this.Controls.Add(this.label5);
|
||||
this.Controls.Add(this.labVersion);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.lnkWebsite);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.lnkContactEmail);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.lnkTerms);
|
||||
this.Controls.Add(this.btnClose);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "AboutForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "About Technitium DNS Server";
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.PictureBox pictureBox1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.LinkLabel lnkTerms;
|
||||
private System.Windows.Forms.Button btnClose;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.LinkLabel lnkWebsite;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.LinkLabel lnkContactEmail;
|
||||
private System.Windows.Forms.Label labVersion;
|
||||
private System.Windows.Forms.Label label5;
|
||||
}
|
||||
}
|
||||
48
DnsServerSystemTrayApp/AboutForm.cs
Normal file
48
DnsServerSystemTrayApp/AboutForm.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DnsServerSystemTrayApp
|
||||
{
|
||||
public partial class AboutForm : Form
|
||||
{
|
||||
public AboutForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
labVersion.Text = "version " + Application.ProductVersion + " (beta)";
|
||||
}
|
||||
|
||||
private void lnkContactEmail_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||
{
|
||||
System.Diagnostics.Process.Start("mailto:" + lnkContactEmail.Text);
|
||||
}
|
||||
|
||||
private void lnkWebsite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||
{
|
||||
System.Diagnostics.Process.Start(@"https://" + lnkWebsite.Text);
|
||||
}
|
||||
|
||||
private void lnkTerms_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||||
{
|
||||
System.Diagnostics.Process.Start(@"https://github.com/TechnitiumSoftware/DnsServer/blob/master/LICENSE");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,111 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="panel1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="pictureBox1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
Qk02DQAAAAAAADYEAAAoAAAAMAAAADAAAAABAAgAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAAA/wAA
|
||||
gP8AgAD/AICA/4AAAP+AAID/gIAA/8DAwP/A3MD/8Mqm/wQEBP8ICAj/DAwM/xEREf8WFhb/HBwc/yIi
|
||||
Iv8pKSn/VVVV/01NTf9CQkL/OTk5/4B8//9QUP//kwDW///szP/G1u//1ufn/5Cprf8AADP/AABm/wAA
|
||||
mf8AAMz/ADMA/wAzM/8AM2b/ADOZ/wAzzP8AM///AGYA/wBmM/8AZmb/AGaZ/wBmzP8AZv//AJkA/wCZ
|
||||
M/8AmWb/AJmZ/wCZzP8Amf//AMwA/wDMM/8AzGb/AMyZ/wDMzP8AzP//AP9m/wD/mf8A/8z/MwAA/zMA
|
||||
M/8zAGb/MwCZ/zMAzP8zAP//MzMA/zMzM/8zM2b/MzOZ/zMzzP8zM///M2YA/zNmM/8zZmb/M2aZ/zNm
|
||||
zP8zZv//M5kA/zOZM/8zmWb/M5mZ/zOZzP8zmf//M8wA/zPMM/8zzGb/M8yZ/zPMzP8zzP//M/8z/zP/
|
||||
Zv8z/5n/M//M/zP///9mAAD/ZgAz/2YAZv9mAJn/ZgDM/2YA//9mMwD/ZjMz/2YzZv9mM5n/ZjPM/2Yz
|
||||
//9mZgD/ZmYz/2ZmZv9mZpn/ZmbM/2aZAP9mmTP/Zplm/2aZmf9mmcz/Zpn//2bMAP9mzDP/ZsyZ/2bM
|
||||
zP9mzP//Zv8A/2b/M/9m/5n/Zv/M/8wA////AMz/mZkA/5kzmf+ZAJn/mQDM/5kAAP+ZMzP/mQBm/5kz
|
||||
zP+ZAP//mWYA/5lmM/+ZM2b/mWaZ/5lmzP+ZM///mZkz/5mZZv+ZmZn/mZnM/5mZ//+ZzAD/mcwz/2bM
|
||||
Zv+ZzJn/mczM/5nM//+Z/wD/mf8z/5nMZv+Z/5n/mf/M/5n////MAAD/mQAz/8wAZv/MAJn/zADM/5kz
|
||||
AP/MMzP/zDNm/8wzmf/MM8z/zDP//8xmAP/MZjP/mWZm/8xmmf/MZsz/mWb//8yZAP/MmTP/zJlm/8yZ
|
||||
mf/Mmcz/zJn//8zMAP/MzDP/zMxm/8zMmf/MzMz/zMz//8z/AP/M/zP/mf9m/8z/mf/M/8z/zP///8wA
|
||||
M///AGb//wCZ/8wzAP//MzP//zNm//8zmf//M8z//zP///9mAP//ZjP/zGZm//9mmf//Zsz/zGb///+Z
|
||||
AP//mTP//5lm//+Zmf//mcz//5n////MAP//zDP//8xm///Mmf//zMz//8z/////M//M/2b///+Z////
|
||||
zP9mZv//Zv9m/2b/////Zmb//2b/////Zv8hAKX/X19f/3d3d/+Ghob/lpaW/8vLy/+ysrL/19fX/93d
|
||||
3f/j4+P/6urq//Hx8f/4+Pj/8Pv//6SgoP+AgID/AAD//wD/AP8A/////wAA//8A/////wD//////9XV
|
||||
1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV
|
||||
1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV////////1dXV////////////////////
|
||||
///////////////////////////V1dXV////////1dXV////////////////////////////////////
|
||||
///////////V1dXV////////1dXV///////////////////////////////////////////////V1dXV
|
||||
////////1dXV///////////////////////////////////////////////V1dXV////////1dXV////
|
||||
///////////////////////////////////////////V1dXV////////1dXV////////////////////
|
||||
///////////////////////////V1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V
|
||||
1dXV1dXV1dXV1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV1dXV1dXV1dXV
|
||||
////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV1dXV1dXV1dXV////////////////
|
||||
///////////////////V1dX////////V1dX////////V1dXV////////////////////////////////
|
||||
///V1dX////////V1dX////////V1dXV///////////////////////////////////V1dX////////V
|
||||
1dX////////V1dXV///////////////////////////////////V1dX////////V1dX////////V1dXV
|
||||
///////////////////////////////////V1dX////////V1dX////////V1dXV////////////////
|
||||
///////////////////V1dX////////V1dX////////V1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV
|
||||
1dXV1dX////////V1dX////////V1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V
|
||||
1dX////////V1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV
|
||||
////////1dXV////////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV////////1dXV////
|
||||
////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV
|
||||
1dXV1dX////////V1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV1dXV1dX////////V
|
||||
1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV
|
||||
////////1dXV////////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV////////1dXV////
|
||||
////1dXV1dXV1dXV1dXV1dX////////V1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV
|
||||
1dXV1dX////////V1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV
|
||||
1dX////////V1dXV////////1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV
|
||||
////////1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV////////1dXV////
|
||||
////1dXV///////////////////////////////////V1dXV////////1dXV////////1dXV////////
|
||||
///////////////////////////V1dXV////////1dXV////////1dXV////////////////////////
|
||||
///////////V1dXV////////1dXV////////1dXV///////////////////////////////////V1dXV
|
||||
////////1dXV////////1dXV///////////////////////////////////V1dXV////////1dXV////
|
||||
////1dXV///////////////////////////////////V1dXV1dXV1dXV1dXV////////1dXV1dXV1dXV
|
||||
1dXV1dXV1dXV1dXV1dX////////V1dXV1dXV1dXV1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV
|
||||
1dX////////V1dXV1dXV1dXV1dXV////////1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dX////////V1dXV
|
||||
///////////////////////////////////////////////V1dX////////V1dXV////////////////
|
||||
///////////////////////////////V1dX////////V1dXV////////////////////////////////
|
||||
///////////////V1dX////////V1dXV///////////////////////////////////////////////V
|
||||
1dX////////V1dXV///////////////////////////////////////////////V1dX////////V1dXV
|
||||
///////////////////////////////////////////////V1dX////////V1dXV1dXV1dXV1dXV1dXV
|
||||
1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV
|
||||
1dXV1dXV1dXV1dXV1dXV1dXV1dXV1Q==
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="label2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="label4.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<data name="label4.Text" xml:space="preserve">
|
||||
<value>Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
|
||||
This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Click link below for details:</value>
|
||||
</data>
|
||||
<metadata name="lnkTerms.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="btnClose.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="label3.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="lnkWebsite.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="label1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="lnkContactEmail.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="labVersion.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="label5.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
AAABAAUAICAQAAAAAADoAgAAVgAAACAgAAAAAAAAqAgAAD4DAAAwMAAAAAAAAKgOAADmCwAAEBAQAAAA
|
||||
@@ -6,8 +6,8 @@
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{2F91BD07-2CEE-47FA-8486-457B54612B4C}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>DnsServerTrayIcon</RootNamespace>
|
||||
<AssemblyName>DnsServerTrayIcon</AssemblyName>
|
||||
<RootNamespace>DnsServerSystemTrayApp</RootNamespace>
|
||||
<AssemblyName>DnsServerSystemTrayApp</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
@@ -32,19 +32,21 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>logo2.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="TechnitiumLibrary.IO, Version=2.5.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\TechnitiumLibrary\bin\TechnitiumLibrary.IO.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AboutForm.cs">
|
||||
@@ -53,12 +55,10 @@
|
||||
<Compile Include="AboutForm.Designer.cs">
|
||||
<DependentUpon>AboutForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BuildAssemblyExtensions.cs" />
|
||||
<Compile Include="ContextMenuNotifyIconExtensions.cs" />
|
||||
<Compile Include="NotifyIconExtension.cs" />
|
||||
<Compile Include="MainApplicationContext.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WindowsServiceController.cs" />
|
||||
<EmbeddedResource Include="AboutForm.resx">
|
||||
<DependentUpon>AboutForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@@ -86,15 +86,7 @@
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Favicon.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DnsService\DnsService.csproj">
|
||||
<Project>{7873b2b8-01ba-48bc-b4b0-0857ffd873c9}</Project>
|
||||
<Name>DnsService</Name>
|
||||
</ProjectReference>
|
||||
<Content Include="logo2.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
713
DnsServerSystemTrayApp/MainApplicationContext.cs
Normal file
713
DnsServerSystemTrayApp/MainApplicationContext.cs
Normal file
@@ -0,0 +1,713 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using DnsServerSystemTrayApp.Properties;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Management;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using TechnitiumLibrary.IO;
|
||||
|
||||
namespace DnsServerSystemTrayApp
|
||||
{
|
||||
public class MainApplicationContext : ApplicationContext
|
||||
{
|
||||
#region variables
|
||||
|
||||
const int SERVICE_WAIT_TIMEOUT_SECONDS = 30;
|
||||
private readonly ServiceController _service = new ServiceController("DnsService");
|
||||
|
||||
readonly IPAddress[] _cloudflareDns = new IPAddress[] { IPAddress.Parse("1.1.1.1"), IPAddress.Parse("1.0.0.1") };
|
||||
readonly IPAddress[] _googleDns = new IPAddress[] { IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4") };
|
||||
readonly IPAddress[] _quad9Dns = new IPAddress[] { IPAddress.Parse("9.9.9.9") };
|
||||
|
||||
private NotifyIcon TrayIcon;
|
||||
private ContextMenuStrip TrayIconContextMenu;
|
||||
private ToolStripMenuItem DashboardMenuItem;
|
||||
private ToolStripMenuItem NetworkDnsMenuItem;
|
||||
private ToolStripMenuItem DefaultNetworkDnsMenuItem;
|
||||
private ToolStripMenuItem TechnitiumNetworkDnsMenuItem;
|
||||
private ToolStripMenuItem CloudflareNetworkDnsMenuItem;
|
||||
private ToolStripMenuItem GoogleNetworkDnsMenuItem;
|
||||
private ToolStripMenuItem Quad9NetworkDnsMenuItem;
|
||||
private ToolStripMenuItem ServiceMenuItem;
|
||||
private ToolStripMenuItem StartServiceMenuItem;
|
||||
private ToolStripMenuItem RestartServiceMenuItem;
|
||||
private ToolStripMenuItem StopServiceMenuItem;
|
||||
private ToolStripMenuItem AboutMenuItem;
|
||||
private ToolStripMenuItem AutoStartMenuItem;
|
||||
private ToolStripMenuItem ExitMenuItem;
|
||||
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
|
||||
public MainApplicationContext()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
TrayIcon?.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
//
|
||||
// TrayIconContextMenu
|
||||
//
|
||||
TrayIconContextMenu = new ContextMenuStrip();
|
||||
TrayIconContextMenu.SuspendLayout();
|
||||
|
||||
//
|
||||
// TrayIcon
|
||||
//
|
||||
var resources = new ComponentResourceManager(typeof(AboutForm));
|
||||
TrayIcon = new NotifyIcon();
|
||||
TrayIcon.Icon = (Icon)resources.GetObject("$this.Icon");
|
||||
TrayIcon.Visible = true;
|
||||
TrayIcon.MouseUp += TrayIcon_MouseUp;
|
||||
TrayIcon.ContextMenuStrip = TrayIconContextMenu;
|
||||
TrayIcon.Text = Resources.ServiceName;
|
||||
|
||||
//
|
||||
// DashboardMenuItem
|
||||
//
|
||||
DashboardMenuItem = new ToolStripMenuItem();
|
||||
DashboardMenuItem.Name = "DashboardMenuItem";
|
||||
DashboardMenuItem.Text = Resources.DashboardMenuItem;
|
||||
DashboardMenuItem.Click += DashboardMenuItem_Click;
|
||||
|
||||
|
||||
//
|
||||
// NetworkDnsMenuItem
|
||||
//
|
||||
NetworkDnsMenuItem = new ToolStripMenuItem();
|
||||
NetworkDnsMenuItem.Name = "NetworkDnsMenuItem";
|
||||
NetworkDnsMenuItem.Text = Resources.NetworkDnsMenuItem;
|
||||
|
||||
DefaultNetworkDnsMenuItem = new ToolStripMenuItem("Default");
|
||||
DefaultNetworkDnsMenuItem.Click += DefaultNetworkDnsMenuItem_Click;
|
||||
|
||||
TechnitiumNetworkDnsMenuItem = new ToolStripMenuItem("Technitium");
|
||||
TechnitiumNetworkDnsMenuItem.Click += TechnitiumNetworkDnsMenuItem_Click;
|
||||
|
||||
CloudflareNetworkDnsMenuItem = new ToolStripMenuItem("Cloudflare");
|
||||
CloudflareNetworkDnsMenuItem.Click += CloudflareNetworkDnsMenuItem_Click;
|
||||
|
||||
GoogleNetworkDnsMenuItem = new ToolStripMenuItem("Google");
|
||||
GoogleNetworkDnsMenuItem.Click += GoogleNetworkDnsMenuItem_Click;
|
||||
|
||||
Quad9NetworkDnsMenuItem = new ToolStripMenuItem("IBM Quad9");
|
||||
Quad9NetworkDnsMenuItem.Click += Quad9NetworkDnsMenuItem_Click;
|
||||
|
||||
NetworkDnsMenuItem.DropDownItems.AddRange(new ToolStripItem[]
|
||||
{
|
||||
DefaultNetworkDnsMenuItem,
|
||||
new ToolStripSeparator(),
|
||||
TechnitiumNetworkDnsMenuItem,
|
||||
CloudflareNetworkDnsMenuItem,
|
||||
GoogleNetworkDnsMenuItem,
|
||||
Quad9NetworkDnsMenuItem
|
||||
});
|
||||
|
||||
//
|
||||
// ServiceMenuItem
|
||||
//
|
||||
ServiceMenuItem = new ToolStripMenuItem();
|
||||
ServiceMenuItem.Name = "ServiceMenuItem";
|
||||
ServiceMenuItem.Text = Resources.ServiceMenuItem;
|
||||
|
||||
StartServiceMenuItem = new ToolStripMenuItem(Resources.ServiceStartMenuItem);
|
||||
StartServiceMenuItem.Click += StartServiceMenuItem_Click;
|
||||
|
||||
RestartServiceMenuItem = new ToolStripMenuItem(Resources.ServiceRestartMenuItem);
|
||||
RestartServiceMenuItem.Click += RestartServiceMenuItem_Click;
|
||||
|
||||
StopServiceMenuItem = new ToolStripMenuItem(Resources.ServiceStopMenuItem);
|
||||
StopServiceMenuItem.Click += StopServiceMenuItem_Click;
|
||||
|
||||
ServiceMenuItem.DropDownItems.AddRange(new ToolStripItem[]
|
||||
{
|
||||
StartServiceMenuItem,
|
||||
RestartServiceMenuItem,
|
||||
StopServiceMenuItem
|
||||
});
|
||||
|
||||
//
|
||||
// AboutMenuItem
|
||||
//
|
||||
AboutMenuItem = new ToolStripMenuItem();
|
||||
AboutMenuItem.Name = "AboutMenuItem";
|
||||
AboutMenuItem.Text = Resources.AboutMenuItem;
|
||||
AboutMenuItem.Click += AboutMenuItem_Click;
|
||||
|
||||
//
|
||||
// AutoStartMenuItem
|
||||
//
|
||||
AutoStartMenuItem = new ToolStripMenuItem();
|
||||
AutoStartMenuItem.Name = "AutoStartMenuItem";
|
||||
AutoStartMenuItem.Text = "&Auto Start Icon";
|
||||
AutoStartMenuItem.Click += AutoStartMenuItem_Click;
|
||||
|
||||
//
|
||||
// ExitMenuItem
|
||||
//
|
||||
ExitMenuItem = new ToolStripMenuItem();
|
||||
ExitMenuItem.Name = "ExitMenuItem";
|
||||
ExitMenuItem.Text = Resources.ExitMenuItem;
|
||||
ExitMenuItem.Click += ExitMenuItem_Click;
|
||||
|
||||
TrayIconContextMenu.Items.AddRange(new ToolStripItem[]
|
||||
{
|
||||
DashboardMenuItem,
|
||||
new ToolStripSeparator(),
|
||||
NetworkDnsMenuItem,
|
||||
ServiceMenuItem,
|
||||
AboutMenuItem,
|
||||
new ToolStripSeparator(),
|
||||
AutoStartMenuItem,
|
||||
ExitMenuItem
|
||||
});
|
||||
|
||||
TrayIconContextMenu.ResumeLayout(false);
|
||||
}
|
||||
|
||||
private static void SetNameServerIPv4(NetworkInterface nic, IPAddress[] dnsAddresses)
|
||||
{
|
||||
ManagementClass networkAdapterConfig = new ManagementClass("Win32_NetworkAdapterConfiguration");
|
||||
ManagementObjectCollection instances = networkAdapterConfig.GetInstances();
|
||||
|
||||
foreach (ManagementObject obj in instances)
|
||||
{
|
||||
if ((bool)obj["IPEnabled"] && obj["SettingID"].Equals(nic.Id))
|
||||
{
|
||||
string[] dnsServers = new string[dnsAddresses.Length];
|
||||
|
||||
for (int i = 0; i < dnsServers.Length; i++)
|
||||
{
|
||||
if (dnsAddresses[i].AddressFamily != AddressFamily.InterNetwork)
|
||||
throw new ArgumentException();
|
||||
|
||||
dnsServers[i] = dnsAddresses[i].ToString();
|
||||
}
|
||||
ManagementBaseObject objParameter = obj.GetMethodParameters("SetDNSServerSearchOrder");
|
||||
objParameter["DNSServerSearchOrder"] = dnsServers;
|
||||
|
||||
ManagementBaseObject response = obj.InvokeMethod("SetDNSServerSearchOrder", objParameter, null);
|
||||
uint returnValue = (uint)response.GetPropertyValue("ReturnValue");
|
||||
|
||||
switch (returnValue)
|
||||
{
|
||||
case 0: //success
|
||||
case 1: //reboot required
|
||||
break;
|
||||
|
||||
case 64:
|
||||
throw new Exception("Method not supported on this platform. WMI error code: " + returnValue);
|
||||
|
||||
case 65:
|
||||
throw new Exception("Unknown failure. WMI error code: " + returnValue);
|
||||
|
||||
case 70:
|
||||
throw new Exception("Invalid IP address. WMI error code: " + returnValue);
|
||||
|
||||
case 96:
|
||||
throw new Exception("Unable to notify DNS service. WMI error code: " + returnValue);
|
||||
|
||||
case 97:
|
||||
throw new Exception("Interface not configurable. WMI error code: " + returnValue);
|
||||
|
||||
default:
|
||||
throw new Exception("WMI error code: " + returnValue);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetNameServerIPv6(NetworkInterface nic, IPAddress[] dnsAddresses)
|
||||
{
|
||||
//HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces\{}
|
||||
|
||||
string nameServer = null;
|
||||
|
||||
foreach (IPAddress dnsAddress in dnsAddresses)
|
||||
{
|
||||
if (dnsAddress.AddressFamily != AddressFamily.InterNetworkV6)
|
||||
throw new ArgumentException();
|
||||
|
||||
if (nameServer == null)
|
||||
nameServer = dnsAddress.ToString();
|
||||
else
|
||||
nameServer += "," + dnsAddress.ToString();
|
||||
}
|
||||
|
||||
if (nameServer == null)
|
||||
nameServer = "";
|
||||
|
||||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\Interfaces\" + nic.Id, true))
|
||||
{
|
||||
if (key != null)
|
||||
key.SetValue("NameServer", nameServer, RegistryValueKind.String);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool AddressExists(IPAddress checkAddress, IPAddress[] addresses)
|
||||
{
|
||||
foreach (IPAddress address in addresses)
|
||||
{
|
||||
if (checkAddress.Equals(address))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void TrayIcon_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
#region Network DNS
|
||||
|
||||
bool isDefaultDns = false;
|
||||
bool isTechnitiumDns = false;
|
||||
bool isCloudflareDns = false;
|
||||
bool isGoogleDns = false;
|
||||
bool isQuad9Dns = false;
|
||||
|
||||
try
|
||||
{
|
||||
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (nic.OperationalStatus != OperationalStatus.Up)
|
||||
continue;
|
||||
|
||||
foreach (IPAddress dnsAddress in nic.GetIPProperties().DnsAddresses)
|
||||
{
|
||||
if (IPAddress.IsLoopback(dnsAddress))
|
||||
{
|
||||
isTechnitiumDns = true;
|
||||
}
|
||||
else if (AddressExists(dnsAddress, _cloudflareDns))
|
||||
{
|
||||
isCloudflareDns = true;
|
||||
}
|
||||
else if (AddressExists(dnsAddress, _googleDns))
|
||||
{
|
||||
isGoogleDns = true;
|
||||
}
|
||||
else if (AddressExists(dnsAddress, _quad9Dns))
|
||||
{
|
||||
isQuad9Dns = true;
|
||||
}
|
||||
else if (!dnsAddress.IsIPv6SiteLocal)
|
||||
{
|
||||
isDefaultDns = true;
|
||||
}
|
||||
|
||||
if (isDefaultDns && isTechnitiumDns && isCloudflareDns && isGoogleDns && isQuad9Dns)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
|
||||
DefaultNetworkDnsMenuItem.Checked = isDefaultDns;
|
||||
TechnitiumNetworkDnsMenuItem.Checked = isTechnitiumDns;
|
||||
CloudflareNetworkDnsMenuItem.Checked = isCloudflareDns;
|
||||
GoogleNetworkDnsMenuItem.Checked = isGoogleDns;
|
||||
Quad9NetworkDnsMenuItem.Checked = isQuad9Dns;
|
||||
|
||||
#endregion
|
||||
|
||||
#region service
|
||||
|
||||
try
|
||||
{
|
||||
switch (_service.Status)
|
||||
{
|
||||
case ServiceControllerStatus.Stopped:
|
||||
TechnitiumNetworkDnsMenuItem.Enabled = false;
|
||||
DashboardMenuItem.Enabled = false;
|
||||
StartServiceMenuItem.Enabled = true;
|
||||
RestartServiceMenuItem.Enabled = false;
|
||||
StopServiceMenuItem.Enabled = false;
|
||||
break;
|
||||
|
||||
case ServiceControllerStatus.Running:
|
||||
TechnitiumNetworkDnsMenuItem.Enabled = true;
|
||||
DashboardMenuItem.Enabled = true;
|
||||
StartServiceMenuItem.Enabled = false;
|
||||
RestartServiceMenuItem.Enabled = true;
|
||||
StopServiceMenuItem.Enabled = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
TechnitiumNetworkDnsMenuItem.Enabled = false;
|
||||
DashboardMenuItem.Enabled = false;
|
||||
StartServiceMenuItem.Enabled = false;
|
||||
RestartServiceMenuItem.Enabled = false;
|
||||
StopServiceMenuItem.Enabled = false;
|
||||
break;
|
||||
}
|
||||
|
||||
ServiceMenuItem.Enabled = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
TechnitiumNetworkDnsMenuItem.Enabled = false;
|
||||
DashboardMenuItem.Enabled = false;
|
||||
ServiceMenuItem.Enabled = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region auto start
|
||||
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
string autoStartPath = key.GetValue("Technitium DNS System Tray") as string;
|
||||
|
||||
AutoStartMenuItem.Checked = (autoStartPath != null) && autoStartPath.Equals("\"" + Assembly.GetEntryAssembly().Location + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
TrayIcon.ShowContextMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void DashboardMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
int port = 5380;
|
||||
|
||||
try
|
||||
{
|
||||
//try finding port number from dns config file
|
||||
|
||||
string dnsConfigFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "config", "dns.config");
|
||||
|
||||
using (FileStream fS = new FileStream(dnsConfigFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
BinaryReader bR = new BinaryReader(fS);
|
||||
|
||||
if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "DS") //format
|
||||
throw new InvalidDataException("DnsServer config file format is invalid.");
|
||||
|
||||
int version = bR.ReadByte();
|
||||
|
||||
if (version > 1)
|
||||
{
|
||||
string serverDomain = bR.ReadShortString();
|
||||
port = bR.ReadInt32();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
|
||||
Process.Start("http://localhost:" + port.ToString());
|
||||
}
|
||||
|
||||
private void DefaultNetworkDnsMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (nic.OperationalStatus != OperationalStatus.Up)
|
||||
continue;
|
||||
|
||||
SetNameServerIPv6(nic, new IPAddress[] { });
|
||||
|
||||
IPInterfaceProperties properties = nic.GetIPProperties();
|
||||
|
||||
if (properties.GetIPv4Properties().IsDhcpEnabled)
|
||||
{
|
||||
SetNameServerIPv4(nic, new IPAddress[] { });
|
||||
}
|
||||
else if (properties.GatewayAddresses.Count > 0)
|
||||
{
|
||||
SetNameServerIPv4(nic, new IPAddress[] { properties.GatewayAddresses[0].Address });
|
||||
}
|
||||
else
|
||||
{
|
||||
SetNameServerIPv4(nic, new IPAddress[] { });
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("The network DNS servers were set to default successfully.", "Default DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while setting default network DNS servers. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void TechnitiumNetworkDnsMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (nic.OperationalStatus != OperationalStatus.Up)
|
||||
continue;
|
||||
|
||||
IPInterfaceProperties properties = nic.GetIPProperties();
|
||||
|
||||
if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal)
|
||||
{
|
||||
SetNameServerIPv6(nic, new IPAddress[] { IPAddress.IPv6Loopback });
|
||||
SetNameServerIPv4(nic, new IPAddress[] { IPAddress.Loopback });
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("The network DNS servers were set to Technitium DNS successfully.", "Technitium DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while setting Technitium as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CloudflareNetworkDnsMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (nic.OperationalStatus != OperationalStatus.Up)
|
||||
continue;
|
||||
|
||||
IPInterfaceProperties properties = nic.GetIPProperties();
|
||||
|
||||
if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal)
|
||||
{
|
||||
SetNameServerIPv6(nic, new IPAddress[] { });
|
||||
SetNameServerIPv4(nic, _cloudflareDns);
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("The network DNS servers were set to Cloudflare DNS successfully.", "Cloudflare DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while setting Cloudflare as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void GoogleNetworkDnsMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (nic.OperationalStatus != OperationalStatus.Up)
|
||||
continue;
|
||||
|
||||
IPInterfaceProperties properties = nic.GetIPProperties();
|
||||
|
||||
if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal)
|
||||
{
|
||||
SetNameServerIPv6(nic, new IPAddress[] { });
|
||||
SetNameServerIPv4(nic, _googleDns);
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("The network DNS servers were set to Google DNS successfully.", "Google DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while setting Google as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Quad9NetworkDnsMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (nic.OperationalStatus != OperationalStatus.Up)
|
||||
continue;
|
||||
|
||||
IPInterfaceProperties properties = nic.GetIPProperties();
|
||||
|
||||
if ((properties.DnsAddresses.Count > 0) && !properties.DnsAddresses[0].IsIPv6SiteLocal)
|
||||
{
|
||||
SetNameServerIPv6(nic, new IPAddress[] { });
|
||||
SetNameServerIPv4(nic, _quad9Dns);
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("The network DNS servers were set to IBM Quad9 DNS successfully.", "IBM Quad9 DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while setting IBM Quad9 as network DNS server. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void StartServiceMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_service.Start();
|
||||
_service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, SERVICE_WAIT_TIMEOUT_SECONDS));
|
||||
|
||||
MessageBox.Show("The service was started successfully.", "Service Started - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (System.ServiceProcess.TimeoutException ex)
|
||||
{
|
||||
MessageBox.Show("The service did not respond in time." + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while starting service. " + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void RestartServiceMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_service.Stop();
|
||||
_service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, SERVICE_WAIT_TIMEOUT_SECONDS));
|
||||
_service.Start();
|
||||
_service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, SERVICE_WAIT_TIMEOUT_SECONDS));
|
||||
|
||||
MessageBox.Show("The service was restarted successfully.", "Service Restarted - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (System.ServiceProcess.TimeoutException ex)
|
||||
{
|
||||
MessageBox.Show("The service did not respond in time." + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while restarting service. " + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void StopServiceMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_service.Stop();
|
||||
_service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, SERVICE_WAIT_TIMEOUT_SECONDS));
|
||||
|
||||
MessageBox.Show("The service was stopped successfully.", "Service Stopped - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (System.ServiceProcess.TimeoutException ex)
|
||||
{
|
||||
MessageBox.Show("The service did not respond in time." + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while stopping service. " + ex.Message, "Service Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AboutMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (AboutForm aboutForm = new AboutForm())
|
||||
{
|
||||
aboutForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoStartMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (AutoStartMenuItem.Checked)
|
||||
{
|
||||
//remove
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
|
||||
{
|
||||
if (key != null)
|
||||
key.DeleteValue("Technitium DNS System Tray", false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while removing auto start registry entry. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//add
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
|
||||
{
|
||||
if (key != null)
|
||||
key.SetValue("Technitium DNS System Tray", "\"" + Assembly.GetEntryAssembly().Location + "\"", RegistryValueKind.String);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occured while adding auto start registry entry. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExitMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show(Resources.AreYouSureYouWantToQuit, Resources.Quit + " - " + Resources.ServiceName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
33
DnsServerSystemTrayApp/NotifyIconExtension.cs
Normal file
33
DnsServerSystemTrayApp/NotifyIconExtension.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DnsServerSystemTrayApp
|
||||
{
|
||||
public static class NotifyIconExtension
|
||||
{
|
||||
public static void ShowContextMenu(this NotifyIcon notifyIcon)
|
||||
{
|
||||
MethodInfo methodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
methodInfo.Invoke(notifyIcon, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
94
DnsServerSystemTrayApp/Program.cs
Normal file
94
DnsServerSystemTrayApp/Program.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
Technitium DNS Server
|
||||
Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DnsServerSystemTrayApp
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
#region variables
|
||||
|
||||
public const string MUTEX_NAME = "TechnitiumDnsServerSystemTrayApp";
|
||||
|
||||
static Mutex _app;
|
||||
|
||||
#endregion
|
||||
|
||||
#region public
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
#region admin elevation
|
||||
|
||||
bool isAdmin = (new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
if (!isAdmin)
|
||||
{
|
||||
string appPath = Assembly.GetEntryAssembly().Location;
|
||||
ProcessStartInfo processInfo = new ProcessStartInfo(appPath, string.Join(" ", args));
|
||||
|
||||
processInfo.UseShellExecute = true;
|
||||
processInfo.Verb = "runas";
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(processInfo);
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{ }
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error! " + ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region check for multiple instances
|
||||
|
||||
bool createdNewMutex;
|
||||
|
||||
_app = new Mutex(true, MUTEX_NAME, out createdNewMutex);
|
||||
|
||||
if (!createdNewMutex)
|
||||
{
|
||||
MessageBox.Show("Technitium DNS Server system tray app is already running.", "Already Running!", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Application.Run(new MainApplicationContext());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DnsServerTrayIcon")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyTitle("Technitium DNS Server")]
|
||||
[assembly: AssemblyDescription("Technitium DNS Server")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Technitium")]
|
||||
[assembly: AssemblyProduct("DnsServerTrayIcon")]
|
||||
[assembly: AssemblyCopyright("Copyright © Technitium 2018")]
|
||||
[assembly: AssemblyProduct("Technitium DNS Server")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
@@ -8,7 +8,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace DnsServerTrayIcon.Properties {
|
||||
namespace DnsServerSystemTrayApp.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace DnsServerTrayIcon.Properties {
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DnsServerTrayIcon.Properties.Resources", typeof(Resources).Assembly);
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DnsServerSystemTrayApp.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
@@ -61,7 +61,7 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to A&bout....
|
||||
/// Looks up a localized string similar to A&bout.
|
||||
/// </summary>
|
||||
internal static string AboutMenuItem {
|
||||
get {
|
||||
@@ -70,7 +70,9 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to If you quit Technitium DNS Server Tray Icon, Technitium DNS Server will continue to run in the background, are you sure you want to quit?.
|
||||
/// Looks up a localized string similar to Are you sure to close the system tray icon?
|
||||
///
|
||||
///Closing the system tray icon will not stop Technitium DNS Server..
|
||||
/// </summary>
|
||||
internal static string AreYouSureYouWantToQuit {
|
||||
get {
|
||||
@@ -79,7 +81,7 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to D&ashboard....
|
||||
/// Looks up a localized string similar to &Dashboard.
|
||||
/// </summary>
|
||||
internal static string DashboardMenuItem {
|
||||
get {
|
||||
@@ -87,15 +89,6 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to .
|
||||
/// </summary>
|
||||
internal static string ErrorOccurred {
|
||||
get {
|
||||
return ResourceManager.GetString("ErrorOccurred", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to E&xit.
|
||||
/// </summary>
|
||||
@@ -106,7 +99,16 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Quit Technitium DNS Server Tray Icon?.
|
||||
/// Looks up a localized string similar to Network DNS.
|
||||
/// </summary>
|
||||
internal static string NetworkDnsMenuItem {
|
||||
get {
|
||||
return ResourceManager.GetString("NetworkDnsMenuItem", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Close System Tray Icon?.
|
||||
/// </summary>
|
||||
internal static string Quit {
|
||||
get {
|
||||
@@ -115,7 +117,7 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Service.
|
||||
/// Looks up a localized string similar to &Service.
|
||||
/// </summary>
|
||||
internal static string ServiceMenuItem {
|
||||
get {
|
||||
@@ -133,7 +135,7 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Restart.
|
||||
/// Looks up a localized string similar to R&estart.
|
||||
/// </summary>
|
||||
internal static string ServiceRestartMenuItem {
|
||||
get {
|
||||
@@ -142,7 +144,7 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Start.
|
||||
/// Looks up a localized string similar to &Start.
|
||||
/// </summary>
|
||||
internal static string ServiceStartMenuItem {
|
||||
get {
|
||||
@@ -151,7 +153,7 @@ namespace DnsServerTrayIcon.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Stop.
|
||||
/// Looks up a localized string similar to St&op.
|
||||
/// </summary>
|
||||
internal static string ServiceStopMenuItem {
|
||||
get {
|
||||
@@ -118,36 +118,38 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="AboutMenuItem" xml:space="preserve">
|
||||
<value>A&bout...</value>
|
||||
<value>A&bout</value>
|
||||
</data>
|
||||
<data name="AreYouSureYouWantToQuit" xml:space="preserve">
|
||||
<value>If you quit Technitium DNS Server Tray Icon, Technitium DNS Server will continue to run in the background, are you sure you want to quit?</value>
|
||||
<value>Are you sure to close the system tray icon?
|
||||
|
||||
Closing the system tray icon will not stop Technitium DNS Server.</value>
|
||||
</data>
|
||||
<data name="DashboardMenuItem" xml:space="preserve">
|
||||
<value>D&ashboard...</value>
|
||||
</data>
|
||||
<data name="ErrorOccurred" xml:space="preserve">
|
||||
<value />
|
||||
<value>&Dashboard</value>
|
||||
</data>
|
||||
<data name="ExitMenuItem" xml:space="preserve">
|
||||
<value>E&xit</value>
|
||||
</data>
|
||||
<data name="NetworkDnsMenuItem" xml:space="preserve">
|
||||
<value>Network DNS</value>
|
||||
</data>
|
||||
<data name="Quit" xml:space="preserve">
|
||||
<value>Quit Technitium DNS Server Tray Icon?</value>
|
||||
<value>Close System Tray Icon?</value>
|
||||
</data>
|
||||
<data name="ServiceMenuItem" xml:space="preserve">
|
||||
<value>Service</value>
|
||||
<value>&Service</value>
|
||||
</data>
|
||||
<data name="ServiceName" xml:space="preserve">
|
||||
<value>Technitium DNS Server</value>
|
||||
</data>
|
||||
<data name="ServiceRestartMenuItem" xml:space="preserve">
|
||||
<value>Restart</value>
|
||||
<value>R&estart</value>
|
||||
</data>
|
||||
<data name="ServiceStartMenuItem" xml:space="preserve">
|
||||
<value>Start</value>
|
||||
<value>&Start</value>
|
||||
</data>
|
||||
<data name="ServiceStopMenuItem" xml:space="preserve">
|
||||
<value>Stop</value>
|
||||
<value>St&op</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -8,21 +8,17 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace DnsServerTrayIcon.Properties
|
||||
{
|
||||
namespace DnsServerSystemTrayApp.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
64
DnsServerTrayIcon/AboutForm.Designer.cs
generated
64
DnsServerTrayIcon/AboutForm.Designer.cs
generated
@@ -1,64 +0,0 @@
|
||||
namespace DnsServerTrayIcon
|
||||
{
|
||||
partial class AboutForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm));
|
||||
this.VersionLabel = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// VersionLabel
|
||||
//
|
||||
this.VersionLabel.AutoSize = true;
|
||||
this.VersionLabel.Location = new System.Drawing.Point(24, 23);
|
||||
this.VersionLabel.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
|
||||
this.VersionLabel.Name = "VersionLabel";
|
||||
this.VersionLabel.Size = new System.Drawing.Size(0, 25);
|
||||
this.VersionLabel.TabIndex = 0;
|
||||
//
|
||||
// AboutForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(656, 142);
|
||||
this.Controls.Add(this.VersionLabel);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6);
|
||||
this.Name = "AboutForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "About";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label VersionLabel;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using DnsServerTrayIcon.Properties;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DnsServerTrayIcon
|
||||
{
|
||||
public partial class AboutForm : Form
|
||||
{
|
||||
public AboutForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Image image = Image.FromFile("Favicon.ico");
|
||||
var bitmap = new Bitmap(image);
|
||||
Icon = Icon.FromHandle(bitmap.GetHicon());
|
||||
|
||||
VersionLabel.Text = Resources.ServiceName;
|
||||
VersionLabel.Text += "\r\n";
|
||||
VersionLabel.Text += GetLegalCopyright();
|
||||
VersionLabel.Text += "\r\n";
|
||||
VersionLabel.Text += Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName) + " " + Assembly.GetExecutingAssembly().GetBuildVersion();
|
||||
}
|
||||
|
||||
private string GetLegalCopyright()
|
||||
{
|
||||
var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
|
||||
return versionInfo.LegalCopyright;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DnsServerTrayIcon
|
||||
{
|
||||
public static class BuildAssemblyExtensions
|
||||
{
|
||||
public static DateTime GetLinkerTime(this Assembly assembly, TimeZoneInfo target = null)
|
||||
{
|
||||
var filePath = assembly.Location;
|
||||
const int c_PeHeaderOffset = 60;
|
||||
const int c_LinkerTimestampOffset = 8;
|
||||
|
||||
var buffer = new byte[2048];
|
||||
|
||||
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
stream.Read(buffer, 0, 2048);
|
||||
|
||||
var offset = BitConverter.ToInt32(buffer, c_PeHeaderOffset);
|
||||
var secondsSince1970 = BitConverter.ToInt32(buffer, offset + c_LinkerTimestampOffset);
|
||||
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
var linkTimeUtc = epoch.AddSeconds(secondsSince1970);
|
||||
|
||||
var tz = target ?? TimeZoneInfo.Local;
|
||||
var localTime = TimeZoneInfo.ConvertTimeFromUtc(linkTimeUtc, tz);
|
||||
|
||||
return localTime;
|
||||
}
|
||||
|
||||
public static string GetBuildVersion(this Assembly assembly)
|
||||
{
|
||||
var linkTimeLocal = assembly.GetLinkerTime(TimeZoneInfo.Utc);
|
||||
return new Version(1, 0, 0,
|
||||
((int)new TimeSpan(linkTimeLocal.Hour, linkTimeLocal.Minute, linkTimeLocal.Second).TotalSeconds) / 2).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DnsServerTrayIcon
|
||||
{
|
||||
public static class ContextMenuNotifyIconExtensions
|
||||
{
|
||||
public static void ShowContextMenu(this NotifyIcon notifyIcon)
|
||||
{
|
||||
MethodInfo methodInfo = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
methodInfo.Invoke(notifyIcon, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
using DnsServerTrayIcon.Properties;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DnsServerTrayIcon
|
||||
{
|
||||
public class MainApplicationContext : ApplicationContext
|
||||
{
|
||||
private readonly WindowsServiceController _service = new WindowsServiceController("DnsService");
|
||||
|
||||
private NotifyIcon TrayIcon;
|
||||
private ContextMenuStrip TrayIconContextMenu;
|
||||
private ToolStripMenuItem DashboardMenuItem;
|
||||
private ToolStripMenuItem ServiceMenuItem;
|
||||
private ToolStripMenuItem StartServiceMenuItem;
|
||||
private ToolStripMenuItem RestartServiceMenuItem;
|
||||
private ToolStripMenuItem StopServiceMenuItem;
|
||||
private ToolStripMenuItem AboutMenuItem;
|
||||
private ToolStripSeparator DividerMenuItem;
|
||||
private ToolStripMenuItem ExitMenuItem;
|
||||
|
||||
public MainApplicationContext()
|
||||
{
|
||||
Application.ApplicationExit += new EventHandler(OnApplicationExit);
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
//
|
||||
// TrayIconContextMenu
|
||||
//
|
||||
TrayIconContextMenu = new ContextMenuStrip();
|
||||
TrayIconContextMenu.SuspendLayout();
|
||||
|
||||
//
|
||||
// TrayIcon
|
||||
//
|
||||
var resources = new ComponentResourceManager(typeof(AboutForm));
|
||||
TrayIcon = new NotifyIcon();
|
||||
TrayIcon.Icon = (Icon)resources.GetObject("$this.Icon");
|
||||
TrayIcon.Visible = true;
|
||||
TrayIcon.MouseUp += TrayIcon_MouseUp;
|
||||
TrayIcon.ContextMenuStrip = TrayIconContextMenu;
|
||||
TrayIcon.Text = Resources.ServiceName;
|
||||
|
||||
//
|
||||
// DashboardMenuItem
|
||||
//
|
||||
DashboardMenuItem = new ToolStripMenuItem();
|
||||
DashboardMenuItem.Name = "DashboardMenuItem";
|
||||
DashboardMenuItem.Text = Resources.DashboardMenuItem;
|
||||
DashboardMenuItem.Click += new EventHandler(DashboardMenuItem_Click);
|
||||
|
||||
//
|
||||
// ServiceMenuItem
|
||||
//
|
||||
ServiceMenuItem = new ToolStripMenuItem();
|
||||
ServiceMenuItem.Name = "ServiceMenuItem";
|
||||
ServiceMenuItem.Text = Resources.ServiceMenuItem;
|
||||
ServiceMenuItem.MouseHover += new EventHandler(ServiceMenuItem_MouseHover);
|
||||
// Prove the user feedback that there is a sub menu.
|
||||
ServiceMenuItem.DropDownItems.Add(new ToolStripMenuItem());
|
||||
|
||||
StartServiceMenuItem = new ToolStripMenuItem(Resources.ServiceStartMenuItem);
|
||||
StartServiceMenuItem.Click += new EventHandler(StartServiceMenuItem_Click);
|
||||
|
||||
RestartServiceMenuItem = new ToolStripMenuItem(Resources.ServiceRestartMenuItem);
|
||||
RestartServiceMenuItem.Click += new EventHandler(RestartServiceMenuItem_Click);
|
||||
|
||||
StopServiceMenuItem = new ToolStripMenuItem(Resources.ServiceStopMenuItem);
|
||||
StopServiceMenuItem.Click += new EventHandler(StopServiceMenuItem_Click);
|
||||
|
||||
//
|
||||
// AboutMenuItem
|
||||
//
|
||||
AboutMenuItem = new ToolStripMenuItem();
|
||||
AboutMenuItem.Name = "AboutMenuItem";
|
||||
AboutMenuItem.Text = Resources.AboutMenuItem;
|
||||
AboutMenuItem.Click += new EventHandler(AboutMenuItem_Click);
|
||||
|
||||
//
|
||||
// DividerMenuItem
|
||||
//
|
||||
DividerMenuItem = new ToolStripSeparator();
|
||||
|
||||
//
|
||||
// CloseMenuItem
|
||||
//
|
||||
ExitMenuItem = new ToolStripMenuItem();
|
||||
ExitMenuItem.Name = "ExitMenuItem";
|
||||
ExitMenuItem.Text = Resources.ExitMenuItem;
|
||||
ExitMenuItem.Click += new EventHandler(ExitMenuItem_Click);
|
||||
|
||||
TrayIconContextMenu.ResumeLayout(false);
|
||||
}
|
||||
|
||||
private void TrayIcon_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
BuildContextMenu();
|
||||
TrayIcon.ShowContextMenu();
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildContextMenu()
|
||||
{
|
||||
TrayIconContextMenu.Hide();
|
||||
TrayIconContextMenu.Items.Clear();
|
||||
|
||||
TrayIconContextMenu.Items.Add(DashboardMenuItem);
|
||||
|
||||
if (_service.IsInstalled)
|
||||
TrayIconContextMenu.Items.Add(ServiceMenuItem);
|
||||
|
||||
TrayIconContextMenu.Items.AddRange(new ToolStripItem[]
|
||||
{
|
||||
DividerMenuItem,
|
||||
AboutMenuItem,
|
||||
DividerMenuItem,
|
||||
ExitMenuItem
|
||||
});
|
||||
}
|
||||
|
||||
private void ServiceMenuItem_MouseHover(object sender, EventArgs e)
|
||||
{
|
||||
ServiceMenuItem.DropDownItems.Clear();
|
||||
if (_service.IsRunning)
|
||||
{
|
||||
ServiceMenuItem.DropDownItems.Add(RestartServiceMenuItem);
|
||||
ServiceMenuItem.DropDownItems.Add(StopServiceMenuItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServiceMenuItem.DropDownItems.Add(StartServiceMenuItem);
|
||||
}
|
||||
ServiceMenuItem.ShowDropDown();
|
||||
}
|
||||
|
||||
private void StartServiceMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
_service.Start();
|
||||
}
|
||||
|
||||
private void RestartServiceMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
_service.Restart();
|
||||
}
|
||||
|
||||
private void StopServiceMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
_service.Stop();
|
||||
}
|
||||
|
||||
private void OnApplicationExit(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Clean up so that the icon will be removed when the application is closed.
|
||||
TrayIcon.Visible = false;
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
// The application is probably closing so safe to ignore.
|
||||
}
|
||||
}
|
||||
|
||||
private void DashboardMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
//TODO: Parse the config file to determine the port.
|
||||
Process.Start("http://127.0.0.1:5380");
|
||||
}
|
||||
|
||||
private void AboutMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var aboutForm = new AboutForm();
|
||||
aboutForm.ShowDialog();
|
||||
}
|
||||
|
||||
private void ExitMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult dialogResult = MessageBox.Show(
|
||||
Resources.AreYouSureYouWantToQuit,
|
||||
Resources.Quit,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.None,
|
||||
MessageBoxDefaultButton.Button2);
|
||||
|
||||
if (dialogResult == DialogResult.Yes)
|
||||
{
|
||||
Application.Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DnsServerTrayIcon
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.Run(new MainApplicationContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
|
||||
namespace DnsServerTrayIcon
|
||||
{
|
||||
public class WindowsServiceController
|
||||
{
|
||||
private readonly string _serviceName;
|
||||
|
||||
public WindowsServiceController(string serviceName)
|
||||
{
|
||||
_serviceName = serviceName;
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
{
|
||||
Stop();
|
||||
Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var service = new ServiceController(_serviceName))
|
||||
{
|
||||
service.Stop();
|
||||
service.WaitForStatus(ServiceControllerStatus.Stopped);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var service = new ServiceController(_serviceName))
|
||||
{
|
||||
service.Start();
|
||||
service.WaitForStatus(ServiceControllerStatus.Running);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
public bool IsRunning => Status == ServiceControllerStatus.Running;
|
||||
|
||||
public bool IsStopped => Status == ServiceControllerStatus.Stopped;
|
||||
|
||||
public ServiceControllerStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var service = new ServiceController(_serviceName))
|
||||
{
|
||||
return service.Status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsInstalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServiceController.GetServices().Any(s => s.ServiceName == _serviceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user