mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 18:57:28 -07:00
Improved Jira code with the latest state of Dapplo.Jira [skip ci]
This commit is contained in:
parent
28358f4a9a
commit
4029e01491
8 changed files with 37 additions and 158 deletions
|
@ -29,7 +29,7 @@ using System;
|
|||
using System.Runtime.Caching;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Dapplo.Log.Facade;
|
||||
using Dapplo.Log;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -34,32 +34,42 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="Dapplo.HttpExtensions, Version=0.5.43.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.HttpExtensions.0.5.43\lib\net45\Dapplo.HttpExtensions.dll</HintPath>
|
||||
<Reference Include="Dapplo.HttpExtensions, Version=0.6.8.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.HttpExtensions.0.6.8\lib\net45\Dapplo.HttpExtensions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Dapplo.Jira, Version=0.1.65.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.Jira.0.1.65\lib\net45\Dapplo.Jira.dll</HintPath>
|
||||
<Reference Include="Dapplo.Jira, Version=0.3.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.Jira.0.3.1\lib\net45\Dapplo.Jira.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Dapplo.Log.Facade, Version=0.5.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.Log.Facade.0.5.4\lib\net45\Dapplo.Log.Facade.dll</HintPath>
|
||||
<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>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Svg, Version=2.2.1.38382, Culture=neutral, PublicKeyToken=12a0bac221edeae2, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Svg.2.2.2\lib\net35\Svg.dll</HintPath>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="Svg, Version=2.2.1.39233, Culture=neutral, PublicKeyToken=12a0bac221edeae2, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Svg.2.3.0\lib\net35\Svg.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Net.Http.WebRequest" />
|
||||
<Reference Include="System.Runtime.Caching" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AsyncMemoryCache.cs" />
|
||||
|
@ -94,7 +104,6 @@
|
|||
<Compile Include="LanguageKeys.cs" />
|
||||
<Compile Include="Log4NetLogger.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SvgBitmapHttpContentConverter.cs" />
|
||||
<Compile Include="SvgImage.cs" />
|
||||
<None Include="Languages\language_jiraplugin-de-DE.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
|
|
@ -24,12 +24,13 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.HttpExtensions;
|
||||
using Dapplo.HttpExtensions.Extensions;
|
||||
using Dapplo.Jira;
|
||||
using Dapplo.Jira.Converters;
|
||||
using Dapplo.Jira.Entities;
|
||||
using Greenshot.IniFile;
|
||||
using GreenshotPlugin.Core;
|
||||
|
@ -49,25 +50,17 @@ namespace GreenshotJiraPlugin {
|
|||
private readonly int _timeout;
|
||||
private JiraApi _jiraApi;
|
||||
private IssueTypeBitmapCache _issueTypeBitmapCache;
|
||||
private static readonly SvgBitmapHttpContentConverter SvgBitmapHttpContentConverterInstance = new SvgBitmapHttpContentConverter();
|
||||
|
||||
/// <summary>
|
||||
/// Initialize some basic stuff, in the case the SVG to bitmap converter
|
||||
/// </summary>
|
||||
static JiraConnector()
|
||||
{
|
||||
if (HttpExtensionsGlobals.HttpContentConverters.All(x => x.GetType() != typeof(SvgBitmapHttpContentConverter)))
|
||||
{
|
||||
HttpExtensionsGlobals.HttpContentConverters.Add(SvgBitmapHttpContentConverterInstance);
|
||||
}
|
||||
SvgBitmapHttpContentConverterInstance.Width = CoreConfig.IconSize.Width;
|
||||
SvgBitmapHttpContentConverterInstance.Height = CoreConfig.IconSize.Height;
|
||||
CoreConfig.PropertyChanged += (sender, args) =>
|
||||
{
|
||||
if (args.PropertyName == nameof(CoreConfig.IconSize))
|
||||
{
|
||||
SvgBitmapHttpContentConverterInstance.Width = CoreConfig.IconSize.Width;
|
||||
SvgBitmapHttpContentConverterInstance.Height = CoreConfig.IconSize.Height;
|
||||
JiraPlugin.Instance.JiraConnector._jiraApi?.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height });
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -111,6 +104,8 @@ namespace GreenshotJiraPlugin {
|
|||
return false;
|
||||
}
|
||||
_jiraApi = new JiraApi(new Uri(JiraConfig.Url));
|
||||
_jiraApi.Behaviour.SetConfig(new SvgConfiguration { Width = CoreConfig.IconSize.Width, Height = CoreConfig.IconSize.Height });
|
||||
|
||||
_issueTypeBitmapCache = new IssueTypeBitmapCache(_jiraApi);
|
||||
LoginInfo loginInfo;
|
||||
try
|
||||
|
@ -226,7 +221,7 @@ namespace GreenshotJiraPlugin {
|
|||
await CheckCredentialsAsync();
|
||||
try
|
||||
{
|
||||
return await _jiraApi.GetIssueAsync(issueKey).ConfigureAwait(false);
|
||||
return await _jiraApi.Issue.GetAsync(issueKey).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -248,7 +243,7 @@ namespace GreenshotJiraPlugin {
|
|||
{
|
||||
content.WriteToStream(memoryStream);
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
await _jiraApi.AttachAsync(issueKey, memoryStream, content.Filename, content.ContentType, cancellationToken).ConfigureAwait(false);
|
||||
await _jiraApi.Attachment.AttachAsync(issueKey, memoryStream, content.Filename, content.ContentType, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,7 +257,7 @@ namespace GreenshotJiraPlugin {
|
|||
public async Task AddCommentAsync(string issueKey, string body, string visibility = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
await CheckCredentialsAsync();
|
||||
await _jiraApi.AddCommentAsync(issueKey, body, visibility, cancellationToken).ConfigureAwait(false);
|
||||
await _jiraApi.Issue.AddCommentAsync(issueKey, body, visibility, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -274,7 +269,7 @@ namespace GreenshotJiraPlugin {
|
|||
public async Task<IList<Issue>> SearchAsync(Filter filter, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
await CheckCredentialsAsync();
|
||||
var searchResult = await _jiraApi.SearchAsync(filter.Jql, 20, new[] { "summary", "reporter", "assignee", "created", "issuetype" }, cancellationToken).ConfigureAwait(false);
|
||||
var searchResult = await _jiraApi.Issue.SearchAsync(filter.Jql, 20, new[] { "summary", "reporter", "assignee", "created", "issuetype" }, cancellationToken).ConfigureAwait(false);
|
||||
return searchResult.Issues;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ using System.Text.RegularExpressions;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Dapplo.Jira;
|
||||
using Dapplo.Log.Facade;
|
||||
using Dapplo.Log;
|
||||
using GreenshotJiraPlugin.Hooking;
|
||||
|
||||
namespace GreenshotJiraPlugin
|
||||
|
@ -45,6 +45,7 @@ namespace GreenshotJiraPlugin
|
|||
private readonly IList<JiraApi> _jiraInstances = new List<JiraApi>();
|
||||
private readonly IDictionary<string, JiraApi> _projectJiraApiMap = new Dictionary<string, JiraApi>();
|
||||
private readonly int _maxEntries;
|
||||
// TODO: Add issues from issueHistory (JQL -> Where.IssueKey.InIssueHistory())
|
||||
private IDictionary<string, JiraDetails> _recentJiras = new Dictionary<string, JiraDetails>();
|
||||
|
||||
/// <summary>
|
||||
|
@ -144,7 +145,7 @@ namespace GreenshotJiraPlugin
|
|||
JiraApi jiraApi;
|
||||
if (_projectJiraApiMap.TryGetValue(jiraDetails.ProjectKey, out jiraApi))
|
||||
{
|
||||
var issue = await jiraApi.GetIssueAsync(jiraDetails.JiraKey).ConfigureAwait(false);
|
||||
var issue = await jiraApi.Issue.GetAsync(jiraDetails.JiraKey).ConfigureAwait(false);
|
||||
jiraDetails.JiraIssue = issue;
|
||||
}
|
||||
// Send event
|
||||
|
|
|
@ -24,7 +24,7 @@ using Greenshot.IniFile;
|
|||
using Greenshot.Plugin;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Dapplo.Log.Facade;
|
||||
using Dapplo.Log;
|
||||
using GreenshotJiraPlugin.Forms;
|
||||
using GreenshotPlugin.Core;
|
||||
using log4net;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Dapplo.Log.Facade;
|
||||
using Dapplo.Log;
|
||||
using log4net;
|
||||
|
||||
namespace GreenshotJiraPlugin
|
||||
|
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2016 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.Drawing;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Dapplo.HttpExtensions;
|
||||
using Dapplo.HttpExtensions.ContentConverter;
|
||||
using Dapplo.HttpExtensions.Extensions;
|
||||
using Dapplo.HttpExtensions.Support;
|
||||
using Dapplo.Log.Facade;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace GreenshotJiraPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// This adds SVG image support for the Jira Plugin
|
||||
/// </summary>
|
||||
public class SvgBitmapHttpContentConverter : IHttpContentConverter
|
||||
{
|
||||
private static readonly LogSource Log = new LogSource();
|
||||
private static readonly IList<string> SupportedContentTypes = new List<string>();
|
||||
|
||||
static SvgBitmapHttpContentConverter()
|
||||
{
|
||||
SupportedContentTypes.Add(MediaTypes.Svg.EnumValueOf());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => 0;
|
||||
|
||||
public int Width { get; set; }
|
||||
|
||||
public int Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This checks if the HttpContent can be converted to a Bitmap and is assignable to the specified Type
|
||||
/// </summary>
|
||||
/// <param name="typeToConvertTo">This should be something we can assign Bitmap to</param>
|
||||
/// <param name="httpContent">HttpContent to process</param>
|
||||
/// <returns>true if it can convert</returns>
|
||||
public bool CanConvertFromHttpContent(Type typeToConvertTo, HttpContent httpContent)
|
||||
{
|
||||
if (typeToConvertTo == typeof(object) || !typeToConvertTo.IsAssignableFrom(typeof(Bitmap)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var httpBehaviour = HttpBehaviour.Current;
|
||||
return !httpBehaviour.ValidateResponseContentType || SupportedContentTypes.Contains(httpContent.GetContentType());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<object> ConvertFromHttpContentAsync(Type resultType, HttpContent httpContent, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (!CanConvertFromHttpContent(resultType, httpContent))
|
||||
{
|
||||
var exMessage = "CanConvertFromHttpContent resulted in false, ConvertFromHttpContentAsync is not supposed to be called.";
|
||||
Log.Error().WriteLine(exMessage);
|
||||
throw new NotSupportedException(exMessage);
|
||||
}
|
||||
using (var memoryStream = (MemoryStream) await StreamHttpContentConverter.Instance.ConvertFromHttpContentAsync(typeof(MemoryStream), httpContent, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
Log.Debug().WriteLine("Creating a Bitmap from the SVG.");
|
||||
var svgImage = new SvgImage(memoryStream)
|
||||
{
|
||||
Height = Height,
|
||||
Width = Width
|
||||
};
|
||||
return svgImage.Image;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool CanConvertToHttpContent(Type typeToConvert, object content)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public HttpContent ConvertToHttpContent(Type typeToConvert, object content)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddAcceptHeadersForType(Type resultType, HttpRequestMessage httpRequestMessage)
|
||||
{
|
||||
if (resultType == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(resultType));
|
||||
}
|
||||
if (httpRequestMessage == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(httpRequestMessage));
|
||||
}
|
||||
if (resultType == typeof(object) || !resultType.IsAssignableFrom(typeof(Bitmap)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
httpRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypes.Svg.EnumValueOf()));
|
||||
Log.Debug().WriteLine("Modified the header(s) of the HttpRequestMessage: Accept: {0}", httpRequestMessage.Headers.Accept);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Dapplo.HttpExtensions" version="0.5.43" targetFramework="net45" />
|
||||
<package id="Dapplo.Jira" version="0.1.65" targetFramework="net45" />
|
||||
<package id="Dapplo.Log.Facade" version="0.5.4" targetFramework="net45" />
|
||||
<package id="Dapplo.HttpExtensions" version="0.6.8" targetFramework="net45" />
|
||||
<package id="Dapplo.Jira" version="0.3.1" targetFramework="net45" />
|
||||
<package id="Dapplo.Log" version="1.0.22" targetFramework="net45" />
|
||||
<package id="LibZ.Tool" version="1.2.0.0" targetFramework="net45" />
|
||||
<package id="Svg" version="2.2.2" targetFramework="net45" />
|
||||
<package id="Svg" version="2.3.0" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue