Code quality changes

This commit is contained in:
Robin 2016-09-22 20:40:13 +02:00
commit 610f45d082
189 changed files with 4609 additions and 5203 deletions

View file

@ -23,27 +23,19 @@ using System.Drawing;
using Greenshot.IniFile;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
namespace GreenshotDropboxPlugin {
internal class DropboxDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DropboxDestination));
private static readonly DropboxPluginConfiguration config = IniConfig.GetIniSection<DropboxPluginConfiguration>();
private static readonly DropboxPluginConfiguration DropboxConfig = IniConfig.GetIniSection<DropboxPluginConfiguration>();
private readonly DropboxPlugin plugin = null;
private readonly DropboxPlugin _plugin;
public DropboxDestination(DropboxPlugin plugin) {
this.plugin = plugin;
_plugin = plugin;
}
public override string Designation {
get {
return "Dropbox";
}
}
public override string Designation => "Dropbox";
public override string Description {
get {
return Language.GetString("dropbox", LangKey.upload_menu_item);
}
}
public override string Description => Language.GetString("dropbox", LangKey.upload_menu_item);
public override Image DisplayIcon {
get {
@ -55,11 +47,11 @@ namespace GreenshotDropboxPlugin {
public override ExportInformation ExportCapture(bool manually, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(Designation, Description);
string uploadUrl;
bool uploaded = plugin.Upload(captureDetails, surface, out uploadUrl);
bool uploaded = _plugin.Upload(captureDetails, surface, out uploadUrl);
if (uploaded) {
exportInformation.Uri = uploadUrl;
exportInformation.ExportMade = true;
if (config.AfterUploadLinkToClipBoard) {
if (DropboxConfig.AfterUploadLinkToClipBoard) {
ClipboardHelper.SetClipboardData(uploadUrl);
}
}

View file

@ -55,9 +55,6 @@ namespace GreenshotDropboxPlugin {
}
}
public DropboxPlugin() {
}
public IEnumerable<IDestination> Destinations() {
yield return new DropboxDestination(this);
}
@ -123,7 +120,8 @@ namespace GreenshotDropboxPlugin {
try {
string dropboxUrl = null;
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("dropbox", LangKey.communication_wait),
delegate() {
delegate
{
string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails));
dropboxUrl = DropboxUtils.UploadToDropbox(surfaceToUpload, outputSettings, filename);
}

View file

@ -30,36 +30,38 @@ namespace GreenshotDropboxPlugin {
/// Description of DropboxUtils.
/// </summary>
public class DropboxUtils {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DropboxUtils));
private static readonly DropboxPluginConfiguration config = IniConfig.GetIniSection<DropboxPluginConfiguration>();
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(DropboxUtils));
private static readonly DropboxPluginConfiguration DropboxConfig = IniConfig.GetIniSection<DropboxPluginConfiguration>();
private DropboxUtils() {
}
public static string UploadToDropbox(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string filename) {
OAuthSession oAuth = new OAuthSession(DropBoxCredentials.CONSUMER_KEY, DropBoxCredentials.CONSUMER_SECRET);
oAuth.BrowserSize = new Size(1080, 650);
oAuth.CheckVerifier = false;
oAuth.AccessTokenUrl = "https://api.dropbox.com/1/oauth/access_token";
oAuth.AuthorizeUrl = "https://api.dropbox.com/1/oauth/authorize";
oAuth.RequestTokenUrl = "https://api.dropbox.com/1/oauth/request_token";
oAuth.LoginTitle = "Dropbox authorization";
oAuth.Token = config.DropboxToken;
oAuth.TokenSecret = config.DropboxTokenSecret;
var oAuth = new OAuthSession(DropBoxCredentials.CONSUMER_KEY, DropBoxCredentials.CONSUMER_SECRET)
{
BrowserSize = new Size(1080, 650),
CheckVerifier = false,
AccessTokenUrl = "https://api.dropbox.com/1/oauth/access_token",
AuthorizeUrl = "https://api.dropbox.com/1/oauth/authorize",
RequestTokenUrl = "https://api.dropbox.com/1/oauth/request_token",
LoginTitle = "Dropbox authorization",
Token = DropboxConfig.DropboxToken,
TokenSecret = DropboxConfig.DropboxTokenSecret
};
try {
SurfaceContainer imageToUpload = new SurfaceContainer(surfaceToUpload, outputSettings, filename);
string uploadResponse = oAuth.MakeOAuthRequest(HTTPMethod.POST, "https://api-content.dropbox.com/1/files_put/sandbox/" + OAuthSession.UrlEncode3986(filename), null, null, imageToUpload);
LOG.DebugFormat("Upload response: {0}", uploadResponse);
Log.DebugFormat("Upload response: {0}", uploadResponse);
} catch (Exception ex) {
LOG.Error("Upload error: ", ex);
Log.Error("Upload error: ", ex);
throw;
} finally {
if (!string.IsNullOrEmpty(oAuth.Token)) {
config.DropboxToken = oAuth.Token;
DropboxConfig.DropboxToken = oAuth.Token;
}
if (!string.IsNullOrEmpty(oAuth.TokenSecret)) {
config.DropboxTokenSecret = oAuth.TokenSecret;
DropboxConfig.DropboxTokenSecret = oAuth.TokenSecret;
}
}
@ -67,16 +69,16 @@ namespace GreenshotDropboxPlugin {
try {
string responseString = oAuth.MakeOAuthRequest(HTTPMethod.GET, "https://api.dropbox.com/1/shares/sandbox/" + OAuthSession.UrlEncode3986(filename), null, null, null);
if (responseString != null) {
LOG.DebugFormat("Parsing output: {0}", responseString);
Log.DebugFormat("Parsing output: {0}", responseString);
IDictionary<string, object> returnValues = JSONHelper.JsonDecode(responseString);
if (returnValues.ContainsKey("url")) {
return returnValues["url"] as string;
}
}
} catch (Exception ex) {
LOG.Error("Can't parse response.", ex);
Log.Error("Can't parse response.", ex);
}
return null;
}
}
}
}

View file

@ -20,16 +20,12 @@
*/
using GreenshotDropboxPlugin.Forms;
using Greenshot.IniFile;
namespace GreenshotDropboxPlugin {
/// <summary>
/// Description of PasswordRequestForm.
/// </summary>
public partial class SettingsForm : DropboxForm {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(SettingsForm));
private static DropboxPluginConfiguration config = IniConfig.GetIniSection<DropboxPluginConfiguration>();
public SettingsForm() {
//
// The InitializeComponent() call is required for Windows Forms designer support.