Added another progressbar

This commit is contained in:
Norbi Peti 2016-04-19 21:43:03 +02:00
parent 4ac73f7a03
commit a811d376dc
4 changed files with 68 additions and 13 deletions

View file

@ -37,6 +37,7 @@
this.label4 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.progressBar2 = new System.Windows.Forms.ProgressBar();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
@ -121,7 +122,7 @@
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(402, 199);
this.textBox1.Size = new System.Drawing.Size(402, 196);
this.textBox1.TabIndex = 6;
this.textBox1.Text = resources.GetString("textBox1.Text");
//
@ -129,16 +130,26 @@
//
this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressBar1.Location = new System.Drawing.Point(16, 305);
this.progressBar1.Location = new System.Drawing.Point(16, 327);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(402, 23);
this.progressBar1.TabIndex = 7;
//
// progressBar2
//
this.progressBar2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressBar2.Location = new System.Drawing.Point(16, 298);
this.progressBar2.Name = "progressBar2";
this.progressBar2.Size = new System.Drawing.Size(402, 23);
this.progressBar2.TabIndex = 8;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(440, 340);
this.ClientSize = new System.Drawing.Size(440, 366);
this.Controls.Add(this.progressBar2);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label4);
@ -165,6 +176,7 @@
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.ProgressBar progressBar2;
}
}

View file

@ -18,6 +18,7 @@ namespace DEIFR
numericUpDown1.Value = Program.MaxImages;
checkBox1.Checked = Program.KeepImages;
Program.Progress = progressBar1;
Program.AllProgress = progressBar2;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)

View file

@ -8,6 +8,7 @@ using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
namespace DEIFR
@ -25,18 +26,44 @@ namespace DEIFR
using (WebClient client = new WebClient())
{
client.DownloadProgressChanged += DownloadProgress;
client.DownloadStringCompleted += DownloadedLinks;
client.DownloadStringAsync(new Uri("http://www.reddit.com/r/EarthPorn/.json?limit=" + Program.MaxImages));
JObject obj = JObject.Parse(response);
data = obj["data"]["children"].Children().ToList();
i = 0;
files = Directory.GetFiles("wallpapers").ToList();
enumerator = data.GetEnumerator();
}
Task.Run(() =>
}
private static void DownloadedLinks(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
while (!Next())
;
});
MessageBox.Show("Error while getting list from Reddit:\n" + e.Error);
return;
}
JObject obj = JObject.Parse(e.Result);
data = obj["data"]["children"].Children().ToList();
i = 0;
files = Directory.GetFiles("wallpapers").ToList();
enumerator = data.GetEnumerator();
Program.Form.Invoke(new Action(delegate
{
Program.AllProgress.Maximum = data.Count + 1;
Program.AllProgress.Value++;
}));
while (!Next())
{
Program.Form.Invoke(new Action(delegate
{
Program.AllProgress.Value++;
}));
}
}
private static void DownloadProgress(object sender, DownloadProgressChangedEventArgs e)
{
Program.Form.Invoke(new Action(delegate
{
Program.Progress.Value = e.ProgressPercentage;
}));
}
private static void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
@ -49,8 +76,22 @@ namespace DEIFR
private static void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
if (MessageBox.Show("Error while downloading imgae:\n" + e.Error, "Error", MessageBoxButtons.RetryCancel) == DialogResult.Cancel)
return;
}
Program.Form.Invoke(new Action(delegate
{
Program.AllProgress.Value++;
}));
while (!Next())
;
{
Program.Form.Invoke(new Action(delegate
{
Program.AllProgress.Value++;
}));
}
}
private static bool Next()

View file

@ -13,6 +13,7 @@ namespace DEIFR
public static int MaxImages;
public static ProgressBar Progress;
public static Form1 Form;
public static ProgressBar AllProgress;
/// <summary>
/// The main entry point for the application.