示例#1
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public Error.Types UpdateSiteImage(byte[] data)
        {
            BinaryType = "SiteImage";
            var imageData = new Libraries.Images.ImageData(
                data,
                ReferenceId,
                Libraries.Images.ImageData.Types.SiteImage);

            switch (Parameters.BinaryStorage.Provider)
            {
            case "Local": imageData.WriteToLocal(); break;

            default:
                Bin       = imageData.ReSizeBytes(Libraries.Images.ImageData.SizeTypes.Regular);
                Thumbnail = imageData.ReSizeBytes(
                    Libraries.Images.ImageData.SizeTypes.Thumbnail);
                Icon = imageData.ReSizeBytes(Libraries.Images.ImageData.SizeTypes.Icon);
                Rds.ExecuteNonQuery(transactional: true, statements:
                                    Rds.UpdateOrInsertBinaries(
                                        selectIdentity: true,
                                        where : Rds.BinariesWhere()
                                        .ReferenceId(ReferenceId)
                                        .BinaryType("SiteImage"),
                                        param: Rds.BinariesParamDefault(this, setDefault: true)));
                break;
            }
            return(Error.Types.None);
        }
示例#2
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public Error.Types UpdateSiteImage(Context context, byte[] bin)
        {
            BinaryType = "SiteImage";
            var imageData = new Libraries.Images.ImageData(
                bin,
                ReferenceId,
                Libraries.Images.ImageData.Types.SiteImage);

            switch (Parameters.BinaryStorage.Provider)
            {
            case "Local": imageData.WriteToLocal(); break;

            default:
                Bin       = imageData.ReSizeBytes(Libraries.Images.ImageData.SizeTypes.Regular);
                Thumbnail = imageData.ReSizeBytes(
                    Libraries.Images.ImageData.SizeTypes.Thumbnail);
                Icon        = imageData.ReSizeBytes(Libraries.Images.ImageData.SizeTypes.Icon);
                ContentType = "image/png";
                Repository.ExecuteNonQuery(
                    context: context,
                    transactional: true,
                    statements: Rds.UpdateOrInsertBinaries(
                        where : Rds.BinariesWhere()
                        .ReferenceId(ReferenceId)
                        .BinaryType("SiteImage"),
                        param: Rds.BinariesParamDefault(
                            context: context,
                            binaryModel: this,
                            setDefault: true)));
                break;
            }
            return(Error.Types.None);
        }
        /// <summary>
        /// Fixed:
        /// </summary>
        public Error.Types UpdateTenantImage(IContext context, byte[] bin)
        {
            BinaryType = "TenantImage";
            var imageData = new Libraries.Images.ImageData(
                bin,
                ReferenceId,
                Libraries.Images.ImageData.Types.TenantImage);

            switch (Parameters.BinaryStorage.Provider)
            {
            case "Local": imageData.WriteToLocal(); break;

            default:
                Bin = imageData.ReSizeBytes(Libraries.Images.ImageData.SizeTypes.Logo);
                Rds.ExecuteNonQuery(
                    context: context,
                    transactional: true,
                    statements: Rds.UpdateOrInsertBinaries(
                        where : Rds.BinariesWhere()
                        .ReferenceId(ReferenceId)
                        .BinaryType("TenantImage"),
                        param: Rds.BinariesParamDefault(
                            context: context,
                            binaryModel: this,
                            setDefault: true)));
                break;
            }
            return(Error.Types.None);
        }
示例#4
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UploadImage(Context context, long id)
        {
            var invalid = BinaryValidators.OnUploadingImage(context: context);

            switch (invalid)
            {
            case Error.Types.OverTenantStorageSize:
                return(Messages.ResponseOverTenantStorageSize(
                           context: context,
                           data: context.ContractSettings.StorageSize.ToString()).ToJson());

            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            var file       = context.PostedFiles.FirstOrDefault();
            var bin        = file.Byte();
            var columnName = context.Forms.Data("ControlId");

            if (columnName.Contains("_"))
            {
                columnName = columnName.Substring(columnName.IndexOf("_") + 1);
            }
            if (columnName.StartsWith("Comment"))
            {
                columnName = "Comments";
            }
            var ss = new ItemModel(
                context: context,
                referenceId: id)
                     .GetSite(
                context: context,
                initSiteSettings: true)
                     .SiteSettings;
            var thumbnailLimitSize = ss.GetColumn(
                context: context,
                columnName: columnName)?.ThumbnailLimitSize
                                     ?? Parameters.BinaryStorage.ThumbnailLimitSize;
            var imageData = new Libraries.Images.ImageData(
                bin,
                ss.ReferenceId,
                Libraries.Images.ImageData.Types.SiteImage);

            if (Parameters.BinaryStorage.ImageLimitSize?.ToInt() > 0)
            {
                bin = imageData.ReSizeBytes(Parameters.BinaryStorage.ImageLimitSize);
            }
            var thumbnail = thumbnailLimitSize > 0
                ? imageData.ReSizeBytes(thumbnailLimitSize)
                : null;

            if (Parameters.BinaryStorage.IsLocal())
            {
                bin.Write(System.IO.Path.Combine(
                              Directories.BinaryStorage(),
                              "Images",
                              file.Guid));
                if (thumbnailLimitSize > 0)
                {
                    thumbnail.Write(System.IO.Path.Combine(
                                        Directories.BinaryStorage(),
                                        "Images",
                                        file.Guid + "_thumbnail"));
                }
            }
            Repository.ExecuteNonQuery(
                context: context,
                statements: Rds.InsertBinaries(
                    param: Rds.BinariesParam()
                    .TenantId(context.TenantId)
                    .ReferenceId(id)
                    .Guid(file.Guid)
                    .BinaryType("Images")
                    .Title(file.FileName)
                    .Bin(bin, _using: !Parameters.BinaryStorage.IsLocal())
                    .Thumbnail(thumbnail, _using: thumbnail != null)
                    .FileName(file.FileName)
                    .Extension(file.Extension)
                    .Size(file.Size)
                    .ContentType(file.ContentType)));
            return(new ResponseCollection()
                   .InsertText(
                       "#" + context.Forms.ControlId(),
                       "![image]({0})".Params(Locations.ShowFile(
                                                  context: context,
                                                  guid: file.Guid)))
                   .ToJson());
        }