mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
BUG-2016: Added SVG support for the jira plugin, need to decide if it's worth the extra KB's...
This commit is contained in:
parent
4dd67df1dd
commit
745a56291c
10 changed files with 248 additions and 34 deletions
|
@ -37,7 +37,8 @@ namespace GreenshotJiraPlugin.Forms {
|
||||||
private readonly JiraConnector _jiraConnector;
|
private readonly JiraConnector _jiraConnector;
|
||||||
private Issue _selectedIssue;
|
private Issue _selectedIssue;
|
||||||
private readonly GreenshotColumnSorter _columnSorter;
|
private readonly GreenshotColumnSorter _columnSorter;
|
||||||
private readonly JiraConfiguration _config = IniConfig.GetIniSection<JiraConfiguration>();
|
private static readonly JiraConfiguration JiraConfig = IniConfig.GetIniSection<JiraConfiguration>();
|
||||||
|
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
public JiraForm(JiraConnector jiraConnector) {
|
public JiraForm(JiraConnector jiraConnector) {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -83,12 +84,12 @@ namespace GreenshotJiraPlugin.Forms {
|
||||||
jiraFilterBox.SelectedIndex = 0;
|
jiraFilterBox.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
ChangeModus(true);
|
ChangeModus(true);
|
||||||
if (_config.LastUsedJira != null)
|
if (JiraConfig.LastUsedJira != null)
|
||||||
{
|
{
|
||||||
_selectedIssue = await _jiraConnector.GetIssueAsync(_config.LastUsedJira);
|
_selectedIssue = await _jiraConnector.GetIssueAsync(JiraConfig.LastUsedJira);
|
||||||
if (_selectedIssue != null)
|
if (_selectedIssue != null)
|
||||||
{
|
{
|
||||||
jiraKey.Text = _config.LastUsedJira;
|
jiraKey.Text = JiraConfig.LastUsedJira;
|
||||||
uploadButton.Enabled = true;
|
uploadButton.Enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +118,7 @@ namespace GreenshotJiraPlugin.Forms {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UploadAsync(IBinaryContainer attachment) {
|
public async Task UploadAsync(IBinaryContainer attachment) {
|
||||||
_config.LastUsedJira = _selectedIssue.Key;
|
JiraConfig.LastUsedJira = _selectedIssue.Key;
|
||||||
attachment.Filename = jiraFilenameBox.Text;
|
attachment.Filename = jiraFilenameBox.Text;
|
||||||
await _jiraConnector.AttachAsync(_selectedIssue.Key, attachment);
|
await _jiraConnector.AttachAsync(_selectedIssue.Key, attachment);
|
||||||
|
|
||||||
|
@ -145,31 +146,50 @@ namespace GreenshotJiraPlugin.Forms {
|
||||||
MessageBox.Show(this, ex.Message, "Error in filter", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(this, ex.Message, "Error in filter", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
jiraListView.BeginUpdate();
|
|
||||||
jiraListView.Items.Clear();
|
jiraListView.Items.Clear();
|
||||||
if (issues?.Count > 0) {
|
if (issues?.Count > 0) {
|
||||||
jiraListView.Columns.Clear();
|
jiraListView.Columns.Clear();
|
||||||
LangKey[] columns = { LangKey.column_id, LangKey.column_created, LangKey.column_assignee, LangKey.column_reporter, LangKey.column_summary };
|
LangKey[] columns = { LangKey.column_issueType, LangKey.column_id, LangKey.column_created, LangKey.column_assignee, LangKey.column_reporter, LangKey.column_summary };
|
||||||
foreach (LangKey column in columns) {
|
foreach (LangKey column in columns)
|
||||||
jiraListView.Columns.Add(Language.GetString("jira", column));
|
{
|
||||||
}
|
string translation;
|
||||||
foreach (var issue in issues) {
|
if (!Language.TryGetString("jira", column, out translation))
|
||||||
var item = new ListViewItem(issue.Key)
|
|
||||||
{
|
{
|
||||||
Tag = issue
|
translation = "";
|
||||||
|
}
|
||||||
|
jiraListView.Columns.Add(translation);
|
||||||
|
}
|
||||||
|
var imageList = new ImageList {
|
||||||
|
ImageSize = CoreConfig.IconSize
|
||||||
|
};
|
||||||
|
jiraListView.SmallImageList = imageList;
|
||||||
|
jiraListView.LargeImageList = imageList;
|
||||||
|
|
||||||
|
foreach (var issue in issues) {
|
||||||
|
var issueIcon = await _jiraConnector.GetIssueTypeBitmapAsync(issue);
|
||||||
|
imageList.Images.Add(issueIcon);
|
||||||
|
|
||||||
|
var item = new ListViewItem
|
||||||
|
{
|
||||||
|
Tag = issue,
|
||||||
|
ImageIndex = imageList.Images.Count - 1
|
||||||
};
|
};
|
||||||
|
item.SubItems.Add(issue.Key);
|
||||||
item.SubItems.Add(issue.Fields.Created.ToString("d", DateTimeFormatInfo.InvariantInfo));
|
item.SubItems.Add(issue.Fields.Created.ToString("d", DateTimeFormatInfo.InvariantInfo));
|
||||||
item.SubItems.Add(issue.Fields.Assignee?.DisplayName);
|
item.SubItems.Add(issue.Fields.Assignee?.DisplayName);
|
||||||
item.SubItems.Add(issue.Fields.Reporter?.DisplayName);
|
item.SubItems.Add(issue.Fields.Reporter?.DisplayName);
|
||||||
item.SubItems.Add(issue.Fields.Summary);
|
item.SubItems.Add(issue.Fields.Summary);
|
||||||
jiraListView.Items.Add(item);
|
jiraListView.Items.Add(item);
|
||||||
|
for (int i = 0; i < columns.Length; i++)
|
||||||
|
{
|
||||||
|
jiraListView.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.ColumnContent);
|
||||||
|
}
|
||||||
|
jiraListView.Invalidate();
|
||||||
|
jiraListView.Update();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < columns.Length; i++) {
|
|
||||||
jiraListView.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.ColumnContent);
|
jiraListView.Refresh();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
jiraListView.EndUpdate();
|
|
||||||
jiraListView.Refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,13 @@
|
||||||
<Reference Include="log4net">
|
<Reference Include="log4net">
|
||||||
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
|
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Svg, Version=2.2.1.1459, Culture=neutral, PublicKeyToken=12a0bac221edeae2, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Svg.2.2.1\lib\net35\Svg.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Runtime.Caching" />
|
<Reference Include="System.Runtime.Caching" />
|
||||||
<Reference Include="System.Web.Services" />
|
<Reference Include="System.Web.Services" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
@ -82,6 +87,7 @@
|
||||||
<Compile Include="LanguageKeys.cs" />
|
<Compile Include="LanguageKeys.cs" />
|
||||||
<Compile Include="Log4NetLogger.cs" />
|
<Compile Include="Log4NetLogger.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="SvgBitmapHttpContentConverter.cs" />
|
||||||
<None Include="Languages\language_jiraplugin-de-DE.xml">
|
<None Include="Languages\language_jiraplugin-de-DE.xml">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
@ -105,6 +111,10 @@
|
||||||
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
|
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
|
||||||
<Name>GreenshotPlugin</Name>
|
<Name>GreenshotPlugin</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Greenshot\Greenshot.csproj">
|
||||||
|
<Project>{CD642BF4-D815-4D67-A0B5-C69F0B8231AF}</Project>
|
||||||
|
<Name>Greenshot</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"
|
<PostBuildEvent>mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"
|
||||||
|
@ -112,12 +122,13 @@
|
||||||
del /q /s "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"\*
|
del /q /s "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)"\*
|
||||||
|
|
||||||
if "$(ConfigurationName)" == "Release" (
|
if "$(ConfigurationName)" == "Release" (
|
||||||
..\..\..\packages\LibZ.Tool.1.2.0.0\tools\libz.exe inject-dll --assembly $(ProjectDir)bin\$(Configuration)\$(TargetFileName) --include $(ProjectDir)bin\$(Configuration)\dapplo*.dll --move
|
..\..\..\packages\LibZ.Tool.1.2.0.0\tools\libz.exe inject-dll --assembly $(ProjectDir)bin\$(Configuration)\$(TargetFileName) --include $(ProjectDir)bin\$(Configuration)\dapplo*.dll --include $(ProjectDir)bin\$(Configuration)\svg.dll --move
|
||||||
)
|
)
|
||||||
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"
|
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"
|
||||||
|
|
||||||
if "$(ConfigurationName)" == "Debug" (
|
if "$(ConfigurationName)" == "Debug" (
|
||||||
copy "$(ProjectDir)bin\$(Configuration)\Dapplo.*" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\"
|
copy "$(ProjectDir)bin\$(Configuration)\Dapplo.*" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\"
|
||||||
|
copy "$(ProjectDir)bin\$(Configuration)\Svg.dll" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\"
|
||||||
copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\"
|
copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace GreenshotJiraPlugin
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the bach for the IssueType bitmaps
|
/// This is the bach for the IssueType bitmaps
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class IssueTypeBitmapCache : AsyncMemoryCache<Issue, Bitmap>
|
public class IssueTypeBitmapCache : AsyncMemoryCache<IssueType, Bitmap>
|
||||||
{
|
{
|
||||||
private readonly JiraApi _jiraApi;
|
private readonly JiraApi _jiraApi;
|
||||||
|
|
||||||
|
@ -42,9 +42,14 @@ namespace GreenshotJiraPlugin
|
||||||
ExpireTimeSpan = TimeSpan.FromHours(1);
|
ExpireTimeSpan = TimeSpan.FromHours(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<Bitmap> CreateAsync(Issue issue, CancellationToken cancellationToken = new CancellationToken())
|
protected override string CreateKey(IssueType keyObject)
|
||||||
{
|
{
|
||||||
return await _jiraApi.GetUriContentAsync<Bitmap>(issue.Fields.IssueType.IconUri, cancellationToken).ConfigureAwait(false);
|
return keyObject.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<Bitmap> CreateAsync(IssueType issueType, CancellationToken cancellationToken = new CancellationToken())
|
||||||
|
{
|
||||||
|
return await _jiraApi.GetUriContentAsync<Bitmap>(issueType.IconUri, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,11 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Dapplo.HttpExtensions;
|
||||||
using Dapplo.Jira;
|
using Dapplo.Jira;
|
||||||
using Dapplo.Jira.Entities;
|
using Dapplo.Jira.Entities;
|
||||||
using Greenshot.IniFile;
|
using Greenshot.IniFile;
|
||||||
|
@ -38,7 +40,8 @@ namespace GreenshotJiraPlugin {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JiraConnector : IDisposable {
|
public class JiraConnector : IDisposable {
|
||||||
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(JiraConnector));
|
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(JiraConnector));
|
||||||
private static readonly JiraConfiguration Config = IniConfig.GetIniSection<JiraConfiguration>();
|
private static readonly JiraConfiguration JiraConfig = IniConfig.GetIniSection<JiraConfiguration>();
|
||||||
|
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
// Used to remove the wsdl information from the old SOAP Uri
|
// Used to remove the wsdl information from the old SOAP Uri
|
||||||
public const string DefaultPostfix = "/rpc/soap/jirasoapservice-v2?wsdl";
|
public const string DefaultPostfix = "/rpc/soap/jirasoapservice-v2?wsdl";
|
||||||
private DateTimeOffset _loggedInTime = DateTimeOffset.MinValue;
|
private DateTimeOffset _loggedInTime = DateTimeOffset.MinValue;
|
||||||
|
@ -48,6 +51,26 @@ namespace GreenshotJiraPlugin {
|
||||||
private string _url;
|
private string _url;
|
||||||
private JiraApi _jiraApi;
|
private JiraApi _jiraApi;
|
||||||
private IssueTypeBitmapCache _issueTypeBitmapCache;
|
private IssueTypeBitmapCache _issueTypeBitmapCache;
|
||||||
|
private static readonly SvgBitmapHttpContentConverter SvgBitmapHttpContentConverterInstance = new SvgBitmapHttpContentConverter();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
if (_jiraApi != null)
|
if (_jiraApi != null)
|
||||||
|
@ -56,9 +79,10 @@ namespace GreenshotJiraPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JiraConnector() {
|
public JiraConnector()
|
||||||
_url = Config.Url.Replace(DefaultPostfix, "");
|
{
|
||||||
_timeout = Config.Timeout;
|
_url = JiraConfig.Url.Replace(DefaultPostfix, "");
|
||||||
|
_timeout = JiraConfig.Timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -86,7 +110,7 @@ namespace GreenshotJiraPlugin {
|
||||||
{
|
{
|
||||||
loginInfo = await _jiraApi.StartSessionAsync(user, password);
|
loginInfo = await _jiraApi.StartSessionAsync(user, password);
|
||||||
// Worked, store the url in the configuration
|
// Worked, store the url in the configuration
|
||||||
Config.Url = _url;
|
JiraConfig.Url = _url;
|
||||||
IniConfig.Save();
|
IniConfig.Save();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -177,7 +201,14 @@ namespace GreenshotJiraPlugin {
|
||||||
public async Task<Issue> GetIssueAsync(string issueKey)
|
public async Task<Issue> GetIssueAsync(string issueKey)
|
||||||
{
|
{
|
||||||
await CheckCredentials();
|
await CheckCredentials();
|
||||||
return await _jiraApi.GetIssueAsync(issueKey).ConfigureAwait(false);
|
try
|
||||||
|
{
|
||||||
|
return await _jiraApi.GetIssueAsync(issueKey).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -185,7 +216,6 @@ namespace GreenshotJiraPlugin {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="issueKey"></param>
|
/// <param name="issueKey"></param>
|
||||||
/// <param name="content">IBinaryContainer</param>
|
/// <param name="content">IBinaryContainer</param>
|
||||||
/// <param name="filename"></param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task AttachAsync(string issueKey, IBinaryContainer content, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task AttachAsync(string issueKey, IBinaryContainer content, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
|
@ -221,7 +251,7 @@ namespace GreenshotJiraPlugin {
|
||||||
public async Task<IList<Issue>> SearchAsync(Filter filter, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<IList<Issue>> SearchAsync(Filter filter, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
await CheckCredentials();
|
await CheckCredentials();
|
||||||
var searchResult = await _jiraApi.SearchAsync(filter.Jql, 20, new[] { "summary", "reporter", "assignee", "created" }, cancellationToken).ConfigureAwait(false);
|
var searchResult = await _jiraApi.SearchAsync(filter.Jql, 20, new[] { "summary", "reporter", "assignee", "created", "issuetype" }, cancellationToken).ConfigureAwait(false);
|
||||||
return searchResult.Issues;
|
return searchResult.Issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +263,7 @@ namespace GreenshotJiraPlugin {
|
||||||
/// <returns>Bitmap</returns>
|
/// <returns>Bitmap</returns>
|
||||||
public async Task<Bitmap> GetIssueTypeBitmapAsync(Issue issue, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<Bitmap> GetIssueTypeBitmapAsync(Issue issue, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
return await _issueTypeBitmapCache.GetOrCreateAsync(issue, cancellationToken).ConfigureAwait(false);
|
return await _issueTypeBitmapCache.GetOrCreateAsync(issue.Fields.IssueType, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri JiraBaseUri => _jiraApi.JiraBaseUri;
|
public Uri JiraBaseUri => _jiraApi.JiraBaseUri;
|
||||||
|
|
|
@ -24,7 +24,6 @@ using Greenshot.IniFile;
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapplo.HttpExtensions.ContentConverter;
|
|
||||||
using Dapplo.Log.Facade;
|
using Dapplo.Log.Facade;
|
||||||
using GreenshotJiraPlugin.Forms;
|
using GreenshotJiraPlugin.Forms;
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,11 @@ namespace GreenshotJiraPlugin {
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error(ex);
|
Log.Error(ex);
|
||||||
|
// Remove issue from the last used jira config, as it caused an issue (probably not there)
|
||||||
|
if (Config.LastUsedJira == jiraKey)
|
||||||
|
{
|
||||||
|
Config.LastUsedJira = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jiraIssues.Count > 0) {
|
if (jiraIssues.Count > 0) {
|
||||||
|
|
|
@ -20,10 +20,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace GreenshotJiraPlugin {
|
namespace GreenshotJiraPlugin {
|
||||||
public enum LangKey {
|
public enum LangKey {
|
||||||
upload_menu_item,
|
upload_menu_item,
|
||||||
column_assignee,
|
column_assignee,
|
||||||
column_created,
|
column_created,
|
||||||
|
column_issueType,
|
||||||
column_id,
|
column_id,
|
||||||
column_reporter,
|
column_reporter,
|
||||||
column_summary,
|
column_summary,
|
||||||
|
@ -41,5 +42,5 @@ namespace GreenshotJiraPlugin {
|
||||||
upload_success,
|
upload_success,
|
||||||
upload_failure,
|
upload_failure,
|
||||||
communication_wait,
|
communication_wait,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
129
GreenshotJiraPlugin/SvgBitmapHttpContentConverter.cs
Normal file
129
GreenshotJiraPlugin/SvgBitmapHttpContentConverter.cs
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* 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.Drawing.Imaging;
|
||||||
|
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;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
using Svg;
|
||||||
|
|
||||||
|
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 bitmap = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent, 96, 96);
|
||||||
|
var svgDoc = SvgDocument.Open<SvgDocument>(memoryStream);
|
||||||
|
svgDoc.Width = Width;
|
||||||
|
svgDoc.Height = Height;
|
||||||
|
svgDoc.Draw(bitmap);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,4 +4,5 @@
|
||||||
<package id="Dapplo.Jira" version="0.1.59" targetFramework="net45" />
|
<package id="Dapplo.Jira" version="0.1.59" targetFramework="net45" />
|
||||||
<package id="Dapplo.Log.Facade" version="0.5.4" targetFramework="net45" />
|
<package id="Dapplo.Log.Facade" version="0.5.4" targetFramework="net45" />
|
||||||
<package id="LibZ.Tool" version="1.2.0.0" targetFramework="net45" />
|
<package id="LibZ.Tool" version="1.2.0.0" targetFramework="net45" />
|
||||||
|
<package id="Svg" version="2.2.1" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
|
@ -532,6 +532,19 @@ namespace GreenshotPlugin.Core {
|
||||||
return resources.TryGetValue(prefix + "." + key, out languageString);
|
return resources.TryGetValue(prefix + "." + key, out languageString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// TryGet method which combines hasKey & GetString
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prefix">string with prefix</param>
|
||||||
|
/// <param name="key">Enum with key</param>
|
||||||
|
/// <param name="languageString">out string</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool TryGetString(string prefix, Enum key, out string languageString)
|
||||||
|
{
|
||||||
|
return resources.TryGetValue(prefix + "." + key, out languageString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static string Translate(object key) {
|
public static string Translate(object key) {
|
||||||
string typename = key.GetType().Name;
|
string typename = key.GetType().Name;
|
||||||
string enumKey = typename + "." + key;
|
string enumKey = typename + "." + key;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue