TexCompiler implemented; UploadManager slight refactoring; Tex and Math UBBCodes implemented

main
Inga 🏳‍🌈 14 years ago
parent 228d002877
commit 4693392a61
  1. 2
      Builder/IISMainHandler/build.txt
  2. 10
      Builder/IISMainHandler/product.wxs
  3. 21
      Common/BBCodes/Math.cs
  4. 21
      Common/BBCodes/Tex.cs
  5. 19
      Common/BBCodes/helpers/TexProcessor.cs
  6. 7
      Common/Common.csproj
  7. 2
      Common/UBBParser.cs
  8. 15
      Common/UploadManager.cs
  9. 8
      FLocal.sln
  10. 7
      IISMainHandler/handlers/request/UploadHandler.cs
  11. 6
      IISMainHandler/handlers/request/avatars/AddHandler.cs
  12. 59
      TexCompiler/Compiler.cs
  13. 36
      TexCompiler/Properties/AssemblyInfo.cs
  14. 63
      TexCompiler/TexCompiler.csproj

@ -72,6 +72,12 @@
<Component Id="PJonDevelopment.BBCode.pdb" Guid="EFFBA1FA-A3A8-4D20-8894-AFD255B9F00{targetId}">
<File Id="PJonDevelopment.BBCode.pdb" Source="..\..\ThirdParty\BBCode\bin\Release\PJonDevelopment.BBCode.pdb" KeyPath="yes" Checksum="yes"/>
</Component>
<Component Id="TexCompiler.dll" Guid="6FD050AF-61D7-4BFF-B206-A4420A83FB5{targetId}">
<File Id="TexCompiler.dll" Source="..\..\TexCompiler\bin\Release\TexCompiler.dll" KeyPath="yes" Checksum="yes"/>
</Component>
<Component Id="TexCompiler.pdb" Guid="707304A1-9774-446F-B672-FA25EAD8E4F{targetId}">
<File Id="TexCompiler.pdb" Source="..\..\TexCompiler\bin\Release\TexCompiler.pdb" KeyPath="yes" Checksum="yes"/>
</Component>
<!--Component Id="MySql.Data.dll" Guid="90646729-6B21-4BEE-94C3-F39F5288EFB{targetId}">
<File Id="MySql.Data.dll" Source="..\..\ThirdParty\mysql-connector-net-6.2.3\MySql.Data\Provider\bin\Release\MySql.Data.dll" KeyPath="yes" Checksum="yes"/>
</Component>
@ -116,6 +122,10 @@
<ComponentRef Id='MySQLConnector.dll' />
<ComponentRef Id='MySQLConnector.pdb' />
</Feature>
<Feature Id='TexCompiler' Title='Compiler of TeX code' Level='1'>
<ComponentRef Id='TexCompiler.dll' />
<ComponentRef Id='TexCompiler.pdb' />
</Feature>
<Feature Id='ThirdParty' Title='ThirdParty libraries/tools' Level='1'>
<Feature Id='NConsoler' Title='NConsoler' Level='1'>
<ComponentRef Id='NConsoler.dll' />

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class Math : BBCode {
public Math()
: base("math") {
}
public override string Format(ITextFormatter formatter) {
string tex = "$$" + this.InnerBBCode + "$$";
var upload = helpers.TexProcessor.getCompiled(tex);
return "<f:img><f:src>/Upload/Item/" + upload.id.ToString() + "/</f:src><f:alt>" + this.Safe(tex) + "</f:alt></f:img>";
}
}
}

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJonDevelopment.BBCode;
namespace FLocal.Common.BBCodes {
class Tex : BBCode {
public Tex()
: base("tex") {
}
public override string Format(ITextFormatter formatter) {
string tex = this.InnerBBCode;
var upload = helpers.TexProcessor.getCompiled(tex);
return "<f:img><f:src>/Upload/Item/" + upload.id.ToString() + "/</f:src><f:alt>" + this.Safe(tex) + "</f:alt></f:img>";
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.TexCompiler;
using System.IO;
namespace FLocal.Common.BBCodes.helpers {
static class TexProcessor {
public static dataobjects.Upload getCompiled(string tex) {
dataobjects.User uploader = dataobjects.User.LoadByName("Mr. TeX compiler");
using(Stream stream = Compiler.GetPngStream(tex)) {
return UploadManager.SafeUploadFile(stream, "tex.png", uploader);
}
}
}
}

@ -65,10 +65,12 @@
<Compile Include="BBCodes\helpers\BBCode.cs" />
<Compile Include="BBCodes\Code.cs" />
<Compile Include="BBCodes\FUrl.cs" />
<Compile Include="BBCodes\helpers\TexProcessor.cs" />
<Compile Include="BBCodes\Image.cs" />
<Compile Include="BBCodes\List.cs" />
<Compile Include="BBCodes\ListElem.cs" />
<Compile Include="BBCodes\Lurk.cs" />
<Compile Include="BBCodes\Math.cs" />
<Compile Include="BBCodes\Poll.cs" />
<Compile Include="BBCodes\Post.cs" />
<Compile Include="BBCodes\Quote.cs" />
@ -76,6 +78,7 @@
<Compile Include="BBCodes\RuWiki.cs" />
<Compile Include="BBCodes\S.cs" />
<Compile Include="BBCodes\Spoiler.cs" />
<Compile Include="BBCodes\Tex.cs" />
<Compile Include="BBCodes\Thread.cs" />
<Compile Include="BBCodes\U.cs" />
<Compile Include="BBCodes\UploadImage.cs" />
@ -134,6 +137,10 @@
<Project>{E38DE5B1-F9C2-43BA-A5DF-0743ABD4DFC7}</Project>
<Name>MySQLConnector</Name>
</ProjectReference>
<ProjectReference Include="..\TexCompiler\TexCompiler.csproj">
<Project>{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}</Project>
<Name>TexCompiler</Name>
</ProjectReference>
<ProjectReference Include="..\ThirdParty\BBCode\BBCode.vbproj">
<Project>{ACDDD5D1-119F-4B82-8FE6-6515C812795B}</Project>
<Name>BBCode</Name>

@ -121,12 +121,14 @@ namespace FLocal.Common {
this.parser.ElementTypes.Add("image", typeof(BBCodes.Image), true);
this.parser.ElementTypes.Add("list", typeof(BBCodes.List), true);
this.parser.ElementTypes.Add("lurk", typeof(BBCodes.Lurk), true);
this.parser.ElementTypes.Add("math", typeof(BBCodes.Math), true);
this.parser.ElementTypes.Add("*", typeof(BBCodes.ListElem), false);
this.parser.ElementTypes.Add("poll", typeof(BBCodes.Poll), true);
this.parser.ElementTypes.Add("post", typeof(BBCodes.Post), true);
this.parser.ElementTypes.Add("quote", typeof(BBCodes.Quote), true);this.parser.ElementTypes.Add("q", typeof(BBCodes.Quote), true);
this.parser.ElementTypes.Add("s", typeof(BBCodes.S), true);
this.parser.ElementTypes.Add("spoiler", typeof(BBCodes.Spoiler), true);this.parser.ElementTypes.Add("cut", typeof(BBCodes.Spoiler), true);
this.parser.ElementTypes.Add("tex", typeof(BBCodes.Tex), true);
this.parser.ElementTypes.Add("thread", typeof(BBCodes.Thread), true);
this.parser.ElementTypes.Add("u", typeof(BBCodes.U), true);
this.parser.ElementTypes.Add("uploadimage", typeof(BBCodes.UploadImage), true);

@ -50,8 +50,9 @@ namespace FLocal.Common {
if(fileStream.Length > MAX_UPLOAD_FILESIZE) throw new FLocalException("File is too big");
byte[] data = new byte[fileStream.Length];
if(fileStream.Read(data, 0, (int)fileStream.Length) != fileStream.Length) {
throw new FLocalException("File is incomplete");
int readBytes = fileStream.Read(data, 0, (int)fileStream.Length);
if(readBytes != fileStream.Length) {
throw new FLocalException("File is incomplete (read " + readBytes + " of " + fileStream.Length + ")");
}
string file_md5 = Util.md5(fileStream);
@ -118,5 +119,15 @@ namespace FLocal.Common {
return Upload.LoadById(uploadId.Value);
}
public static Upload SafeUploadFile(Stream fileStream, string filename, User uploader) {
Upload upload;
try {
upload = UploadManager.UploadFile(fileStream, filename, DateTime.Now, uploader, null);
} catch(UploadManager.AlreadyUploadedException e) {
upload = Upload.LoadById(e.uploadId);
}
return upload;
}
}
}

@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IISUploadHandler", "IISUplo
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "BBCode", "ThirdParty\BBCode\BBCode.vbproj", "{ACDDD5D1-119F-4B82-8FE6-6515C812795B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TexCompiler", "TexCompiler\TexCompiler.csproj", "{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -89,6 +91,12 @@ Global
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Release|Any CPU.Build.0 = Release|Any CPU
{ACDDD5D1-119F-4B82-8FE6-6515C812795B}.Release|x86.ActiveCfg = Release|Any CPU
{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Debug|x86.ActiveCfg = Debug|Any CPU
{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Release|Any CPU.Build.0 = Release|Any CPU
{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -24,12 +24,7 @@ namespace FLocal.IISHandler.handlers.request {
HttpPostedFile file = context.httprequest.Files["file"];
if(file == null) throw new FLocalException("file not uploaded");
if(file.ContentLength != file.InputStream.Length) throw new FLocalException("file is not uploaded completely");
Upload upload;
try {
upload = UploadManager.UploadFile(file.InputStream, System.IO.Path.GetFileName(file.FileName), DateTime.Now, context.session.account.user, null);
} catch(UploadManager.AlreadyUploadedException e) {
upload = Upload.LoadById(e.uploadId);
}
Upload upload = UploadManager.SafeUploadFile(file.InputStream, System.IO.Path.GetFileName(file.FileName), context.session.account.user);
return new XElement[] {
new XElement("uploadedId", upload.id)
};

@ -25,11 +25,7 @@ namespace FLocal.IISHandler.handlers.request.avatars {
if(context.httprequest.Files["file"] != null && context.httprequest.Files["file"].ContentLength > 0) {
HttpPostedFile file = context.httprequest.Files["file"];
if(file.ContentLength != file.InputStream.Length) throw new FLocalException("file is not uploaded completely");
try {
upload = UploadManager.UploadFile(file.InputStream, System.IO.Path.GetFileName(file.FileName), DateTime.Now, context.session.account.user, null);
} catch(UploadManager.AlreadyUploadedException e) {
upload = Upload.LoadById(e.uploadId);
}
upload = UploadManager.SafeUploadFile(file.InputStream, System.IO.Path.GetFileName(file.FileName), context.session.account.user);
} else {
upload = Upload.LoadById(int.Parse(context.httprequest.Form["uploadId"]));
}

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Web;
namespace FLocal.TexCompiler {
public static class Compiler {
private static readonly Encoding ENCODING = Encoding.UTF8;
/// <summary>
/// http://msdn.microsoft.com/en-us/library/system.io.stream.write.aspx
/// </summary>
private static void CopyTo(this Stream input, Stream output) {
const int size = 4096;
byte[] bytes = new byte[4096];
int numBytes;
while((numBytes = input.Read(bytes, 0, size)) > 0) {
output.Write(bytes, 0, numBytes);
}
}
public static Stream GetPngStream(string tex) {
Dictionary<string, string> postData = new Dictionary<string,string> {
{ "dev", "png16m" },
{ "template", "textutf8" },
{ "src", tex },
};
string post = string.Join("&", (from kvp in postData select string.Format("{0}={1}", HttpUtility.UrlEncode(kvp.Key, ENCODING), HttpUtility.UrlEncode(kvp.Value, ENCODING))).ToArray());
byte[] postBytes = Encoding.ASCII.GetBytes(post);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://sciencesoft.at/image/latexurl/img.png");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
request.ContentLength = postBytes.Length;
using(Stream stream = request.GetRequestStream()) {
stream.Write(postBytes, 0, postBytes.Length);
}
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
try {
MemoryStream memoryStream = new MemoryStream();
using(Stream responseStream = response.GetResponseStream()) {
responseStream.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
} finally {
response.Close();
}
}
}
}
}

@ -0,0 +1,36 @@
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("TexCompiler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("TexCompiler")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 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("870c99b5-cc00-4b9e-946c-55556ec15f3f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,63 @@
<?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>{7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FLocal.TexCompiler</RootNamespace>
<AssemblyName>TexCompiler</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>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Net">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Web" />
<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="Compiler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</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>
Loading…
Cancel
Save