Fixed memory leak (and refactored code).
This commit is contained in:
parent
ab80a18c18
commit
5bd3f0e0b4
1 changed files with 193 additions and 213 deletions
|
@ -22,7 +22,7 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
|
||||||
private const string ConfigHelpHtmlValue = "Config consists of three lines:<br/><i><Url></i> - The base url to the Unfuddle API (i.e. http://account_name.unfuddle.com/api/v1/projects/project_ID)<br/><i><Username></i> - The username to the unfuddle account to use for authentication<br/><i><Password></i> - The password to the unfuddle account to use for authentication<br/>";
|
private const string ConfigHelpHtmlValue = "Config consists of three lines:<br/><i><Url></i> - The base url to the Unfuddle API (i.e. http://account_name.unfuddle.com/api/v1/projects/project_ID)<br/><i><Username></i> - The username to the unfuddle account to use for authentication<br/><i><Password></i> - The password to the unfuddle account to use for authentication<br/>";
|
||||||
private const string LoadErrorMessage = "Unable to load ticket report at this time.";
|
private const string LoadErrorMessage = "Unable to load ticket report at this time.";
|
||||||
private static readonly Regex UnfuddleRegex = new Regex(@"{unfuddle}", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
private static readonly Regex UnfuddleRegex = new Regex(@"{unfuddle}", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
||||||
private static readonly ComponentInformation Info = new ComponentInformation("Unfuddle Tickets Plugin", "Threeplicate Srl", "3.0.1.472", "http://www.screwturn.eu", "http://www.screwturn.eu/Version/PluginPack/UnfuddleTickets2.txt");
|
private static readonly ComponentInformation Info = new ComponentInformation("Unfuddle Tickets Plugin", "Threeplicate Srl", "3.0.2.538", "http://www.screwturn.eu", "http://www.screwturn.eu/Version/PluginPack/UnfuddleTickets2.txt");
|
||||||
|
|
||||||
private string _config;
|
private string _config;
|
||||||
private IHostV30 _host;
|
private IHostV30 _host;
|
||||||
|
@ -30,50 +30,36 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
|
||||||
private string _username;
|
private string _username;
|
||||||
private string _password;
|
private string _password;
|
||||||
|
|
||||||
#region IFormatterProviderV30 Members
|
private XslCompiledTransform _xslTransform = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies whether or not to execute Phase 1.
|
/// Initializes the Storage Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool PerformPhase1 {
|
/// <param name="host">The Host of the Component.</param>
|
||||||
get {
|
/// <param name="config">The Configuration data, if any.</param>
|
||||||
return false;
|
/// <remarks>If the configuration string is not valid, the methoud should throw a <see cref="InvalidConfigurationException"/>.</remarks>
|
||||||
}
|
public void Init(IHostV30 host, string config) {
|
||||||
}
|
_host = host;
|
||||||
|
_config = config ?? string.Empty;
|
||||||
|
var configEntries = _config.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
/// <summary>
|
if(configEntries.Length != 3) throw new InvalidConfigurationException("Configuration is missing required parameters");
|
||||||
/// Specifies whether or not to execute Phase 2.
|
|
||||||
/// </summary>
|
|
||||||
public bool PerformPhase2 {
|
|
||||||
get {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
_baseUrl = configEntries[0];
|
||||||
/// Specifies whether or not to execute Phase 3.
|
|
||||||
/// </summary>
|
|
||||||
public bool PerformPhase3 {
|
|
||||||
get {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
if(_baseUrl.EndsWith("/"))
|
||||||
/// Gets the execution priority of the provider (0 lowest, 100 highest).
|
_baseUrl = _baseUrl.Substring(0, _baseUrl.Length - 1);
|
||||||
/// </summary>
|
|
||||||
public int ExecutionPriority {
|
|
||||||
get {
|
|
||||||
return 50;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
_username = configEntries[1];
|
||||||
/// Gets the Information about the Provider.
|
_password = configEntries[2];
|
||||||
/// </summary>
|
|
||||||
public ComponentInformation Information {
|
var settings = new XsltSettings {
|
||||||
get {
|
EnableScript = true,
|
||||||
return Info;
|
EnableDocumentFunction = true
|
||||||
|
};
|
||||||
|
_xslTransform = new XslCompiledTransform(true);
|
||||||
|
using(var reader = XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("ScrewTurn.Wiki.Plugins.PluginPack.Resources.UnfuddleTickets.xsl"))) {
|
||||||
|
_xslTransform.Load(reader, settings, new XmlUrlResolver());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,29 +105,6 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the Storage Provider.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="host">The Host of the Component.</param>
|
|
||||||
/// <param name="config">The Configuration data, if any.</param>
|
|
||||||
/// <remarks>If the configuration string is not valid, the methoud should throw a <see cref="InvalidConfigurationException"/>.</remarks>
|
|
||||||
public void Init(IHostV30 host, string config) {
|
|
||||||
_host = host;
|
|
||||||
_config = config ?? string.Empty;
|
|
||||||
var configEntries = _config.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
|
|
||||||
if(configEntries.Length != 3)
|
|
||||||
throw new InvalidConfigurationException("Configuration missing required parameters.");
|
|
||||||
|
|
||||||
_baseUrl = configEntries[0];
|
|
||||||
|
|
||||||
if(_baseUrl.EndsWith("/"))
|
|
||||||
_baseUrl = _baseUrl.Substring(0, _baseUrl.Length - 1);
|
|
||||||
|
|
||||||
_username = configEntries[1];
|
|
||||||
_password = configEntries[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method invoked on shutdown.
|
/// Method invoked on shutdown.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -154,14 +117,43 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
|
||||||
/// Gets a brief summary of the configuration string format, in HTML. Returns <c>null</c> if no configuration is needed.
|
/// Gets a brief summary of the configuration string format, in HTML. Returns <c>null</c> if no configuration is needed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ConfigHelpHtml {
|
public string ConfigHelpHtml {
|
||||||
get {
|
get { return ConfigHelpHtmlValue; }
|
||||||
return ConfigHelpHtmlValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
/// <summary>
|
||||||
|
/// Specifies whether or not to execute Phase 1.
|
||||||
|
/// </summary>
|
||||||
|
public bool PerformPhase1 {
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
#region Private Methods
|
/// <summary>
|
||||||
|
/// Specifies whether or not to execute Phase 2.
|
||||||
|
/// </summary>
|
||||||
|
public bool PerformPhase2 {
|
||||||
|
get { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies whether or not to execute Phase 3.
|
||||||
|
/// </summary>
|
||||||
|
public bool PerformPhase3 {
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the execution priority of the provider (0 lowest, 100 highest).
|
||||||
|
/// </summary>
|
||||||
|
public int ExecutionPriority {
|
||||||
|
get { return 50; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Information about the Provider.
|
||||||
|
/// </summary>
|
||||||
|
public ComponentInformation Information {
|
||||||
|
get { return Info; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds and removes the first occurrence of the custom tag.
|
/// Finds and removes the first occurrence of the custom tag.
|
||||||
|
@ -186,22 +178,12 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
|
||||||
/// <returns>An html string that contains the tables to display the ticket information, or null</returns>
|
/// <returns>An html string that contains the tables to display the ticket information, or null</returns>
|
||||||
private string LoadUnfuddleTicketsFromWeb() {
|
private string LoadUnfuddleTicketsFromWeb() {
|
||||||
var xml = BuildXmlFromApiCalls();
|
var xml = BuildXmlFromApiCalls();
|
||||||
if(xml == null)
|
if(xml == null) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
var settings = new XsltSettings {
|
|
||||||
EnableScript = true,
|
|
||||||
EnableDocumentFunction = true
|
|
||||||
};
|
|
||||||
var xsl = new XslCompiledTransform(true);
|
|
||||||
using(var reader = XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("ScrewTurn.Wiki.Plugins.PluginPack.Resources.UnfuddleTickets.xsl"))) {
|
|
||||||
xsl.Load(reader, settings, new XmlUrlResolver());
|
|
||||||
}
|
|
||||||
|
|
||||||
string results;
|
string results;
|
||||||
using(var sw = new StringWriter()) {
|
using(var sw = new StringWriter()) {
|
||||||
using(var xnr = new XmlNodeReader(xml)) {
|
using(var xnr = new XmlNodeReader(xml)) {
|
||||||
xsl.Transform(xnr, null, sw);
|
_xslTransform.Transform(xnr, null, sw);
|
||||||
}
|
}
|
||||||
results = sw.ToString();
|
results = sw.ToString();
|
||||||
}
|
}
|
||||||
|
@ -285,8 +267,6 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
|
||||||
_host.LogEntry(message, LogEntryType.Warning, null, this);
|
_host.LogEntry(message, LogEntryType.Warning, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue