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:
parent
0a54e553cc
commit
c89e576368
26 changed files with 905 additions and 936 deletions
147
MultilanguageContentPlugin/MultilanguageContentPlugin.cs
Normal file
147
MultilanguageContentPlugin/MultilanguageContentPlugin.cs
Normal file
|
@ -0,0 +1,147 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using ScrewTurn.Wiki.PluginFramework;
|
||||
|
||||
namespace ScrewTurn.Wiki.Plugins.PluginPack {
|
||||
|
||||
/// <summary>
|
||||
/// Implements a Formatter Provider that allows to write multi-language content in Wiki Pages.
|
||||
/// </summary>
|
||||
public class MultilanguageContentPlugin : IFormatterProviderV30 {
|
||||
|
||||
private IHostV30 host;
|
||||
private string config;
|
||||
private ComponentInformation info = new ComponentInformation("Multilanguage Content Plugin", "Threeplicate Srl", "3.0.1.472", "http://www.screwturn.eu", "http://www.screwturn.eu/Version/PluginPack/Multilanguage2.txt");
|
||||
|
||||
private string defaultLanguage = "en-us";
|
||||
private bool displayWarning = false;
|
||||
|
||||
private const string DivStyle = "padding: 2px; margin-bottom: 10px; font-size: 11px; background-color: #FFFFC4; border: solid 1px #DDDDDD;";
|
||||
private const string StandardMessage = @"<div style=""" + DivStyle + @""">The content of this Page is localized in your language. To change the language settings, please go to the <a href=""Language.aspx"">Language Selection</a> page.</div>";
|
||||
private const string NotLocalizedMessage = @"<div style=""" + DivStyle + @""">The content of this Page is <b>not</b> available in your language, and it is displayed in the default language of the Wiki. To change the language settings, please go to the <a href=""Language.aspx"">Language Selection</a> page.</div>";
|
||||
|
||||
/// <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 false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether or not to execute Phase 3.
|
||||
/// </summary>
|
||||
public bool PerformPhase3 {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
/// <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) {
|
||||
string result = ExtractLocalizedContent(context.Language, raw); // Try to load localized content
|
||||
bool notLocalized = false;
|
||||
bool noLocalization = false;
|
||||
if(result == null) {
|
||||
result = ExtractLocalizedContent(defaultLanguage, raw); // Load content in the default language
|
||||
notLocalized = true;
|
||||
noLocalization = false;
|
||||
}
|
||||
if(result == null) {
|
||||
result = raw; // The Page is not localized, return all the content
|
||||
notLocalized = false;
|
||||
noLocalization = true;
|
||||
}
|
||||
if(displayWarning && !noLocalization && context.Page != null) {
|
||||
if(notLocalized) return NotLocalizedMessage + result;
|
||||
else return StandardMessage + result;
|
||||
}
|
||||
else return result;
|
||||
}
|
||||
|
||||
private string ExtractLocalizedContent(string language, string content) {
|
||||
string head = "\\<" + language + "\\>", tail = "\\<\\/" + language + "\\>";
|
||||
Regex regex = new Regex(head + "(.+?)" + tail, RegexOptions.IgnoreCase | RegexOptions.Singleline);
|
||||
Match match = regex.Match(content);
|
||||
StringBuilder sb = new StringBuilder(1000);
|
||||
while(match.Success) {
|
||||
sb.Append(match.Groups[1].Value);
|
||||
match = regex.Match(content, match.Index + match.Length);
|
||||
}
|
||||
if(sb.Length > 0) return sb.ToString();
|
||||
else return null;
|
||||
}
|
||||
|
||||
/// <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) {
|
||||
this.host = host;
|
||||
this.config = config != null ? config : "";
|
||||
defaultLanguage = host.GetSettingValue(SettingName.DefaultLanguage);
|
||||
displayWarning = config.ToLowerInvariant().Equals("display warning");
|
||||
}
|
||||
|
||||
/// <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 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) {
|
||||
string result = ExtractLocalizedContent(context.Language, title); // Try to load localized content
|
||||
if(context.ForIndexing || result == null) {
|
||||
result = ExtractLocalizedContent(defaultLanguage, title); // Load content in the default language
|
||||
}
|
||||
if(result == null) {
|
||||
result = title; // The Page is not localized, return all the content
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <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 "Specify 'display warning' to notify the user of the available content languages."; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
72
MultilanguageContentPlugin/MultilanguageContentPlugin.csproj
Normal file
72
MultilanguageContentPlugin/MultilanguageContentPlugin.csproj
Normal 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>{94DDE3D4-0595-405C-9EA6-358B74EC6BC5}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ScrewTurn.Wiki.Plugins.PluginPack</RootNamespace>
|
||||
<AssemblyName>MultilanguageContentPlugin</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\MultilanguageContentPlugin.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\MultilanguageContentPlugin.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="MultilanguageContentPlugin.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>
|
18
MultilanguageContentPlugin/Properties/AssemblyInfo.cs
Normal file
18
MultilanguageContentPlugin/Properties/AssemblyInfo.cs
Normal 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 Multilanguage Content 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("d39feb9c-97b6-4a10-b5fe-91c1eec36e55")]
|
Loading…
Add table
Add a link
Reference in a new issue