Exemplo n.º 1
0
        public SettingsForm(TFSConfiguration 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());
            }

            TFSUtils.LoadHistory();

            if (config.runtimeTfsHistory.Count > 0)
            {
                historyButton.Enabled = true;
            }
            else
            {
                historyButton.Enabled = false;
            }
        }
Exemplo n.º 2
0
        public static void LoadHistory()
        {
            if (config.runtimeTfsHistory == null)
            {
                return;
            }
            if (config.TfsUploadHistory == null)
            {
                return;
            }

            if (config.runtimeTfsHistory.Count == config.TfsUploadHistory.Count)
            {
                return;
            }
            // Load the TFS history
            List <string> hashes = new List <string>();

            foreach (string hash in config.TfsUploadHistory.Keys)
            {
                hashes.Add(hash);
            }

            bool saveNeeded = false;

            foreach (string hash in hashes)
            {
                if (config.runtimeTfsHistory.ContainsKey(hash))
                {
                    // Already loaded
                    continue;
                }
                try {
                    TFSInfo tfsInfo = TFSUtils.RetrieveTFSInfo(hash);
                    if (tfsInfo != null)
                    {
                        //TFSUtils.RetrieveTFSThumbnail(imgurInfo);
                        config.runtimeTfsHistory.Add(hash, tfsInfo);
                    }
                    else
                    {
                        LOG.DebugFormat("Deleting not found TFS {0} from config.", hash);
                        config.TfsUploadHistory.Remove(hash);
                        saveNeeded = true;
                    }
                } catch (Exception e) {
                    LOG.Error("Problem loading TFS history for hash " + hash, e);
                }
            }
            if (saveNeeded)
            {
                // Save needed changes
                IniConfig.Save();
            }
        }
Exemplo n.º 3
0
        public bool Upload(ICaptureDetails captureDetails, Image image)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                SurfaceOutputSettings outputSettings = new SurfaceOutputSettings
                {
                    Format     = config.UploadFormat,
                    JPGQuality = config.UploadJpegQuality
                };
                ImageOutput.SaveToStream(image, null, stream, outputSettings);
                byte[] buffer = stream.GetBuffer();


                try
                {
                    string  filename    = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
                    string  contentType = $"image/{config.UploadFormat}";
                    TFSInfo tfsInfo     = TFSUtils.UploadToTFS(buffer, captureDetails.DateTime.ToString(CultureInfo.CurrentCulture), filename, contentType);
                    if (tfsInfo == null)
                    {
                        return(false);
                    }
                    else
                    {
                        if (config.TfsUploadHistory == null)
                        {
                            config.TfsUploadHistory = new Dictionary <string, string>();
                        }

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

                            config.TfsUploadHistory.Add(tfsInfo.ID, tfsInfo.ID);
                            config.runtimeTfsHistory.Add(tfsInfo.ID, tfsInfo);
                        }

                        // 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
                        TFSUtils.LoadHistory();

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

                        if (config.AfterUploadLinkToClipBoard && !string.IsNullOrEmpty(tfsInfo.WebEditUrl))
                        {
                            Clipboard.SetText(tfsInfo.WebEditUrl);
                        }
                        if (config.AfterUploadOpenWorkItem && !string.IsNullOrEmpty(tfsInfo.WebEditUrl))
                        {
                            System.Diagnostics.Process.Start(tfsInfo.WebEditUrl);
                        }
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(Language.GetString("tfs", $"{LangKey.upload_failure} {e}"));
                }
                finally
                {
                    //backgroundForm.CloseDialog();
                }
            }
            return(false);
        }
Exemplo n.º 4
0
 public void HistoryMenuClick(object sender, EventArgs eventArgs)
 {
     TFSUtils.LoadHistory();
     TFSHistory.ShowHistory();
 }