Updated the jira code, in the hope to solve BUG-2122

This commit is contained in:
Robin 2017-01-24 21:59:53 +01:00
parent 5bdfcd5306
commit e08985fd6f
5 changed files with 45 additions and 45 deletions

View file

@ -34,16 +34,16 @@
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="Dapplo.HttpExtensions, Version=0.6.10.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.HttpExtensions.0.6.10\lib\net45\Dapplo.HttpExtensions.dll</HintPath>
<Reference Include="Dapplo.HttpExtensions, Version=0.6.17.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.HttpExtensions.0.6.17\lib\net45\Dapplo.HttpExtensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Jira, Version=0.3.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Jira.0.3.4\lib\net45\Dapplo.Jira.dll</HintPath>
<Reference Include="Dapplo.Jira, Version=0.5.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Jira.0.5.8\lib\net45\Dapplo.Jira.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Log, Version=1.0.22.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Log.1.0.22\lib\net45\Dapplo.Log.dll</HintPath>
<Reference Include="Dapplo.Log, Version=1.0.23.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Log.1.0.23\lib\net45\Dapplo.Log.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net">

View file

@ -33,11 +33,11 @@ namespace GreenshotJiraPlugin
/// </summary>
public class IssueTypeBitmapCache : AsyncMemoryCache<IssueType, Bitmap>
{
private readonly JiraApi _jiraApi;
private readonly IJiraClient _jiraClient;
public IssueTypeBitmapCache(JiraApi jiraApi)
public IssueTypeBitmapCache(IJiraClient jiraClient)
{
_jiraApi = jiraApi;
_jiraClient = jiraClient;
// Set the expire timeout to an hour
ExpireTimeSpan = TimeSpan.FromHours(4);
}
@ -49,7 +49,7 @@ namespace GreenshotJiraPlugin
protected override async Task<Bitmap> CreateAsync(IssueType issueType, CancellationToken cancellationToken = new CancellationToken())
{
return await _jiraApi.GetUriContentAsync<Bitmap>(issueType.IconUri, cancellationToken).ConfigureAwait(false);
return await _jiraClient.Server.GetUriContentAsync<Bitmap>(issueType.IconUri, cancellationToken).ConfigureAwait(false);
}
}
}

View file

