mirror of
https://github.com/greenshot/greenshot
synced 2025-08-26 08:06:09 -07:00
Starting using the IHttpSettings which are configurable.
This commit is contained in:
parent
1c805aea7f
commit
540eb7cb19
10 changed files with 228 additions and 194 deletions
|
@ -57,15 +57,20 @@ namespace Greenshot.Addon.Box
|
|||
private static readonly LogSource Log = new LogSource();
|
||||
private readonly IBoxConfiguration _boxConfiguration;
|
||||
private readonly IBoxLanguage _boxLanguage;
|
||||
private readonly INetworkConfiguration _networkConfiguration;
|
||||
private readonly OAuth2Settings _oauth2Settings;
|
||||
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/");
|
||||
|
||||
[ImportingConstructor]
|
||||
public BoxDestination(IBoxConfiguration boxConfiguration, IBoxLanguage boxLanguage)
|
||||
public BoxDestination(
|
||||
IBoxConfiguration boxConfiguration,
|
||||
IBoxLanguage boxLanguage,
|
||||
INetworkConfiguration networkConfiguration)
|
||||
{
|
||||
_boxConfiguration = boxConfiguration;
|
||||
_boxLanguage = boxLanguage;
|
||||
_networkConfiguration = networkConfiguration;
|
||||
|
||||
_oauth2Settings = new OAuth2Settings
|
||||
{
|
||||
|
@ -166,6 +171,8 @@ namespace Greenshot.Addon.Box
|
|||
string filename = surface.GenerateFilename(CoreConfiguration, _boxConfiguration);
|
||||
|
||||
var oauthHttpBehaviour = HttpBehaviour.Current.ShallowClone();
|
||||
// Use the network settings
|
||||
oauthHttpBehaviour.HttpSettings = _networkConfiguration;
|
||||
// Use UploadProgress
|
||||
if (progress != null)
|
||||
{
|
||||
|
|
|
@ -65,7 +65,10 @@ namespace Greenshot.Addon.Dropbox
|
|||
private IHttpBehaviour _oAuthHttpBehaviour;
|
||||
|
||||
[ImportingConstructor]
|
||||
public DropboxDestination(IDropboxConfiguration dropboxPluginConfiguration, IDropboxLanguage dropboxLanguage)
|
||||
public DropboxDestination(
|
||||
IDropboxConfiguration dropboxPluginConfiguration,
|
||||
IDropboxLanguage dropboxLanguage,
|
||||
INetworkConfiguration networkConfiguration)
|
||||
{
|
||||
_dropboxPluginConfiguration = dropboxPluginConfiguration;
|
||||
_dropboxLanguage = dropboxLanguage;
|
||||
|
@ -89,10 +92,14 @@ namespace Greenshot.Addon.Dropbox
|
|||
RedirectUrl = "http://localhost:47336",
|
||||
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
|
||||
{
|
||||
|
|
|
@ -76,7 +76,8 @@ namespace Greenshot.Addon.Flickr
|
|||
});
|
||||
|
||||
[ImportingConstructor]
|
||||
public FlickrDestination(IFlickrConfiguration flickrConfiguration, IFlickrLanguage flickrLanguage)
|
||||
public FlickrDestination(IFlickrConfiguration flickrConfiguration,
|
||||
IFlickrLanguage flickrLanguage, INetworkConfiguration networkConfiguration)
|
||||
{
|
||||
_flickrConfiguration = flickrConfiguration;
|
||||
_flickrLanguage = flickrLanguage;
|
||||
|
@ -105,7 +106,9 @@ namespace Greenshot.Addon.Flickr
|
|||
|
||||
_oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings);
|
||||
_oAuthHttpBehaviour.ValidateResponseContentType = false;
|
||||
}
|
||||
// Use the default network settings
|
||||
_oAuthHttpBehaviour.HttpSettings = networkConfiguration;
|
||||
}
|
||||
|
||||
public override string Description => _flickrLanguage.UploadMenuItem;
|
||||
|
||||
|
|
|
@ -56,13 +56,18 @@ namespace Greenshot.Addon.GooglePhotos
|
|||
private static readonly LogSource Log = new LogSource();
|
||||
private readonly IGooglePhotosConfiguration _googlePhotosConfiguration;
|
||||
private readonly IGooglePhotosLanguage _googlePhotosLanguage;
|
||||
private readonly INetworkConfiguration _networkConfiguration;
|
||||
private readonly OAuth2Settings _oAuth2Settings;
|
||||
|
||||
[ImportingConstructor]
|
||||
public GooglePhotosDestination(IGooglePhotosConfiguration googlePhotosConfiguration, IGooglePhotosLanguage googlePhotosLanguage)
|
||||
public GooglePhotosDestination(
|
||||
IGooglePhotosConfiguration googlePhotosConfiguration,
|
||||
IGooglePhotosLanguage googlePhotosLanguage,
|
||||
INetworkConfiguration networkConfiguration)
|
||||
{
|
||||
_googlePhotosConfiguration = googlePhotosConfiguration;
|
||||
_googlePhotosLanguage = googlePhotosLanguage;
|
||||
_networkConfiguration = networkConfiguration;
|
||||
|
||||
_oAuth2Settings = new OAuth2Settings
|
||||
{
|
||||
|
@ -157,7 +162,7 @@ namespace Greenshot.Addon.GooglePhotos
|
|||
string filename = surface.GenerateFilename(CoreConfiguration, _googlePhotosConfiguration);
|
||||
|
||||
var oAuthHttpBehaviour = HttpBehaviour.Current.ShallowClone();
|
||||
|
||||
oAuthHttpBehaviour.HttpSettings = _networkConfiguration;
|
||||
// Use UploadProgress
|
||||
if (progress != null)
|
||||
{
|
||||
|
|
|
@ -61,7 +61,10 @@ namespace Greenshot.Addon.Imgur
|
|||
private HttpBehaviour Behaviour { get; }
|
||||
|
||||
[ImportingConstructor]
|
||||
public ImgurApi(IImgurConfiguration imgurConfiguration, ICoreConfiguration coreConfiguration)
|
||||
public ImgurApi(
|
||||
IImgurConfiguration imgurConfiguration,
|
||||
ICoreConfiguration coreConfiguration,
|
||||
INetworkConfiguration networkConfiguration)
|
||||
{
|
||||
_imgurConfiguration = imgurConfiguration;
|
||||
_coreConfiguration = coreConfiguration;
|
||||
|
@ -87,7 +90,8 @@ namespace Greenshot.Addon.Imgur
|
|||
|
||||
Behaviour = new HttpBehaviour
|
||||
{
|
||||
JsonSerializer = new JsonNetJsonSerializer(),
|
||||
HttpSettings = networkConfiguration,
|
||||
JsonSerializer = new JsonNetJsonSerializer(),
|
||||
OnHttpClientCreated = httpClient =>
|
||||
{
|
||||
httpClient.SetAuthorization("Client-ID", _imgurConfiguration.ClientId);
|
||||
|
|
|
@ -65,13 +65,17 @@ namespace Greenshot.Addon.Jira
|
|||
private DateTimeOffset _loggedInTime = DateTimeOffset.MinValue;
|
||||
|
||||
[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 = jiraConfiguration;
|
||||
_jiraMonitor = jiraMonitor;
|
||||
_coreConfiguration = coreConfiguration;
|
||||
_jiraClient = JiraClient.Create(new Uri(jiraConfiguration.Url));
|
||||
_jiraClient = JiraClient.Create(new Uri(jiraConfiguration.Url), networkConfiguration);
|
||||
}
|
||||
|
||||
public Bitmap FavIcon { get; private set; }
|
||||
|
|
|
@ -1,165 +1,165 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Dapplo.HttpExtensions;
|
||||
using Dapplo.Log;
|
||||
using Greenshot.Addon.Lutim.Entities;
|
||||
using Greenshot.Addons.Core;
|
||||
using Greenshot.Addons.Interfaces;
|
||||
|
||||
namespace Greenshot.Addon.Lutim
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of Lutim API methods
|
||||
/// </summary>
|
||||
[Export]
|
||||
public class LutimApi
|
||||
{
|
||||
private static readonly LogSource Log = new LogSource();
|
||||
private readonly ILutimConfiguration _lutimConfiguration;
|
||||
private readonly ICoreConfiguration _coreConfiguration;
|
||||
|
||||
[ImportingConstructor]
|
||||
public LutimApi(ILutimConfiguration lutimConfiguration, ICoreConfiguration coreConfiguration)
|
||||
{
|
||||
_lutimConfiguration = lutimConfiguration;
|
||||
_coreConfiguration = coreConfiguration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if we need to load the history
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
return _lutimConfiguration.RuntimeLutimHistory.Count != _lutimConfiguration.LutimUploadHistory.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the complete history of the lutim uploads, with the corresponding information
|
||||
/// </summary>
|
||||
public void LoadHistory()
|
||||
{
|
||||
if (!IsHistoryLoadingNeeded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the ImUr history
|
||||
foreach (string key in _lutimConfiguration.LutimUploadHistory.Keys.ToList())
|
||||
{
|
||||
if (_lutimConfiguration.RuntimeLutimHistory.ContainsKey(key))
|
||||
{
|
||||
// Already loaded
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var value = _lutimConfiguration.LutimUploadHistory[key];
|
||||
// TODO: Read from something
|
||||
//LutimInfo lutimInfo = LutimInfo.FromIniString(key, value);
|
||||
// Config.RuntimeLutimHistory[key] = lutimInfo;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Log.Info().WriteLine("Bad format of lutim history item for short {0}", key);
|
||||
_lutimConfiguration.LutimUploadHistory.Remove(key);
|
||||
_lutimConfiguration.RuntimeLutimHistory.Remove(key);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error().WriteLine(e, "Problem loading lutim history for short " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do the actual upload to Lutim
|
||||
/// For more details on the available parameters, see: http://api.lutim.com/resources_anon
|
||||
/// </summary>
|
||||
/// <param name="surfaceToUpload">ISurface to upload</param>
|
||||
/// <returns>LutimInfo with details</returns>
|
||||
public async Task<LutimInfo> UploadToLutim(ISurface surfaceToUpload)
|
||||
{
|
||||
var baseUrl = new Uri(_lutimConfiguration.LutimUrl);
|
||||
|
||||
// TODO: Upload
|
||||
var result = await baseUrl.PostAsync<AddResult>("");
|
||||
return result.LutimInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete an lutim image, this is done by specifying the delete hash
|
||||
/// </summary>
|
||||
/// <param name="lutimInfo"></param>
|
||||
public async Task DeleteLutimImage(AddResult lutimInfo)
|
||||
{
|
||||
Log.Info().WriteLine("Deleting Lutim image for {0}", lutimInfo.LutimInfo.Short);
|
||||
|
||||
var lutimBaseUri = new Uri(_lutimConfiguration.LutimUrl);
|
||||
var deleteUri = lutimBaseUri.AppendSegments("d", lutimInfo.LutimInfo.RealShort, lutimInfo.LutimInfo.Token).ExtendQuery("format", "json");
|
||||
|
||||
var httpResponse = await deleteUri.GetAsAsync<HttpResponse<string, string>>();
|
||||
|
||||
if (httpResponse.StatusCode != HttpStatusCode.BadRequest)
|
||||
{
|
||||
throw new Exception(httpResponse.ErrorResponse);
|
||||
}
|
||||
|
||||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2018 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Dapplo.HttpExtensions;
|
||||
using Dapplo.Log;
|
||||
using Greenshot.Addon.Lutim.Entities;
|
||||
using Greenshot.Addons.Core;
|
||||
using Greenshot.Addons.Interfaces;
|
||||
|
||||
namespace Greenshot.Addon.Lutim
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection of Lutim API methods
|
||||
/// </summary>
|
||||
[Export]
|
||||
public class LutimApi
|
||||
{
|
||||
private static readonly LogSource Log = new LogSource();
|
||||
private readonly ILutimConfiguration _lutimConfiguration;
|
||||
private readonly ICoreConfiguration _coreConfiguration;
|
||||
|
||||
[ImportingConstructor]
|
||||
public LutimApi(ILutimConfiguration lutimConfiguration, ICoreConfiguration coreConfiguration)
|
||||
{
|
||||
_lutimConfiguration = lutimConfiguration;
|
||||
_coreConfiguration = coreConfiguration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if we need to load the history
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
return _lutimConfiguration.RuntimeLutimHistory.Count != _lutimConfiguration.LutimUploadHistory.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the complete history of the lutim uploads, with the corresponding information
|
||||
/// </summary>
|
||||
public void LoadHistory()
|
||||
{
|
||||
if (!IsHistoryLoadingNeeded())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the ImUr history
|
||||
foreach (string key in _lutimConfiguration.LutimUploadHistory.Keys.ToList())
|
||||
{
|
||||
if (_lutimConfiguration.RuntimeLutimHistory.ContainsKey(key))
|
||||
{
|
||||
// Already loaded
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var value = _lutimConfiguration.LutimUploadHistory[key];
|
||||
// TODO: Read from something
|
||||
//LutimInfo lutimInfo = LutimInfo.FromIniString(key, value);
|
||||
// Config.RuntimeLutimHistory[key] = lutimInfo;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Log.Info().WriteLine("Bad format of lutim history item for short {0}", key);
|
||||
_lutimConfiguration.LutimUploadHistory.Remove(key);
|
||||
_lutimConfiguration.RuntimeLutimHistory.Remove(key);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error().WriteLine(e, "Problem loading lutim history for short " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do the actual upload to Lutim
|
||||
/// For more details on the available parameters, see: http://api.lutim.com/resources_anon
|
||||
/// </summary>
|
||||
/// <param name="surfaceToUpload">ISurface to upload</param>
|
||||
/// <returns>LutimInfo with details</returns>
|
||||
public async Task<LutimInfo> UploadToLutim(ISurface surfaceToUpload)
|
||||
{
|
||||
var baseUrl = new Uri(_lutimConfiguration.LutimUrl);
|
||||
|
||||
// TODO: Upload
|
||||
var result = await baseUrl.PostAsync<AddResult>("");
|
||||
return result.LutimInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete an lutim image, this is done by specifying the delete hash
|
||||
/// </summary>
|
||||
/// <param name="lutimInfo"></param>
|
||||
public async Task DeleteLutimImage(AddResult lutimInfo)
|
||||
{
|
||||
Log.Info().WriteLine("Deleting Lutim image for {0}", lutimInfo.LutimInfo.Short);
|
||||
|
||||
var lutimBaseUri = new Uri(_lutimConfiguration.LutimUrl);
|
||||
var deleteUri = lutimBaseUri.AppendSegments("d", lutimInfo.LutimInfo.RealShort, lutimInfo.LutimInfo.Token).ExtendQuery("format", "json");
|
||||
|
||||
var httpResponse = await deleteUri.GetAsAsync<HttpResponse<string, string>>();
|
||||
|
||||
if (httpResponse.StatusCode != HttpStatusCode.BadRequest)
|
||||
{
|
||||
throw new Exception(httpResponse.ErrorResponse);
|
||||
}
|
||||
|
||||
Log.Info().WriteLine("Delete result: {0}", httpResponse.Response);
|
||||
// Make sure we remove it from the history, if no error occured
|
||||
_lutimConfiguration.RuntimeLutimHistory.Remove(lutimInfo.LutimInfo.Short);
|
||||
_lutimConfiguration.LutimUploadHistory.Remove(lutimInfo.LutimInfo.Short);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper for logging
|
||||
/// </summary>
|
||||
/// <param name="nameValues"></param>
|
||||
/// <param name="key"></param>
|
||||
private void LogHeader(IDictionary<string, string> nameValues, string key)
|
||||
{
|
||||
if (nameValues.ContainsKey(key))
|
||||
{
|
||||
Log.Info().WriteLine("{0}={1}", key, nameValues[key]);
|
||||
}
|
||||
}
|
||||
|
||||
public Task<LutimInfo> RetrieveLutimInfoAsync(string hash, string s, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task RetrieveLutimThumbnailAsync(LutimInfo lutimInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Make sure we remove it from the history, if no error occured
|
||||
_lutimConfiguration.RuntimeLutimHistory.Remove(lutimInfo.LutimInfo.Short);
|
||||
_lutimConfiguration.LutimUploadHistory.Remove(lutimInfo.LutimInfo.Short);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper for logging
|
||||
/// </summary>
|
||||
/// <param name="nameValues"></param>
|
||||
/// <param name="key"></param>
|
||||
private void LogHeader(IDictionary<string, string> nameValues, string key)
|
||||
{
|
||||
if (nameValues.ContainsKey(key))
|
||||
{
|
||||
Log.Info().WriteLine("{0}={1}", key, nameValues[key]);
|
||||
}
|
||||
}
|
||||
|
||||
public Task<LutimInfo> RetrieveLutimInfoAsync(string hash, string s, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task RetrieveLutimThumbnailAsync(LutimInfo lutimInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,13 +66,13 @@ namespace Greenshot.Addon.OneDrive
|
|||
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 HttpBehaviour OneDriveHttpBehaviour = new HttpBehaviour
|
||||
{
|
||||
JsonSerializer = new JsonNetJsonSerializer()
|
||||
};
|
||||
private readonly HttpBehaviour _oneDriveHttpBehaviour;
|
||||
|
||||
[ImportingConstructor]
|
||||
public OneDriveDestination(IOneDriveConfiguration oneDriveConfiguration, IOneDriveLanguage oneDriveLanguage)
|
||||
public OneDriveDestination(
|
||||
IOneDriveConfiguration oneDriveConfiguration,
|
||||
IOneDriveLanguage oneDriveLanguage,
|
||||
INetworkConfiguration networkConfiguration)
|
||||
{
|
||||
_oneDriveConfiguration = oneDriveConfiguration;
|
||||
_oneDriveLanguage = oneDriveLanguage;
|
||||
|
@ -96,6 +96,11 @@ namespace Greenshot.Addon.OneDrive
|
|||
AuthorizeMode = AuthorizeModes.EmbeddedBrowser,
|
||||
Token = oneDriveConfiguration
|
||||
};
|
||||
_oneDriveHttpBehaviour = new HttpBehaviour
|
||||
{
|
||||
HttpSettings = networkConfiguration,
|
||||
JsonSerializer = new JsonNetJsonSerializer()
|
||||
};
|
||||
}
|
||||
|
||||
public override string Description => _oneDriveLanguage.UploadMenuItem;
|
||||
|
@ -196,7 +201,7 @@ namespace Greenshot.Addon.OneDrive
|
|||
{
|
||||
var filename = surfaceToUpload.GenerateFilename(CoreConfiguration, _oneDriveConfiguration);
|
||||
var uploadUri = OneDriveUri.AppendSegments("root:", "Screenshots", filename + ":", "content");
|
||||
var localBehaviour = OneDriveHttpBehaviour.ShallowClone();
|
||||
var localBehaviour = _oneDriveHttpBehaviour.ShallowClone();
|
||||
if (progress != null)
|
||||
{
|
||||
localBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100)), token); };
|
||||
|
@ -219,7 +224,7 @@ namespace Greenshot.Addon.OneDrive
|
|||
string imageId, OneDriveLinkType oneDriveLinkType)
|
||||
{
|
||||
var sharableLink = OneDriveUri.AppendSegments("items", imageId, "createLink");
|
||||
var localBehaviour = OneDriveHttpBehaviour.ShallowClone();
|
||||
var localBehaviour = _oneDriveHttpBehaviour.ShallowClone();
|
||||
var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);
|
||||
oauthHttpBehaviour.MakeCurrent();
|
||||
var body = new OneDriveGetLinkRequest();
|
||||
|
|
|
@ -43,7 +43,6 @@ using Greenshot.Addons.Addons;
|
|||
using Greenshot.Addons.Core;
|
||||
using Greenshot.Addons.Extensions;
|
||||
using Greenshot.Addons.Interfaces;
|
||||
using Greenshot.Addons.Interfaces.Plugin;
|
||||
using Greenshot.Gfx;
|
||||
|
||||
#endregion
|
||||
|
@ -61,6 +60,7 @@ namespace Greenshot.Addon.Photobucket
|
|||
private readonly string _albumPath;
|
||||
private readonly IPhotobucketConfiguration _photobucketConfiguration;
|
||||
private readonly IPhotobucketLanguage _photobucketLanguage;
|
||||
private readonly INetworkConfiguration _networkConfiguration;
|
||||
private readonly OAuth1Settings _oAuthSettings;
|
||||
private readonly OAuth1HttpBehaviour _oAuthHttpBehaviour;
|
||||
private IList<string> _albumsCache;
|
||||
|
@ -71,12 +71,16 @@ namespace Greenshot.Addon.Photobucket
|
|||
/// <param name="photobucketConfiguration">IPhotobucketConfiguration</param>
|
||||
/// <param name="photobucketLanguage">IPhotobucketLanguage</param>
|
||||
[ImportingConstructor]
|
||||
public PhotobucketDestination(IPhotobucketConfiguration photobucketConfiguration, IPhotobucketLanguage photobucketLanguage)
|
||||
public PhotobucketDestination(
|
||||
IPhotobucketConfiguration photobucketConfiguration,
|
||||
IPhotobucketLanguage photobucketLanguage,
|
||||
INetworkConfiguration networkConfiguration)
|
||||
{
|
||||
_photobucketConfiguration = photobucketConfiguration;
|
||||
_photobucketLanguage = photobucketLanguage;
|
||||
_networkConfiguration = networkConfiguration;
|
||||
|
||||
_oAuthSettings = new OAuth1Settings
|
||||
_oAuthSettings = new OAuth1Settings
|
||||
{
|
||||
Token = photobucketConfiguration,
|
||||
ClientId = photobucketConfiguration.ClientId,
|
||||
|
@ -99,6 +103,7 @@ namespace Greenshot.Addon.Photobucket
|
|||
CheckVerifier = false
|
||||
};
|
||||
var oAuthHttpBehaviour = OAuth1HttpBehaviourFactory.Create(_oAuthSettings);
|
||||
oAuthHttpBehaviour.HttpSettings = networkConfiguration;
|
||||
// Store the leftover values
|
||||
oAuthHttpBehaviour.OnAccessTokenValues = values =>
|
||||
{
|
||||
|
@ -140,7 +145,7 @@ namespace Greenshot.Addon.Photobucket
|
|||
/// <param name="photobucketConfiguration">IPhotobucketConfiguration</param>
|
||||
/// <param name="photobucketLanguage">IPhotobucketLanguage</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;
|
||||
_albumPath = albumPath;
|
||||
|
@ -193,7 +198,7 @@ namespace Greenshot.Addon.Photobucket
|
|||
}
|
||||
foreach (var album in albums)
|
||||
{
|
||||
yield return new PhotobucketDestination(_photobucketConfiguration, _photobucketLanguage, album);
|
||||
yield return new PhotobucketDestination(_photobucketConfiguration, _photobucketLanguage, _networkConfiguration, album);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,16 +23,10 @@
|
|||
|
||||
#region Usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using Dapplo.HttpExtensions;
|
||||
using Dapplo.Ini;
|
||||
using Dapplo.InterfaceImpl.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Addons.Core.Enums;
|
||||
using Greenshot.Addons.Interfaces;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue