Beispiel #1
0
        public SettingsForm(BoxConfiguration config)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            InitializeTexts();

            combobox_uploadimageformat.Items.Clear();
            foreach (OutputFormat format in Enum.GetValues(typeof(OutputFormat)))
            {
                combobox_uploadimageformat.Items.Add(format.ToString());
            }

            comboBox_DefaultSize.Items.Clear();
            foreach (PictureDisplaySize displaySize in Enum.GetValues(typeof(PictureDisplaySize)))
            {
                comboBox_DefaultSize.Items.Add(displaySize.ToString());
            }

            BoxUtils.LoadHistory();

            if (config.runtimeBoxHistory.Count > 0)
            {
                historyButton.Enabled = true;
            }
            else
            {
                historyButton.Enabled = false;
            }
        }
        /// <summary>
        /// This will be called when the menu item in the Editor is clicked
        /// </summary>
        public bool Upload(ICaptureDetails captureDetails, Image image)
        {
            if (string.IsNullOrEmpty(config.boxToken))
            {
                MessageBox.Show(lang.GetString(LangKey.TokenNotSet), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
            else
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, lang.GetString(LangKey.communication_wait));

                    host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality);
                    byte[] buffer = stream.GetBuffer();
                    try
                    {
                        string  contentType = "image/" + config.UploadFormat.ToString();
                        string  filename    = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
                        BoxInfo BoxInfo     = BoxUtils.UploadToBox(buffer, captureDetails.Title, filename, contentType);

                        if (config.BoxUploadHistory == null)
                        {
                            config.BoxUploadHistory = new Dictionary <string, string>();
                        }

                        if (BoxInfo.ID != null)
                        {
                            LOG.InfoFormat("Storing Box upload for id {0}", BoxInfo.ID);

                            config.BoxUploadHistory.Add(BoxInfo.ID.ToString(), BoxInfo.ID.ToString());
                            config.runtimeBoxHistory.Add(BoxInfo.ID.ToString(), BoxInfo);
                        }

                        BoxInfo.Image = BoxUtils.CreateThumbnail(image, 90, 90);
                        // Make sure the configuration is save, so we don't lose the deleteHash
                        IniConfig.Save();
                        // Make sure the history is loaded, will be done only once
                        BoxUtils.LoadHistory();

                        // Show
                        if (config.AfterUploadOpenHistory)
                        {
                            BoxHistory.ShowHistory();
                        }

                        if (config.AfterUploadLinkToClipBoard)
                        {
                            Clipboard.SetText(BoxInfo.LinkUrl(config.PictureDisplaySize));
                        }

                        return(true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.ToString());
                        return(false);
                    }
                    finally
                    {
                        backgroundForm.CloseDialog();
                    }
                }
            }
        }
 public void HistoryMenuClick(object sender, EventArgs eventArgs)
 {
     BoxUtils.LoadHistory();
     BoxHistory.ShowHistory();
 }