ProxyInfo static Current class instead using Uploader.ProxyInfo

This commit is contained in:
Jaex 2013-12-04 10:54:32 +02:00
parent b801eedafc
commit 6d7708efd6
6 changed files with 48 additions and 37 deletions

View file

@ -377,7 +377,7 @@ private void RegisterMenuClosing()
private void AfterSettingsJobs()
{
Uploader.ProxyInfo = Program.Settings.ProxySettings;
ProxyInfo.Current = Program.Settings.ProxySettings;
ClipboardHelpers.UseAlternativeCopyImage = Program.Settings.UseAlternativeClipboardCopyImage;
}
@ -409,6 +409,16 @@ private void UpdateUploaderMenuNames()
tsmiSocialServices.Text = tsmiTraySocialServices.Text = "Social networking service: " + Program.DefaultTaskSettings.SocialNetworkingServiceDestination.GetDescription();
}
private void AutoCheckUpdate()
{
if (Program.Settings.AutoCheckUpdate)
{
Thread updateThread = new Thread(CheckUpdate);
updateThread.IsBackground = true;
updateThread.Start();
}
}
private void CheckUpdate()
{
UpdateChecker updateChecker = TaskHelpers.CheckUpdate();
@ -427,16 +437,6 @@ private void CheckUpdate()
}
}
private void AutoCheckUpdate()
{
if (Program.Settings.AutoCheckUpdate)
{
Thread updateThread = new Thread(CheckUpdate);
updateThread.IsBackground = true;
updateThread.Start();
}
}
private void ForceClose()
{
forceClose = true;

View file

@ -323,15 +323,15 @@ public static UpdateChecker CheckUpdate()
{
UpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX");
updateChecker.CurrentVersion = Program.AssemblyVersion;
updateChecker.Proxy = Uploader.ProxyInfo.GetWebProxy();
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
updateChecker.CheckUpdate();
// Backup if GitHub API fails
// Fallback if GitHub API fails
if (updateChecker.UpdateInfo == null || updateChecker.UpdateInfo.Status == UpdateStatus.UpdateCheckFailed)
{
updateChecker = new XMLUpdateChecker("https://raw.github.com/ShareX/ShareX/master/Update.xml", "ShareX");
updateChecker.CurrentVersion = Program.AssemblyVersion;
updateChecker.Proxy = Uploader.ProxyInfo.GetWebProxy();
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
updateChecker.CheckUpdate();
}

View file

@ -72,9 +72,9 @@ public FTP(FTPAccount account, int bufferSize = 8192)
Client.DataTransferMode = account.IsActive ? TransferMode.Active : TransferMode.Passive;
if (Uploader.ProxyInfo != null)
if (ProxyInfo.Current != null)
{
IProxyClient proxy = Uploader.ProxyInfo.GetProxyClient();
IProxyClient proxy = ProxyInfo.Current.GetProxyClient();
if (proxy != null)
{

View file

@ -31,6 +31,25 @@ namespace UploadersLib
{
public class ProxyInfo
{
private static ProxyInfo current;
public static ProxyInfo Current
{
get
{
if (current == null)
{
current = new ProxyInfo();
}
return current;
}
set
{
current = value;
}
}
public ProxyMethod ProxyMethod { get; set; }
public string Username { get; set; }
public string Password { get; set; }

View file

@ -23,17 +23,15 @@
#endregion License Information (GPL v3)
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using UploadersLib.HelperClasses;
namespace UploadersLib.TextUploaders
{
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using Newtonsoft.Json;
using UploadersLib.HelperClasses;
public sealed class Gist : TextUploader
{
private readonly Uri GistUri = new Uri("https://api.github.com/gists");
@ -82,7 +80,7 @@ public bool GetAccessToken(string code)
WebHeaderCollection headers = new WebHeaderCollection();
headers.Add("Accept", "application/json");
string response = this.SendPostRequest(this.GistCompleteUri.ToString(), args, headers: headers);
if (!string.IsNullOrEmpty(response))
@ -98,7 +96,7 @@ public bool GetAccessToken(string code)
return false;
}
public override UploadResult UploadText(string text, string fileName)
{
UploadResult ur = new UploadResult();

View file

@ -40,7 +40,6 @@ namespace UploadersLib
{
public class Uploader
{
public static ProxyInfo ProxyInfo = new ProxyInfo();
public static string UserAgent = string.Format("{0} {1}", Application.ProductName, Application.ProductVersion);
public delegate void ProgressEventHandler(ProgressManager progress);
@ -64,11 +63,6 @@ public Uploader()
ServicePointManager.DefaultConnectionLimit = 25;
ServicePointManager.Expect100Continue = false;
ServicePointManager.UseNagleAlgorithm = false;
if (ProxyInfo == null)
{
ProxyInfo = new ProxyInfo();
}
}
protected void OnProgressChanged(ProgressManager progress)
@ -353,7 +347,7 @@ private HttpWebResponse GetResponseUsingDelete(string url, Dictionary<string, st
headers.Remove("Accept");
}
request.AllowWriteStreamBuffering = ProxyInfo.IsValidProxy();
request.AllowWriteStreamBuffering = ProxyInfo.Current.IsValidProxy();
request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
request.ContentLength = length;
if (!string.IsNullOrEmpty(boundary)) contentType += "; boundary=" + boundary;
@ -365,7 +359,7 @@ private HttpWebResponse GetResponseUsingDelete(string url, Dictionary<string, st
request.Method = HttpMethod.Post.GetDescription();
request.Pipelined = false;
request.ProtocolVersion = HttpVersion.Version11;
request.Proxy = ProxyInfo.GetWebProxy();
request.Proxy = ProxyInfo.Current.GetWebProxy();
request.Timeout = -1;
request.UserAgent = UserAgent;
@ -380,7 +374,7 @@ private HttpWebRequest PrepareGetWebRequest(string url, CookieCollection cookies
if (headers != null) request.Headers.Add(headers);
request.KeepAlive = false;
request.Method = HttpMethod.Get.GetDescription();
IWebProxy proxy = ProxyInfo.GetWebProxy();
IWebProxy proxy = ProxyInfo.Current.GetWebProxy();
if (proxy != null) request.Proxy = proxy;
request.UserAgent = UserAgent;
@ -392,7 +386,7 @@ private HttpWebRequest PrepareDeleteWebRequest(string url)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = false;
request.Method = HttpMethod.Delete.GetDescription();
IWebProxy proxy = ProxyInfo.GetWebProxy();
IWebProxy proxy = ProxyInfo.Current.GetWebProxy();
if (proxy != null) request.Proxy = proxy;
request.UserAgent = UserAgent;