This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
OpenOnCodigaHubSuggestedAction.cs
94 lines (74 loc) · 2.63 KB
/
OpenOnCodigaHubSuggestedAction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Extension.Rosie.Model;
using Microsoft.VisualStudio.Imaging.Interop;
using Microsoft.VisualStudio.Language.Intellisense;
using Process = System.Diagnostics.Process;
namespace Extension.Rosie.Annotation
{
/// <summary>
/// Action to open an associated rule on Codiga Hub, in the browser, to learn more about a violation and a rule.
/// </summary>
public class OpenOnCodigaHubSuggestedAction : ISuggestedAction
{
private readonly RosieAnnotation _annotation;
private readonly string _displayText;
public OpenOnCodigaHubSuggestedAction(RosieAnnotation annotation)
{
_annotation = annotation;
_displayText = $"See rule '{annotation.RuleName}' on the Codiga Hub";
}
/// <summary>
/// Opens the rule's page on Codiga Hub for this particular violation.
/// <br/>
/// Related VS extension: https://github.com/tunnelvisionlabs/OpenInExternalBrowser/blob/master/OpenInExternalBrowser/
/// </summary>
public void Invoke(CancellationToken cancellationToken)
{
try
{
Process.Start(GetUrlString());
}
catch
{
// ignored
}
}
internal string GetUrlString()
{
return $"https://app.codiga.io/hub/ruleset/{_annotation.RulesetName}/{_annotation.RuleName}";
}
#region Action sets and preview
public Task<IEnumerable<SuggestedActionSet>> GetActionSetsAsync(CancellationToken cancellationToken)
{
//There is no subset/submenu of actions for this action
return Task.FromResult<IEnumerable<SuggestedActionSet>>(null);
}
public Task<object> GetPreviewAsync(CancellationToken cancellationToken)
{
//No preview provided
return Task.FromResult<object>(null);
}
#endregion
#region Disposal
public void Dispose()
{
}
#endregion
#region Properties
public bool TryGetTelemetryId(out Guid telemetryId)
{
telemetryId = Guid.Empty;
return false;
}
public bool HasActionSets => false;
public string DisplayText => _displayText;
public ImageMoniker IconMoniker => default;
public string IconAutomationText => null;
public string InputGestureText => null;
public bool HasPreview => false;
#endregion
}
}