TexImage caching implemented

main
Inga 🏳‍🌈 14 years ago
parent 6daac40d29
commit 489fbd1723
  1. 2
      Builder/IISMainHandler/build.txt
  2. 5
      Common/BBCodes/helpers/TexProcessor.cs
  3. 1
      Common/Common.csproj
  4. 1
      Common/TableManager.cs
  5. 1
      Common/actions/ChangeSet.cs
  6. 108
      Common/dataobjects/TexImage.cs
  7. 2
      TexCompiler/Compiler.cs

@ -9,10 +9,7 @@ namespace FLocal.Common.BBCodes.helpers {
static class TexProcessor { static class TexProcessor {
public static dataobjects.Upload getCompiled(string tex) { public static dataobjects.Upload getCompiled(string tex) {
dataobjects.User uploader = dataobjects.User.LoadByName("Mr. TeX compiler"); return dataobjects.TexImage.Save(tex).upload;
using(Stream stream = Compiler.GetPngStream(tex)) {
return UploadManager.SafeUploadFile(stream, "tex.png", uploader);
}
} }
} }

@ -111,6 +111,7 @@
<Compile Include="dataobjects\Revision.cs" /> <Compile Include="dataobjects\Revision.cs" />
<Compile Include="dataobjects\Session.cs" /> <Compile Include="dataobjects\Session.cs" />
<Compile Include="dataobjects\Skin.cs" /> <Compile Include="dataobjects\Skin.cs" />
<Compile Include="dataobjects\TexImage.cs" />
<Compile Include="dataobjects\Thread.cs" /> <Compile Include="dataobjects\Thread.cs" />
<Compile Include="dataobjects\Upload.cs" /> <Compile Include="dataobjects\Upload.cs" />
<Compile Include="dataobjects\User.cs" /> <Compile Include="dataobjects\User.cs" />

@ -30,6 +30,7 @@ namespace FLocal.Common {
dataobjects.Revision.TableSpec.instance, dataobjects.Revision.TableSpec.instance,
dataobjects.Session.TableSpec.instance, dataobjects.Session.TableSpec.instance,
dataobjects.Skin.TableSpec.instance, dataobjects.Skin.TableSpec.instance,
dataobjects.TexImage.TableSpec.instance,
dataobjects.Thread.TableSpec.instance, dataobjects.Thread.TableSpec.instance,
dataobjects.Upload.TableSpec.instance, dataobjects.Upload.TableSpec.instance,
dataobjects.User.TableSpec.instance, dataobjects.User.TableSpec.instance,

@ -39,6 +39,7 @@ namespace FLocal.Common.actions {
dataobjects.Punishment.TableSpec.TABLE, dataobjects.Punishment.TableSpec.TABLE,
dataobjects.PunishmentTransfer.TableSpec.TABLE, dataobjects.PunishmentTransfer.TableSpec.TABLE,
dataobjects.PunishmentLayerChange.TableSpec.TABLE, dataobjects.PunishmentLayerChange.TableSpec.TABLE,
dataobjects.TexImage.TableSpec.TABLE,
dataobjects.Session.TableSpec.TABLE, dataobjects.Session.TableSpec.TABLE,
} }
); );

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using FLocal.Core;
using FLocal.Core.DB;
using FLocal.Core.DB.conditions;
using FLocal.Common.actions;
using FLocal.TexCompiler;
namespace FLocal.Common.dataobjects {
public class TexImage : SqlObject<TexImage> {
public class TableSpec : ISqlObjectTableSpec {
public const string TABLE = "TexImages";
public const string FIELD_ID = "Id";
public const string FIELD_HASH = "MD5";
public const string FIELD_TEXT = "Text";
public const string FIELD_UPLOADID = "UploadId";
public static readonly TableSpec instance = new TableSpec();
public string name { get { return TABLE; } }
public string idName { get { return FIELD_ID; } }
public void refreshSqlObject(int id) { Refresh(id); }
}
protected override ISqlObjectTableSpec table { get { return TableSpec.instance; } }
private string _hash;
public string hash {
get {
this.LoadIfNotLoaded();
return this._hash;
}
}
private string _text;
public string text {
get {
this.LoadIfNotLoaded();
return this._text;
}
}
private int _uploadId;
public int uploadId {
get {
this.LoadIfNotLoaded();
return this._uploadId;
}
}
public Upload upload {
get {
return Upload.LoadById(this.uploadId);
}
}
protected override void doFromHash(Dictionary<string, string> data) {
this._hash = data[TableSpec.FIELD_HASH];
this._text = data[TableSpec.FIELD_TEXT];
this._uploadId = int.Parse(data[TableSpec.FIELD_UPLOADID]);
}
public XElement exportToXml(UserContext context) {
return new XElement("texImage",
new XElement("id", this.id),
new XElement("hash", this.hash),
new XElement("text", this.text),
this.upload.exportToXml(context)
);
}
public static TexImage Save(string text) {
string hash = Util.md5(text);
try {
return TexImage.LoadById(
int.Parse(
Config.instance.mainConnection.LoadIdByField(
TableSpec.instance.getColumnSpec(TableSpec.FIELD_HASH),
hash
)
)
);
} catch(NotFoundInDBException) {
}
User uploader = User.LoadByName("Mr. TeX compiler");
Upload file = UploadManager.SafeUploadFile(Compiler.GetPngStream(text), "tex-" + hash + ".png", uploader);
InsertOrUpdateChange change = new InsertOrUpdateChange(
TableSpec.instance,
new Dictionary<string,AbstractFieldValue> {
{ TableSpec.FIELD_HASH, new ScalarFieldValue(hash) },
{ TableSpec.FIELD_TEXT, new ScalarFieldValue(text) },
{ TableSpec.FIELD_UPLOADID, new ScalarFieldValue(file.id.ToString()) },
},
new Dictionary<string,AbstractFieldValue>(),
new ComparisonCondition(
TableSpec.instance.getColumnSpec(TableSpec.FIELD_HASH),
ComparisonType.EQUAL,
hash
)
);
ChangeSetUtil.ApplyChanges(change);
return TexImage.LoadById(change.getId().Value);
}
}
}

@ -23,7 +23,7 @@ namespace FLocal.TexCompiler {
} }
} }
public static Stream GetPngStream(string tex) { public static MemoryStream GetPngStream(string tex) {
Dictionary<string, string> postData = new Dictionary<string,string> { Dictionary<string, string> postData = new Dictionary<string,string> {
{ "dev", "png16m" }, { "dev", "png16m" },

Loading…
Cancel
Save