Code quality changes

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

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;
}
}
}
}