@ -37,7 +37,7 @@ using GreenshotPlugin.Core;
namespace GreenshotJiraPlugin {
/// <summary>
/// This encapsulates the JiraApi to make it possible to change as less old Greenshot code as needed
/// This encapsulates the JiraClient to make it possible to change as less old Greenshot code as needed
/// </summary>
public class JiraConnector : IDisposable {
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(JiraConnector));
@ -48,7 +48,7 @@ namespace GreenshotJiraPlugin {
private DateTimeOffset _loggedInTime = DateTimeOffset.MinValue;
private bool _loggedIn;
private readonly int _timeout;
private JiraApi _jiraApi;
private IJiraClient _jiraClient;
private IssueTypeBitmapCache _issueTypeBitmapCache;
/// <summary>
@ -60,7 +60,7 @@ namespace GreenshotJiraPlugin {
{
if (args.PropertyName == nameof(CoreConfig.IconSize))
{
JiraPlugin.Instance.JiraConnector._jiraApi?.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height });
JiraPlugin.Instance.JiraConnector._jiraClient?.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height });
}
};
@ -70,7 +70,7 @@ namespace GreenshotJiraPlugin {
/// Dispose, logout the users
/// </summary>
public void Dispose() {
if (_jiraApi != null)
if (_jiraClient != null)
{
Task.Run(async () => await LogoutAsync()).Wait();
}
@ -103,21 +103,21 @@ namespace GreenshotJiraPlugin {
{
return false;
}
_jiraApi = new JiraApi(new Uri(JiraConfig.Url));
_jiraApi.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height });
_jiraClient = JiraClient.Create(new Uri(JiraConfig.Url));
_jiraClient.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height });
_issueTypeBitmapCache = new IssueTypeBitmapCache(_jiraApi);
_issueTypeBitmapCache = new IssueTypeBitmapCache(_jiraClient);
LoginInfo loginInfo;
try
{
loginInfo = await _jiraApi.Session.StartAsync(user, password, cancellationToken);
loginInfo = await _jiraClient.Session.StartAsync(user, password, cancellationToken);
Monitor = new JiraMonitor();
await Monitor.AddJiraInstanceAsync(_jiraApi, cancellationToken);
await Monitor.AddJiraInstanceAsync(_jiraClient, cancellationToken);
var favIconUri = _jiraApi.JiraBaseUri.AppendSegments("favicon.ico");
var favIconUri = _jiraClient.JiraBaseUri.AppendSegments("favicon.ico");
try
{
FavIcon = await _jiraApi.GetUriContentAsync<Bitmap>(favIconUri, cancellationToken);
FavIcon = await _jiraClient.Server.GetUriContentAsync<Bitmap>(favIconUri, cancellationToken);
}
catch (Exception ex)
{
@ -177,10 +177,10 @@ namespace GreenshotJiraPlugin {
/// End the session, if there was one
/// </summary>
public async Task LogoutAsync(CancellationToken cancellationToken = default(CancellationToken)) {
if (_jiraApi != null && _loggedIn)
if (_jiraClient != null && _loggedIn)
{
Monitor.Dispose();
await _jiraApi.Session.EndAsync(cancellationToken);
await _jiraClient.Session.EndAsync(cancellationToken);
_loggedIn = false;
}
}
@ -208,7 +208,7 @@ namespace GreenshotJiraPlugin {
public async Task<IList<Filter>> GetFavoriteFiltersAsync(CancellationToken cancellationToken = default(CancellationToken))
{
await CheckCredentialsAsync(cancellationToken);
return await _jiraApi.Filter.GetFavoritesAsync(cancellationToken).ConfigureAwait(false);
return await _jiraClient.Filter.GetFavoritesAsync(cancellationToken).ConfigureAwait(false);
}
/// <summary>
@ -222,7 +222,7 @@ namespace GreenshotJiraPlugin {
await CheckCredentialsAsync(cancellationToken);
try
{
return await _jiraApi.Issue.GetAsync(issueKey, cancellationToken).ConfigureAwait(false);
return await _jiraClient.Issue.GetAsync(issueKey, cancellationToken).ConfigureAwait(false);
}
catch
{
@ -244,7 +244,7 @@ namespace GreenshotJiraPlugin {
{
content.WriteToStream(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
await _jiraApi.Attachment.AttachAsync(issueKey, memoryStream, content.Filename, content.ContentType, cancellationToken).ConfigureAwait(false);
await _jiraClient.Attachment.AttachAsync(issueKey, memoryStream, content.Filename, content.ContentType, cancellationToken).ConfigureAwait(false);
}
}
@ -258,7 +258,7 @@ namespace GreenshotJiraPlugin {
public async Task AddCommentAsync(string issueKey, string body, string visibility = null, CancellationToken cancellationToken = default(CancellationToken))
{
await CheckCredentialsAsync(cancellationToken);
await _jiraApi.Issue.AddCommentAsync(issueKey, body, visibility, cancellationToken).ConfigureAwait(false);
await _jiraClient.Issue.AddCommentAsync(issueKey, body, visibility, cancellationToken).ConfigureAwait(false);
}
/// <summary>
@ -270,7 +270,7 @@ namespace GreenshotJiraPlugin {
public async Task<IList<Issue>> SearchAsync(Filter filter, CancellationToken cancellationToken = default(CancellationToken))
{
await CheckCredentialsAsync(cancellationToken);
var searchResult = await _jiraApi.Issue.SearchAsync(filter.Jql, 20, new[] { "summary", "reporter", "assignee", "created", "issuetype" }, cancellationToken).ConfigureAwait(false);
var searchResult = await _jiraClient.Issue.SearchAsync(filter.Jql, 20, new[] { "summary", "reporter", "assignee", "created", "issuetype" }, cancellationToken).ConfigureAwait(false);
return searchResult.Issues;
}
@ -288,7 +288,7 @@ namespace GreenshotJiraPlugin {
/// <summary>
/// Get the base uri
/// </summary>
public Uri JiraBaseUri => _jiraApi.JiraBaseUri;
public Uri JiraBaseUri => _jiraClient.JiraBaseUri;
/// <summary>
/// Is the user "logged in?

View file

@ -42,8 +42,8 @@ namespace GreenshotJiraPlugin
private static readonly LogSource Log = new LogSource();
private readonly Regex _jiraKeyPattern = new Regex(@"[A-Z][A-Z0-9]+\-[0-9]+");
private readonly WindowsTitleMonitor _monitor;
private readonly IList<JiraApi> _jiraInstances = new List<JiraApi>();
private readonly IDictionary<string, JiraApi> _projectJiraApiMap = new Dictionary<string, JiraApi>();
private readonly IList<IJiraClient> _jiraInstances = new List<IJiraClient>();
private readonly IDictionary<string, IJiraClient> _projectJiraClientMap = new Dictionary<string, IJiraClient>();
private readonly int _maxEntries;
// TODO: Add issues from issueHistory (JQL -> Where.IssueKey.InIssueHistory())
private IDictionary<string, JiraDetails> _recentJiras = new Dictionary<string, JiraDetails>();
@ -93,10 +93,10 @@ namespace GreenshotJiraPlugin
/// Retrieve the API belonging to a JiraDetails
/// </summary>
/// <param name="jiraDetails"></param>
/// <returns>JiraAPI</returns>
public JiraApi GetJiraApiForKey(JiraDetails jiraDetails)
/// <returns>IJiraClient</returns>
public IJiraClient GetJiraClientForKey(JiraDetails jiraDetails)
{
return _projectJiraApiMap[jiraDetails.ProjectKey];
return _projectJiraClientMap[jiraDetails.ProjectKey];
}
/// <summary>
@ -117,7 +117,7 @@ namespace GreenshotJiraPlugin
/// </summary>
/// <param name="jiraInstance"></param>
/// <param name="token"></param>
public async Task AddJiraInstanceAsync(JiraApi jiraInstance, CancellationToken token = default(CancellationToken))
public async Task AddJiraInstanceAsync(IJiraClient jiraInstance, CancellationToken token = default(CancellationToken))
{
_jiraInstances.Add(jiraInstance);
var projects = await jiraInstance.Project.GetAllAsync(cancellationToken: token).ConfigureAwait(false);
@ -125,9 +125,9 @@ namespace GreenshotJiraPlugin
{
foreach (var project in projects)
{
if (!_projectJiraApiMap.ContainsKey(project.Key))
if (!_projectJiraClientMap.ContainsKey(project.Key))
{
_projectJiraApiMap.Add(project.Key, jiraInstance);
_projectJiraClientMap.Add(project.Key, jiraInstance);
}
}
}
@ -142,10 +142,10 @@ namespace GreenshotJiraPlugin
{
try
{
JiraApi jiraApi;
if (_projectJiraApiMap.TryGetValue(jiraDetails.ProjectKey, out jiraApi))
IJiraClient jiraClient;
if (_projectJiraClientMap.TryGetValue(jiraDetails.ProjectKey, out jiraClient))
{
var issue = await jiraApi.Issue.GetAsync(jiraDetails.JiraKey).ConfigureAwait(false);
var issue = await jiraClient.Issue.GetAsync(jiraDetails.JiraKey).ConfigureAwait(false);
jiraDetails.JiraIssue = issue;
}
// Send event
@ -179,9 +179,9 @@ namespace GreenshotJiraPlugin
var projectKey = jiraKeyParts[0];
var jiraId = jiraKeyParts[1];
JiraApi jiraApi;
IJiraClient jiraClient;
// Check if we have a JIRA instance with a project for this key
if (_projectJiraApiMap.TryGetValue(projectKey, out jiraApi))
if (_projectJiraClientMap.TryGetValue(projectKey, out jiraClient))
{
// We have found a project for this _jira key, so it must be a valid & known JIRA
JiraDetails currentJiraDetails;

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Dapplo.HttpExtensions" version="0.6.10" targetFramework="net45" />
<package id="Dapplo.Jira" version="0.3.4" targetFramework="net45" />
<package id="Dapplo.Log" version="1.0.22" targetFramework="net45" />
<package id="Dapplo.HttpExtensions" version="0.6.17" targetFramework="net45" />
<package id="Dapplo.Jira" version="0.5.8" targetFramework="net45" />
<package id="Dapplo.Log" version="1.0.23" targetFramework="net45" />
<package id="LibZ.Tool" version="1.2.0.0" targetFramework="net45" />
<package id="Svg" version="2.3.0" targetFramework="net45" />
</packages>