예제 #1
0
        public void SetAvatar(Upload avatar)
        {
            if ((avatar != null) && (avatar.size > Upload.AVATAR_MAX_FILESIZE))
            {
                throw new FLocalException("Avatar is too big (max. 80KB allowed)");
            }

            ChangeSetUtil.ApplyChanges(
                new UpdateChange(
                    TableSpec.instance,
                    new Dictionary <string, AbstractFieldValue> {
                { TableSpec.FIELD_AVATARID, new ScalarFieldValue((avatar != null) ? avatar.id.ToString() : null) },
            },
                    this.id
                    )
                );
        }
예제 #2
0
        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));
        }