mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -07:00
Added Proxy support
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@899 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
82207ac607
commit
2cc6277ce2
4 changed files with 201 additions and 102 deletions
|
@ -28,6 +28,7 @@ using System.Windows.Forms;
|
||||||
using Greenshot.Core;
|
using Greenshot.Core;
|
||||||
using Greenshot.Helpers;
|
using Greenshot.Helpers;
|
||||||
using GreenshotConfluencePlugin;
|
using GreenshotConfluencePlugin;
|
||||||
|
using GreenshotCore.Helpers;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For details see the Confluence API site
|
/// For details see the Confluence API site
|
||||||
|
@ -47,7 +48,7 @@ namespace Confluence {
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public class ConfluenceConnector {
|
public class ConfluenceConnector {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceConnector));
|
||||||
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.confluence.rpc.AuthenticationFailedException";
|
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.confluence.rpc.AuthenticationFailedException";
|
||||||
|
|
||||||
private string credentials = null;
|
private string credentials = null;
|
||||||
|
@ -63,6 +64,7 @@ namespace Confluence {
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
confluence = new ConfluenceSoapServiceService();
|
confluence = new ConfluenceSoapServiceService();
|
||||||
confluence.Url = url;
|
confluence.Url = url;
|
||||||
|
confluence.Proxy = NetworkHelper.CreateProxy(new Uri(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
~ConfluenceConnector() {
|
~ConfluenceConnector() {
|
||||||
|
|
|
@ -98,6 +98,7 @@
|
||||||
<Compile Include="Helpers\ImageHelper.cs" />
|
<Compile Include="Helpers\ImageHelper.cs" />
|
||||||
<Compile Include="Helpers\ImageOutput.cs" />
|
<Compile Include="Helpers\ImageOutput.cs" />
|
||||||
<Compile Include="Helpers\MailHelper.cs" />
|
<Compile Include="Helpers\MailHelper.cs" />
|
||||||
|
<Compile Include="Helpers\NetworkHelper.cs" />
|
||||||
<Compile Include="Helpers\Objects.cs" />
|
<Compile Include="Helpers\Objects.cs" />
|
||||||
<Compile Include="Helpers\PluginHelper.cs" />
|
<Compile Include="Helpers\PluginHelper.cs" />
|
||||||
<Compile Include="Helpers\PrintHelper.cs" />
|
<Compile Include="Helpers\PrintHelper.cs" />
|
||||||
|
|
90
GreenshotCore/Helpers/NetworkHelper.cs
Normal file
90
GreenshotCore/Helpers/NetworkHelper.cs
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
|
*
|
||||||
|
* For more information see: http://getgreenshot.org/
|
||||||
|
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 1 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
using Greenshot.Core;
|
||||||
|
|
||||||
|
namespace GreenshotCore.Helpers {
|
||||||
|
/// <summary>
|
||||||
|
/// Description of NetworkHelper.
|
||||||
|
/// </summary>
|
||||||
|
public class NetworkHelper {
|
||||||
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(NetworkHelper));
|
||||||
|
private static CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Download the FavIcon as a Bitmap
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseUri"></param>
|
||||||
|
/// <returns>Bitmap with the FavIcon</returns>
|
||||||
|
public static Bitmap DownloadFavIcon(Uri baseUri) {
|
||||||
|
Uri url = new Uri(baseUri, new Uri("favicon.ico"));
|
||||||
|
try {
|
||||||
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||||
|
request.Proxy = NetworkHelper.CreateProxy(url);
|
||||||
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||||
|
if (request.HaveResponse) {
|
||||||
|
Image image = Image.FromStream(response.GetResponseStream());
|
||||||
|
return (image.Height > 16 && image.Width > 16) ? new Bitmap(image, 16, 16) : new Bitmap(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.Error("Problem downloading the FavIcon from: " + baseUri.ToString(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a IWebProxy Object which can be used to access the Internet
|
||||||
|
/// This method will check the configuration if the proxy is allowed to be used.
|
||||||
|
/// Usages can be found in the DownloadFavIcon or Jira and Confluence plugins
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url"></param>
|
||||||
|
/// <returns>IWebProxy filled with all the proxy details or null if none is set/wanted</returns>
|
||||||
|
public static IWebProxy CreateProxy(Uri uri) {
|
||||||
|
IWebProxy proxyToUse = null;
|
||||||
|
if (config.UseProxy) {
|
||||||
|
proxyToUse = WebRequest.DefaultWebProxy;
|
||||||
|
if (proxyToUse != null) {
|
||||||
|
proxyToUse.Credentials = CredentialCache.DefaultCredentials;
|
||||||
|
if (LOG.IsDebugEnabled) {
|
||||||
|
// check the proxy for the Uri
|
||||||
|
if (!proxyToUse.IsBypassed(uri)) {
|
||||||
|
Uri proxyUri = proxyToUse.GetProxy(uri);
|
||||||
|
if (proxyUri != null) {
|
||||||
|
LOG.Debug("Using proxy: " + proxyUri.ToString() + " for " + uri.ToString());
|
||||||
|
} else {
|
||||||
|
LOG.Debug("No proxy found!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG.Debug("Proxy bypass for: " + uri.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG.Debug("No proxy found!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return proxyToUse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,72 +22,77 @@ using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Core;
|
using Greenshot.Core;
|
||||||
using Greenshot.Helpers;
|
using Greenshot.Helpers;
|
||||||
|
using GreenshotCore.Helpers;
|
||||||
using GreenshotJiraPlugin;
|
using GreenshotJiraPlugin;
|
||||||
|
|
||||||
namespace Jira {
|
namespace Jira {
|
||||||
#region transport classes
|
#region transport classes
|
||||||
public class JiraFilter {
|
public class JiraFilter {
|
||||||
public JiraFilter(string name, string id) {
|
public JiraFilter(string name, string id) {
|
||||||
this.name = name;
|
this.Name = name;
|
||||||
this.id = id;
|
this.Id = id;
|
||||||
}
|
}
|
||||||
public string name {
|
public string Name {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
public string Id {
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
public string id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class JiraIssue {
|
public class JiraIssue {
|
||||||
public JiraIssue(string key, DateTime? created, string reporter, string assignee, string project, string summary, string description, string environment, string [] attachmentNames) {
|
public JiraIssue(string key, DateTime? created, string reporter, string assignee, string project, string summary, string description, string environment, string [] attachmentNames) {
|
||||||
this.key = key;
|
this.Key = key;
|
||||||
this.created = created;
|
this.Created = created;
|
||||||
this.reporter = reporter;
|
this.Reporter = reporter;
|
||||||
this.assignee = assignee;
|
this.Assignee = assignee;
|
||||||
this.project = project;
|
this.Project = project;
|
||||||
this.summary = summary;
|
this.Summary = summary;
|
||||||
this.description = description;
|
this.Description = description;
|
||||||
this.environment = environment;
|
this.Environment = environment;
|
||||||
this.attachmentNames = attachmentNames;
|
this.AttachmentNames = attachmentNames;
|
||||||
}
|
}
|
||||||
public string key {
|
public string Key {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public DateTime? created {
|
public DateTime? Created {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public string reporter {
|
public string Reporter {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public string assignee {
|
public string Assignee {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public string project {
|
public string Project {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public string summary {
|
public string Summary {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public string description {
|
public string Description {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public string environment {
|
public string Environment {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public string[] attachmentNames {
|
public string[] AttachmentNames {
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
@ -95,11 +100,11 @@ namespace Jira {
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public class JiraConnector {
|
public class JiraConnector {
|
||||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(JiraConnector));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(JiraConnector));
|
||||||
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.jira.rpc.exception.RemoteAuthenticationException";
|
private const string AUTH_FAILED_EXCEPTION_NAME = "com.atlassian.jira.rpc.exception.RemoteAuthenticationException";
|
||||||
private string credentials = null;
|
private string credentials;
|
||||||
private DateTime loggedInTime = DateTime.Now;
|
private DateTime loggedInTime = DateTime.Now;
|
||||||
private bool loggedIn = false;
|
private bool loggedIn;
|
||||||
private JiraSoapServiceService jira;
|
private JiraSoapServiceService jira;
|
||||||
private int timeout;
|
private int timeout;
|
||||||
private string url;
|
private string url;
|
||||||
|
@ -110,6 +115,7 @@ namespace Jira {
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
jira = new JiraSoapServiceService();
|
jira = new JiraSoapServiceService();
|
||||||
jira.Url = url;
|
jira.Url = url;
|
||||||
|
jira.Proxy = NetworkHelper.CreateProxy(new Uri(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
~JiraConnector() {
|
~JiraConnector() {
|
||||||
|
@ -135,7 +141,7 @@ namespace Jira {
|
||||||
this.credentials = null;
|
this.credentials = null;
|
||||||
e.Data.Add("user", user);
|
e.Data.Add("user", user);
|
||||||
e.Data.Add("url", url);
|
e.Data.Add("url", url);
|
||||||
throw e;
|
throw;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue