Fixed and closed #494: PluginPack now compiled as separate assemblies. Also implemented Updater plugin to silently replace PluginPack.dll with new DLLs.

This commit is contained in:
Dario Solera 2010-05-02 09:13:57 +00:00
parent 0a54e553cc
commit c89e576368
26 changed files with 905 additions and 936 deletions

View file

@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScrewTurn.Wiki.PluginFramework;
using System.Text.RegularExpressions;
namespace ScrewTurn.Wiki.Plugins.PluginPack {
/// <summary>
/// Implements a footnotes plugin.
/// </summary>
public class Footnotes : IFormatterProviderV30 {
// Kindly contributed by Jens Felsner
private static readonly ComponentInformation info = new ComponentInformation("Footnotes Plugin", "Threeplicate Srl", "3.0.1.472", "http://www.screwturn.eu", "http://www.screwturn.eu/Version/PluginPack/Footnotes2.txt");
private static readonly Regex ReferencesRegex = new Regex("(<[ ]*references[ ]*/[ ]*>|<[ ]*references[ ]*>.*?<[ ]*/[ ]*references[ ]*>)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex RefRegex = new Regex("<[ ]*ref[ ]*>.*?<[ ]*/[ ]*ref[ ]*>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex RefRemovalRegex = new Regex("(<[ ]*ref[ ]*>|<[ ]*/[ ]*ref[ ]*>)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private IHostV30 host = null;
private string config = "";
/// <summary>
/// Initializes the Storage Provider.
/// </summary>
/// <param name="host">The Host of the Component.</param>
/// <param name="config">The Configuration data, if any.</param>
/// <exception cref="ArgumentNullException">If <paramref name="host"/> or <paramref name="config"/> are <c>null</c>.</exception>
/// <exception cref="InvalidConfigurationException">If <paramref name="config"/> is not valid or is incorrect.</exception>
public void Init(IHostV30 host, string config) {
this.host = host;
this.config = config != null ? config : "";
}
// Replaces the first occurence of 'find' in 'input' with 'replace'
private static string ReplaceFirst(string input, string find, string replace) {
return input.Substring(0, input.IndexOf(find)) + replace + input.Substring(input.IndexOf(find) + find.Length);
}
/// <summary>
/// Performs a Formatting phase.
/// </summary>
/// <param name="raw">The raw content to Format.</param>
/// <param name="context">The Context information.</param>
/// <param name="phase">The Phase.</param>
/// <returns>The Formatted content.</returns>
public string Format(string raw, ContextInformation context, FormattingPhase phase) {
// Match all <ref>*</ref>
MatchCollection mc = RefRegex.Matches(raw);
// No ref-tag found, nothing to do
if(mc.Count == 0) return raw;
// No references tag
if(ReferencesRegex.Matches(raw).Count == 0) {
return raw + "<br/><span style=\"color: #FF0000;\">Reference Error! Missing element &lt;references/&gt;</span>";
}
string output = raw;
string ref_string = "<table class=\"footnotes\">";
int footnoteCounter = 0;
// For each <ref>...</ref> replace it with Footnote, append it to ref-section
foreach(Match m in mc) {
footnoteCounter++;
output = ReplaceFirst(output, m.Value, "<a id=\"refnote" + footnoteCounter.ToString() + "\" href=\"#footnote" + footnoteCounter.ToString() + "\"><sup>" + footnoteCounter.ToString() + "</sup></a>");
ref_string += "<tr><td><a id=\"footnote" + footnoteCounter.ToString() + "\" href=\"#refnote" + footnoteCounter.ToString() + "\"><sup>" + footnoteCounter.ToString() + "</sup></a></td><td>" + RefRemovalRegex.Replace(m.Value, "") + "</td></tr>";
}
ref_string += "</table>";
// Replace <reference/> with ref-section
output = ReferencesRegex.Replace(output, ref_string);
return output;
}
#region IFormatterProviderV30 Member
/// <summary>
/// Specifies whether or not to execute Phase 1.
/// </summary>
public bool PerformPhase1 {
get { return false; }
}
/// <summary>
/// Specifies whether or not to execute Phase 2.
/// </summary>
public bool PerformPhase2 {
get { return true; }
}
/// <summary>
/// Specifies whether or not to execute Phase 3.
/// </summary>
public bool PerformPhase3 {
get { return false; }
}
/// <summary>
/// Gets the execution priority of the provider (0 lowest, 100 highest).
/// </summary>
public int ExecutionPriority {
get { return 50; }
}
/// <summary>
/// Prepares the title of an item for display (always during phase 3).
/// </summary>
/// <param name="title">The input title.</param>
/// <param name="context">The context information.</param>
/// <returns>The prepared title (no markup allowed).</returns>
public string PrepareTitle(string title, ContextInformation context) {
return title;
}
#endregion
#region IProviderV30 Member
/// <summary>
/// Method invoked on shutdown.
/// </summary>
/// <remarks>This method might not be invoked in some cases.</remarks>
public void Shutdown() {
}
/// <summary>
/// Gets the Information about the Provider.
/// </summary>
public ComponentInformation Information {
get { return info; }
}
/// <summary>
/// Gets a brief summary of the configuration string format, in HTML. Returns <c>null</c> if no configuration is needed.
/// </summary>
public string ConfigHelpHtml {
get { return null; }
}
#endregion
}
}

View file

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B7EE7C86-5031-40EB-B06C-DF5B3564BE17}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ScrewTurn.Wiki.Plugins.PluginPack</RootNamespace>
<AssemblyName>FootnotesPlugin</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Debug\FootnotesPlugin.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Release\FootnotesPlugin.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\AssemblyVersion.cs">
<Link>AssemblyVersion.cs</Link>
</Compile>
<Compile Include="Footnotes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PluginFramework\PluginFramework.csproj">
<Project>{531A83D6-76F9-4014-91C5-295818E2D948}</Project>
<Name>PluginFramework</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,18 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ScrewTurn Wiki Footnotes Plugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f40e7384-f5cf-4ba4-b05e-a4efb5596a1f")]