From 1e072e5f917e65d8ba1251848748d814894b4c2c Mon Sep 17 00:00:00 2001 From: icylogic Date: Wed, 12 Aug 2015 22:30:09 +0800 Subject: [PATCH 01/22] 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 02/22] 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 03/22] 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 04/22] 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 05/22] 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 12/22] 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 4e1b140dd9055ecf6451a90607141d6a19e9051d Mon Sep 17 00:00:00 2001 From: icylogic Date: Thu, 3 Sep 2015 14:08:35 +0800 Subject: [PATCH 13/22] 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}. - +