示例#1
0
    public void Run(Main main, BackgroundWorker backgroundGoogleDrive)
    {
      this.main = main;
      main.UseWaitCursor = true;
      this.backgroundGoogleDrive = backgroundGoogleDrive;
      // 
      // backgroundGoogleDrive
      // 
      this.backgroundGoogleDrive.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundGoogleDrive_ProgressChanged);
      this.backgroundGoogleDrive.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundGoogleDrive_RunWorkerCompleted);

      this.connecting = new Connecting();
      try
      {
        backgroundGoogleDrive.ReportProgress(-1, "Connecting to Google drive...");
        Run(false).Wait();
      }
      catch (AggregateException ex)
      {
        foreach (var e in ex.InnerExceptions)
        {
          Console.WriteLine("ERROR: " + e.Message);
          try
          {
            backgroundGoogleDrive.ReportProgress(-1, "Reconnecting to Google drive...");
            Run(true).Wait();
          }
          catch (AggregateException ex2)
          {
            foreach (var e2 in ex2.InnerExceptions)
            {
              Console.WriteLine("ERROR: " + e2.Message);
            }
          }
        }
      }
      connecting.Close();
    }
示例#2
0
        internal int Show(int row, Main main)
        {
            Control[] controls = new Control[] {
            Show(new Label(){TextAlign = System.Drawing.ContentAlignment.MiddleLeft,Dock = DockStyle.Fill}, "Start"),
            Show(new Label(){TextAlign = System.Drawing.ContentAlignment.MiddleLeft,Dock = DockStyle.Fill}, "Stopp"),
            GetImage(main.ImageListCancellations, "Ringtyp"),
            GetImage(main.ImageListCancellations, "Oscar"),
            GetImage(main.ImageListCancellations, "Gustaf V"),
            GetImage(main.ImageListCancellations, "Gustav V en face"),
            GetImage(main.ImageListCancellations, "Luftpost"),
            Show(new Label(){TextAlign = System.Drawing.ContentAlignment.MiddleLeft,Dock = DockStyle.Fill}, "Kommentar")
              };

              if (main.BackgroundSurfer.CancellationPending) return row;

              if (main.TableLayoutPanel.Controls.Count < controls.Length)
              {
            main.TableLayoutPanel.Controls.AddRange(controls);
              }

              int imageRow = 0;
              List<aboveTradera.DatabaseRowEntry.KeyValuePair<string, string>> ExtraImages = new List<aboveTradera.DatabaseRowEntry.KeyValuePair<string, string>>();
              foreach (var entry in entries)
              {
            int col = 0;
            Show(GetControl(main.TableLayoutPanel, col++, row), entry.Start);
            if (main.BackgroundSurfer.CancellationPending) return row;
            Show(GetControl(main.TableLayoutPanel, col++, row), entry.Stop);
            if (main.BackgroundSurfer.CancellationPending) return row;
            Show(GetControl(main.TableLayoutPanel, col++, row), entry.Ringtyp);
            if (main.BackgroundSurfer.CancellationPending) return row;
            Show(GetControl(main.TableLayoutPanel, col++, row), entry.Oscar);
            if (main.BackgroundSurfer.CancellationPending) return row;
            Show(GetControl(main.TableLayoutPanel, col++, row), entry.Gustaf);
            if (main.BackgroundSurfer.CancellationPending) return row;
            Show(GetControl(main.TableLayoutPanel, col++, row), entry.Type58);
            if (main.BackgroundSurfer.CancellationPending) return row;
            Show(GetControl(main.TableLayoutPanel, col++, row), entry.Type59);
            if (main.BackgroundSurfer.CancellationPending) return row;
            Show(GetControl(main.TableLayoutPanel, col++, row++), entry.Comment);
            var control = GetImage(main.ImageListCancellations, entry.Start);
            if (main.BackgroundSurfer.CancellationPending) return row;
            bool anyAdded = false;
            if (control != null)
            {
              if (main.BackgroundSurfer.CancellationPending) return row;
              main.TableLayoutPanelCancellations.Controls.Add(control, 0, imageRow);
              foreach (var image in entry.Images)
              {
            if (main.BackgroundSurfer.CancellationPending) return row;
            control = GetImage(main, entry, image, imageRow);
            if (control == null) continue;
            anyAdded = true;
            main.TableLayoutPanelCancellations.Controls.Add(control, 1, imageRow++);
            if (main.BackgroundSurfer.CancellationPending) return row;
              }
              if (!anyAdded) ++imageRow;
            }
            ExtraImages.AddRange(entry.ExtraImages);
              }

              foreach (var image in ExtraImages)
              {
            if (main.BackgroundSurfer.CancellationPending) return row;
            var control = GetImage(main, null, image, imageRow);
            if (control == null) continue;
            main.TableLayoutPanelCancellations.Controls.Add(control, 1, imageRow++);
            if (main.BackgroundSurfer.CancellationPending) return row;
              }

              int populatedRows = row;
              while (main.TableLayoutPanel.GetControlFromPosition(0, row) != null)
              {
            for (int col = 0; col < 8; ++col)
            {
              Control control = main.TableLayoutPanel.GetControlFromPosition(col, row);
              if (control != null)
              {
            control.Text = "";
            control.BackColor = Control.DefaultBackColor;
              }
            }
            ++row;
              }
              return populatedRows;
        }
示例#3
0
 public DownloadImage(Main main, DatabaseRowEntry entry, Control placeHolder, int row, string uri, string cache)
 {
     // TODO: Complete member initialization
     this.main = main;
     this.entry = entry;
     this.placeHolder = placeHolder;
     this.uri = uri;
     this.row = row;
     this.cache = cache;
 }
示例#4
0
 private Control GetImage(Main main, DatabaseRowEntry entry, DatabaseRowEntry.KeyValuePair<string, string> image, int row)
 {
     Picture control = null;
       // First check if we've already downloaded this image.
       string cache = Path.Combine(Path.GetDirectoryName(Properties.Settings.Default.Collection), @"cache");
       if (!File.Exists(cache)) Directory.CreateDirectory(cache);
       cache = Path.Combine(cache, image.Key);
       if (File.Exists(cache))
       {
     control = new Picture(entry) { Image = Image.FromFile(cache), Width = 130, Height = 130, SizeMode = PictureBoxSizeMode.Zoom };
       }
       else
       {
     control = new Picture() { Image = Properties.Resources.loading, Width = 130, Height = 130, SizeMode = PictureBoxSizeMode.CenterImage};
     var imageDownloader = new DownloadImage(main, entry, control, row, image.Value, cache);
     new Thread(new ThreadStart(imageDownloader.Download)).Start();
       }
       return control;
 }