private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     if (this.backgroundWorker1.IsBusy)
     {
         if (e.ProgressPercentage == ChoocingCategoriesMsg)
         {
             List<Category> userState = e.UserState as List<Category>;
             List<Category> categories = new List<Category>();
             FormChoocingCategories formChoocingCategory = new FormChoocingCategories(userState, categories);
             try
             {
                 formChoocingCategory.ShowDialog(this);
             }
             finally
             {
                 if (formChoocingCategory != null)
                 {
                     ((IDisposable)formChoocingCategory).Dispose();
                 }
             }
             userState.Clear();
             userState.AddRange(categories);
             UserHasChoosedCategories = 1;
         }
         else if (e.ProgressPercentage == ChooseBooksMsg)
         {
             Form1.UserHasChoosedCategories = 0;
             List<Category> userState = e.UserState as List<Category>;
             using (var f = new FormChooseBooks())
             {
                 f.Populate(userState);
                 if (f.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
                 {
                     Form1.UserHasChoosedCategories = -1;
                 }
                 else
                 {
                     SelectedBooks = f.SelectedBooks;
                     Form1.UserHasChoosedCategories = 1;
                 }
             }
         }
         else if (e.ProgressPercentage != 4096)
         {
             int progressPercentage = e.ProgressPercentage;
             if ((e.ProgressPercentage < 0 ? true : e.ProgressPercentage > 100))
             {
                 progressPercentage = 0;
             }
             if (this.sync.CurrentStatus == Synchronizer.Status.End)
             {
                 this.toolStripProgressBar1.Value = progressPercentage;
             }
             else
             {
                 this.progressBar1.Value = progressPercentage;
             }
             this.listBoxStatus.Items.Add(e.UserState);
             this.listBoxStatus.SelectedIndex = this.listBoxStatus.Items.Count - 1;
             if (this.sync.CurrentStatus == Synchronizer.Status.Connecting)
             {
                 this.toolStripStatusLabel1.Text = "(1 من 5) يتم الآن الاتصال بالموقع...";
             }
             else if (this.sync.CurrentStatus == Synchronizer.Status.AddingPages)
             {
                 this.toolStripStatusLabel1.Text = "(3 من 5) يتم الآن استكشاف صفحات أقسام الكتب...";
             }
             else if (this.sync.CurrentStatus == Synchronizer.Status.AddingCategories)
             {
                 this.toolStripStatusLabel1.Text = "(2 من 5) يتم الآن استكشاف أقسام الكتب...";
             }
             else if (this.sync.CurrentStatus == Synchronizer.Status.End)
             {
                 this.toolStripProgressBar1.Visible = true;
                 this.toolStripStatusLabel1.Text = "(5 من 5) يتم الآن تحميل الكتب...";
             }
             else if (this.sync.CurrentStatus == Synchronizer.Status.AddingBooks)
             {
                 this.toolStripStatusLabel1.Text = "(4 من 5) يتم الآن استكشاف الكتب...";
             }
         }
         else
         {
             int num = Convert.ToInt32(e.UserState);
             this.progressBar1.Value = (num < 0 || num > 100 ? 0 : num);
         }
     }
 }
 private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     if (this.backgroundWorker1.IsBusy)
     {
         if (e.ProgressPercentage == ChoocingCategoriesMsg)
         {
             List <Category>        userState            = e.UserState as List <Category>;
             List <Category>        categories           = new List <Category>();
             FormChoocingCategories formChoocingCategory = new FormChoocingCategories(userState, categories);
             try
             {
                 formChoocingCategory.ShowDialog(this);
             }
             finally
             {
                 if (formChoocingCategory != null)
                 {
                     ((IDisposable)formChoocingCategory).Dispose();
                 }
             }
             userState.Clear();
             userState.AddRange(categories);
             UserHasChoosedCategories = 1;
         }
         else if (e.ProgressPercentage == ChooseBooksMsg)
         {
             Form1.UserHasChoosedCategories = 0;
             List <Category> userState = e.UserState as List <Category>;
             using (var f = new FormChooseBooks())
             {
                 f.Populate(userState);
                 if (f.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
                 {
                     Form1.UserHasChoosedCategories = -1;
                 }
                 else
                 {
                     SelectedBooks = f.SelectedBooks;
                     Form1.UserHasChoosedCategories = 1;
                 }
             }
         }
         else if (e.ProgressPercentage != 4096)
         {
             int progressPercentage = e.ProgressPercentage;
             if ((e.ProgressPercentage < 0 ? true : e.ProgressPercentage > 100))
             {
                 progressPercentage = 0;
             }
             if (this.sync.CurrentStatus == Synchronizer.Status.End)
             {
                 this.toolStripProgressBar1.Value = progressPercentage;
             }
             else
             {
                 this.progressBar1.Value = progressPercentage;
             }
             this.listBoxStatus.Items.Add(e.UserState);
             this.listBoxStatus.SelectedIndex = this.listBoxStatus.Items.Count - 1;
             if (this.sync.CurrentStatus == Synchronizer.Status.Connecting)
             {
                 this.toolStripStatusLabel1.Text = "(1 من 5) يتم الآن الاتصال بالموقع...";
             }
             else if (this.sync.CurrentStatus == Synchronizer.Status.AddingPages)
             {
                 this.toolStripStatusLabel1.Text = "(3 من 5) يتم الآن استكشاف صفحات أقسام الكتب...";
             }
             else if (this.sync.CurrentStatus == Synchronizer.Status.AddingCategories)
             {
                 this.toolStripStatusLabel1.Text = "(2 من 5) يتم الآن استكشاف أقسام الكتب...";
             }
             else if (this.sync.CurrentStatus == Synchronizer.Status.End)
             {
                 this.toolStripProgressBar1.Visible = true;
                 this.toolStripStatusLabel1.Text    = "(5 من 5) يتم الآن تحميل الكتب...";
             }
             else if (this.sync.CurrentStatus == Synchronizer.Status.AddingBooks)
             {
                 this.toolStripStatusLabel1.Text = "(4 من 5) يتم الآن استكشاف الكتب...";
             }
         }
         else
         {
             int num = Convert.ToInt32(e.UserState);
             this.progressBar1.Value = (num < 0 || num > 100 ? 0 : num);
         }
     }
 }