Starting using the IHttpSettings which are configurable.

This commit is contained in:
Robin 2018-04-16 22:41:15 +02:00
commit 540eb7cb19
10 changed files with 228 additions and 194 deletions

View file

@ -57,15 +57,20 @@ namespace Greenshot.Addon.Box
private static readonly LogSource Log = new LogSource(); private static readonly LogSource Log = new LogSource();
private readonly IBoxConfiguration _boxConfiguration; private readonly IBoxConfiguration _boxConfiguration;
private readonly IBoxLanguage _boxLanguage; private readonly IBoxLanguage _boxLanguage;
private readonly INetworkConfiguration _networkConfiguration;
private readonly OAuth2Settings _oauth2Settings; private readonly OAuth2Settings _oauth2Settings;
private static readonly Uri UploadFileUri = new Uri("https://upload.box.com/api/2.0/files/content"); private static readonly Uri UploadFileUri = new Uri("https://upload.box.com/api/2.0/files/content");
private static readonly Uri FilesUri = new Uri("https://www.box.com/api/2.0/files/"); private static readonly Uri FilesUri = new Uri("https://www.box.com/api/2.0/files/");
[ImportingConstructor] [ImportingConstructor]
public BoxDestination(IBoxConfiguration boxConfiguration, IBoxLanguage boxLanguage) public BoxDestination(
IBoxConfiguration boxConfiguration,
IBoxLanguage boxLanguage,
INetworkConfiguration networkConfiguration)
{ {
_boxConfiguration = boxConfiguration; _boxConfiguration = boxConfiguration;
_boxLanguage = boxLanguage; _boxLanguage = boxLanguage;
_networkConfiguration = networkConfiguration;
_oauth2Settings = new OAuth2Settings _oauth2Settings = new OAuth2Settings
{ {
@ -166,6 +171,8 @@ namespace Greenshot.Addon.Box
string filename = surface.GenerateFilename(CoreConfiguration, _boxConfiguration); string filename = surface.GenerateFilename(CoreConfiguration, _boxConfiguration);
var oauthHttpBehaviour = HttpBehaviour.Current.ShallowClone(); var oauthHttpBehaviour = HttpBehaviour.Current.ShallowClone();
// Use the network settings
oauthHttpBehaviour.HttpSettings = _networkConfiguration;
// Use UploadProgress // Use UploadProgress
if (progress != null) if (progress != null)
{ {

View file

@ -65,7 +65,10 @@ namespace Greenshot.Addon.Dropbox
private IHttpBehaviour _oAuthHttpBehaviour; private IHttpBehaviour _oAuthHttpBehaviour;
[ImportingConstructor] [ImportingConstructor]
public DropboxDestination(IDropboxConfiguration dropboxPluginConfiguration, IDropboxLanguage dropboxLanguage) public DropboxDestination(
IDropboxConfiguration dropboxPluginConfiguration,
IDropboxLanguage dropboxLanguage,
INetworkConfiguration networkConfiguration)
{ {
_dropboxPluginConfiguration = dropboxPluginConfiguration; _dropboxPluginConfiguration = dropboxPluginConfiguration;
_dropboxLanguage = dropboxLanguage; _dropboxLanguage = dropboxLanguage;
@ -89,10 +92,14 @@ namespace Greenshot.Addon.Dropbox
RedirectUrl = "http://localhost:47336", RedirectUrl = "http://localhost:47336",
Token = dropboxPluginConfiguration Token = dropboxPluginConfiguration
}; };
_oAuthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(_oAuth2Settings); var httpBehaviour = OAuth2HttpBehaviourFactory.Create(_oAuth2Settings) as IChangeableHttpBehaviour;
_oAuthHttpBehaviour = httpBehaviour;
// Use the default network settings
httpBehaviour.HttpSettings = networkConfiguration;
} }
public override Bitmap DisplayIcon public override Bitmap DisplayIcon
{ {
get get
{ {

View file

@ -76,7 +76,8 @@ namespace Greenshot.Addon.Flickr
}); });
[ImportingConstructor] [ImportingConstructor]
public FlickrDestination(IFlickrConfiguration flickrConfiguration, IFlickrLanguage flickrLanguage) public FlickrDestination(IFlickrConfiguration flickrConfiguration,
IFlickrLanguage flickrLanguage, INetworkConfiguration networkConfiguration)
{ {
_flickrConfiguration = flickrConfiguration; _flickrConfiguration = flickrConfiguration;
_flickrLanguage = flickrLanguage; _flickrLanguage = flickrLanguage;
@ -105,7 +106,9 @@ namespace Greenshot.Addon.Flickr
_oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings); _oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings);
_oAuthHttpBehaviour.ValidateResponseContentType = false; _oAuthHttpBehaviour.ValidateResponseContentType = false;
} // Use the default network settings
_oAuthHttpBehaviour.HttpSettings = networkConfiguration;
}
public override string Description => _flickrLanguage.UploadMenuItem; public override string Description => _flickrLanguage.UploadMenuItem;

View file

@ -56,13 +56,18 @@ namespace Greenshot.Addon.GooglePhotos
private static readonly LogSource Log = new LogSource(); private static readonly LogSource Log = new LogSource();
private readonly IGooglePhotosConfiguration _googlePhotosConfiguration; private readonly IGooglePhotosConfiguration _googlePhotosConfiguration;
private readonly IGooglePhotosLanguage _googlePhotosLanguage; private readonly IGooglePhotosLanguage _googlePhotosLanguage;
private readonly INetworkConfiguration _networkConfiguration;
private readonly OAuth2Settings _oAuth2Settings; private readonly OAuth2Settings _oAuth2Settings;
[ImportingConstructor] [ImportingConstructor]
public GooglePhotosDestination(IGooglePhotosConfiguration googlePhotosConfiguration, IGooglePhotosLanguage googlePhotosLanguage) public GooglePhotosDestination(
IGooglePhotosConfiguration googlePhotosConfiguration,
IGooglePhotosLanguage googlePhotosLanguage,
INetworkConfiguration networkConfiguration)
{ {
_googlePhotosConfiguration = googlePhotosConfiguration; _googlePhotosConfiguration = googlePhotosConfiguration;
_googlePhotosLanguage = googlePhotosLanguage; _googlePhotosLanguage = googlePhotosLanguage;
_networkConfiguration = networkConfiguration;
_oAuth2Settings = new OAuth2Settings _oAuth2Settings = new OAuth2Settings
{ {
@ -157,7 +162,7 @@ namespace Greenshot.Addon.GooglePhotos
string filename = surface.GenerateFilename(CoreConfiguration, _googlePhotosConfiguration); string filename = surface.GenerateFilename(CoreConfiguration, _googlePhotosConfiguration);
var oAuthHttpBehaviour = HttpBehaviour.Current.ShallowClone(); var oAuthHttpBehaviour = HttpBehaviour.Current.ShallowClone();
oAuthHttpBehaviour.HttpSettings = _networkConfiguration;
// Use UploadProgress // Use UploadProgress
if (progress != null) if (progress != null)
{ {

View file

@ -61,7 +61,10 @@ namespace Greenshot.Addon.Imgur
private HttpBehaviour Behaviour { get; } private HttpBehaviour Behaviour { get; }
[ImportingConstructor] [ImportingConstructor]
public ImgurApi(IImgurConfiguration imgurConfiguration, ICoreConfiguration coreConfiguration) public ImgurApi(
IImgurConfiguration imgurConfiguration,
ICoreConfiguration coreConfiguration,
INetworkConfiguration networkConfiguration)
{ {
_imgurConfiguration = imgurConfiguration; _imgurConfiguration = imgurConfiguration;
_coreConfiguration = coreConfiguration; _coreConfiguration = coreConfiguration;
@ -87,7 +90,8 @@ namespace Greenshot.Addon.Imgur
Behaviour = new HttpBehaviour Behaviour = new HttpBehaviour
{ {
JsonSerializer = new JsonNetJsonSerializer(), HttpSettings = networkConfiguration,
JsonSerializer = new JsonNetJsonSerializer(),
OnHttpClientCreated = httpClient => OnHttpClientCreated = httpClient =>
{ {
httpClient.SetAuthorization("Client-ID", _imgurConfiguration.ClientId); httpClient.SetAuthorization("Client-ID", _imgurConfiguration.ClientId);

View file

@ -65,13 +65,17 @@ namespace Greenshot.Addon.Jira
private DateTimeOffset _loggedInTime = DateTimeOffset.MinValue; private DateTimeOffset _loggedInTime = DateTimeOffset.MinValue;
[ImportingConstructor] [ImportingConstructor]
public JiraConnector(IJiraConfiguration jiraConfiguration, JiraMonitor jiraMonitor, ICoreConfiguration coreConfiguration) public JiraConnector(
IJiraConfiguration jiraConfiguration,
JiraMonitor jiraMonitor,
ICoreConfiguration coreConfiguration,
INetworkConfiguration networkConfiguration)
{ {
jiraConfiguration.Url = jiraConfiguration.Url.Replace(DefaultPostfix, ""); jiraConfiguration.Url = jiraConfiguration.Url.Replace(DefaultPostfix, "");
_jiraConfiguration = jiraConfiguration; _jiraConfiguration = jiraConfiguration;
_jiraMonitor = jiraMonitor; _jiraMonitor = jiraMonitor;
_coreConfiguration = coreConfiguration; _coreConfiguration = coreConfiguration;
_jiraClient = JiraClient.Create(new Uri(jiraConfiguration.Url)); _jiraClient = JiraClient.Create(new Uri(jiraConfiguration.Url), networkConfiguration);
} }
public Bitmap FavIcon { get; private set; } public Bitmap FavIcon { get; private set; }

View file

@ -1,165 +1,165 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom
* *
* For more information see: http://getgreenshot.org/ * For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or * the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dapplo.HttpExtensions; using Dapplo.HttpExtensions;
using Dapplo.Log; using Dapplo.Log;
using Greenshot.Addon.Lutim.Entities; using Greenshot.Addon.Lutim.Entities;
using Greenshot.Addons.Core; using Greenshot.Addons.Core;
using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces;
namespace Greenshot.Addon.Lutim namespace Greenshot.Addon.Lutim
{ {
/// <summary> /// <summary>
/// A collection of Lutim API methods /// A collection of Lutim API methods
/// </summary> /// </summary>
[Export] [Export]
public class LutimApi public class LutimApi
{ {
private static readonly LogSource Log = new LogSource(); private static readonly LogSource Log = new LogSource();
private readonly ILutimConfiguration _lutimConfiguration; private readonly ILutimConfiguration _lutimConfiguration;
private readonly ICoreConfiguration _coreConfiguration; private readonly ICoreConfiguration _coreConfiguration;
[ImportingConstructor] [ImportingConstructor]
public LutimApi(ILutimConfiguration lutimConfiguration, ICoreConfiguration coreConfiguration) public LutimApi(ILutimConfiguration lutimConfiguration, ICoreConfiguration coreConfiguration)
{ {
_lutimConfiguration = lutimConfiguration; _lutimConfiguration = lutimConfiguration;
_coreConfiguration = coreConfiguration; _coreConfiguration = coreConfiguration;
} }
/// <summary> /// <summary>
/// Check if we need to load the history /// Check if we need to load the history
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool IsHistoryLoadingNeeded() public bool IsHistoryLoadingNeeded()
{ {
Log.Info().WriteLine("Checking if lutim cache loading needed, configuration has {0} lutim hashes, loaded are {1} hashes.", _lutimConfiguration.LutimUploadHistory.Count, _lutimConfiguration.RuntimeLutimHistory.Count); Log.Info().WriteLine("Checking if lutim cache loading needed, configuration has {0} lutim hashes, loaded are {1} hashes.", _lutimConfiguration.LutimUploadHistory.Count, _lutimConfiguration.RuntimeLutimHistory.Count);
return _lutimConfiguration.RuntimeLutimHistory.Count != _lutimConfiguration.LutimUploadHistory.Count; return _lutimConfiguration.RuntimeLutimHistory.Count != _lutimConfiguration.LutimUploadHistory.Count;
} }
/// <summary> /// <summary>
/// Load the complete history of the lutim uploads, with the corresponding information /// Load the complete history of the lutim uploads, with the corresponding information
/// </summary> /// </summary>
public void LoadHistory() public void LoadHistory()
{ {
if (!IsHistoryLoadingNeeded()) if (!IsHistoryLoadingNeeded())
{ {
return; return;
} }
// Load the ImUr history // Load the ImUr history
foreach (string key in _lutimConfiguration.LutimUploadHistory.Keys.ToList()) foreach (string key in _lutimConfiguration.LutimUploadHistory.Keys.ToList())
{ {
if (_lutimConfiguration.RuntimeLutimHistory.ContainsKey(key)) if (_lutimConfiguration.RuntimeLutimHistory.ContainsKey(key))
{ {
// Already loaded // Already loaded
continue; continue;
} }
try try
{ {
var value = _lutimConfiguration.LutimUploadHistory[key]; var value = _lutimConfiguration.LutimUploadHistory[key];
// TODO: Read from something // TODO: Read from something
//LutimInfo lutimInfo = LutimInfo.FromIniString(key, value); //LutimInfo lutimInfo = LutimInfo.FromIniString(key, value);
// Config.RuntimeLutimHistory[key] = lutimInfo; // Config.RuntimeLutimHistory[key] = lutimInfo;
} }
catch (ArgumentException) catch (ArgumentException)
{ {
Log.Info().WriteLine("Bad format of lutim history item for short {0}", key); Log.Info().WriteLine("Bad format of lutim history item for short {0}", key);
_lutimConfiguration.LutimUploadHistory.Remove(key); _lutimConfiguration.LutimUploadHistory.Remove(key);
_lutimConfiguration.RuntimeLutimHistory.Remove(key); _lutimConfiguration.RuntimeLutimHistory.Remove(key);
} }
catch (Exception e) catch (Exception e)
{ {
Log.Error().WriteLine(e, "Problem loading lutim history for short " + key); Log.Error().WriteLine(e, "Problem loading lutim history for short " + key);
} }
} }
} }
/// <summary> /// <summary>
/// Do the actual upload to Lutim /// Do the actual upload to Lutim
/// For more details on the available parameters, see: http://api.lutim.com/resources_anon /// For more details on the available parameters, see: http://api.lutim.com/resources_anon
/// </summary> /// </summary>
/// <param name="surfaceToUpload">ISurface to upload</param> /// <param name="surfaceToUpload">ISurface to upload</param>
/// <returns>LutimInfo with details</returns> /// <returns>LutimInfo with details</returns>
public async Task<LutimInfo> UploadToLutim(ISurface surfaceToUpload) public async Task<LutimInfo> UploadToLutim(ISurface surfaceToUpload)
{ {
var baseUrl = new Uri(_lutimConfiguration.LutimUrl); var baseUrl = new Uri(_lutimConfiguration.LutimUrl);
// TODO: Upload // TODO: Upload
var result = await baseUrl.PostAsync<AddResult>(""); var result = await baseUrl.PostAsync<AddResult>("");
return result.LutimInfo; return result.LutimInfo;
} }
/// <summary> /// <summary>
/// Delete an lutim image, this is done by specifying the delete hash /// Delete an lutim image, this is done by specifying the delete hash
/// </summary> /// </summary>
/// <param name="lutimInfo"></param> /// <param name="lutimInfo"></param>
public async Task DeleteLutimImage(AddResult lutimInfo) public async Task DeleteLutimImage(AddResult lutimInfo)
{ {
Log.Info().WriteLine("Deleting Lutim image for {0}", lutimInfo.LutimInfo.Short); Log.Info().WriteLine("Deleting Lutim image for {0}", lutimInfo.LutimInfo.Short);
var lutimBaseUri = new Uri(_lutimConfiguration.LutimUrl); var lutimBaseUri = new Uri(_lutimConfiguration.LutimUrl);
var deleteUri = lutimBaseUri.AppendSegments("d", lutimInfo.LutimInfo.RealShort, lutimInfo.LutimInfo.Token).ExtendQuery("format", "json"); var deleteUri = lutimBaseUri.AppendSegments("d", lutimInfo.LutimInfo.RealShort, lutimInfo.LutimInfo.Token).ExtendQuery("format", "json");
var httpResponse = await deleteUri.GetAsAsync<HttpResponse<string, string>>(); var httpResponse = await deleteUri.GetAsAsync<HttpResponse<string, string>>();
if (httpResponse.StatusCode != HttpStatusCode.BadRequest) if (httpResponse.StatusCode != HttpStatusCode.BadRequest)
{ {
throw new Exception(httpResponse.ErrorResponse); throw new Exception(httpResponse.ErrorResponse);
} }
Log.Info().WriteLine("Delete result: {0}", httpResponse.Response); Log.Info().WriteLine("Delete result: {0}", httpResponse.Response);
// Make sure we remove it from the history, if no error occured // Make sure we remove it from the history, if no error occured
_lutimConfiguration.RuntimeLutimHistory.Remove(lutimInfo.LutimInfo.Short); _lutimConfiguration.RuntimeLutimHistory.Remove(lutimInfo.LutimInfo.Short);
_lutimConfiguration.LutimUploadHistory.Remove(lutimInfo.LutimInfo.Short); _lutimConfiguration.LutimUploadHistory.Remove(lutimInfo.LutimInfo.Short);
} }
/// <summary> /// <summary>
/// Helper for logging /// Helper for logging
/// </summary> /// </summary>
/// <param name="nameValues"></param> /// <param name="nameValues"></param>
/// <param name="key"></param> /// <param name="key"></param>
private void LogHeader(IDictionary<string, string> nameValues, string key) private void LogHeader(IDictionary<string, string> nameValues, string key)
{ {
if (nameValues.ContainsKey(key)) if (nameValues.ContainsKey(key))
{ {
Log.Info().WriteLine("{0}={1}", key, nameValues[key]); Log.Info().WriteLine("{0}={1}", key, nameValues[key]);
} }
} }
public Task<LutimInfo> RetrieveLutimInfoAsync(string hash, string s, CancellationToken cancellationToken) public Task<LutimInfo> RetrieveLutimInfoAsync(string hash, string s, CancellationToken cancellationToken)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task RetrieveLutimThumbnailAsync(LutimInfo lutimInfo, CancellationToken cancellationToken) public Task RetrieveLutimThumbnailAsync(LutimInfo lutimInfo, CancellationToken cancellationToken)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
} }

View file

@ -66,13 +66,13 @@ namespace Greenshot.Addon.OneDrive
private static readonly Uri OneDriveUri = GraphUri.AppendSegments("v1.0", "me", "drive"); private static readonly Uri OneDriveUri = GraphUri.AppendSegments("v1.0", "me", "drive");
private static readonly Uri OAuth2Uri = new Uri("https://login.microsoftonline.com").AppendSegments("common", "oauth2", "v2.0"); private static readonly Uri OAuth2Uri = new Uri("https://login.microsoftonline.com").AppendSegments("common", "oauth2", "v2.0");
private static readonly HttpBehaviour OneDriveHttpBehaviour = new HttpBehaviour private readonly HttpBehaviour _oneDriveHttpBehaviour;
{
JsonSerializer = new JsonNetJsonSerializer()
};
[ImportingConstructor] [ImportingConstructor]
public OneDriveDestination(IOneDriveConfiguration oneDriveConfiguration, IOneDriveLanguage oneDriveLanguage) public OneDriveDestination(
IOneDriveConfiguration oneDriveConfiguration,
IOneDriveLanguage oneDriveLanguage,
INetworkConfiguration networkConfiguration)
{ {
_oneDriveConfiguration = oneDriveConfiguration; _oneDriveConfiguration = oneDriveConfiguration;
_oneDriveLanguage = oneDriveLanguage; _oneDriveLanguage = oneDriveLanguage;
@ -96,6 +96,11 @@ namespace Greenshot.Addon.OneDrive
AuthorizeMode = AuthorizeModes.EmbeddedBrowser, AuthorizeMode = AuthorizeModes.EmbeddedBrowser,
Token = oneDriveConfiguration Token = oneDriveConfiguration
}; };
_oneDriveHttpBehaviour = new HttpBehaviour
{
HttpSettings = networkConfiguration,
JsonSerializer = new JsonNetJsonSerializer()
};
} }
public override string Description => _oneDriveLanguage.UploadMenuItem; public override string Description => _oneDriveLanguage.UploadMenuItem;
@ -196,7 +201,7 @@ namespace Greenshot.Addon.OneDrive
{ {
var filename = surfaceToUpload.GenerateFilename(CoreConfiguration, _oneDriveConfiguration); var filename = surfaceToUpload.GenerateFilename(CoreConfiguration, _oneDriveConfiguration);
var uploadUri = OneDriveUri.AppendSegments("root:", "Screenshots", filename + ":", "content"); var uploadUri = OneDriveUri.AppendSegments("root:", "Screenshots", filename + ":", "content");
var localBehaviour = OneDriveHttpBehaviour.ShallowClone(); var localBehaviour = _oneDriveHttpBehaviour.ShallowClone();
if (progress != null) if (progress != null)
{ {
localBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100)), token); }; localBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100)), token); };
@ -219,7 +224,7 @@ namespace Greenshot.Addon.OneDrive
string imageId, OneDriveLinkType oneDriveLinkType) string imageId, OneDriveLinkType oneDriveLinkType)
{ {
var sharableLink = OneDriveUri.AppendSegments("items", imageId, "createLink"); var sharableLink = OneDriveUri.AppendSegments("items", imageId, "createLink");
var localBehaviour = OneDriveHttpBehaviour.ShallowClone(); var localBehaviour = _oneDriveHttpBehaviour.ShallowClone();
var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour); var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);
oauthHttpBehaviour.MakeCurrent(); oauthHttpBehaviour.MakeCurrent();
var body = new OneDriveGetLinkRequest(); var body = new OneDriveGetLinkRequest();

View file

@ -43,7 +43,6 @@ using Greenshot.Addons.Addons;
using Greenshot.Addons.Core; using Greenshot.Addons.Core;
using Greenshot.Addons.Extensions; using Greenshot.Addons.Extensions;
using Greenshot.Addons.Interfaces; using Greenshot.Addons.Interfaces;
using Greenshot.Addons.Interfaces.Plugin;
using Greenshot.Gfx; using Greenshot.Gfx;
#endregion #endregion
@ -61,6 +60,7 @@ namespace Greenshot.Addon.Photobucket
private readonly string _albumPath; private readonly string _albumPath;
private readonly IPhotobucketConfiguration _photobucketConfiguration; private readonly IPhotobucketConfiguration _photobucketConfiguration;
private readonly IPhotobucketLanguage _photobucketLanguage; private readonly IPhotobucketLanguage _photobucketLanguage;
private readonly INetworkConfiguration _networkConfiguration;
private readonly OAuth1Settings _oAuthSettings; private readonly OAuth1Settings _oAuthSettings;
private readonly OAuth1HttpBehaviour _oAuthHttpBehaviour; private readonly OAuth1HttpBehaviour _oAuthHttpBehaviour;
private IList<string> _albumsCache; private IList<string> _albumsCache;
@ -71,12 +71,16 @@ namespace Greenshot.Addon.Photobucket
/// <param name="photobucketConfiguration">IPhotobucketConfiguration</param> /// <param name="photobucketConfiguration">IPhotobucketConfiguration</param>
/// <param name="photobucketLanguage">IPhotobucketLanguage</param> /// <param name="photobucketLanguage">IPhotobucketLanguage</param>
[ImportingConstructor] [ImportingConstructor]
public PhotobucketDestination(IPhotobucketConfiguration photobucketConfiguration, IPhotobucketLanguage photobucketLanguage) public PhotobucketDestination(
IPhotobucketConfiguration photobucketConfiguration,
IPhotobucketLanguage photobucketLanguage,
INetworkConfiguration networkConfiguration)
{ {
_photobucketConfiguration = photobucketConfiguration; _photobucketConfiguration = photobucketConfiguration;
_photobucketLanguage = photobucketLanguage; _photobucketLanguage = photobucketLanguage;
_networkConfiguration = networkConfiguration;
_oAuthSettings = new OAuth1Settings _oAuthSettings = new OAuth1Settings
{ {
Token = photobucketConfiguration, Token = photobucketConfiguration,
ClientId = photobucketConfiguration.ClientId, ClientId = photobucketConfiguration.ClientId,
@ -99,6 +103,7 @@ namespace Greenshot.Addon.Photobucket
CheckVerifier = false CheckVerifier = false
}; };
var oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings); var oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings);
oAuthHttpBehaviour.HttpSettings = networkConfiguration;
// Store the leftover values // Store the leftover values
oAuthHttpBehaviour.OnAccessTokenValues = values => oAuthHttpBehaviour.OnAccessTokenValues = values =>
{ {
@ -140,7 +145,7 @@ namespace Greenshot.Addon.Photobucket
/// <param name="photobucketConfiguration">IPhotobucketConfiguration</param> /// <param name="photobucketConfiguration">IPhotobucketConfiguration</param>
/// <param name="photobucketLanguage">IPhotobucketLanguage</param> /// <param name="photobucketLanguage">IPhotobucketLanguage</param>
/// <param name="albumPath">path to the album, null for default</param> /// <param name="albumPath">path to the album, null for default</param>
public PhotobucketDestination(IPhotobucketConfiguration photobucketConfiguration, IPhotobucketLanguage photobucketLanguage, string albumPath) : this (photobucketConfiguration, photobucketLanguage) public PhotobucketDestination(IPhotobucketConfiguration photobucketConfiguration, IPhotobucketLanguage photobucketLanguage, INetworkConfiguration networkConfiguration, string albumPath) : this (photobucketConfiguration, photobucketLanguage, networkConfiguration)
{ {
_photobucketConfiguration = photobucketConfiguration; _photobucketConfiguration = photobucketConfiguration;
_albumPath = albumPath; _albumPath = albumPath;
@ -193,7 +198,7 @@ namespace Greenshot.Addon.Photobucket
} }
foreach (var album in albums) foreach (var album in albums)
{ {
yield return new PhotobucketDestination(_photobucketConfiguration, _photobucketLanguage, album); yield return new PhotobucketDestination(_photobucketConfiguration, _photobucketLanguage, _networkConfiguration, album);
} }
} }

View file

@ -23,16 +23,10 @@
#region Usings #region Usings
using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing;
using Dapplo.HttpExtensions; using Dapplo.HttpExtensions;
using Dapplo.Ini; using Dapplo.Ini;
using Dapplo.InterfaceImpl.Extensions; using Dapplo.InterfaceImpl.Extensions;
using Dapplo.Windows.Common.Structs;
using Greenshot.Addons.Core.Enums;
using Greenshot.Addons.Interfaces;
#endregion #endregion