From 1e072e5f917e65d8ba1251848748d814894b4c2c Mon Sep 17 00:00:00 2001 From: icylogic Date: Wed, 12 Aug 2015 22:30:09 +0800 Subject: [PATCH 001/109] initial form design --- shadowsocks-csharp/View/MenuViewController.cs | 9 + .../StatisticsStrategyOptionsForm.Designer.cs | 453 ++++++++++++++++++ .../View/StatisticsStrategyOptionsForm.cs | 56 +++ .../View/StatisticsStrategyOptionsForm.resx | 120 +++++ shadowsocks-csharp/app.manifest | 2 +- shadowsocks-csharp/shadowsocks-csharp.csproj | 16 + 6 files changed, 655 insertions(+), 1 deletion(-) create mode 100644 shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs create mode 100644 shadowsocks-csharp/View/StatisticsStrategyOptionsForm.cs create mode 100644 shadowsocks-csharp/View/StatisticsStrategyOptionsForm.resx diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index b8c9bb81..8d68a0aa 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -165,6 +165,7 @@ namespace Shadowsocks.View this.SeperatorItem = new MenuItem("-"), this.ConfigItem = CreateMenuItem("Edit Servers...", new EventHandler(this.Config_Click)), CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)), + CreateMenuItem("Statistics Stategy Options", new EventHandler(StatisticsStrategyOptionsItem_Click)), CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click)) }), CreateMenuGroup("PAC ", new MenuItem[] { @@ -426,6 +427,14 @@ namespace Shadowsocks.View qrCodeForm.Show(); } + private static void StatisticsStrategyOptionsItem_Click(object sender, EventArgs e) + { + //TODO: Load options + var statisticsStrategyOptionsForm = new StatisticsStrategyOptionsForm(); + statisticsStrategyOptionsForm.Show(); + //TODO: Save options + } + private void ScanQRCodeItem_Click(object sender, EventArgs e) { foreach (Screen screen in Screen.AllScreens) diff --git a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs new file mode 100644 index 00000000..98232dc6 --- /dev/null +++ b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs @@ -0,0 +1,453 @@ +namespace Shadowsocks.View +{ + partial class StatisticsStrategyOptionsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.StatisticsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.radioButton2 = new System.Windows.Forms.RadioButton(); + this.radioButton1 = new System.Windows.Forms.RadioButton(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.checkBox2 = new System.Windows.Forms.CheckBox(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label6 = new System.Windows.Forms.Label(); + this.splitContainer3 = new System.Windows.Forms.SplitContainer(); + this.label1 = new System.Windows.Forms.Label(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.panel3 = new System.Windows.Forms.Panel(); + this.label5 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.textBox5 = new System.Windows.Forms.TextBox(); + this.comboBox3 = new System.Windows.Forms.ComboBox(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).BeginInit(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit(); + this.splitContainer3.Panel1.SuspendLayout(); + this.splitContainer3.Panel2.SuspendLayout(); + this.splitContainer3.SuspendLayout(); + this.flowLayoutPanel1.SuspendLayout(); + this.panel3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); + this.SuspendLayout(); + // + // StatisticsChart + // + this.StatisticsChart.BackColor = System.Drawing.Color.Transparent; + chartArea1.AxisX.MajorGrid.Enabled = false; + chartArea1.AxisY.MajorGrid.Enabled = false; + chartArea1.AxisY2.MajorGrid.Enabled = false; + chartArea1.BackColor = System.Drawing.Color.Transparent; + chartArea1.Name = "ChartArea"; + this.StatisticsChart.ChartAreas.Add(chartArea1); + this.StatisticsChart.Dock = System.Windows.Forms.DockStyle.Fill; + legend1.BackColor = System.Drawing.Color.Transparent; + legend1.Name = "ChartLegend"; + this.StatisticsChart.Legends.Add(legend1); + this.StatisticsChart.Location = new System.Drawing.Point(0, 0); + this.StatisticsChart.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.StatisticsChart.Name = "StatisticsChart"; + this.StatisticsChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Pastel; + series1.ChartArea = "ChartArea"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; + series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); + series1.Legend = "ChartLegend"; + series1.Name = "Data Transferred"; + series2.ChartArea = "ChartArea"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; + series2.Color = System.Drawing.Color.Red; + series2.Legend = "ChartLegend"; + series2.Name = "Package Loss"; + series2.YValuesPerPoint = 4; + series3.BorderWidth = 4; + series3.ChartArea = "ChartArea"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Legend = "ChartLegend"; + series3.Name = "Ping"; + this.StatisticsChart.Series.Add(series1); + this.StatisticsChart.Series.Add(series2); + this.StatisticsChart.Series.Add(series3); + this.StatisticsChart.Size = new System.Drawing.Size(1216, 454); + this.StatisticsChart.TabIndex = 2; + this.StatisticsChart.Click += new System.EventHandler(this.StatisticsChart_Click); + // + // checkBox1 + // + this.checkBox1.AutoSize = true; + this.checkBox1.Location = new System.Drawing.Point(13, 16); + this.checkBox1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(254, 25); + this.checkBox1.TabIndex = 5; + this.checkBox1.Text = "Choose strategy by geolocation"; + this.checkBox1.UseVisualStyleBackColor = true; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(9, 80); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(128, 21); + this.label2.TabIndex = 8; + this.label2.Text = "Cache choice for "; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(144, 111); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(66, 21); + this.label3.TabIndex = 9; + this.label3.Text = "minutes"; + this.label3.Click += new System.EventHandler(this.label3_Click); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(13, 144); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(41, 21); + this.label4.TabIndex = 10; + this.label4.Text = "Ping"; + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.radioButton2); + this.groupBox1.Controls.Add(this.radioButton1); + this.groupBox1.Location = new System.Drawing.Point(1008, 358); + this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.groupBox1.Size = new System.Drawing.Size(195, 80); + this.groupBox1.TabIndex = 3; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Chart Mode"; + // + // radioButton2 + // + this.radioButton2.AutoSize = true; + this.radioButton2.Location = new System.Drawing.Point(8, 47); + this.radioButton2.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.radioButton2.Name = "radioButton2"; + this.radioButton2.Size = new System.Drawing.Size(51, 25); + this.radioButton2.TabIndex = 1; + this.radioButton2.TabStop = true; + this.radioButton2.Text = "all"; + this.radioButton2.UseVisualStyleBackColor = true; + // + // radioButton1 + // + this.radioButton1.AutoSize = true; + this.radioButton1.Location = new System.Drawing.Point(8, 22); + this.radioButton1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.radioButton1.Name = "radioButton1"; + this.radioButton1.Size = new System.Drawing.Size(62, 25); + this.radioButton1.TabIndex = 0; + this.radioButton1.TabStop = true; + this.radioButton1.Text = "24h"; + this.radioButton1.UseVisualStyleBackColor = true; + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.splitContainer1.Name = "splitContainer1"; + this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.splitContainer2); + this.splitContainer1.Panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.splitContainer1_Panel1_Paint); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.groupBox1); + this.splitContainer1.Panel2.Controls.Add(this.StatisticsChart); + this.splitContainer1.Size = new System.Drawing.Size(1216, 920); + this.splitContainer1.SplitterDistance = 459; + this.splitContainer1.SplitterWidth = 7; + this.splitContainer1.TabIndex = 12; + // + // splitContainer2 + // + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer2.Location = new System.Drawing.Point(0, 0); + this.splitContainer2.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.splitContainer2.Name = "splitContainer2"; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.numericUpDown2); + this.splitContainer2.Panel1.Controls.Add(this.checkBox2); + this.splitContainer2.Panel1.Controls.Add(this.numericUpDown1); + this.splitContainer2.Panel1.Controls.Add(this.label6); + this.splitContainer2.Panel1.Controls.Add(this.label2); + this.splitContainer2.Panel1.Controls.Add(this.label4); + this.splitContainer2.Panel1.Controls.Add(this.checkBox1); + this.splitContainer2.Panel1.Controls.Add(this.label3); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.splitContainer3); + this.splitContainer2.Size = new System.Drawing.Size(1216, 459); + this.splitContainer2.SplitterDistance = 297; + this.splitContainer2.TabIndex = 7; + // + // checkBox2 + // + this.checkBox2.AutoSize = true; + this.checkBox2.Location = new System.Drawing.Point(13, 48); + this.checkBox2.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.checkBox2.Name = "checkBox2"; + this.checkBox2.Size = new System.Drawing.Size(254, 25); + this.checkBox2.TabIndex = 15; + this.checkBox2.Text = "Choose strategy by geolocation"; + this.checkBox2.UseVisualStyleBackColor = true; + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(62, 142); + this.numericUpDown1.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(75, 29); + this.numericUpDown1.TabIndex = 14; + this.numericUpDown1.Value = new decimal(new int[] { + 4, + 0, + 0, + 0}); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(143, 144); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(147, 21); + this.label6.TabIndex = 13; + this.label6.Text = "packages everytime"; + // + // splitContainer3 + // + this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer3.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer3.Location = new System.Drawing.Point(0, 0); + this.splitContainer3.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.splitContainer3.Name = "splitContainer3"; + this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer3.Panel1 + // + this.splitContainer3.Panel1.Controls.Add(this.label1); + // + // splitContainer3.Panel2 + // + this.splitContainer3.Panel2.Controls.Add(this.flowLayoutPanel1); + this.splitContainer3.Size = new System.Drawing.Size(915, 459); + this.splitContainer3.SplitterDistance = 34; + this.splitContainer3.SplitterWidth = 7; + this.splitContainer3.TabIndex = 6; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(4, 9); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(192, 21); + this.label1.TabIndex = 0; + this.label1.Text = "Design evaluation method"; + this.label1.Click += new System.EventHandler(this.label1_Click); + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.AutoScroll = true; + this.flowLayoutPanel1.Controls.Add(this.panel3); + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(915, 418); + this.flowLayoutPanel1.TabIndex = 1; + // + // panel3 + // + this.panel3.AutoSize = true; + this.panel3.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.panel3.Controls.Add(this.label5); + this.panel3.Controls.Add(this.label7); + this.panel3.Controls.Add(this.textBox5); + this.panel3.Controls.Add(this.comboBox3); + this.panel3.Location = new System.Drawing.Point(4, 7); + this.panel3.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(437, 43); + this.panel3.TabIndex = 4; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(4, 10); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(21, 21); + this.label5.TabIndex = 3; + this.label5.Text = "+"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(240, 10); + this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(21, 21); + this.label7.TabIndex = 2; + this.label7.Text = "×"; + // + // textBox5 + // + this.textBox5.Location = new System.Drawing.Point(269, 7); + this.textBox5.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.textBox5.Name = "textBox5"; + this.textBox5.Size = new System.Drawing.Size(164, 29); + this.textBox5.TabIndex = 1; + // + // comboBox3 + // + this.comboBox3.FormattingEnabled = true; + this.comboBox3.Location = new System.Drawing.Point(33, 7); + this.comboBox3.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.comboBox3.Name = "comboBox3"; + this.comboBox3.Size = new System.Drawing.Size(199, 29); + this.comboBox3.TabIndex = 0; + // + // numericUpDown2 + // + this.numericUpDown2.Location = new System.Drawing.Point(13, 109); + this.numericUpDown2.Maximum = new decimal(new int[] { + 60, + 0, + 0, + 0}); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(120, 29); + this.numericUpDown2.TabIndex = 16; + // + // StatisticsStrategyOptionsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 21F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.ClientSize = new System.Drawing.Size(1216, 920); + this.Controls.Add(this.splitContainer1); + this.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.MinimumSize = new System.Drawing.Size(800, 400); + this.Name = "StatisticsStrategyOptionsForm"; + this.Text = "StatisticsStrategyConfigurationForm"; + this.Load += new System.EventHandler(this.StatisticsStrategyOptionsForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel1.PerformLayout(); + this.splitContainer2.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.splitContainer3.Panel1.ResumeLayout(false); + this.splitContainer3.Panel1.PerformLayout(); + this.splitContainer3.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit(); + this.splitContainer3.ResumeLayout(false); + this.flowLayoutPanel1.ResumeLayout(false); + this.flowLayoutPanel1.PerformLayout(); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.DataVisualization.Charting.Chart StatisticsChart; + private System.Windows.Forms.CheckBox checkBox1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.RadioButton radioButton2; + private System.Windows.Forms.RadioButton radioButton1; + private System.Windows.Forms.SplitContainer splitContainer1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.Windows.Forms.SplitContainer splitContainer3; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.TextBox textBox5; + private System.Windows.Forms.ComboBox comboBox3; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.CheckBox checkBox2; + private System.Windows.Forms.NumericUpDown numericUpDown2; + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.cs b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.cs new file mode 100644 index 00000000..ca91bf7c --- /dev/null +++ b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace Shadowsocks.View +{ + public partial class StatisticsStrategyOptionsForm: Form + { + private static readonly int emSize = 8; + public StatisticsStrategyOptionsForm() + { + InitializeComponent(); + } + + + private void chart1_Click(object sender, EventArgs e) + { + + } + + private void StatisticsChart_Click(object sender, EventArgs e) + { + + } + + private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void label5_Click(object sender, EventArgs e) + { + + } + + private void StatisticsStrategyOptionsForm_Load(object sender, EventArgs e) + { + + } + + private void label3_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.resx b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/shadowsocks-csharp/app.manifest b/shadowsocks-csharp/app.manifest index 2f6c64aa..3cffa5a2 100755 --- a/shadowsocks-csharp/app.manifest +++ b/shadowsocks-csharp/app.manifest @@ -10,7 +10,7 @@ - true + True/PM \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 4a4b6db7..200393d3 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -63,11 +63,18 @@ + + + + + + + @@ -184,6 +191,12 @@ Form + + Form + + + StatisticsStrategyOptionsForm.cs + ConfigForm.cs Designer @@ -199,6 +212,9 @@ QRCodeForm.cs + + StatisticsStrategyOptionsForm.cs + Designer From 273b7d23308b24cfb2d763665417101da598df4a Mon Sep 17 00:00:00 2001 From: icylogic Date: Wed, 12 Aug 2015 22:32:04 +0800 Subject: [PATCH 002/109] adjust ui --- .../StatisticsStrategyOptionsForm.Designer.cs | 239 +++++++++--------- 1 file changed, 122 insertions(+), 117 deletions(-) diff --git a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs index 98232dc6..22c39b63 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs +++ b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs @@ -28,11 +28,11 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series7 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series8 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series9 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.StatisticsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.label2 = new System.Windows.Forms.Label(); @@ -43,6 +43,7 @@ this.radioButton1 = new System.Windows.Forms.RadioButton(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); this.checkBox2 = new System.Windows.Forms.CheckBox(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.label6 = new System.Windows.Forms.Label(); @@ -54,7 +55,6 @@ this.label7 = new System.Windows.Forms.Label(); this.textBox5 = new System.Windows.Forms.TextBox(); this.comboBox3 = new System.Windows.Forms.ComboBox(); - this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).BeginInit(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -65,6 +65,7 @@ this.splitContainer2.Panel1.SuspendLayout(); this.splitContainer2.Panel2.SuspendLayout(); this.splitContainer2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit(); this.splitContainer3.Panel1.SuspendLayout(); @@ -72,77 +73,76 @@ this.splitContainer3.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout(); this.panel3.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); this.SuspendLayout(); // // StatisticsChart // this.StatisticsChart.BackColor = System.Drawing.Color.Transparent; - chartArea1.AxisX.MajorGrid.Enabled = false; - chartArea1.AxisY.MajorGrid.Enabled = false; - chartArea1.AxisY2.MajorGrid.Enabled = false; - chartArea1.BackColor = System.Drawing.Color.Transparent; - chartArea1.Name = "ChartArea"; - this.StatisticsChart.ChartAreas.Add(chartArea1); + chartArea3.AxisX.MajorGrid.Enabled = false; + chartArea3.AxisY.MajorGrid.Enabled = false; + chartArea3.AxisY2.MajorGrid.Enabled = false; + chartArea3.BackColor = System.Drawing.Color.Transparent; + chartArea3.Name = "ChartArea"; + this.StatisticsChart.ChartAreas.Add(chartArea3); this.StatisticsChart.Dock = System.Windows.Forms.DockStyle.Fill; - legend1.BackColor = System.Drawing.Color.Transparent; - legend1.Name = "ChartLegend"; - this.StatisticsChart.Legends.Add(legend1); + legend3.BackColor = System.Drawing.Color.Transparent; + legend3.Name = "ChartLegend"; + this.StatisticsChart.Legends.Add(legend3); this.StatisticsChart.Location = new System.Drawing.Point(0, 0); - this.StatisticsChart.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.StatisticsChart.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.StatisticsChart.Name = "StatisticsChart"; this.StatisticsChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Pastel; - series1.ChartArea = "ChartArea"; - series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; - series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); - series1.Legend = "ChartLegend"; - series1.Name = "Data Transferred"; - series2.ChartArea = "ChartArea"; - series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; - series2.Color = System.Drawing.Color.Red; - series2.Legend = "ChartLegend"; - series2.Name = "Package Loss"; - series2.YValuesPerPoint = 4; - series3.BorderWidth = 4; - series3.ChartArea = "ChartArea"; - series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series3.Legend = "ChartLegend"; - series3.Name = "Ping"; - this.StatisticsChart.Series.Add(series1); - this.StatisticsChart.Series.Add(series2); - this.StatisticsChart.Series.Add(series3); - this.StatisticsChart.Size = new System.Drawing.Size(1216, 454); + series7.ChartArea = "ChartArea"; + series7.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; + series7.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); + series7.Legend = "ChartLegend"; + series7.Name = "Data Transferred"; + series8.ChartArea = "ChartArea"; + series8.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; + series8.Color = System.Drawing.Color.Red; + series8.Legend = "ChartLegend"; + series8.Name = "Package Loss"; + series8.YValuesPerPoint = 4; + series9.BorderWidth = 4; + series9.ChartArea = "ChartArea"; + series9.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series9.Legend = "ChartLegend"; + series9.Name = "Ping"; + this.StatisticsChart.Series.Add(series7); + this.StatisticsChart.Series.Add(series8); + this.StatisticsChart.Series.Add(series9); + this.StatisticsChart.Size = new System.Drawing.Size(1029, 239); this.StatisticsChart.TabIndex = 2; this.StatisticsChart.Click += new System.EventHandler(this.StatisticsChart_Click); // // checkBox1 // this.checkBox1.AutoSize = true; - this.checkBox1.Location = new System.Drawing.Point(13, 16); - this.checkBox1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.checkBox1.Location = new System.Drawing.Point(16, 21); + this.checkBox1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.checkBox1.Name = "checkBox1"; - this.checkBox1.Size = new System.Drawing.Size(254, 25); + this.checkBox1.Size = new System.Drawing.Size(204, 32); this.checkBox1.TabIndex = 5; - this.checkBox1.Text = "Choose strategy by geolocation"; + this.checkBox1.Text = "By ISP/geolocation"; this.checkBox1.UseVisualStyleBackColor = true; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(9, 80); - this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Location = new System.Drawing.Point(11, 107); + this.label2.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(128, 21); + this.label2.Size = new System.Drawing.Size(160, 28); this.label2.TabIndex = 8; this.label2.Text = "Cache choice for "; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(144, 111); - this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Location = new System.Drawing.Point(176, 148); + this.label3.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(66, 21); + this.label3.Size = new System.Drawing.Size(81, 28); this.label3.TabIndex = 9; this.label3.Text = "minutes"; this.label3.Click += new System.EventHandler(this.label3_Click); @@ -150,10 +150,10 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(13, 144); - this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Location = new System.Drawing.Point(16, 192); + this.label4.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(41, 21); + this.label4.Size = new System.Drawing.Size(51, 28); this.label4.TabIndex = 10; this.label4.Text = "Ping"; // @@ -162,11 +162,11 @@ this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.radioButton2); this.groupBox1.Controls.Add(this.radioButton1); - this.groupBox1.Location = new System.Drawing.Point(1008, 358); - this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.groupBox1.Location = new System.Drawing.Point(775, 107); + this.groupBox1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 7, 4, 7); - this.groupBox1.Size = new System.Drawing.Size(195, 80); + this.groupBox1.Padding = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.groupBox1.Size = new System.Drawing.Size(239, 107); this.groupBox1.TabIndex = 3; this.groupBox1.TabStop = false; this.groupBox1.Text = "Chart Mode"; @@ -174,10 +174,10 @@ // radioButton2 // this.radioButton2.AutoSize = true; - this.radioButton2.Location = new System.Drawing.Point(8, 47); - this.radioButton2.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.radioButton2.Location = new System.Drawing.Point(10, 63); + this.radioButton2.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.radioButton2.Name = "radioButton2"; - this.radioButton2.Size = new System.Drawing.Size(51, 25); + this.radioButton2.Size = new System.Drawing.Size(57, 32); this.radioButton2.TabIndex = 1; this.radioButton2.TabStop = true; this.radioButton2.Text = "all"; @@ -186,10 +186,10 @@ // radioButton1 // this.radioButton1.AutoSize = true; - this.radioButton1.Location = new System.Drawing.Point(8, 22); - this.radioButton1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.radioButton1.Location = new System.Drawing.Point(10, 30); + this.radioButton1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.radioButton1.Name = "radioButton1"; - this.radioButton1.Size = new System.Drawing.Size(62, 25); + this.radioButton1.Size = new System.Drawing.Size(70, 32); this.radioButton1.TabIndex = 0; this.radioButton1.TabStop = true; this.radioButton1.Text = "24h"; @@ -199,7 +199,7 @@ // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.Location = new System.Drawing.Point(0, 0); - this.splitContainer1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.splitContainer1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.splitContainer1.Name = "splitContainer1"; this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; // @@ -212,17 +212,18 @@ // this.splitContainer1.Panel2.Controls.Add(this.groupBox1); this.splitContainer1.Panel2.Controls.Add(this.StatisticsChart); - this.splitContainer1.Size = new System.Drawing.Size(1216, 920); - this.splitContainer1.SplitterDistance = 459; - this.splitContainer1.SplitterWidth = 7; + this.splitContainer1.Size = new System.Drawing.Size(1029, 496); + this.splitContainer1.SplitterDistance = 247; + this.splitContainer1.SplitterWidth = 10; this.splitContainer1.TabIndex = 12; // // splitContainer2 // this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer2.IsSplitterFixed = true; this.splitContainer2.Location = new System.Drawing.Point(0, 0); - this.splitContainer2.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.splitContainer2.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.splitContainer2.Name = "splitContainer2"; // // splitContainer2.Panel1 @@ -239,31 +240,46 @@ // splitContainer2.Panel2 // this.splitContainer2.Panel2.Controls.Add(this.splitContainer3); - this.splitContainer2.Size = new System.Drawing.Size(1216, 459); - this.splitContainer2.SplitterDistance = 297; + this.splitContainer2.Size = new System.Drawing.Size(1029, 247); + this.splitContainer2.SplitterDistance = 365; + this.splitContainer2.SplitterWidth = 5; this.splitContainer2.TabIndex = 7; // + // numericUpDown2 + // + this.numericUpDown2.Location = new System.Drawing.Point(16, 145); + this.numericUpDown2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.numericUpDown2.Maximum = new decimal(new int[] { + 60, + 0, + 0, + 0}); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(146, 34); + this.numericUpDown2.TabIndex = 16; + // // checkBox2 // this.checkBox2.AutoSize = true; - this.checkBox2.Location = new System.Drawing.Point(13, 48); - this.checkBox2.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.checkBox2.Location = new System.Drawing.Point(16, 64); + this.checkBox2.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.checkBox2.Name = "checkBox2"; - this.checkBox2.Size = new System.Drawing.Size(254, 25); + this.checkBox2.Size = new System.Drawing.Size(165, 32); this.checkBox2.TabIndex = 15; - this.checkBox2.Text = "Choose strategy by geolocation"; + this.checkBox2.Text = "By hour of day"; this.checkBox2.UseVisualStyleBackColor = true; // // numericUpDown1 // - this.numericUpDown1.Location = new System.Drawing.Point(62, 142); + this.numericUpDown1.Location = new System.Drawing.Point(76, 189); + this.numericUpDown1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.numericUpDown1.Maximum = new decimal(new int[] { 10, 0, 0, 0}); this.numericUpDown1.Name = "numericUpDown1"; - this.numericUpDown1.Size = new System.Drawing.Size(75, 29); + this.numericUpDown1.Size = new System.Drawing.Size(91, 34); this.numericUpDown1.TabIndex = 14; this.numericUpDown1.Value = new decimal(new int[] { 4, @@ -274,9 +290,9 @@ // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(143, 144); + this.label6.Location = new System.Drawing.Point(175, 192); this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(147, 21); + this.label6.Size = new System.Drawing.Size(184, 28); this.label6.TabIndex = 13; this.label6.Text = "packages everytime"; // @@ -284,8 +300,9 @@ // this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer3.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer3.IsSplitterFixed = true; this.splitContainer3.Location = new System.Drawing.Point(0, 0); - this.splitContainer3.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.splitContainer3.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.splitContainer3.Name = "splitContainer3"; this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal; // @@ -296,18 +313,18 @@ // splitContainer3.Panel2 // this.splitContainer3.Panel2.Controls.Add(this.flowLayoutPanel1); - this.splitContainer3.Size = new System.Drawing.Size(915, 459); - this.splitContainer3.SplitterDistance = 34; - this.splitContainer3.SplitterWidth = 7; + this.splitContainer3.Size = new System.Drawing.Size(659, 247); + this.splitContainer3.SplitterDistance = 46; + this.splitContainer3.SplitterWidth = 10; this.splitContainer3.TabIndex = 6; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(4, 9); - this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Location = new System.Drawing.Point(5, 12); + this.label1.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(192, 21); + this.label1.Size = new System.Drawing.Size(242, 28); this.label1.TabIndex = 0; this.label1.Text = "Design evaluation method"; this.label1.Click += new System.EventHandler(this.label1_Click); @@ -318,9 +335,9 @@ this.flowLayoutPanel1.Controls.Add(this.panel3); this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); - this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(915, 418); + this.flowLayoutPanel1.Size = new System.Drawing.Size(659, 191); this.flowLayoutPanel1.TabIndex = 1; // // panel3 @@ -331,71 +348,59 @@ this.panel3.Controls.Add(this.label7); this.panel3.Controls.Add(this.textBox5); this.panel3.Controls.Add(this.comboBox3); - this.panel3.Location = new System.Drawing.Point(4, 7); - this.panel3.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.panel3.Location = new System.Drawing.Point(5, 10); + this.panel3.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(437, 43); + this.panel3.Size = new System.Drawing.Size(533, 56); this.panel3.TabIndex = 4; // // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(4, 10); - this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label5.Location = new System.Drawing.Point(5, 13); + this.label5.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(21, 21); + this.label5.Size = new System.Drawing.Size(26, 28); this.label5.TabIndex = 3; this.label5.Text = "+"; // // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(240, 10); - this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label7.Location = new System.Drawing.Point(294, 13); + this.label7.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(21, 21); + this.label7.Size = new System.Drawing.Size(26, 28); this.label7.TabIndex = 2; this.label7.Text = "×"; // // textBox5 // - this.textBox5.Location = new System.Drawing.Point(269, 7); - this.textBox5.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.textBox5.Location = new System.Drawing.Point(329, 10); + this.textBox5.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.textBox5.Name = "textBox5"; - this.textBox5.Size = new System.Drawing.Size(164, 29); + this.textBox5.Size = new System.Drawing.Size(199, 34); this.textBox5.TabIndex = 1; // // comboBox3 // this.comboBox3.FormattingEnabled = true; - this.comboBox3.Location = new System.Drawing.Point(33, 7); - this.comboBox3.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); + this.comboBox3.Location = new System.Drawing.Point(41, 10); + this.comboBox3.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.comboBox3.Name = "comboBox3"; - this.comboBox3.Size = new System.Drawing.Size(199, 29); + this.comboBox3.Size = new System.Drawing.Size(243, 36); this.comboBox3.TabIndex = 0; // - // numericUpDown2 - // - this.numericUpDown2.Location = new System.Drawing.Point(13, 109); - this.numericUpDown2.Maximum = new decimal(new int[] { - 60, - 0, - 0, - 0}); - this.numericUpDown2.Name = "numericUpDown2"; - this.numericUpDown2.Size = new System.Drawing.Size(120, 29); - this.numericUpDown2.TabIndex = 16; - // // StatisticsStrategyOptionsForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 21F); + this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 28F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; - this.ClientSize = new System.Drawing.Size(1216, 920); + this.ClientSize = new System.Drawing.Size(1029, 496); this.Controls.Add(this.splitContainer1); - this.Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Margin = new System.Windows.Forms.Padding(4, 7, 4, 7); - this.MinimumSize = new System.Drawing.Size(800, 400); + this.Font = new System.Drawing.Font("Segoe UI", 10F); + this.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.MinimumSize = new System.Drawing.Size(973, 514); this.Name = "StatisticsStrategyOptionsForm"; this.Text = "StatisticsStrategyConfigurationForm"; this.Load += new System.EventHandler(this.StatisticsStrategyOptionsForm_Load); @@ -411,6 +416,7 @@ this.splitContainer2.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); this.splitContainer2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.splitContainer3.Panel1.ResumeLayout(false); this.splitContainer3.Panel1.PerformLayout(); @@ -421,7 +427,6 @@ this.flowLayoutPanel1.PerformLayout(); this.panel3.ResumeLayout(false); this.panel3.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); this.ResumeLayout(false); } From 76f0433eb27006a8534543fa929b50ab7601aaec Mon Sep 17 00:00:00 2001 From: icylogic Date: Wed, 12 Aug 2015 22:34:57 +0800 Subject: [PATCH 003/109] adjust form design --- .../StatisticsStrategyOptionsForm.Designer.cs | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs index 22c39b63..ca2dff75 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs +++ b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs @@ -28,11 +28,11 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series7 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series8 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series9 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.StatisticsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.label2 = new System.Windows.Forms.Label(); @@ -78,39 +78,40 @@ // StatisticsChart // this.StatisticsChart.BackColor = System.Drawing.Color.Transparent; - chartArea3.AxisX.MajorGrid.Enabled = false; - chartArea3.AxisY.MajorGrid.Enabled = false; - chartArea3.AxisY2.MajorGrid.Enabled = false; - chartArea3.BackColor = System.Drawing.Color.Transparent; - chartArea3.Name = "ChartArea"; - this.StatisticsChart.ChartAreas.Add(chartArea3); + chartArea1.AxisX.MajorGrid.Enabled = false; + chartArea1.AxisY.MajorGrid.Enabled = false; + chartArea1.AxisY2.MajorGrid.Enabled = false; + chartArea1.BackColor = System.Drawing.Color.Transparent; + chartArea1.Name = "ChartArea"; + this.StatisticsChart.ChartAreas.Add(chartArea1); this.StatisticsChart.Dock = System.Windows.Forms.DockStyle.Fill; - legend3.BackColor = System.Drawing.Color.Transparent; - legend3.Name = "ChartLegend"; - this.StatisticsChart.Legends.Add(legend3); + legend1.BackColor = System.Drawing.Color.Transparent; + legend1.Name = "ChartLegend"; + this.StatisticsChart.Legends.Add(legend1); this.StatisticsChart.Location = new System.Drawing.Point(0, 0); this.StatisticsChart.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.StatisticsChart.Name = "StatisticsChart"; this.StatisticsChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Pastel; - series7.ChartArea = "ChartArea"; - series7.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; - series7.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); - series7.Legend = "ChartLegend"; - series7.Name = "Data Transferred"; - series8.ChartArea = "ChartArea"; - series8.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; - series8.Color = System.Drawing.Color.Red; - series8.Legend = "ChartLegend"; - series8.Name = "Package Loss"; - series8.YValuesPerPoint = 4; - series9.BorderWidth = 4; - series9.ChartArea = "ChartArea"; - series9.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series9.Legend = "ChartLegend"; - series9.Name = "Ping"; - this.StatisticsChart.Series.Add(series7); - this.StatisticsChart.Series.Add(series8); - this.StatisticsChart.Series.Add(series9); + series1.ChartArea = "ChartArea"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; + series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); + series1.Legend = "ChartLegend"; + series1.Name = "Data Transferred"; + series2.ChartArea = "ChartArea"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; + series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(221)))), ((int)(((byte)(88)))), ((int)(((byte)(0))))); + series2.Legend = "ChartLegend"; + series2.Name = "Package Loss"; + series2.YValuesPerPoint = 4; + series3.BorderWidth = 4; + series3.ChartArea = "ChartArea"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Color = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(77)))), ((int)(((byte)(150))))); + series3.Legend = "ChartLegend"; + series3.Name = "Ping"; + this.StatisticsChart.Series.Add(series1); + this.StatisticsChart.Series.Add(series2); + this.StatisticsChart.Series.Add(series3); this.StatisticsChart.Size = new System.Drawing.Size(1029, 239); this.StatisticsChart.TabIndex = 2; this.StatisticsChart.Click += new System.EventHandler(this.StatisticsChart_Click); From e15ba8dc8b88308659892e41507a28809aad6040 Mon Sep 17 00:00:00 2001 From: icylogic Date: Wed, 12 Aug 2015 23:15:13 +0800 Subject: [PATCH 004/109] Refactor code with syntactic sugars in c#. --- .../Service/AvailabilityStatistics.cs | 71 +++++++++---------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs index 5a95dbc2..19cf64ad 100644 --- a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs +++ b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs @@ -5,27 +5,26 @@ using System.Linq; using System.Net.NetworkInformation; using System.Threading; using Shadowsocks.Model; -using System.Reflection; namespace Shadowsocks.Controller { class AvailabilityStatistics { - private static readonly string StatisticsFilesName = "shadowsocks.availability.csv"; - private static readonly string Delimiter = ","; - private static readonly int Timeout = 500; - private static readonly int Repeat = 4; //repeat times every evaluation - private static readonly int Interval = 10 * 60 * 1000; //evaluate proxies every 15 minutes - private Timer timer = null; - private State state = null; - private List servers; + private const string StatisticsFilesName = "shadowsocks.availability.csv"; + private const string Delimiter = ","; + private const int Timeout = 500; + private const int Repeat = 4; //repeat times every evaluation + private const int Interval = 10*60*1000; //evaluate proxies every 15 minutes + private Timer _timer; + private State _state; + private List _servers; public static string AvailabilityStatisticsFile; //static constructor to initialize every public static fields before refereced static AvailabilityStatistics() { - string temppath = Path.GetTempPath(); + var temppath = Path.GetTempPath(); AvailabilityStatisticsFile = Path.Combine(temppath, StatisticsFilesName); } @@ -35,15 +34,13 @@ namespace Shadowsocks.Controller { if (enabled) { - if (timer?.Change(0, Interval) == null) - { - state = new State(); - timer = new Timer(Evaluate, state, 0, Interval); - } + if (_timer?.Change(0, Interval) != null) return true; + _state = new State(); + _timer = new Timer(Evaluate, _state, 0, Interval); } else { - timer?.Dispose(); + _timer?.Dispose(); } return true; } @@ -56,54 +53,56 @@ namespace Shadowsocks.Controller private void Evaluate(object obj) { - Ping ping = new Ping(); - State state = (State) obj; - foreach (var server in servers) + var ping = new Ping(); + var state = (State) obj; + foreach (var server in _servers) { Logging.Debug("eveluating " + server.FriendlyName()); foreach (var _ in Enumerable.Range(0, Repeat)) { //TODO: do simple analyze of data to provide friendly message, like package loss. - string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //ICMP echo. we can also set options and special bytes - //seems no need to use SendPingAsync - PingReply reply = ping.Send(server.server, Timeout); - state.data = new List>(); - state.data.Add(new KeyValuePair("Timestamp", timestamp)); - state.data.Add(new KeyValuePair("Server", server.FriendlyName())); - state.data.Add(new KeyValuePair("Status", reply.Status.ToString())); - state.data.Add(new KeyValuePair("RoundtripTime", reply.RoundtripTime.ToString())); + //seems no need to use SendPingAsync: + var reply = ping.Send(server.server, Timeout); + state.Data = new List> + { + new KeyValuePair("Timestamp", timestamp), + new KeyValuePair("Server", server.FriendlyName()), + new KeyValuePair("Status", reply?.Status.ToString()), + new KeyValuePair("RoundtripTime", reply?.RoundtripTime.ToString()) + }; //state.data.Add(new KeyValuePair("data", reply.Buffer.ToString())); // The data of reply - Append(state.data); + Append(state.Data); } } } private static void Append(List> data) { - string dataLine = string.Join(Delimiter, data.Select(kv => kv.Value).ToArray()); + var dataLine = string.Join(Delimiter, data.Select(kv => kv.Value).ToArray()); string[] lines; if (!File.Exists(AvailabilityStatisticsFile)) { - string headerLine = string.Join(Delimiter, data.Select(kv => kv.Key).ToArray()); - lines = new string[] { headerLine, dataLine }; + var headerLine = string.Join(Delimiter, data.Select(kv => kv.Key).ToArray()); + lines = new[] { headerLine, dataLine }; } else { - lines = new string[] { dataLine }; + lines = new[] { dataLine }; } File.AppendAllLines(AvailabilityStatisticsFile, lines); } - internal void UpdateConfiguration(Configuration _config) + internal void UpdateConfiguration(Configuration config) { - Set(_config.availabilityStatistics); - servers = _config.configs; + Set(config.availabilityStatistics); + _servers = config.configs; } private class State { - public List> data = new List>(); + public List> Data = new List>(); } } } From c08463710e7536152490ec14a523daf59c273a87 Mon Sep 17 00:00:00 2001 From: icylogic Date: Thu, 13 Aug 2015 04:11:34 +0800 Subject: [PATCH 005/109] feature: get ISP --- .../Service/AvailabilityStatistics.cs | 87 ++++++++++++++----- shadowsocks-csharp/app.config | 21 ++++- shadowsocks-csharp/packages.config | 6 ++ shadowsocks-csharp/shadowsocks-csharp.csproj | 33 +++++++ 4 files changed, 121 insertions(+), 26 deletions(-) create mode 100644 shadowsocks-csharp/packages.config diff --git a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs index 19cf64ad..a6ddc578 100644 --- a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs +++ b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs @@ -2,12 +2,20 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; +using SimpleJson; +using System.Net.Http; using System.Net.NetworkInformation; -using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; using Shadowsocks.Model; +using SimpleJson = SimpleJson.SimpleJson; +using Timer = System.Threading.Timer; namespace Shadowsocks.Controller { + using DataUnit = KeyValuePair; + using DataList = List>; class AvailabilityStatistics { private const string StatisticsFilesName = "shadowsocks.availability.csv"; @@ -51,35 +59,67 @@ namespace Shadowsocks.Controller } } - private void Evaluate(object obj) + //hardcode + //TODO: backup reliable isp&geolocation provider or a local database is required + private static async Task getGeolocationAndISP() { + Logging.Debug("Retrive information of geolocation and isp"); + const string api = "http://ip-api.com/json"; + var jsonString = await new HttpClient().GetStringAsync(api); + var ret = new DataList + { + new DataUnit(State.Geolocation, State.Unknown), + new DataUnit(State.ISP, State.Unknown), + }; + dynamic obj; + if (!global::SimpleJson.SimpleJson.TryDeserializeObject(jsonString, out obj)) return ret; + string country = obj["country"]; + string city = obj["city"]; + string isp = obj["isp"]; + string regionName= obj["regionName"]; + if (country == null || city == null || isp == null || regionName == null) return ret; + ret[0] = new DataUnit(State.Geolocation, $"{country} {regionName} {city}"); + ret[1] = new DataUnit(State.ISP, isp); + return ret; + } + + private static async Task> ICMPTest(Server server) + { + Logging.Debug("eveluating " + server.FriendlyName()); var ping = new Ping(); - var state = (State) obj; - foreach (var server in _servers) + var ret = new List(); + foreach (var timestamp in Enumerable.Range(0, Repeat).Select(_ => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))) + { + //ICMP echo. we can also set options and special bytes + var reply = await ping.SendTaskAsync(server.server, Timeout); + ret.Add(new List> + { + new KeyValuePair("Timestamp", timestamp), + new KeyValuePair("Server", server.FriendlyName()), + new KeyValuePair("Status", reply?.Status.ToString()), + new KeyValuePair("RoundtripTime", reply?.RoundtripTime.ToString()) + //new KeyValuePair("data", reply.Buffer.ToString()); // The data of reply + }); + } + return ret; + } + + private async void Evaluate(object obj) + { + var geolocationAndIsp = getGeolocationAndISP(); + foreach (var dataLists in await TaskEx.WhenAll(_servers.Select(ICMPTest))) { - Logging.Debug("eveluating " + server.FriendlyName()); - foreach (var _ in Enumerable.Range(0, Repeat)) + await geolocationAndIsp; + foreach (var dataList in dataLists) { - //TODO: do simple analyze of data to provide friendly message, like package loss. - var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - //ICMP echo. we can also set options and special bytes - //seems no need to use SendPingAsync: - var reply = ping.Send(server.server, Timeout); - state.Data = new List> - { - new KeyValuePair("Timestamp", timestamp), - new KeyValuePair("Server", server.FriendlyName()), - new KeyValuePair("Status", reply?.Status.ToString()), - new KeyValuePair("RoundtripTime", reply?.RoundtripTime.ToString()) - }; - //state.data.Add(new KeyValuePair("data", reply.Buffer.ToString())); // The data of reply - Append(state.Data); + Append(dataList, geolocationAndIsp.Result); } } } - private static void Append(List> data) + private static void Append(DataList dataList, IEnumerable extra) { + var data = dataList.Concat(extra); var dataLine = string.Join(Delimiter, data.Select(kv => kv.Value).ToArray()); string[] lines; if (!File.Exists(AvailabilityStatisticsFile)) @@ -102,7 +142,10 @@ namespace Shadowsocks.Controller private class State { - public List> Data = new List>(); + public DataList dataList = new DataList(); + public const string Geolocation = "Geolocation"; + public const string ISP = "ISP"; + public const string Unknown = "Unknown"; } } } diff --git a/shadowsocks-csharp/app.config b/shadowsocks-csharp/app.config index 867ff468..a7ba1069 100755 --- a/shadowsocks-csharp/app.config +++ b/shadowsocks-csharp/app.config @@ -1,6 +1,19 @@ - + - - - + + + + + + + + + + + + + + + + diff --git a/shadowsocks-csharp/packages.config b/shadowsocks-csharp/packages.config new file mode 100644 index 00000000..2dd04b78 --- /dev/null +++ b/shadowsocks-csharp/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 200393d3..832a20c8 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -62,12 +62,39 @@ app.manifest + + + 3rd\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll + True + + + 3rd\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll + True + + + 3rd\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll + True + + + 3rd\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll + True + + + + + 3rd\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll + True + + + 3rd\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll + True + @@ -225,6 +252,7 @@ + @@ -267,6 +295,11 @@ + + + + + + + Shadowsocks.Model.StatisticsStrategyConfiguration, Shadowsocks, Version=2.5.2.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/shadowsocks-csharp/View/CalculationControl.Designer.cs b/shadowsocks-csharp/View/CalculationControl.Designer.cs new file mode 100644 index 00000000..62266759 --- /dev/null +++ b/shadowsocks-csharp/View/CalculationControl.Designer.cs @@ -0,0 +1,108 @@ +namespace Shadowsocks.View +{ + partial class CalculationControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.factorNum = new System.Windows.Forms.NumericUpDown(); + this.multiply = new System.Windows.Forms.Label(); + this.plus = new System.Windows.Forms.Label(); + this.valueLabel = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.factorNum)).BeginInit(); + this.SuspendLayout(); + // + // factorNum + // + this.factorNum.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.factorNum.Increment = new decimal(new int[] { + 1, + 0, + 0, + 131072}); + this.factorNum.Location = new System.Drawing.Point(320, 7); + this.factorNum.Minimum = new decimal(new int[] { + 1000, + 0, + 0, + -2147418112}); + this.factorNum.Name = "factorNum"; + this.factorNum.Size = new System.Drawing.Size(86, 34); + this.factorNum.TabIndex = 6; + // + // multiply + // + this.multiply.AutoSize = true; + this.multiply.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.multiply.Location = new System.Drawing.Point(286, 9); + this.multiply.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.multiply.Name = "multiply"; + this.multiply.Size = new System.Drawing.Size(26, 28); + this.multiply.TabIndex = 2; + this.multiply.Text = "×"; + // + // plus + // + this.plus.AutoSize = true; + this.plus.Font = new System.Drawing.Font("Segoe UI", 10F); + this.plus.Location = new System.Drawing.Point(5, 9); + this.plus.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.plus.Name = "plus"; + this.plus.Size = new System.Drawing.Size(26, 28); + this.plus.TabIndex = 3; + this.plus.Text = "+"; + // + // valueLabel + // + this.valueLabel.AutoSize = true; + this.valueLabel.Location = new System.Drawing.Point(39, 17); + this.valueLabel.Name = "valueLabel"; + this.valueLabel.Size = new System.Drawing.Size(0, 18); + this.valueLabel.TabIndex = 7; + // + // CalculationControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.valueLabel); + this.Controls.Add(this.factorNum); + this.Controls.Add(this.multiply); + this.Controls.Add(this.plus); + this.Name = "CalculationControl"; + this.Size = new System.Drawing.Size(425, 46); + ((System.ComponentModel.ISupportInitialize)(this.factorNum)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.NumericUpDown factorNum; + private System.Windows.Forms.Label multiply; + private System.Windows.Forms.Label plus; + private System.Windows.Forms.Label valueLabel; + } +} diff --git a/shadowsocks-csharp/View/CalculationControl.cs b/shadowsocks-csharp/View/CalculationControl.cs new file mode 100644 index 00000000..89a2228d --- /dev/null +++ b/shadowsocks-csharp/View/CalculationControl.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace Shadowsocks.View +{ + public partial class CalculationControl : UserControl + { + public CalculationControl(string value) + { + InitializeComponent(); + valueLabel.Text = value; + } + + public string Value => valueLabel.Text; + public float Factor => float.Parse(factorNum.Text); + } +} diff --git a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.resx b/shadowsocks-csharp/View/CalculationControl.resx similarity index 100% rename from shadowsocks-csharp/View/StatisticsStrategyOptionsForm.resx rename to shadowsocks-csharp/View/CalculationControl.resx diff --git a/shadowsocks-csharp/View/LogForm.Designer.cs b/shadowsocks-csharp/View/LogForm.Designer.cs index 7eb921ed..6320610d 100644 --- a/shadowsocks-csharp/View/LogForm.Designer.cs +++ b/shadowsocks-csharp/View/LogForm.Designer.cs @@ -44,19 +44,21 @@ this.textBox1.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.textBox1.ForeColor = System.Drawing.Color.White; this.textBox1.Location = new System.Drawing.Point(0, 0); + this.textBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.textBox1.MaxLength = 2147483647; this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; this.textBox1.ReadOnly = true; this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.textBox1.Size = new System.Drawing.Size(547, 382); + this.textBox1.Size = new System.Drawing.Size(820, 529); this.textBox1.TabIndex = 0; this.textBox1.WordWrap = false; // // contextMenuStrip1 // + this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); + this.contextMenuStrip1.Size = new System.Drawing.Size(74, 4); // // mainMenu1 // @@ -85,10 +87,11 @@ // // LogForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(547, 382); + this.ClientSize = new System.Drawing.Size(820, 529); this.Controls.Add(this.textBox1); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Menu = this.mainMenu1; this.Name = "LogForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 8d68a0aa..02ae335a 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -29,7 +29,6 @@ namespace Shadowsocks.View private MenuItem enableItem; private MenuItem modeItem; private MenuItem AutoStartupItem; - private MenuItem AvailabilityStatistics; private MenuItem ShareOverLANItem; private MenuItem SeperatorItem; private MenuItem ConfigItem; @@ -179,7 +178,6 @@ namespace Shadowsocks.View }), new MenuItem("-"), this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)), - this.AvailabilityStatistics = CreateMenuItem("Availability Statistics", new EventHandler(this.AvailabilityStatisticsItem_Click)), this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)), new MenuItem("-"), CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)), @@ -263,7 +261,6 @@ namespace Shadowsocks.View PACModeItem.Checked = !config.global; ShareOverLANItem.Checked = config.shareOverLan; AutoStartupItem.Checked = AutoStartup.Check(); - AvailabilityStatistics.Checked = config.availabilityStatistics; onlinePACItem.Checked = onlinePACItem.Enabled && config.useOnlinePac; localPACItem.Checked = !onlinePACItem.Checked; UpdatePACItemsEnabledStatus(); @@ -427,10 +424,10 @@ namespace Shadowsocks.View qrCodeForm.Show(); } - private static void StatisticsStrategyOptionsItem_Click(object sender, EventArgs e) + private void StatisticsStrategyOptionsItem_Click(object sender, EventArgs e) { //TODO: Load options - var statisticsStrategyOptionsForm = new StatisticsStrategyOptionsForm(); + var statisticsStrategyOptionsForm = new StatisticsStrategyConfigurationForm(controller); statisticsStrategyOptionsForm.Show(); //TODO: Save options } @@ -536,11 +533,6 @@ namespace Shadowsocks.View } } - private void AvailabilityStatisticsItem_Click(object sender, EventArgs e) { - AvailabilityStatistics.Checked = !AvailabilityStatistics.Checked; - controller.ToggleAvailabilityStatistics(AvailabilityStatistics.Checked); - } - private void LocalPACItem_Click(object sender, EventArgs e) { if (!localPACItem.Checked) diff --git a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs similarity index 50% rename from shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs rename to shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs index ca2dff75..8563fcc5 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.Designer.cs +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs @@ -1,6 +1,6 @@ namespace Shadowsocks.View { - partial class StatisticsStrategyOptionsForm + partial class StatisticsStrategyConfigurationForm { /// /// Required designer variable. @@ -28,13 +28,15 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.StatisticsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); - this.checkBox1 = new System.Windows.Forms.CheckBox(); + this.byISPCheckBox = new System.Windows.Forms.CheckBox(); + this.bindingConfiguration = new System.Windows.Forms.BindingSource(this.components); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); @@ -43,19 +45,21 @@ this.radioButton1 = new System.Windows.Forms.RadioButton(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); - this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); - this.checkBox2 = new System.Windows.Forms.CheckBox(); - this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label9 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.dataCollectionMinutesNum = new System.Windows.Forms.NumericUpDown(); + this.StatisticsEnabledCheckBox = new System.Windows.Forms.CheckBox(); + this.choiceKeptMinutesNum = new System.Windows.Forms.NumericUpDown(); + this.byHourOfDayCheckBox = new System.Windows.Forms.CheckBox(); + this.repeatTimesNum = new System.Windows.Forms.NumericUpDown(); this.label6 = new System.Windows.Forms.Label(); this.splitContainer3 = new System.Windows.Forms.SplitContainer(); this.label1 = new System.Windows.Forms.Label(); - this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); - this.panel3 = new System.Windows.Forms.Panel(); - this.label5 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - this.textBox5 = new System.Windows.Forms.TextBox(); - this.comboBox3 = new System.Windows.Forms.ComboBox(); + this.calculationContainer = new System.Windows.Forms.FlowLayoutPanel(); + this.OKButton = new System.Windows.Forms.Button(); + this.CancelButton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.bindingConfiguration)).BeginInit(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); @@ -65,93 +69,95 @@ this.splitContainer2.Panel1.SuspendLayout(); this.splitContainer2.Panel2.SuspendLayout(); this.splitContainer2.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataCollectionMinutesNum)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.choiceKeptMinutesNum)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.repeatTimesNum)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit(); this.splitContainer3.Panel1.SuspendLayout(); this.splitContainer3.Panel2.SuspendLayout(); this.splitContainer3.SuspendLayout(); - this.flowLayoutPanel1.SuspendLayout(); - this.panel3.SuspendLayout(); this.SuspendLayout(); // // StatisticsChart // this.StatisticsChart.BackColor = System.Drawing.Color.Transparent; - chartArea1.AxisX.MajorGrid.Enabled = false; - chartArea1.AxisY.MajorGrid.Enabled = false; - chartArea1.AxisY2.MajorGrid.Enabled = false; - chartArea1.BackColor = System.Drawing.Color.Transparent; - chartArea1.Name = "ChartArea"; - this.StatisticsChart.ChartAreas.Add(chartArea1); + chartArea2.AxisX.MajorGrid.Enabled = false; + chartArea2.AxisY.MajorGrid.Enabled = false; + chartArea2.AxisY2.MajorGrid.Enabled = false; + chartArea2.BackColor = System.Drawing.Color.Transparent; + chartArea2.Name = "ChartArea"; + this.StatisticsChart.ChartAreas.Add(chartArea2); this.StatisticsChart.Dock = System.Windows.Forms.DockStyle.Fill; - legend1.BackColor = System.Drawing.Color.Transparent; - legend1.Name = "ChartLegend"; - this.StatisticsChart.Legends.Add(legend1); + legend2.BackColor = System.Drawing.Color.Transparent; + legend2.Name = "ChartLegend"; + this.StatisticsChart.Legends.Add(legend2); this.StatisticsChart.Location = new System.Drawing.Point(0, 0); this.StatisticsChart.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.StatisticsChart.Name = "StatisticsChart"; this.StatisticsChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Pastel; - series1.ChartArea = "ChartArea"; - series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; - series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); - series1.Legend = "ChartLegend"; - series1.Name = "Data Transferred"; - series2.ChartArea = "ChartArea"; - series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; - series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(221)))), ((int)(((byte)(88)))), ((int)(((byte)(0))))); - series2.Legend = "ChartLegend"; - series2.Name = "Package Loss"; - series2.YValuesPerPoint = 4; - series3.BorderWidth = 4; - series3.ChartArea = "ChartArea"; - series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series3.Color = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(77)))), ((int)(((byte)(150))))); - series3.Legend = "ChartLegend"; - series3.Name = "Ping"; - this.StatisticsChart.Series.Add(series1); - this.StatisticsChart.Series.Add(series2); - this.StatisticsChart.Series.Add(series3); - this.StatisticsChart.Size = new System.Drawing.Size(1029, 239); + series4.ChartArea = "ChartArea"; + series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; + series4.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); + series4.Legend = "ChartLegend"; + series4.Name = "Data Transferred"; + series5.ChartArea = "ChartArea"; + series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; + series5.Color = System.Drawing.Color.FromArgb(((int)(((byte)(221)))), ((int)(((byte)(88)))), ((int)(((byte)(0))))); + series5.Legend = "ChartLegend"; + series5.Name = "Package Loss"; + series5.YValuesPerPoint = 4; + series6.BorderWidth = 4; + series6.ChartArea = "ChartArea"; + series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series6.Color = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(77)))), ((int)(((byte)(150))))); + series6.Legend = "ChartLegend"; + series6.Name = "Ping"; + this.StatisticsChart.Series.Add(series4); + this.StatisticsChart.Series.Add(series5); + this.StatisticsChart.Series.Add(series6); + this.StatisticsChart.Size = new System.Drawing.Size(951, 221); this.StatisticsChart.TabIndex = 2; - this.StatisticsChart.Click += new System.EventHandler(this.StatisticsChart_Click); // - // checkBox1 + // byISPCheckBox // - this.checkBox1.AutoSize = true; - this.checkBox1.Location = new System.Drawing.Point(16, 21); - this.checkBox1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.checkBox1.Name = "checkBox1"; - this.checkBox1.Size = new System.Drawing.Size(204, 32); - this.checkBox1.TabIndex = 5; - this.checkBox1.Text = "By ISP/geolocation"; - this.checkBox1.UseVisualStyleBackColor = true; + this.byISPCheckBox.AutoSize = true; + this.byISPCheckBox.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.bindingConfiguration, "ByIsp", true)); + this.byISPCheckBox.Location = new System.Drawing.Point(12, 56); + this.byISPCheckBox.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.byISPCheckBox.Name = "byISPCheckBox"; + this.byISPCheckBox.Size = new System.Drawing.Size(204, 32); + this.byISPCheckBox.TabIndex = 5; + this.byISPCheckBox.Text = "By ISP/geolocation"; + this.byISPCheckBox.UseVisualStyleBackColor = true; + // + // bindingConfiguration + // + this.bindingConfiguration.DataSource = typeof(Shadowsocks.Model.StatisticsStrategyConfiguration); // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(11, 107); + this.label2.Location = new System.Drawing.Point(7, 141); this.label2.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(160, 28); + this.label2.Size = new System.Drawing.Size(152, 28); this.label2.TabIndex = 8; - this.label2.Text = "Cache choice for "; + this.label2.Text = "Keep choice for "; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(176, 148); + this.label3.Location = new System.Drawing.Point(261, 141); this.label3.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(81, 28); this.label3.TabIndex = 9; this.label3.Text = "minutes"; - this.label3.Click += new System.EventHandler(this.label3_Click); // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(16, 192); + this.label4.Location = new System.Drawing.Point(12, 226); this.label4.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(51, 28); @@ -163,7 +169,7 @@ this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.radioButton2); this.groupBox1.Controls.Add(this.radioButton1); - this.groupBox1.Location = new System.Drawing.Point(775, 107); + this.groupBox1.Location = new System.Drawing.Point(698, 12); this.groupBox1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.groupBox1.Name = "groupBox1"; this.groupBox1.Padding = new System.Windows.Forms.Padding(5, 10, 5, 10); @@ -207,14 +213,15 @@ // splitContainer1.Panel1 // this.splitContainer1.Panel1.Controls.Add(this.splitContainer2); - this.splitContainer1.Panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.splitContainer1_Panel1_Paint); // // splitContainer1.Panel2 // + this.splitContainer1.Panel2.Controls.Add(this.CancelButton); + this.splitContainer1.Panel2.Controls.Add(this.OKButton); this.splitContainer1.Panel2.Controls.Add(this.groupBox1); this.splitContainer1.Panel2.Controls.Add(this.StatisticsChart); - this.splitContainer1.Size = new System.Drawing.Size(1029, 496); - this.splitContainer1.SplitterDistance = 247; + this.splitContainer1.Size = new System.Drawing.Size(951, 458); + this.splitContainer1.SplitterDistance = 227; this.splitContainer1.SplitterWidth = 10; this.splitContainer1.TabIndex = 12; // @@ -229,60 +236,143 @@ // // splitContainer2.Panel1 // - this.splitContainer2.Panel1.Controls.Add(this.numericUpDown2); - this.splitContainer2.Panel1.Controls.Add(this.checkBox2); - this.splitContainer2.Panel1.Controls.Add(this.numericUpDown1); + this.splitContainer2.Panel1.Controls.Add(this.label9); + this.splitContainer2.Panel1.Controls.Add(this.label8); + this.splitContainer2.Panel1.Controls.Add(this.dataCollectionMinutesNum); + this.splitContainer2.Panel1.Controls.Add(this.StatisticsEnabledCheckBox); + this.splitContainer2.Panel1.Controls.Add(this.choiceKeptMinutesNum); + this.splitContainer2.Panel1.Controls.Add(this.byHourOfDayCheckBox); + this.splitContainer2.Panel1.Controls.Add(this.repeatTimesNum); this.splitContainer2.Panel1.Controls.Add(this.label6); this.splitContainer2.Panel1.Controls.Add(this.label2); this.splitContainer2.Panel1.Controls.Add(this.label4); - this.splitContainer2.Panel1.Controls.Add(this.checkBox1); + this.splitContainer2.Panel1.Controls.Add(this.byISPCheckBox); this.splitContainer2.Panel1.Controls.Add(this.label3); // // splitContainer2.Panel2 // this.splitContainer2.Panel2.Controls.Add(this.splitContainer3); - this.splitContainer2.Size = new System.Drawing.Size(1029, 247); + this.splitContainer2.Size = new System.Drawing.Size(951, 227); this.splitContainer2.SplitterDistance = 365; this.splitContainer2.SplitterWidth = 5; this.splitContainer2.TabIndex = 7; // - // numericUpDown2 + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(7, 181); + this.label9.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(152, 28); + this.label9.TabIndex = 20; + this.label9.Text = "Collect Data per"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(261, 183); + this.label8.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(81, 28); + this.label8.TabIndex = 19; + this.label8.Text = "minutes"; + // + // dataCollectionMinutesNum + // + this.dataCollectionMinutesNum.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingConfiguration, "DataCollectionMinutes", true)); + this.dataCollectionMinutesNum.Increment = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.dataCollectionMinutesNum.Location = new System.Drawing.Point(161, 188); + this.dataCollectionMinutesNum.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataCollectionMinutesNum.Maximum = new decimal(new int[] { + 120, + 0, + 0, + 0}); + this.dataCollectionMinutesNum.Minimum = new decimal(new int[] { + 5, + 0, + 0, + 0}); + this.dataCollectionMinutesNum.Name = "dataCollectionMinutesNum"; + this.dataCollectionMinutesNum.Size = new System.Drawing.Size(92, 34); + this.dataCollectionMinutesNum.TabIndex = 18; + this.dataCollectionMinutesNum.Value = new decimal(new int[] { + 5, + 0, + 0, + 0}); + // + // StatisticsEnabledCheckBox + // + this.StatisticsEnabledCheckBox.AutoSize = true; + this.StatisticsEnabledCheckBox.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.bindingConfiguration, "StatisticsEnabled", true)); + this.StatisticsEnabledCheckBox.Location = new System.Drawing.Point(12, 12); + this.StatisticsEnabledCheckBox.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.StatisticsEnabledCheckBox.Name = "StatisticsEnabledCheckBox"; + this.StatisticsEnabledCheckBox.Size = new System.Drawing.Size(177, 32); + this.StatisticsEnabledCheckBox.TabIndex = 17; + this.StatisticsEnabledCheckBox.Text = "Enable Statistics"; + this.StatisticsEnabledCheckBox.UseVisualStyleBackColor = true; // - this.numericUpDown2.Location = new System.Drawing.Point(16, 145); - this.numericUpDown2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.numericUpDown2.Maximum = new decimal(new int[] { - 60, + // choiceKeptMinutesNum + // + this.choiceKeptMinutesNum.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingConfiguration, "ChoiceKeptMinutes", true)); + this.choiceKeptMinutesNum.Increment = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.choiceKeptMinutesNum.Location = new System.Drawing.Point(161, 139); + this.choiceKeptMinutesNum.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.choiceKeptMinutesNum.Maximum = new decimal(new int[] { + 120, + 0, + 0, + 0}); + this.choiceKeptMinutesNum.Minimum = new decimal(new int[] { + 5, + 0, + 0, + 0}); + this.choiceKeptMinutesNum.Name = "choiceKeptMinutesNum"; + this.choiceKeptMinutesNum.Size = new System.Drawing.Size(92, 34); + this.choiceKeptMinutesNum.TabIndex = 16; + this.choiceKeptMinutesNum.Value = new decimal(new int[] { + 5, 0, 0, 0}); - this.numericUpDown2.Name = "numericUpDown2"; - this.numericUpDown2.Size = new System.Drawing.Size(146, 34); - this.numericUpDown2.TabIndex = 16; - // - // checkBox2 - // - this.checkBox2.AutoSize = true; - this.checkBox2.Location = new System.Drawing.Point(16, 64); - this.checkBox2.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.checkBox2.Name = "checkBox2"; - this.checkBox2.Size = new System.Drawing.Size(165, 32); - this.checkBox2.TabIndex = 15; - this.checkBox2.Text = "By hour of day"; - this.checkBox2.UseVisualStyleBackColor = true; - // - // numericUpDown1 - // - this.numericUpDown1.Location = new System.Drawing.Point(76, 189); - this.numericUpDown1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.numericUpDown1.Maximum = new decimal(new int[] { + // + // byHourOfDayCheckBox + // + this.byHourOfDayCheckBox.AutoSize = true; + this.byHourOfDayCheckBox.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.bindingConfiguration, "ByHourOfDay", true)); + this.byHourOfDayCheckBox.Location = new System.Drawing.Point(12, 98); + this.byHourOfDayCheckBox.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.byHourOfDayCheckBox.Name = "byHourOfDayCheckBox"; + this.byHourOfDayCheckBox.Size = new System.Drawing.Size(165, 32); + this.byHourOfDayCheckBox.TabIndex = 15; + this.byHourOfDayCheckBox.Text = "By hour of day"; + this.byHourOfDayCheckBox.UseVisualStyleBackColor = true; + // + // repeatTimesNum + // + this.repeatTimesNum.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.bindingConfiguration, "RepeatTimesNum", true)); + this.repeatTimesNum.Location = new System.Drawing.Point(72, 223); + this.repeatTimesNum.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.repeatTimesNum.Maximum = new decimal(new int[] { 10, 0, 0, 0}); - this.numericUpDown1.Name = "numericUpDown1"; - this.numericUpDown1.Size = new System.Drawing.Size(91, 34); - this.numericUpDown1.TabIndex = 14; - this.numericUpDown1.Value = new decimal(new int[] { + this.repeatTimesNum.Name = "repeatTimesNum"; + this.repeatTimesNum.Size = new System.Drawing.Size(91, 34); + this.repeatTimesNum.TabIndex = 14; + this.repeatTimesNum.Value = new decimal(new int[] { 4, 0, 0, @@ -291,7 +381,7 @@ // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(175, 192); + this.label6.Location = new System.Drawing.Point(171, 226); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(184, 28); this.label6.TabIndex = 13; @@ -313,8 +403,8 @@ // // splitContainer3.Panel2 // - this.splitContainer3.Panel2.Controls.Add(this.flowLayoutPanel1); - this.splitContainer3.Size = new System.Drawing.Size(659, 247); + this.splitContainer3.Panel2.Controls.Add(this.calculationContainer); + this.splitContainer3.Size = new System.Drawing.Size(581, 227); this.splitContainer3.SplitterDistance = 46; this.splitContainer3.SplitterWidth = 10; this.splitContainer3.TabIndex = 6; @@ -328,84 +418,51 @@ this.label1.Size = new System.Drawing.Size(242, 28); this.label1.TabIndex = 0; this.label1.Text = "Design evaluation method"; - this.label1.Click += new System.EventHandler(this.label1_Click); - // - // flowLayoutPanel1 - // - this.flowLayoutPanel1.AutoScroll = true; - this.flowLayoutPanel1.Controls.Add(this.panel3); - this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); - this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(659, 191); - this.flowLayoutPanel1.TabIndex = 1; - // - // panel3 - // - this.panel3.AutoSize = true; - this.panel3.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.panel3.Controls.Add(this.label5); - this.panel3.Controls.Add(this.label7); - this.panel3.Controls.Add(this.textBox5); - this.panel3.Controls.Add(this.comboBox3); - this.panel3.Location = new System.Drawing.Point(5, 10); - this.panel3.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(533, 56); - this.panel3.TabIndex = 4; - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(5, 13); - this.label5.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(26, 28); - this.label5.TabIndex = 3; - this.label5.Text = "+"; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(294, 13); - this.label7.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(26, 28); - this.label7.TabIndex = 2; - this.label7.Text = "×"; - // - // textBox5 - // - this.textBox5.Location = new System.Drawing.Point(329, 10); - this.textBox5.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.textBox5.Name = "textBox5"; - this.textBox5.Size = new System.Drawing.Size(199, 34); - this.textBox5.TabIndex = 1; - // - // comboBox3 - // - this.comboBox3.FormattingEnabled = true; - this.comboBox3.Location = new System.Drawing.Point(41, 10); - this.comboBox3.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); - this.comboBox3.Name = "comboBox3"; - this.comboBox3.Size = new System.Drawing.Size(243, 36); - this.comboBox3.TabIndex = 0; - // - // StatisticsStrategyOptionsForm + // + // calculationContainer + // + this.calculationContainer.AutoScroll = true; + this.calculationContainer.Dock = System.Windows.Forms.DockStyle.Fill; + this.calculationContainer.Location = new System.Drawing.Point(0, 0); + this.calculationContainer.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); + this.calculationContainer.Name = "calculationContainer"; + this.calculationContainer.Size = new System.Drawing.Size(581, 171); + this.calculationContainer.TabIndex = 1; + // + // OKButton + // + this.OKButton.Location = new System.Drawing.Point(745, 166); + this.OKButton.Name = "OKButton"; + this.OKButton.Size = new System.Drawing.Size(93, 43); + this.OKButton.TabIndex = 4; + this.OKButton.Text = "OK"; + this.OKButton.UseVisualStyleBackColor = true; + this.OKButton.Click += new System.EventHandler(this.OKButton_Click); + // + // CancelButton + // + this.CancelButton.Location = new System.Drawing.Point(844, 166); + this.CancelButton.Name = "CancelButton"; + this.CancelButton.Size = new System.Drawing.Size(93, 43); + this.CancelButton.TabIndex = 5; + this.CancelButton.Text = "Cancel"; + this.CancelButton.UseVisualStyleBackColor = true; + this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click); + // + // StatisticsStrategyConfigurationForm // this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 28F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; - this.ClientSize = new System.Drawing.Size(1029, 496); + this.ClientSize = new System.Drawing.Size(951, 458); this.Controls.Add(this.splitContainer1); this.Font = new System.Drawing.Font("Segoe UI", 10F); this.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.MinimumSize = new System.Drawing.Size(973, 514); - this.Name = "StatisticsStrategyOptionsForm"; + this.Name = "StatisticsStrategyConfigurationForm"; this.Text = "StatisticsStrategyConfigurationForm"; - this.Load += new System.EventHandler(this.StatisticsStrategyOptionsForm_Load); ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.bindingConfiguration)).EndInit(); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.splitContainer1.Panel1.ResumeLayout(false); @@ -417,24 +474,21 @@ this.splitContainer2.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); this.splitContainer2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataCollectionMinutesNum)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.choiceKeptMinutesNum)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.repeatTimesNum)).EndInit(); this.splitContainer3.Panel1.ResumeLayout(false); this.splitContainer3.Panel1.PerformLayout(); this.splitContainer3.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit(); this.splitContainer3.ResumeLayout(false); - this.flowLayoutPanel1.ResumeLayout(false); - this.flowLayoutPanel1.PerformLayout(); - this.panel3.ResumeLayout(false); - this.panel3.PerformLayout(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.DataVisualization.Charting.Chart StatisticsChart; - private System.Windows.Forms.CheckBox checkBox1; + private System.Windows.Forms.CheckBox byISPCheckBox; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; @@ -444,16 +498,18 @@ private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.Label label1; private System.Windows.Forms.SplitContainer splitContainer2; - private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.Windows.Forms.FlowLayoutPanel calculationContainer; private System.Windows.Forms.SplitContainer splitContainer3; - private System.Windows.Forms.Panel panel3; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.TextBox textBox5; - private System.Windows.Forms.ComboBox comboBox3; - private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.NumericUpDown repeatTimesNum; private System.Windows.Forms.Label label6; - private System.Windows.Forms.CheckBox checkBox2; - private System.Windows.Forms.NumericUpDown numericUpDown2; + private System.Windows.Forms.CheckBox byHourOfDayCheckBox; + private System.Windows.Forms.NumericUpDown choiceKeptMinutesNum; + private System.Windows.Forms.CheckBox StatisticsEnabledCheckBox; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.NumericUpDown dataCollectionMinutesNum; + private System.Windows.Forms.BindingSource bindingConfiguration; + private System.Windows.Forms.Button CancelButton; + private System.Windows.Forms.Button OKButton; } } \ No newline at end of file diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs new file mode 100644 index 00000000..970b5761 --- /dev/null +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using Shadowsocks.Controller; +using Shadowsocks.Model; +using SimpleJson; + +namespace Shadowsocks.View +{ + public partial class StatisticsStrategyConfigurationForm: Form + { + private ShadowsocksController _controller; + private StatisticsStrategyConfiguration _configuration; + + public StatisticsStrategyConfigurationForm(ShadowsocksController controller) + { + if (controller == null) return; + InitializeComponent(); + _controller = controller; + _controller.ConfigChanged += (sender, args) => LoadConfiguration(); + LoadConfiguration(); + Load += (sender, args) => InitData(); + } + + private void LoadConfiguration() + { + _configuration = _controller.GetConfigurationCopy()?.statisticsStrategyConfiguration + ?? new StatisticsStrategyConfiguration(); + } + + private void InitData() + { + bindingConfiguration.Add(_configuration); + foreach (var kv in _configuration.Calculations) + { + var calculation = new CalculationControl(kv.Key); + calculationContainer.Controls.Add(calculation); + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void OKButton_Click(object sender, EventArgs e) + { + foreach (CalculationControl calculation in calculationContainer.Controls) + { + _configuration.Calculations[calculation.Value] = calculation.Factor; + } + _controller?.SaveStrategyConfigurations(_configuration); + Close(); + } + } +} diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx new file mode 100644 index 00000000..55c9d750 --- /dev/null +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 1, 30 + + + 1, 30 + + \ No newline at end of file diff --git a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.cs b/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.cs deleted file mode 100644 index ca91bf7c..00000000 --- a/shadowsocks-csharp/View/StatisticsStrategyOptionsForm.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; - -namespace Shadowsocks.View -{ - public partial class StatisticsStrategyOptionsForm: Form - { - private static readonly int emSize = 8; - public StatisticsStrategyOptionsForm() - { - InitializeComponent(); - } - - - private void chart1_Click(object sender, EventArgs e) - { - - } - - private void StatisticsChart_Click(object sender, EventArgs e) - { - - } - - private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e) - { - - } - - private void label1_Click(object sender, EventArgs e) - { - - } - - private void label5_Click(object sender, EventArgs e) - { - - } - - private void StatisticsStrategyOptionsForm_Load(object sender, EventArgs e) - { - - } - - private void label3_Click(object sender, EventArgs e) - { - - } - } -} diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 128a903e..6fb5da2c 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -167,7 +167,7 @@ - + @@ -189,6 +189,7 @@ + True True @@ -210,6 +211,12 @@ + + UserControl + + + CalculationControl.cs + Form @@ -226,11 +233,11 @@ Form - + Form - - StatisticsStrategyOptionsForm.cs + + StatisticsStrategyConfigurationForm.cs ConfigForm.cs @@ -241,14 +248,17 @@ Designer Resources.Designer.cs + + CalculationControl.cs + LogForm.cs QRCodeForm.cs - - StatisticsStrategyOptionsForm.cs + + StatisticsStrategyConfigurationForm.cs @@ -261,6 +271,7 @@ + From 99baeb89f39e2b8a3bf573d3d8a79e3be4d78fd7 Mon Sep 17 00:00:00 2001 From: icylogic Date: Mon, 17 Aug 2015 11:28:41 +0800 Subject: [PATCH 012/109] log "No such host is known" exception --- .../Service/AvailabilityStatistics.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs index 532ec466..1c69298d 100644 --- a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs +++ b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs @@ -96,15 +96,22 @@ namespace Shadowsocks.Controller foreach (var timestamp in Enumerable.Range(0, Repeat).Select(_ => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))) { //ICMP echo. we can also set options and special bytes - var reply = await ping.SendTaskAsync(server.server, Timeout); - ret.Add(new List> + try { - new KeyValuePair("Timestamp", timestamp), - new KeyValuePair("Server", server.FriendlyName()), - new KeyValuePair("Status", reply?.Status.ToString()), - new KeyValuePair("RoundtripTime", reply?.RoundtripTime.ToString()) - //new KeyValuePair("data", reply.Buffer.ToString()); // The data of reply - }); + var reply = await ping.SendTaskAsync(server.server, Timeout); + ret.Add(new List> + { + new KeyValuePair("Timestamp", timestamp), + new KeyValuePair("Server", server.FriendlyName()), + new KeyValuePair("Status", reply?.Status.ToString()), + new KeyValuePair("RoundtripTime", reply?.RoundtripTime.ToString()) + //new KeyValuePair("data", reply.Buffer.ToString()); // The data of reply + }); + } + catch (PingException e) + { + Logging.LogUsefulException(e); + } } return ret; } From 6ed32ff7094e9776262bf113bf4c51f60ebeb8dc Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Thu, 20 Aug 2015 17:17:21 +0800 Subject: [PATCH 013/109] improved `log viewer`: 1. add menu items for `clear logs`, `change fonts`, `wrap text` and `top most` functions. 2. hide toolbar default. but you can trigger it out by menu. --- shadowsocks-csharp/Data/cn.txt | 6 +- shadowsocks-csharp/View/LogForm.Designer.cs | 159 ++++++++++++++------ shadowsocks-csharp/View/LogForm.cs | 109 +++++++++++++- shadowsocks-csharp/View/LogForm.resx | 5 +- 4 files changed, 217 insertions(+), 62 deletions(-) diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index 81022f99..79f8d6f4 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -50,10 +50,12 @@ Move D&own=下移(&O) &File=文件(&F) &Open Location=在资源管理器中打开(&O) E&xit=退出(&X) -&Clean logs=清空(&C) -&Font=字体(&F) +&View=视图(&V) +&Clean logs=清空日志(&C) +Change &font=设置字体(&F) &Wrap text=自动换行(&W) &Top most=置顶(&T) +&Show toolbar=显示工具栏(&S) Log Viewer=日志查看器 # QRCode Form diff --git a/shadowsocks-csharp/View/LogForm.Designer.cs b/shadowsocks-csharp/View/LogForm.Designer.cs index d0913d16..187ab948 100644 --- a/shadowsocks-csharp/View/LogForm.Designer.cs +++ b/shadowsocks-csharp/View/LogForm.Designer.cs @@ -30,19 +30,25 @@ { this.components = new System.ComponentModel.Container(); this.LogMessageTextBox = new System.Windows.Forms.TextBox(); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components); + this.MainMenu = new System.Windows.Forms.MainMenu(this.components); this.FileMenuItem = new System.Windows.Forms.MenuItem(); this.OpenLocationMenuItem = new System.Windows.Forms.MenuItem(); this.ExitMenuItem = new System.Windows.Forms.MenuItem(); - this.panel1 = new System.Windows.Forms.Panel(); + this.ViewMenuItem = new System.Windows.Forms.MenuItem(); + this.CleanLogsMenuItem = new System.Windows.Forms.MenuItem(); + this.ChangeFontMenuItem = new System.Windows.Forms.MenuItem(); + this.WrapTextMenuItem = new System.Windows.Forms.MenuItem(); + this.TopMostMenuItem = new System.Windows.Forms.MenuItem(); + this.MenuItemSeparater = new System.Windows.Forms.MenuItem(); + this.ShowToolbarMenuItem = new System.Windows.Forms.MenuItem(); + this.TopMostCheckBox = new System.Windows.Forms.CheckBox(); this.ChangeFontButton = new System.Windows.Forms.Button(); this.CleanLogsButton = new System.Windows.Forms.Button(); this.WrapTextCheckBox = new System.Windows.Forms.CheckBox(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.TopMostCheckBox = new System.Windows.Forms.CheckBox(); - this.panel1.SuspendLayout(); + this.ToolbarFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); this.tableLayoutPanel1.SuspendLayout(); + this.ToolbarFlowLayoutPanel.SuspendLayout(); this.SuspendLayout(); // // LogMessageTextBox @@ -51,25 +57,20 @@ this.LogMessageTextBox.Dock = System.Windows.Forms.DockStyle.Fill; this.LogMessageTextBox.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.LogMessageTextBox.ForeColor = System.Drawing.Color.White; - this.LogMessageTextBox.Location = new System.Drawing.Point(3, 43); + this.LogMessageTextBox.Location = new System.Drawing.Point(3, 38); this.LogMessageTextBox.MaxLength = 2147483647; this.LogMessageTextBox.Multiline = true; this.LogMessageTextBox.Name = "LogMessageTextBox"; this.LogMessageTextBox.ReadOnly = true; this.LogMessageTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.LogMessageTextBox.Size = new System.Drawing.Size(541, 307); + this.LogMessageTextBox.Size = new System.Drawing.Size(584, 377); this.LogMessageTextBox.TabIndex = 0; - this.LogMessageTextBox.WordWrap = false; - // - // contextMenuStrip1 // - this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); + // MainMenu // - // mainMenu1 - // - this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { - this.FileMenuItem}); + this.MainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.FileMenuItem, + this.ViewMenuItem}); // // FileMenuItem // @@ -91,21 +92,70 @@ this.ExitMenuItem.Text = "E&xit"; this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click); // - // panel1 + // ViewMenuItem + // + this.ViewMenuItem.Index = 1; + this.ViewMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.CleanLogsMenuItem, + this.ChangeFontMenuItem, + this.WrapTextMenuItem, + this.TopMostMenuItem, + this.MenuItemSeparater, + this.ShowToolbarMenuItem}); + this.ViewMenuItem.Text = "&View"; + // + // CleanLogsMenuItem + // + this.CleanLogsMenuItem.Index = 0; + this.CleanLogsMenuItem.Text = "&Clean logs"; + this.CleanLogsMenuItem.Click += new System.EventHandler(this.CleanLogsMenuItem_Click); + // + // ChangeFontMenuItem + // + this.ChangeFontMenuItem.Index = 1; + this.ChangeFontMenuItem.Text = "Change &font"; + this.ChangeFontMenuItem.Click += new System.EventHandler(this.ChangeFontMenuItem_Click); // - this.panel1.Controls.Add(this.TopMostCheckBox); - this.panel1.Controls.Add(this.ChangeFontButton); - this.panel1.Controls.Add(this.CleanLogsButton); - this.panel1.Controls.Add(this.WrapTextCheckBox); - this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel1.Location = new System.Drawing.Point(3, 3); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(541, 34); - this.panel1.TabIndex = 1; + // WrapTextMenuItem + // + this.WrapTextMenuItem.Index = 2; + this.WrapTextMenuItem.Text = "&Wrap text"; + this.WrapTextMenuItem.Click += new System.EventHandler(this.WrapTextMenuItem_Click); + // + // TopMostMenuItem + // + this.TopMostMenuItem.Index = 3; + this.TopMostMenuItem.Text = "&Top most"; + this.TopMostMenuItem.Click += new System.EventHandler(this.TopMostMenuItem_Click); + // + // MenuItemSeparater + // + this.MenuItemSeparater.Index = 4; + this.MenuItemSeparater.Text = "-"; + // + // ShowToolbarMenuItem + // + this.ShowToolbarMenuItem.Index = 5; + this.ShowToolbarMenuItem.Text = "&Show toolbar"; + this.ShowToolbarMenuItem.Click += new System.EventHandler(this.ShowToolbarMenuItem_Click); + // + // TopMostCheckBox + // + this.TopMostCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.TopMostCheckBox.AutoSize = true; + this.TopMostCheckBox.Location = new System.Drawing.Point(249, 3); + this.TopMostCheckBox.Name = "TopMostCheckBox"; + this.TopMostCheckBox.Size = new System.Drawing.Size(72, 23); + this.TopMostCheckBox.TabIndex = 3; + this.TopMostCheckBox.Text = "&Top most"; + this.TopMostCheckBox.UseVisualStyleBackColor = true; + this.TopMostCheckBox.CheckedChanged += new System.EventHandler(this.TopMostCheckBox_CheckedChanged); // // ChangeFontButton // - this.ChangeFontButton.Location = new System.Drawing.Point(107, 4); + this.ChangeFontButton.AutoSize = true; + this.ChangeFontButton.Location = new System.Drawing.Point(84, 3); this.ChangeFontButton.Name = "ChangeFontButton"; this.ChangeFontButton.Size = new System.Drawing.Size(75, 23); this.ChangeFontButton.TabIndex = 2; @@ -115,7 +165,8 @@ // // CleanLogsButton // - this.CleanLogsButton.Location = new System.Drawing.Point(9, 4); + this.CleanLogsButton.AutoSize = true; + this.CleanLogsButton.Location = new System.Drawing.Point(3, 3); this.CleanLogsButton.Name = "CleanLogsButton"; this.CleanLogsButton.Size = new System.Drawing.Size(75, 23); this.CleanLogsButton.TabIndex = 1; @@ -125,10 +176,12 @@ // // WrapTextCheckBox // + this.WrapTextCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); this.WrapTextCheckBox.AutoSize = true; - this.WrapTextCheckBox.Location = new System.Drawing.Point(209, 9); + this.WrapTextCheckBox.Location = new System.Drawing.Point(165, 3); this.WrapTextCheckBox.Name = "WrapTextCheckBox"; - this.WrapTextCheckBox.Size = new System.Drawing.Size(78, 16); + this.WrapTextCheckBox.Size = new System.Drawing.Size(78, 23); this.WrapTextCheckBox.TabIndex = 0; this.WrapTextCheckBox.Text = "&Wrap text"; this.WrapTextCheckBox.UseVisualStyleBackColor = true; @@ -138,45 +191,47 @@ // this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 0); this.tableLayoutPanel1.Controls.Add(this.LogMessageTextBox, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.ToolbarFlowLayoutPanel, 0, 0); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 2; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.Size = new System.Drawing.Size(547, 353); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.Size = new System.Drawing.Size(590, 418); this.tableLayoutPanel1.TabIndex = 2; // - // TopMostCheckBox + // ToolbarFlowLayoutPanel // - this.TopMostCheckBox.AutoSize = true; - this.TopMostCheckBox.Location = new System.Drawing.Point(311, 9); - this.TopMostCheckBox.Name = "TopMostCheckBox"; - this.TopMostCheckBox.Size = new System.Drawing.Size(72, 16); - this.TopMostCheckBox.TabIndex = 3; - this.TopMostCheckBox.Text = "&Top most"; - this.TopMostCheckBox.UseVisualStyleBackColor = true; - this.TopMostCheckBox.CheckedChanged += new System.EventHandler(this.TopMostCheckBox_CheckedChanged); + this.ToolbarFlowLayoutPanel.AutoSize = true; + this.ToolbarFlowLayoutPanel.Controls.Add(this.CleanLogsButton); + this.ToolbarFlowLayoutPanel.Controls.Add(this.ChangeFontButton); + this.ToolbarFlowLayoutPanel.Controls.Add(this.WrapTextCheckBox); + this.ToolbarFlowLayoutPanel.Controls.Add(this.TopMostCheckBox); + this.ToolbarFlowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.ToolbarFlowLayoutPanel.Location = new System.Drawing.Point(3, 3); + this.ToolbarFlowLayoutPanel.Name = "ToolbarFlowLayoutPanel"; + this.ToolbarFlowLayoutPanel.Size = new System.Drawing.Size(584, 29); + this.ToolbarFlowLayoutPanel.TabIndex = 2; // // LogForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(547, 353); + this.ClientSize = new System.Drawing.Size(590, 418); this.Controls.Add(this.tableLayoutPanel1); - this.Menu = this.mainMenu1; + this.Menu = this.MainMenu; this.Name = "LogForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Log Viewer"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LogForm_FormClosing); this.Load += new System.EventHandler(this.LogForm_Load); this.Shown += new System.EventHandler(this.LogForm_Shown); - this.panel1.ResumeLayout(false); - this.panel1.PerformLayout(); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); + this.ToolbarFlowLayoutPanel.ResumeLayout(false); + this.ToolbarFlowLayoutPanel.PerformLayout(); this.ResumeLayout(false); } @@ -184,16 +239,22 @@ #endregion private System.Windows.Forms.TextBox LogMessageTextBox; - private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; - private System.Windows.Forms.MainMenu mainMenu1; + private System.Windows.Forms.MainMenu MainMenu; private System.Windows.Forms.MenuItem FileMenuItem; private System.Windows.Forms.MenuItem OpenLocationMenuItem; private System.Windows.Forms.MenuItem ExitMenuItem; - private System.Windows.Forms.Panel panel1; private System.Windows.Forms.CheckBox WrapTextCheckBox; private System.Windows.Forms.Button CleanLogsButton; private System.Windows.Forms.Button ChangeFontButton; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.CheckBox TopMostCheckBox; + private System.Windows.Forms.MenuItem ViewMenuItem; + private System.Windows.Forms.MenuItem CleanLogsMenuItem; + private System.Windows.Forms.MenuItem ChangeFontMenuItem; + private System.Windows.Forms.MenuItem WrapTextMenuItem; + private System.Windows.Forms.MenuItem TopMostMenuItem; + private System.Windows.Forms.FlowLayoutPanel ToolbarFlowLayoutPanel; + private System.Windows.Forms.MenuItem MenuItemSeparater; + private System.Windows.Forms.MenuItem ShowToolbarMenuItem; } } \ No newline at end of file diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index c4fcaf51..dcbbf1e2 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -34,9 +34,15 @@ namespace Shadowsocks.View OpenLocationMenuItem.Text = I18N.GetString("&Open Location"); ExitMenuItem.Text = I18N.GetString("E&xit"); CleanLogsButton.Text = I18N.GetString("&Clean logs"); - ChangeFontButton.Text = I18N.GetString("&Font"); + ChangeFontButton.Text = I18N.GetString("Change &font"); WrapTextCheckBox.Text = I18N.GetString("&Wrap text"); TopMostCheckBox.Text = I18N.GetString("&Top most"); + ViewMenuItem.Text = I18N.GetString("&View"); + CleanLogsMenuItem.Text = I18N.GetString("&Clean logs"); + ChangeFontMenuItem.Text = I18N.GetString("Change &font"); + WrapTextMenuItem.Text = I18N.GetString("&Wrap text"); + TopMostMenuItem.Text = I18N.GetString("&Top most"); + ShowToolbarMenuItem.Text = I18N.GetString("&Show toolbar"); this.Text = I18N.GetString("Log Viewer"); } @@ -97,6 +103,9 @@ namespace Shadowsocks.View timer.Interval = 300; timer.Tick += Timer_Tick; timer.Start(); + this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = TopMostTrigger; + LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked = WrapTextMenuItem.Checked = WrapTextTrigger; + ToolbarFlowLayoutPanel.Visible = ShowToolbarTrigger; } private void LogForm_FormClosing(object sender, FormClosingEventArgs e) @@ -121,18 +130,25 @@ namespace Shadowsocks.View LogMessageTextBox.ScrollToCaret(); } - private void WrapTextCheckBox_CheckedChanged(object sender, EventArgs e) + #region Clean up the content in LogMessageTextBox. + private void DoCleanLogs() { - LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked; - LogMessageTextBox.ScrollToCaret(); + LogMessageTextBox.Clear(); + } + + private void CleanLogsMenuItem_Click(object sender, EventArgs e) + { + DoCleanLogs(); } private void CleanLogsButton_Click(object sender, EventArgs e) { - LogMessageTextBox.Clear(); + DoCleanLogs(); } + #endregion - private void ChangeFontButton_Click(object sender, EventArgs e) + #region Change the font settings applied in LogMessageTextBox. + private void DoChangeFont() { FontDialog fd = new FontDialog(); fd.Font = LogMessageTextBox.Font; @@ -142,9 +158,88 @@ namespace Shadowsocks.View } } + private void ChangeFontMenuItem_Click(object sender, EventArgs e) + { + DoChangeFont(); + } + + private void ChangeFontButton_Click(object sender, EventArgs e) + { + DoChangeFont(); + } + #endregion + + #region Trigger the log messages wrapable, or not. + bool WrapTextTrigger = false; + bool WrapTextTriggerLock = false; + + private void TriggerWrapText() + { + WrapTextTriggerLock = true; + + WrapTextTrigger = !WrapTextTrigger; + LogMessageTextBox.WordWrap = WrapTextTrigger; + LogMessageTextBox.ScrollToCaret(); + WrapTextMenuItem.Checked = WrapTextCheckBox.Checked = WrapTextTrigger; + + WrapTextTriggerLock = false; + } + + private void WrapTextMenuItem_Click(object sender, EventArgs e) + { + if (!WrapTextTriggerLock) + { + TriggerWrapText(); + } + } + + private void WrapTextCheckBox_CheckedChanged(object sender, EventArgs e) + { + if (!WrapTextTriggerLock) + { + TriggerWrapText(); + } + } + #endregion + + #region Trigger this window top most, or not. + bool TopMostTrigger = false; + bool TopMostTriggerLock = false; + + private void TriggerTopMost() + { + TopMostTriggerLock = true; + + TopMostTrigger = !TopMostTrigger; + this.TopMost = TopMostTrigger; + TopMostMenuItem.Checked = TopMostCheckBox.Checked = TopMostTrigger; + + TopMostTriggerLock = false; + } + private void TopMostCheckBox_CheckedChanged(object sender, EventArgs e) { - this.TopMost = TopMostCheckBox.Checked; + if (!TopMostTriggerLock) + { + TriggerTopMost(); + } + } + + private void TopMostMenuItem_Click(object sender, EventArgs e) + { + if (!TopMostTriggerLock) + { + TriggerTopMost(); + } + } + #endregion + + private bool ShowToolbarTrigger = false; + private void ShowToolbarMenuItem_Click(object sender, EventArgs e) + { + ShowToolbarTrigger = !ShowToolbarTrigger; + ToolbarFlowLayoutPanel.Visible = ShowToolbarTrigger; + ShowToolbarMenuItem.Checked = ShowToolbarTrigger; } } } diff --git a/shadowsocks-csharp/View/LogForm.resx b/shadowsocks-csharp/View/LogForm.resx index 34b690ce..e8bf04bf 100644 --- a/shadowsocks-csharp/View/LogForm.resx +++ b/shadowsocks-csharp/View/LogForm.resx @@ -117,10 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - - 172, 17 - \ No newline at end of file From 9953ae2e6821148bb41d698ff97d26d856b229b2 Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Thu, 20 Aug 2015 21:01:40 +0800 Subject: [PATCH 014/109] fix variables' name: (first letter uppercase -> lowercase) 1. WrapTextTrigger -> wrapTextTrigger 2. WrapTextTriggerLock -> wrapTextTriggerLock 3. TopMostTrigger -> topMostTrigger 4. TopMostTriggerLock -> topMostTriggerLock 5. ShowToolbarTrigger -> toolbarTrigger --- shadowsocks-csharp/View/LogForm.cs | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index dcbbf1e2..214dbba3 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -103,9 +103,9 @@ namespace Shadowsocks.View timer.Interval = 300; timer.Tick += Timer_Tick; timer.Start(); - this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = TopMostTrigger; - LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked = WrapTextMenuItem.Checked = WrapTextTrigger; - ToolbarFlowLayoutPanel.Visible = ShowToolbarTrigger; + this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = topMostTrigger; + LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked = WrapTextMenuItem.Checked = wrapTextTrigger; + ToolbarFlowLayoutPanel.Visible = toolbarTrigger; } private void LogForm_FormClosing(object sender, FormClosingEventArgs e) @@ -170,24 +170,24 @@ namespace Shadowsocks.View #endregion #region Trigger the log messages wrapable, or not. - bool WrapTextTrigger = false; - bool WrapTextTriggerLock = false; + bool wrapTextTrigger = false; + bool wrapTextTriggerLock = false; private void TriggerWrapText() { - WrapTextTriggerLock = true; + wrapTextTriggerLock = true; - WrapTextTrigger = !WrapTextTrigger; - LogMessageTextBox.WordWrap = WrapTextTrigger; + wrapTextTrigger = !wrapTextTrigger; + LogMessageTextBox.WordWrap = wrapTextTrigger; LogMessageTextBox.ScrollToCaret(); - WrapTextMenuItem.Checked = WrapTextCheckBox.Checked = WrapTextTrigger; + WrapTextMenuItem.Checked = WrapTextCheckBox.Checked = wrapTextTrigger; - WrapTextTriggerLock = false; + wrapTextTriggerLock = false; } private void WrapTextMenuItem_Click(object sender, EventArgs e) { - if (!WrapTextTriggerLock) + if (!wrapTextTriggerLock) { TriggerWrapText(); } @@ -195,7 +195,7 @@ namespace Shadowsocks.View private void WrapTextCheckBox_CheckedChanged(object sender, EventArgs e) { - if (!WrapTextTriggerLock) + if (!wrapTextTriggerLock) { TriggerWrapText(); } @@ -203,23 +203,23 @@ namespace Shadowsocks.View #endregion #region Trigger this window top most, or not. - bool TopMostTrigger = false; - bool TopMostTriggerLock = false; + bool topMostTrigger = false; + bool topMostTriggerLock = false; private void TriggerTopMost() { - TopMostTriggerLock = true; + topMostTriggerLock = true; - TopMostTrigger = !TopMostTrigger; - this.TopMost = TopMostTrigger; - TopMostMenuItem.Checked = TopMostCheckBox.Checked = TopMostTrigger; + topMostTrigger = !topMostTrigger; + this.TopMost = topMostTrigger; + TopMostMenuItem.Checked = TopMostCheckBox.Checked = topMostTrigger; - TopMostTriggerLock = false; + topMostTriggerLock = false; } private void TopMostCheckBox_CheckedChanged(object sender, EventArgs e) { - if (!TopMostTriggerLock) + if (!topMostTriggerLock) { TriggerTopMost(); } @@ -227,19 +227,19 @@ namespace Shadowsocks.View private void TopMostMenuItem_Click(object sender, EventArgs e) { - if (!TopMostTriggerLock) + if (!topMostTriggerLock) { TriggerTopMost(); } } #endregion - private bool ShowToolbarTrigger = false; + private bool toolbarTrigger = false; private void ShowToolbarMenuItem_Click(object sender, EventArgs e) { - ShowToolbarTrigger = !ShowToolbarTrigger; - ToolbarFlowLayoutPanel.Visible = ShowToolbarTrigger; - ShowToolbarMenuItem.Checked = ShowToolbarTrigger; + toolbarTrigger = !toolbarTrigger; + ToolbarFlowLayoutPanel.Visible = toolbarTrigger; + ShowToolbarMenuItem.Checked = toolbarTrigger; } } } From 79e9a23d94feaa5324cf769acf1d71b70c535040 Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Thu, 20 Aug 2015 21:03:38 +0800 Subject: [PATCH 015/109] add feature: save LogForm's config into json file. --- shadowsocks-csharp/Model/Configuration.cs | 1 + shadowsocks-csharp/Model/LogViewerConfig.cs | 63 ++++++++++++++++++++ shadowsocks-csharp/View/LogForm.cs | 36 ++++++++++- shadowsocks-csharp/shadowsocks-csharp.csproj | 1 + 4 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 shadowsocks-csharp/Model/LogViewerConfig.cs diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 1ccba56c..d9de24f5 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -23,6 +23,7 @@ namespace Shadowsocks.Model public string pacUrl; public bool useOnlinePac; public bool availabilityStatistics; + public LogViewerConfig logViewer; private static string CONFIG_FILE = "gui-config.json"; diff --git a/shadowsocks-csharp/Model/LogViewerConfig.cs b/shadowsocks-csharp/Model/LogViewerConfig.cs new file mode 100644 index 00000000..28471084 --- /dev/null +++ b/shadowsocks-csharp/Model/LogViewerConfig.cs @@ -0,0 +1,63 @@ +using System; +using System.Drawing; + +namespace Shadowsocks.Model +{ + [Serializable] + public class LogViewerConfig + { + public string fontName; + public float fontSize; + public string bgColor; + public string textColor; + public bool topMost; + public bool wrapText; + public bool toolbarShown; + + public LogViewerConfig() + { + this.fontName = "Console"; + this.fontSize = 8; + this.bgColor = "black"; + this.textColor = "white"; + this.topMost = false; + this.wrapText = false; + this.toolbarShown = false; + } + + public Color GetBackgroundColor() + { + try + { + return ColorTranslator.FromHtml(bgColor); + } + catch (Exception) + { + return ColorTranslator.FromHtml("black"); + } + } + + public void SetBackgroundColor(Color color) + { + bgColor = ColorTranslator.ToHtml(color); + } + + public Color GetTextColor() + { + try + { + return ColorTranslator.FromHtml(textColor); + } + catch (Exception) + { + return ColorTranslator.FromHtml("white"); + throw; + } + } + + public void SetTextColor(Color color) + { + textColor = ColorTranslator.ToHtml(color); + } + } +} diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index 214dbba3..91eb69bb 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -18,6 +18,7 @@ namespace Shadowsocks.View string filename; Timer timer; const int BACK_OFFSET = 65536; + Model.Configuration config; public LogForm(string filename) { @@ -25,6 +26,21 @@ namespace Shadowsocks.View InitializeComponent(); this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); + config = Model.Configuration.Load(); + if (config.logViewer == null) + { + config.logViewer = new Model.LogViewerConfig(); + } + else + { + topMostTrigger = config.logViewer.topMost; + wrapTextTrigger = config.logViewer.wrapText; + toolbarTrigger = config.logViewer.toolbarShown; + LogMessageTextBox.Font = new Font(config.logViewer.fontName, config.logViewer.fontSize); + LogMessageTextBox.BackColor = config.logViewer.GetBackgroundColor(); + LogMessageTextBox.ForeColor = config.logViewer.GetTextColor(); + } + UpdateTexts(); } @@ -103,14 +119,29 @@ namespace Shadowsocks.View timer.Interval = 300; timer.Tick += Timer_Tick; timer.Start(); + + topMostTriggerLock = true; this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = topMostTrigger; - LogMessageTextBox.WordWrap = WrapTextCheckBox.Checked = WrapTextMenuItem.Checked = wrapTextTrigger; - ToolbarFlowLayoutPanel.Visible = toolbarTrigger; + topMostTriggerLock = false; + + wrapTextTriggerLock = true; + LogMessageTextBox.WordWrap = WrapTextMenuItem.Checked = WrapTextCheckBox.Checked = wrapTextTrigger; + wrapTextTriggerLock = false; + + ToolbarFlowLayoutPanel.Visible = ShowToolbarMenuItem.Checked = toolbarTrigger; } private void LogForm_FormClosing(object sender, FormClosingEventArgs e) { timer.Stop(); + config.logViewer.topMost = topMostTrigger; + config.logViewer.wrapText = wrapTextTrigger; + config.logViewer.toolbarShown = toolbarTrigger; + config.logViewer.fontName = LogMessageTextBox.Font.Name; + config.logViewer.fontSize = LogMessageTextBox.Font.Size; + config.logViewer.SetBackgroundColor(LogMessageTextBox.BackColor); + config.logViewer.SetTextColor(LogMessageTextBox.ForeColor); + Model.Configuration.Save(config); } private void OpenLocationMenuItem_Click(object sender, EventArgs e) @@ -235,6 +266,7 @@ namespace Shadowsocks.View #endregion private bool toolbarTrigger = false; + private void ShowToolbarMenuItem_Click(object sender, EventArgs e) { toolbarTrigger = !toolbarTrigger; diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 8200aa07..dd957ffb 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -145,6 +145,7 @@ + From b1f17e02a11a07627e5d0b4da920ee434db8aba1 Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Fri, 21 Aug 2015 16:47:56 +0800 Subject: [PATCH 016/109] 1. limit the windows' minimized size 2. store window's size & position in config file. 3. fix: scroll bar sometimes disappear while sizing the window. --- shadowsocks-csharp/Model/LogViewerConfig.cs | 9 +++++++++ shadowsocks-csharp/View/LogForm.Designer.cs | 9 +++++---- shadowsocks-csharp/View/LogForm.cs | 9 +++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/shadowsocks-csharp/Model/LogViewerConfig.cs b/shadowsocks-csharp/Model/LogViewerConfig.cs index 28471084..80bb220d 100644 --- a/shadowsocks-csharp/Model/LogViewerConfig.cs +++ b/shadowsocks-csharp/Model/LogViewerConfig.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using System.Windows.Forms; namespace Shadowsocks.Model { @@ -13,6 +14,10 @@ namespace Shadowsocks.Model public bool topMost; public bool wrapText; public bool toolbarShown; + public int width; + public int height; + public int top; + public int left; public LogViewerConfig() { @@ -23,6 +28,10 @@ namespace Shadowsocks.Model this.topMost = false; this.wrapText = false; this.toolbarShown = false; + this.width = 600; + this.height = 400; + this.top = (Screen.PrimaryScreen.WorkingArea.Height - height) / 2; + this.left = (Screen.PrimaryScreen.WorkingArea.Width - width) / 2; } public Color GetBackgroundColor() diff --git a/shadowsocks-csharp/View/LogForm.Designer.cs b/shadowsocks-csharp/View/LogForm.Designer.cs index 187ab948..ba090850 100644 --- a/shadowsocks-csharp/View/LogForm.Designer.cs +++ b/shadowsocks-csharp/View/LogForm.Designer.cs @@ -63,7 +63,7 @@ this.LogMessageTextBox.Name = "LogMessageTextBox"; this.LogMessageTextBox.ReadOnly = true; this.LogMessageTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.LogMessageTextBox.Size = new System.Drawing.Size(584, 377); + this.LogMessageTextBox.Size = new System.Drawing.Size(378, 99); this.LogMessageTextBox.TabIndex = 0; // // MainMenu @@ -199,7 +199,7 @@ this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.Size = new System.Drawing.Size(590, 418); + this.tableLayoutPanel1.Size = new System.Drawing.Size(384, 140); this.tableLayoutPanel1.TabIndex = 2; // // ToolbarFlowLayoutPanel @@ -212,16 +212,17 @@ this.ToolbarFlowLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.ToolbarFlowLayoutPanel.Location = new System.Drawing.Point(3, 3); this.ToolbarFlowLayoutPanel.Name = "ToolbarFlowLayoutPanel"; - this.ToolbarFlowLayoutPanel.Size = new System.Drawing.Size(584, 29); + this.ToolbarFlowLayoutPanel.Size = new System.Drawing.Size(378, 29); this.ToolbarFlowLayoutPanel.TabIndex = 2; // // LogForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(590, 418); + this.ClientSize = new System.Drawing.Size(384, 140); this.Controls.Add(this.tableLayoutPanel1); this.Menu = this.MainMenu; + this.MinimumSize = new System.Drawing.Size(400, 200); this.Name = "LogForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Log Viewer"; diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index 91eb69bb..a80965fd 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -120,6 +120,11 @@ namespace Shadowsocks.View timer.Tick += Timer_Tick; timer.Start(); + this.Top = config.logViewer.top; + this.Left = config.logViewer.left; + this.Height = config.logViewer.height; + this.Width = config.logViewer.width; + topMostTriggerLock = true; this.TopMost = TopMostMenuItem.Checked = TopMostCheckBox.Checked = topMostTrigger; topMostTriggerLock = false; @@ -141,6 +146,10 @@ namespace Shadowsocks.View config.logViewer.fontSize = LogMessageTextBox.Font.Size; config.logViewer.SetBackgroundColor(LogMessageTextBox.BackColor); config.logViewer.SetTextColor(LogMessageTextBox.ForeColor); + config.logViewer.top = this.Top; + config.logViewer.left = this.Left; + config.logViewer.height = this.Height; + config.logViewer.width = this.Width; Model.Configuration.Save(config); } From 17c75de9c064f20342e4b832e420c31476a7b59e Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Fri, 21 Aug 2015 17:12:11 +0800 Subject: [PATCH 017/109] convert "\r\n" -> Environment.NewLine --- shadowsocks-csharp/View/LogForm.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index a80965fd..ee85698c 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -80,7 +80,7 @@ namespace Shadowsocks.View string line = ""; while ((line = reader.ReadLine()) != null) - LogMessageTextBox.AppendText(line + "\r\n"); + LogMessageTextBox.AppendText(line + Environment.NewLine); LogMessageTextBox.ScrollToCaret(); @@ -100,7 +100,7 @@ namespace Shadowsocks.View while ((line = reader.ReadLine()) != null) { changed = true; - LogMessageTextBox.AppendText(line + "\r\n"); + LogMessageTextBox.AppendText(line + Environment.NewLine); } if (changed) From b2c2d05c940cf7249c3597274cd5a3281b93749b Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Fri, 21 Aug 2015 22:12:14 +0800 Subject: [PATCH 018/109] support auto check `user-rule.txt`'s change, and update the PAC file. Note: This is a dirty hack. --- .../Controller/Service/GfwListUpdater.cs | 3 +- .../Controller/Service/PACServer.cs | 57 ++++++++++++++----- .../Controller/ShadowsocksController.cs | 43 ++++++++++++++ 3 files changed, 88 insertions(+), 15 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/GfwListUpdater.cs b/shadowsocks-csharp/Controller/Service/GfwListUpdater.cs index 70720fb9..dc8d692c 100644 --- a/shadowsocks-csharp/Controller/Service/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/Service/GfwListUpdater.cs @@ -36,6 +36,7 @@ namespace Shadowsocks.Controller { try { + File.WriteAllText(Utils.GetTempPath() + "\\gfwlist.txt", e.Result, Encoding.UTF8); List lines = ParseResult(e.Result); if (File.Exists(USER_RULE_FILE)) { @@ -82,7 +83,7 @@ namespace Shadowsocks.Controller http.DownloadStringAsync(new Uri(GFWLIST_URL)); } - public List ParseResult(string response) + public static List ParseResult(string response) { byte[] bytes = Convert.FromBase64String(response); string content = Encoding.ASCII.GetString(bytes); diff --git a/shadowsocks-csharp/Controller/Service/PACServer.cs b/shadowsocks-csharp/Controller/Service/PACServer.cs index f8fc80e8..52ea241d 100644 --- a/shadowsocks-csharp/Controller/Service/PACServer.cs +++ b/shadowsocks-csharp/Controller/Service/PACServer.cs @@ -18,14 +18,17 @@ namespace Shadowsocks.Controller public static string USER_RULE_FILE = "user-rule.txt"; - FileSystemWatcher watcher; + FileSystemWatcher PACFileWatcher; + FileSystemWatcher UserRuleFileWatcher; private Configuration _config; public event EventHandler PACFileChanged; + public event EventHandler UserRuleFileChanged; public PACServer() { this.WatchPacFile(); + this.WatchUserRuleFile(); } public void UpdateConfiguration(Configuration config) @@ -167,28 +170,54 @@ Connection: Close private void WatchPacFile() { - if (watcher != null) - { - watcher.Dispose(); - } - watcher = new FileSystemWatcher(Directory.GetCurrentDirectory()); - watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; - watcher.Filter = PAC_FILE; - watcher.Changed += Watcher_Changed; - watcher.Created += Watcher_Changed; - watcher.Deleted += Watcher_Changed; - watcher.Renamed += Watcher_Changed; - watcher.EnableRaisingEvents = true; + if (PACFileWatcher != null) + { + PACFileWatcher.Dispose(); + } + PACFileWatcher = new FileSystemWatcher(Directory.GetCurrentDirectory()); + PACFileWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; + PACFileWatcher.Filter = PAC_FILE; + PACFileWatcher.Changed += PACFileWatcher_Changed; + PACFileWatcher.Created += PACFileWatcher_Changed; + PACFileWatcher.Deleted += PACFileWatcher_Changed; + PACFileWatcher.Renamed += PACFileWatcher_Changed; + PACFileWatcher.EnableRaisingEvents = true; + } + + private void WatchUserRuleFile() + { + if (UserRuleFileWatcher != null) + { + UserRuleFileWatcher.Dispose(); + } + UserRuleFileWatcher = new FileSystemWatcher(Directory.GetCurrentDirectory()); + UserRuleFileWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; + UserRuleFileWatcher.Filter = USER_RULE_FILE; + UserRuleFileWatcher.Changed += UserRuleFileWatcher_Changed; + UserRuleFileWatcher.Created += UserRuleFileWatcher_Changed; + UserRuleFileWatcher.Deleted += UserRuleFileWatcher_Changed; + UserRuleFileWatcher.Renamed += UserRuleFileWatcher_Changed; + UserRuleFileWatcher.EnableRaisingEvents = true; } - private void Watcher_Changed(object sender, FileSystemEventArgs e) + private void PACFileWatcher_Changed(object sender, FileSystemEventArgs e) { if (PACFileChanged != null) { + Console.WriteLine("Detected: PAC file '{0}' was {1}.", e.Name, e.ChangeType.ToString().ToLower()); PACFileChanged(this, new EventArgs()); } } + private void UserRuleFileWatcher_Changed(object sender, FileSystemEventArgs e) + { + if (UserRuleFileChanged != null) + { + Console.WriteLine("Detected: User Rule file '{0}' was {1}.", e.Name, e.ChangeType.ToString().ToLower()); + UserRuleFileChanged(this, new EventArgs()); + } + } + private string GetPACAddress(byte[] requestBuf, int length, IPEndPoint localEndPoint, bool useSocks) { //try diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 2e2f5528..87496199 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -7,6 +7,8 @@ using System.Threading; using System.Net.Sockets; using Shadowsocks.Controller.Strategy; using System.Net; +using Shadowsocks.Util; +using Shadowsocks.Properties; namespace Shadowsocks.Controller { @@ -293,6 +295,7 @@ namespace Shadowsocks.Controller { _pacServer = new PACServer(); _pacServer.PACFileChanged += pacServer_PACFileChanged; + _pacServer.UserRuleFileChanged += pacServer_UserRuleFileChanged; } _pacServer.UpdateConfiguration(_config); if (gfwListUpdater == null) @@ -404,6 +407,46 @@ namespace Shadowsocks.Controller UpdatePACFromGFWListError(this, e); } + private void pacServer_UserRuleFileChanged(object sender, EventArgs e) + { + // TODO: this is a dirty hack. (from code GListUpdater.http_DownloadStringCompleted()) + + //UpdatePACFromGFWList(); // TODO: code like this temporary + //try + //{ + List lines = GFWListUpdater.ParseResult(File.ReadAllText(Utils.GetTempPath() + "\\gfwlist.txt")); + if (File.Exists(PACServer.USER_RULE_FILE)) + { + string local = File.ReadAllText(PACServer.USER_RULE_FILE, Encoding.UTF8); + string[] rules = local.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + foreach (string rule in rules) + { + if (rule.StartsWith("!") || rule.StartsWith("[")) + continue; + lines.Add(rule); + } + } + string abpContent = Utils.UnGzip(Resources.abp_js); + abpContent = abpContent.Replace("__RULES__", SimpleJson.SimpleJson.SerializeObject(lines)); + if (File.Exists(PACServer.PAC_FILE)) + { + string original = File.ReadAllText(PACServer.PAC_FILE, Encoding.UTF8); + if (original == abpContent) + { + return; + } + } + File.WriteAllText(PACServer.PAC_FILE, abpContent, Encoding.UTF8); + //} + //catch (Exception ex) + //{ + // if (Error != null) + // { + // Error(this, new ErrorEventArgs(ex)); + // } + //} + } + private void StartReleasingMemory() { _ramThread = new Thread(new ThreadStart(ReleaseMemory)); From 3283c93857c791ee41f1e187157dea86ecf77968 Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Sat, 22 Aug 2015 12:26:26 +0800 Subject: [PATCH 019/109] fix: auto detected `user-rule.txt`'s change while no `gfwlist.txt` file, the application crashs. --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 87496199..263852a0 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -414,7 +414,12 @@ namespace Shadowsocks.Controller //UpdatePACFromGFWList(); // TODO: code like this temporary //try //{ - List lines = GFWListUpdater.ParseResult(File.ReadAllText(Utils.GetTempPath() + "\\gfwlist.txt")); + if (!File.Exists(Utils.GetTempPath() + "\\gfwlist.txt")) + { + UpdatePACFromGFWList(); + return; + } + List lines = GFWListUpdater.ParseResult(File.ReadAllText(Utils.GetTempPath() + "\\gfwlist.txt")); if (File.Exists(PACServer.USER_RULE_FILE)) { string local = File.ReadAllText(PACServer.USER_RULE_FILE, Encoding.UTF8); From bdd29e8384eebd12b3d08d13021b630c12b95497 Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Thu, 27 Aug 2015 04:38:52 +0800 Subject: [PATCH 020/109] fixed: Log Form will hidden when restart Windows --- shadowsocks-csharp/View/LogForm.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index ee85698c..babf11f7 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -120,8 +120,8 @@ namespace Shadowsocks.View timer.Tick += Timer_Tick; timer.Start(); - this.Top = config.logViewer.top; - this.Left = config.logViewer.left; + this.Top = (config.logViewer.top >=0) ? config.logViewer.top : 0; + this.Left = (config.logViewer.left >=0) ? config.logViewer.left : 0; this.Height = config.logViewer.height; this.Width = config.logViewer.width; From 1280f43878d4874d93f8e988f5973a05090366f9 Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Thu, 27 Aug 2015 06:04:04 +0800 Subject: [PATCH 021/109] fixed: file changes event triggers twice --- .../Controller/Service/PACServer.cs | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/PACServer.cs b/shadowsocks-csharp/Controller/Service/PACServer.cs index 52ea241d..a4aa33b6 100644 --- a/shadowsocks-csharp/Controller/Service/PACServer.cs +++ b/shadowsocks-csharp/Controller/Service/PACServer.cs @@ -2,6 +2,7 @@ using Shadowsocks.Properties; using Shadowsocks.Util; using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -200,24 +201,51 @@ Connection: Close UserRuleFileWatcher.EnableRaisingEvents = true; } + #region FileSystemWatcher.OnChanged() + + // FileSystemWatcher Changed event is raised twice + // http://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice + private static Hashtable fileChangedTime = new Hashtable(); + private void PACFileWatcher_Changed(object sender, FileSystemEventArgs e) { - if (PACFileChanged != null) + string path = e.FullPath.ToString(); + string currentLastWriteTime = File.GetLastWriteTime(e.FullPath).ToString(); + + // if there is no path info stored yet or stored path has different time of write then the one now is inspected + if (!fileChangedTime.ContainsKey(path) || fileChangedTime[path].ToString() != currentLastWriteTime) { - Console.WriteLine("Detected: PAC file '{0}' was {1}.", e.Name, e.ChangeType.ToString().ToLower()); - PACFileChanged(this, new EventArgs()); + if (PACFileChanged != null) + { + Console.WriteLine("Detected: PAC file '{0}' was {1}.", e.Name, e.ChangeType.ToString().ToLower()); + PACFileChanged(this, new EventArgs()); + } + + //lastly we update the last write time in the hashtable + fileChangedTime[path] = currentLastWriteTime; } } private void UserRuleFileWatcher_Changed(object sender, FileSystemEventArgs e) { - if (UserRuleFileChanged != null) + string path = e.FullPath.ToString(); + string currentLastWriteTime = File.GetLastWriteTime(e.FullPath).ToString(); + + // if there is no path info stored yet or stored path has different time of write then the one now is inspected + if (!fileChangedTime.ContainsKey(path) || fileChangedTime[path].ToString() != currentLastWriteTime) { - Console.WriteLine("Detected: User Rule file '{0}' was {1}.", e.Name, e.ChangeType.ToString().ToLower()); - UserRuleFileChanged(this, new EventArgs()); + if (UserRuleFileChanged != null) + { + Console.WriteLine("Detected: User Rule file '{0}' was {1}.", e.Name, e.ChangeType.ToString().ToLower()); + UserRuleFileChanged(this, new EventArgs()); + } + //lastly we update the last write time in the hashtable + fileChangedTime[path] = currentLastWriteTime; } } + #endregion + private string GetPACAddress(byte[] requestBuf, int length, IPEndPoint localEndPoint, bool useSocks) { //try From 0bf8132d564e84287ee3aa0be221b7c97c5b17fe Mon Sep 17 00:00:00 2001 From: kimw <1@kimwong.me> Date: Sun, 30 Aug 2015 03:46:20 +0800 Subject: [PATCH 022/109] update urls --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 83bff1ef..52a39e5b 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,9 @@ Visual Studio 2015 is required. GPLv3 -[Appveyor]: https://ci.appveyor.com/project/clowwindy/shadowsocks-csharp -[Build Status]: https://ci.appveyor.com/api/projects/status/gknc8l1lxy423ehv/branch/master -[latest release]: https://github.com/shadowsocks/shadowsocks-csharp/releases +[Appveyor]: https://ci.appveyor.com/project/kimw/shadowsocks-windows +[Build Status]: https://ci.appveyor.com/api/projects/status/q0h3wsyisbic5fpt/branch/master +[latest release]: https://github.com/kimw/shadowsocks-windows/releases [GFWList]: https://github.com/gfwlist/gfwlist -[Servers]: https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#linux--server-side -[中文说明]: https://github.com/shadowsocks/shadowsocks-windows/wiki/Shadowsocks-Windows-%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E +[Servers]: https://github.com/kimw/shadowsocks/wiki/Ports-and-Clients#linux--server-side +[中文说明]: https://github.com/kimw/shadowsocks-windows/wiki/Shadowsocks-Windows-%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E From 879163dc2b808ddd0bb812fda5c7f770b2360ffc Mon Sep 17 00:00:00 2001 From: icylogic Date: Wed, 2 Sep 2015 01:23:32 +0800 Subject: [PATCH 023/109] Add more clear log --- .../Controller/Service/AvailabilityStatistics.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs index f3d088c5..08125e92 100644 --- a/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs +++ b/shadowsocks-csharp/Controller/Service/AvailabilityStatistics.cs @@ -6,8 +6,8 @@ using System.Net.NetworkInformation; using System.Threading; using Shadowsocks.Model; using System.Reflection; -using Shadowsocks.Util; - +using Shadowsocks.Util; + namespace Shadowsocks.Controller { class AvailabilityStatistics @@ -81,6 +81,7 @@ namespace Shadowsocks.Controller } catch (Exception e) { + Console.WriteLine($"An exception occured when eveluating {server.FriendlyName()}"); Logging.LogUsefulException(e); } } From 4e1b140dd9055ecf6451a90607141d6a19e9051d Mon Sep 17 00:00:00 2001 From: icylogic Date: Thu, 3 Sep 2015 14:08:35 +0800 Subject: [PATCH 024/109] Add Json.Net and separate out Statistics Configuration file Import Json.Net since it's difficult for SimpleJson to deal with nested type. --- .../Controller/ShadowsocksController.cs | 9 +- .../Controller/Strategy/StatisticsStrategy.cs | 2 +- shadowsocks-csharp/Model/Configuration.cs | 2 - .../Model/StatisticsStrategyConfiguration.cs | 39 ++++++ shadowsocks-csharp/View/MenuViewController.cs | 8 ++ ...sticsStrategyConfigurationForm.Designer.cs | 117 +++++++++--------- .../StatisticsStrategyConfigurationForm.cs | 8 +- .../StatisticsStrategyConfigurationForm.resx | 3 - shadowsocks-csharp/packages.config | 3 +- shadowsocks-csharp/shadowsocks-csharp.csproj | 12 +- 10 files changed, 132 insertions(+), 71 deletions(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 50c56b7e..15a5d76a 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -26,6 +26,8 @@ namespace Shadowsocks.Controller private PolipoRunner polipoRunner; private GFWListUpdater gfwListUpdater; private AvailabilityStatistics _availabilityStatics; + public StatisticsStrategyConfiguration StatisticsConfiguration { get; private set; } + private bool stopped = false; private bool _systemProxyIsDirty = false; @@ -53,10 +55,12 @@ namespace Shadowsocks.Controller public ShadowsocksController() { _config = Configuration.Load(); + StatisticsConfiguration = StatisticsStrategyConfiguration.Load(); _strategyManager = new StrategyManager(this); StartReleasingMemory(); } + public void Start() { Reload(); @@ -127,8 +131,8 @@ namespace Shadowsocks.Controller public void SaveStrategyConfigurations(StatisticsStrategyConfiguration configuration) { - _config.statisticsStrategyConfiguration = configuration; - SaveConfig(_config); + StatisticsConfiguration = configuration; + StatisticsStrategyConfiguration.Save(configuration); } public bool AddServerBySSURL(string ssURL) @@ -290,6 +294,7 @@ namespace Shadowsocks.Controller { // some logic in configuration updated the config when saving, we need to read it again _config = Configuration.Load(); + StatisticsConfiguration = StatisticsStrategyConfiguration.Load(); if (polipoRunner == null) { diff --git a/shadowsocks-csharp/Controller/Strategy/StatisticsStrategy.cs b/shadowsocks-csharp/Controller/Strategy/StatisticsStrategy.cs index 17bda19c..8bbe13e4 100644 --- a/shadowsocks-csharp/Controller/Strategy/StatisticsStrategy.cs +++ b/shadowsocks-csharp/Controller/Strategy/StatisticsStrategy.cs @@ -93,7 +93,7 @@ namespace Shadowsocks.Controller.Strategy return (double)data.SuccessTimes / (data.SuccessTimes + data.TimedOutTimes); //simply choose min package loss } - private class StatisticsData + public class StatisticsData { public int SuccessTimes; public int TimedOutTimes; diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 06e0d690..ea8ff27f 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -25,8 +25,6 @@ namespace Shadowsocks.Model public bool useOnlinePac; public bool availabilityStatistics; - public StatisticsStrategyConfiguration statisticsStrategyConfiguration; - private static string CONFIG_FILE = "gui-config.json"; public Server GetCurrentServer() diff --git a/shadowsocks-csharp/Model/StatisticsStrategyConfiguration.cs b/shadowsocks-csharp/Model/StatisticsStrategyConfiguration.cs index 452ecc1d..b427355b 100644 --- a/shadowsocks-csharp/Model/StatisticsStrategyConfiguration.cs +++ b/shadowsocks-csharp/Model/StatisticsStrategyConfiguration.cs @@ -1,8 +1,12 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; +using Shadowsocks.Controller; using Shadowsocks.Controller.Strategy; +using SimpleJson; +using Newtonsoft.Json; namespace Shadowsocks.Model { @@ -17,6 +21,41 @@ namespace Shadowsocks.Model private int _dataCollectionMinutes; private int _repeatTimesNum; + + private const string ConfigFile = "statistics-config.json"; + + public static StatisticsStrategyConfiguration Load() + { + try + { + var content = File.ReadAllText(ConfigFile); + var configuration = JsonConvert.DeserializeObject(content); + return configuration; + } + catch (FileNotFoundException e) + { + return new StatisticsStrategyConfiguration(); + } + catch (Exception e) + { + Logging.LogUsefulException(e); + return new StatisticsStrategyConfiguration(); + } + } + + public static void Save(StatisticsStrategyConfiguration configuration) + { + try + { + var content = JsonConvert.SerializeObject(configuration, Formatting.Indented); + File.WriteAllText(ConfigFile, content); + } + catch (Exception e) + { + Logging.LogUsefulException(e); + } + } + public Dictionary Calculations; public StatisticsStrategyConfiguration() diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index c8a4c0eb..9c73f320 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -164,6 +164,7 @@ namespace Shadowsocks.View this.ServersItem = CreateMenuGroup("Servers", new MenuItem[] { this.SeperatorItem = new MenuItem("-"), this.ConfigItem = CreateMenuItem("Edit Servers...", new EventHandler(this.Config_Click)), + CreateMenuItem("Statistics Config...", StatisticsConfigItem_Click), CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)), CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click)) }), @@ -188,6 +189,7 @@ namespace Shadowsocks.View }); } + private void controller_ConfigChanged(object sender, EventArgs e) { LoadCurrentConfiguration(); @@ -417,6 +419,12 @@ namespace Shadowsocks.View new LogForm(argument).Show(); } + + private void StatisticsConfigItem_Click(object sender, EventArgs e) + { + StatisticsStrategyConfigurationForm form = new StatisticsStrategyConfigurationForm(controller); + form.Show(); + } private void QRCodeItem_Click(object sender, EventArgs e) { diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs index 8563fcc5..801d9821 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.Designer.cs @@ -29,14 +29,13 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series4 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series(); - System.Windows.Forms.DataVisualization.Charting.Series series6 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.StatisticsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.byISPCheckBox = new System.Windows.Forms.CheckBox(); - this.bindingConfiguration = new System.Windows.Forms.BindingSource(this.components); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); @@ -56,10 +55,10 @@ this.splitContainer3 = new System.Windows.Forms.SplitContainer(); this.label1 = new System.Windows.Forms.Label(); this.calculationContainer = new System.Windows.Forms.FlowLayoutPanel(); - this.OKButton = new System.Windows.Forms.Button(); this.CancelButton = new System.Windows.Forms.Button(); + this.OKButton = new System.Windows.Forms.Button(); + this.bindingConfiguration = new System.Windows.Forms.BindingSource(this.components); ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.bindingConfiguration)).BeginInit(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); @@ -76,46 +75,47 @@ this.splitContainer3.Panel1.SuspendLayout(); this.splitContainer3.Panel2.SuspendLayout(); this.splitContainer3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.bindingConfiguration)).BeginInit(); this.SuspendLayout(); // // StatisticsChart // this.StatisticsChart.BackColor = System.Drawing.Color.Transparent; - chartArea2.AxisX.MajorGrid.Enabled = false; - chartArea2.AxisY.MajorGrid.Enabled = false; - chartArea2.AxisY2.MajorGrid.Enabled = false; - chartArea2.BackColor = System.Drawing.Color.Transparent; - chartArea2.Name = "ChartArea"; - this.StatisticsChart.ChartAreas.Add(chartArea2); + chartArea1.AxisX.MajorGrid.Enabled = false; + chartArea1.AxisY.MajorGrid.Enabled = false; + chartArea1.AxisY2.MajorGrid.Enabled = false; + chartArea1.BackColor = System.Drawing.Color.Transparent; + chartArea1.Name = "ChartArea"; + this.StatisticsChart.ChartAreas.Add(chartArea1); this.StatisticsChart.Dock = System.Windows.Forms.DockStyle.Fill; - legend2.BackColor = System.Drawing.Color.Transparent; - legend2.Name = "ChartLegend"; - this.StatisticsChart.Legends.Add(legend2); + legend1.BackColor = System.Drawing.Color.Transparent; + legend1.Name = "ChartLegend"; + this.StatisticsChart.Legends.Add(legend1); this.StatisticsChart.Location = new System.Drawing.Point(0, 0); this.StatisticsChart.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.StatisticsChart.Name = "StatisticsChart"; this.StatisticsChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Pastel; - series4.ChartArea = "ChartArea"; - series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; - series4.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); - series4.Legend = "ChartLegend"; - series4.Name = "Data Transferred"; - series5.ChartArea = "ChartArea"; - series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; - series5.Color = System.Drawing.Color.FromArgb(((int)(((byte)(221)))), ((int)(((byte)(88)))), ((int)(((byte)(0))))); - series5.Legend = "ChartLegend"; - series5.Name = "Package Loss"; - series5.YValuesPerPoint = 4; - series6.BorderWidth = 4; - series6.ChartArea = "ChartArea"; - series6.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series6.Color = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(77)))), ((int)(((byte)(150))))); - series6.Legend = "ChartLegend"; - series6.Name = "Ping"; - this.StatisticsChart.Series.Add(series4); - this.StatisticsChart.Series.Add(series5); - this.StatisticsChart.Series.Add(series6); - this.StatisticsChart.Size = new System.Drawing.Size(951, 221); + series1.ChartArea = "ChartArea"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Area; + series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(204)))), ((int)(((byte)(204))))); + series1.Legend = "ChartLegend"; + series1.Name = "Data Transferred"; + series2.ChartArea = "ChartArea"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bubble; + series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(221)))), ((int)(((byte)(88)))), ((int)(((byte)(0))))); + series2.Legend = "ChartLegend"; + series2.Name = "Package Loss"; + series2.YValuesPerPoint = 4; + series3.BorderWidth = 4; + series3.ChartArea = "ChartArea"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Color = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(77)))), ((int)(((byte)(150))))); + series3.Legend = "ChartLegend"; + series3.Name = "Ping"; + this.StatisticsChart.Series.Add(series1); + this.StatisticsChart.Series.Add(series2); + this.StatisticsChart.Series.Add(series3); + this.StatisticsChart.Size = new System.Drawing.Size(951, 222); this.StatisticsChart.TabIndex = 2; // // byISPCheckBox @@ -130,10 +130,6 @@ this.byISPCheckBox.Text = "By ISP/geolocation"; this.byISPCheckBox.UseVisualStyleBackColor = true; // - // bindingConfiguration - // - this.bindingConfiguration.DataSource = typeof(Shadowsocks.Model.StatisticsStrategyConfiguration); - // // label2 // this.label2.AutoSize = true; @@ -169,7 +165,7 @@ this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.radioButton2); this.groupBox1.Controls.Add(this.radioButton1); - this.groupBox1.Location = new System.Drawing.Point(698, 12); + this.groupBox1.Location = new System.Drawing.Point(698, 7); this.groupBox1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.groupBox1.Name = "groupBox1"; this.groupBox1.Padding = new System.Windows.Forms.Padding(5, 10, 5, 10); @@ -205,6 +201,7 @@ // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.IsSplitterFixed = true; this.splitContainer1.Location = new System.Drawing.Point(0, 0); this.splitContainer1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.splitContainer1.Name = "splitContainer1"; @@ -221,7 +218,7 @@ this.splitContainer1.Panel2.Controls.Add(this.groupBox1); this.splitContainer1.Panel2.Controls.Add(this.StatisticsChart); this.splitContainer1.Size = new System.Drawing.Size(951, 458); - this.splitContainer1.SplitterDistance = 227; + this.splitContainer1.SplitterDistance = 226; this.splitContainer1.SplitterWidth = 10; this.splitContainer1.TabIndex = 12; // @@ -252,7 +249,7 @@ // splitContainer2.Panel2 // this.splitContainer2.Panel2.Controls.Add(this.splitContainer3); - this.splitContainer2.Size = new System.Drawing.Size(951, 227); + this.splitContainer2.Size = new System.Drawing.Size(951, 226); this.splitContainer2.SplitterDistance = 365; this.splitContainer2.SplitterWidth = 5; this.splitContainer2.TabIndex = 7; @@ -404,7 +401,7 @@ // splitContainer3.Panel2 // this.splitContainer3.Panel2.Controls.Add(this.calculationContainer); - this.splitContainer3.Size = new System.Drawing.Size(581, 227); + this.splitContainer3.Size = new System.Drawing.Size(581, 226); this.splitContainer3.SplitterDistance = 46; this.splitContainer3.SplitterWidth = 10; this.splitContainer3.TabIndex = 6; @@ -426,11 +423,23 @@ this.calculationContainer.Location = new System.Drawing.Point(0, 0); this.calculationContainer.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10); this.calculationContainer.Name = "calculationContainer"; - this.calculationContainer.Size = new System.Drawing.Size(581, 171); + this.calculationContainer.Size = new System.Drawing.Size(581, 170); this.calculationContainer.TabIndex = 1; // + // CancelButton + // + this.CancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.CancelButton.Location = new System.Drawing.Point(844, 166); + this.CancelButton.Name = "CancelButton"; + this.CancelButton.Size = new System.Drawing.Size(93, 43); + this.CancelButton.TabIndex = 5; + this.CancelButton.Text = "Cancel"; + this.CancelButton.UseVisualStyleBackColor = true; + this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click); + // // OKButton // + this.OKButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.OKButton.Location = new System.Drawing.Point(745, 166); this.OKButton.Name = "OKButton"; this.OKButton.Size = new System.Drawing.Size(93, 43); @@ -439,15 +448,9 @@ this.OKButton.UseVisualStyleBackColor = true; this.OKButton.Click += new System.EventHandler(this.OKButton_Click); // - // CancelButton + // bindingConfiguration // - this.CancelButton.Location = new System.Drawing.Point(844, 166); - this.CancelButton.Name = "CancelButton"; - this.CancelButton.Size = new System.Drawing.Size(93, 43); - this.CancelButton.TabIndex = 5; - this.CancelButton.Text = "Cancel"; - this.CancelButton.UseVisualStyleBackColor = true; - this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click); + this.bindingConfiguration.DataSource = typeof(Shadowsocks.Model.StatisticsStrategyConfiguration); // // StatisticsStrategyConfigurationForm // @@ -462,7 +465,6 @@ this.Name = "StatisticsStrategyConfigurationForm"; this.Text = "StatisticsStrategyConfigurationForm"; ((System.ComponentModel.ISupportInitialize)(this.StatisticsChart)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.bindingConfiguration)).EndInit(); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.splitContainer1.Panel1.ResumeLayout(false); @@ -482,6 +484,7 @@ this.splitContainer3.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit(); this.splitContainer3.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.bindingConfiguration)).EndInit(); this.ResumeLayout(false); } @@ -509,7 +512,7 @@ private System.Windows.Forms.Label label8; private System.Windows.Forms.NumericUpDown dataCollectionMinutesNum; private System.Windows.Forms.BindingSource bindingConfiguration; - private System.Windows.Forms.Button CancelButton; + private new System.Windows.Forms.Button CancelButton; private System.Windows.Forms.Button OKButton; } } \ No newline at end of file diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs index 970b5761..587153c7 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.cs @@ -9,7 +9,7 @@ namespace Shadowsocks.View { public partial class StatisticsStrategyConfigurationForm: Form { - private ShadowsocksController _controller; + private readonly ShadowsocksController _controller; private StatisticsStrategyConfiguration _configuration; public StatisticsStrategyConfigurationForm(ShadowsocksController controller) @@ -24,8 +24,12 @@ namespace Shadowsocks.View private void LoadConfiguration() { - _configuration = _controller.GetConfigurationCopy()?.statisticsStrategyConfiguration + _configuration = _controller.StatisticsConfiguration ?? new StatisticsStrategyConfiguration(); + if (_configuration.Calculations == null) + { + _configuration = new StatisticsStrategyConfiguration(); + } } private void InitData() diff --git a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx index 55c9d750..fa7d769a 100644 --- a/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx +++ b/shadowsocks-csharp/View/StatisticsStrategyConfigurationForm.resx @@ -120,7 +120,4 @@ 1, 30 - - 1, 30 - \ No newline at end of file diff --git a/shadowsocks-csharp/packages.config b/shadowsocks-csharp/packages.config index b9a6cbf2..b309fb97 100644 --- a/shadowsocks-csharp/packages.config +++ b/shadowsocks-csharp/packages.config @@ -1,8 +1,9 @@  - + + \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 19e91b95..61660623 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -81,6 +81,10 @@ False + + 3rd\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll + True + @@ -280,7 +284,9 @@ - + + Designer + @@ -321,12 +327,12 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - +