コード例 #1
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string DeleteSiteImage(SiteModel siteModel)
        {
            siteModel.SiteSettings = SiteSettingsUtilities.Get(siteModel, siteModel.SiteId);
            var invalid = BinaryValidators.OnDeletingSiteImage(siteModel.SiteSettings);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var error = new BinaryModel(siteModel.SiteId).DeleteSiteImage();

            if (error.Has())
            {
                return(error.MessageJson());
            }
            else
            {
                return(new ResponseCollection()
                       .Html(
                           "#SiteImageIconContainer",
                           new HtmlBuilder().SiteImageIcon(
                               ss: siteModel.SiteSettings,
                               siteId: siteModel.SiteId))
                       .Html(
                           "#SiteImageSettingsEditor",
                           new HtmlBuilder().SiteImageSettingsEditor(
                               ss: siteModel.SiteSettings))
                       .Message(Messages.FileDeleteCompleted())
                       .ToJson());
            }
        }
コード例 #2
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static bool ExistsTenantImage(
            Context context,
            SiteSettings ss,
            long referenceId,
            Libraries.Images.ImageData.SizeTypes sizeType)
        {
            var invalid = BinaryValidators.OnGetting(
                context: context,
                ss: ss);

            switch (invalid.Type)
            {
            case Error.Types.None: break;

            default: return(false);
            }
            switch (Parameters.BinaryStorage.Provider)
            {
            case "Local":
                return(new Libraries.Images.ImageData(
                           referenceId, Libraries.Images.ImageData.Types.TenantImage)
                       .Exists(sizeType));

            default:
                return(Rds.ExecuteScalar_int(
                           context: context,
                           statements: Rds.SelectBinaries(
                               column: Rds.BinariesColumn().BinariesCount(),
                               where : Rds.BinariesWhere()
                               .ReferenceId(referenceId)
                               .BinaryType("TenantImage"))) == 1);
            }
        }
コード例 #3
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string DeleteTenantImage(Context context, TenantModel tenantModel)
        {
            var ss      = SiteSettingsUtilities.TenantsSiteSettings(context);
            var invalid = BinaryValidators.OnDeletingTenantImage(
                context: context,
                ss: ss);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            var error = new BinaryModel(tenantModel.TenantId)
                        .DeleteTenantImage(context: context);

            if (error.Has())
            {
                return(error.MessageJson(context: context));
            }
            else
            {
                return(new ResponseCollection()
                       .ReplaceAll(
                           "#Logo",
                           new HtmlBuilder().HeaderLogo(
                               context: context))
                       .ReplaceAll(
                           "#TenantImageSettingsEditor",
                           new HtmlBuilder().TenantImageSettingsEditor(
                               context: context, tenantModel: tenantModel))
                       .Message(Messages.FileDeleteCompleted(context: context))
                       .ToJson());
            }
        }
コード例 #4
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static (byte[] bytes, string contentType) TenantImageLogo(Context context, TenantModel tenantModel)
        {
            var ss      = SiteSettingsUtilities.TenantsSiteSettings(context);
            var invalid = BinaryValidators.OnGetting(
                context: context,
                ss: ss);

            switch (invalid.Type)
            {
            case Error.Types.None: break;

            default: return(null, null);
            }
            var binaryModel = new BinaryModel(
                context: context,
                referenceId: tenantModel.TenantId,
                binaryType: "TenantImage");

            return(
                binaryModel.TenantImage(
                    context: context,
                    sizeType: Libraries.Images.ImageData.SizeTypes.Logo,
                    column: Rds.BinariesColumn().Bin()),
                binaryModel.ContentType.IsNullOrEmpty()
                    ? "image/bmp"
                    : binaryModel.ContentType);
        }
コード例 #5
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static (byte[] bytes, string contentType) SiteImageIcon(Context context, SiteModel siteModel)
        {
            siteModel.SiteSettings = SiteSettingsUtilities.Get(
                context: context,
                siteModel: siteModel,
                referenceId: siteModel.SiteId);
            var invalid = BinaryValidators.OnGetting(
                context: context,
                ss: siteModel.SiteSettings);

            switch (invalid.Type)
            {
            case Error.Types.None: break;

            default: return(null, null);
            }
            var binaryModel = new BinaryModel(
                context: context,
                referenceId: siteModel.SiteId,
                binaryType: "SiteImage");

            return(
                binaryModel.SiteImage(
                    context: context,
                    sizeType: Libraries.Images.ImageData.SizeTypes.Icon,
                    column: Rds.BinariesColumn().Icon()),
                binaryModel.ContentType.IsNullOrEmpty()
                    ? "image/bmp"
                    : binaryModel.ContentType);
        }
コード例 #6
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string DeleteImage(Context context, string guid)
        {
            var binaryModel = new BinaryModel()
                              .Get(
                context: context,
                where : Rds.BinariesWhere()
                .TenantId(context.TenantId)
                .Guid(guid));
            var ss = new ItemModel(
                context: context,
                referenceId: binaryModel.ReferenceId)
                     .GetSite(
                context: context,
                initSiteSettings: true)
                     .SiteSettings;
            var invalid = BinaryValidators.OnDeletingImage(
                context: context,
                ss: ss,
                binaryModel: binaryModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            binaryModel.Delete(context: context);
            return(new ResponseCollection()
                   .Message(Messages.DeletedImage(context: context))
                   .Remove($"#ImageLib .item[data-id=\"{guid}\"]")
                   .ToJson());
        }
コード例 #7
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UploadImage(IContext context, long id)
        {
            var controlId = context.Forms.ControlId();
            var ss        = new ItemModel(
                context: context,
                referenceId: id).GetSite(
                context: context,
                initSiteSettings: true)
                            .SiteSettings;
            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();

            if (Parameters.BinaryStorage.IsLocal())
            {
                bin.Write(System.IO.Path.Combine(
                              Directories.BinaryStorage(),
                              "Images",
                              file.Guid));
            }
            else
            {
                Rds.ExecuteNonQuery(
                    context: context,
                    statements: Rds.InsertBinaries(
                        param: Rds.BinariesParam()
                        .TenantId(context.TenantId)
                        .ReferenceId(id)
                        .Guid(file.Guid)
                        .BinaryType("Images")
                        .Title(file.FileName)
                        .Bin(bin)
                        .FileName(file.FileName)
                        .Extension(file.Extension)
                        .Size(file.Size)
                        .ContentType(file.ContentType)));
            }
            var hb = new HtmlBuilder();

            return(new ResponseCollection()
                   .InsertText(
                       "#" + context.Forms.ControlId(),
                       "![image]({0})".Params(Locations.ShowFile(
                                                  context: context,
                                                  guid: file.Guid)))
                   .ToJson());
        }
コード例 #8
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UploadImage(
            Context context, System.Web.HttpPostedFileBase[] files, long id)
        {
            var controlId = Forms.ControlId();
            var ss        = new ItemModel(
                context: context,
                referenceId: id).GetSite(
                context: context,
                initSiteSettings: true)
                            .SiteSettings;
            var invalid = BinaryValidators.OnUploadingImage(
                context: context,
                files: files);

            switch (invalid)
            {
            case Error.Types.OverTenantStorageSize:
                return(Messages.ResponseOverTenantStorageSize(
                           Contract.TenantStorageSize(context: context).ToString()).ToJson());

            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var guid = Strings.NewGuid();
            var file = files[0];
            var size = file.ContentLength;
            var bin  = file.Byte();

            Rds.ExecuteNonQuery(
                context: context,
                statements: Rds.InsertBinaries(
                    param: Rds.BinariesParam()
                    .TenantId(context.TenantId)
                    .ReferenceId(id)
                    .Guid(guid)
                    .BinaryType("Images")
                    .Title(file.FileName)
                    .Bin(bin, _using: !Parameters.BinaryStorage.IsLocal())
                    .FileName(file.FileName)
                    .Extension(file.Extension())
                    .Size(size)
                    .ContentType(file.ContentType)));
            if (Parameters.BinaryStorage.IsLocal())
            {
                bin.Write(System.IO.Path.Combine(Directories.BinaryStorage(), "Images", guid));
            }
            var hb = new HtmlBuilder();

            return(new ResponseCollection()
                   .InsertText("#" + Forms.ControlId(), $"![image]({Locations.ShowFile(guid)})")
                   .ToJson());
        }
コード例 #9
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string MultiUpload(System.Web.HttpPostedFileBase[] files, long id)
        {
            var controlId   = Forms.ControlId();
            var ss          = new ItemModel(id).GetSite(initSiteSettings: true).SiteSettings;
            var column      = ss.GetColumn(Forms.Data("ColumnName"));
            var attachments = Forms.Data("AttachmentsData").Deserialize <Attachments>();
            var invalid     = BinaryValidators.OnUploading(column, attachments, files);

            switch (invalid)
            {
            case Error.Types.OverLimitQuantity:
                return(Messages.ResponseOverLimitQuantity(
                           column.LimitQuantity.ToString()).ToJson());

            case Error.Types.OverLimitSize:
                return(Messages.ResponseOverLimitSize(
                           column.LimitSize.ToString()).ToJson());

            case Error.Types.OverTotalLimitSize:
                return(Messages.ResponseOverTotalLimitSize(
                           column.TotalLimitSize.ToString()).ToJson());

            case Error.Types.OverTenantStorageSize:
                return(Messages.ResponseOverTenantStorageSize(
                           Contract.TenantStorageSize().ToString()).ToJson());

            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            files.ForEach(file => attachments.Add(new Attachment()
            {
                Guid        = file.WriteToTemp(),
                Name        = file.FileName.Split('\\').Last(),
                Size        = file.ContentLength,
                Extention   = file.Extension(),
                ContentType = file.ContentType,
                Added       = true,
                Deleted     = false
            }));
            var hb = new HtmlBuilder();

            return(new ResponseCollection()
                   .ReplaceAll($"#{controlId}Field", new HtmlBuilder()
                               .Field(
                                   ss: ss,
                                   column: column,
                                   value: attachments.ToJson(),
                                   columnPermissionType: column.ColumnPermissionType()))
                   .SetData("#" + controlId)
                   .ToJson());
        }
コード例 #10
0
        private static ErrorData OnAttaching(
            Context context, SiteSettings ss, IssueModel issueModel)
        {
            foreach (var column in ss.Columns.Where(o => o.TypeCs == "Attachments"))
            {
                if (issueModel.Attachments_Updated(
                        columnName: column.Name,
                        context: context,
                        column: column))
                {
                    var invalid = BinaryValidators.OnUploading(
                        context: context,
                        ss: ss,
                        attachmentsHash: issueModel.AttachmentsHash);
                    switch (invalid)
                    {
                    case Error.Types.OverLimitQuantity:
                        return(new ErrorData(
                                   type: Error.Types.OverLimitQuantity,
                                   data: column.LimitQuantity.ToInt().ToString()));

                    case Error.Types.OverLimitSize:
                        return(new ErrorData(
                                   type: Error.Types.OverLimitSize,
                                   data: column.LimitSize.ToInt().ToString()));

                    case Error.Types.OverTotalLimitSize:
                        return(new ErrorData(
                                   type: Error.Types.OverTotalLimitSize,
                                   data: column.TotalLimitSize.ToInt().ToString()));

                    case Error.Types.OverLocalFolderLimitSize:
                        return(new ErrorData(
                                   type: Error.Types.OverLocalFolderLimitSize,
                                   data: column.LocalFolderLimitSize.ToInt().ToString()));

                    case Error.Types.OverLocalFolderTotalLimitSize:
                        return(new ErrorData(
                                   type: Error.Types.OverLocalFolderTotalLimitSize,
                                   data: column.LocalFolderTotalLimitSize.ToInt().ToString()));

                    case Error.Types.OverTenantStorageSize:
                        return(new ErrorData(
                                   type: Error.Types.OverTenantStorageSize,
                                   data: context.ContractSettings.StorageSize.ToInt().ToString()));
                    }
                }
            }
            return(new ErrorData(type: Error.Types.None));
        }
コード例 #11
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static byte[] SiteImageIcon(SiteModel siteModel)
        {
            siteModel.SiteSettings = SiteSettingsUtilities.Get(siteModel, siteModel.SiteId);
            var invalid = BinaryValidators.OnGetting(siteModel.SiteSettings);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(null);
            }
            return(new BinaryModel(siteModel.SiteId).SiteImage(
                       Libraries.Images.ImageData.SizeTypes.Icon,
                       Rds.BinariesColumn().Icon()));
        }
コード例 #12
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string SiteImagePrefix(
            SiteSettings ss,
            long referenceId,
            Libraries.Images.ImageData.SizeTypes sizeType)
        {
            var invalid = BinaryValidators.OnGetting(ss);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(string.Empty);
            }
            return(new BinaryModel(referenceId).SiteImagePrefix(sizeType));
        }
コード例 #13
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UpdateSiteImage(Context context, SiteModel siteModel)
        {
            siteModel.SiteSettings = SiteSettingsUtilities.Get(
                context: context,
                siteModel: siteModel,
                referenceId: siteModel.SiteId);
            var bin     = context.PostedFiles.FirstOrDefault()?.Byte();
            var invalid = BinaryValidators.OnUploadingSiteImage(
                context: context,
                ss: siteModel.SiteSettings,
                bin: bin);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            var error = new BinaryModel(siteModel.SiteId).UpdateSiteImage(
                context: context,
                ss: siteModel.SiteSettings,
                bin: bin);

            if (error.Has())
            {
                return(error.MessageJson(context: context));
            }
            else
            {
                return(new ResponseCollection()
                       .Html(
                           "#TenantImageLogoContainer",
                           new HtmlBuilder().SiteImageIcon(
                               context: context,
                               ss: siteModel.SiteSettings,
                               siteId: siteModel.TenantId))
                       .Html(
                           "#TenantImageSettingsEditor",
                           new HtmlBuilder().SiteImageSettingsEditor(
                               context: context,
                               ss: siteModel.SiteSettings))
                       .Message(Messages.FileUpdateCompleted(context: context))
                       .ToJson());
            }
        }
コード例 #14
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static byte[] TenantImageLogo(Context context, TenantModel tenantModel)
        {
            var ss      = SiteSettingsUtilities.TenantsSiteSettings(context);
            var invalid = BinaryValidators.OnGetting(
                context: context,
                ss: ss);

            switch (invalid.Type)
            {
            case Error.Types.None: break;

            default: return(null);
            }
            return(new BinaryModel(tenantModel.TenantId).TenantImage(
                       context: context,
                       sizeType: Libraries.Images.ImageData.SizeTypes.Logo,
                       column: Rds.BinariesColumn().Bin()));
        }
コード例 #15
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UpdateSiteImage(Context context, SiteModel siteModel)
        {
            siteModel.SiteSettings = SiteSettingsUtilities.Get(
                context: context,
                siteModel: siteModel,
                referenceId: siteModel.SiteId);
            var file    = Forms.File(Libraries.Images.ImageData.Types.SiteImage.ToString());
            var invalid = BinaryValidators.OnUploadingSiteImage(
                context: context,
                ss: siteModel.SiteSettings,
                file: file);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var error = new BinaryModel(siteModel.SiteId).UpdateSiteImage(
                context: context, file: file);

            if (error.Has())
            {
                return(error.MessageJson());
            }
            else
            {
                return(new ResponseCollection()
                       .Html(
                           "#SiteImageIconContainer",
                           new HtmlBuilder().SiteImageIcon(
                               context: context,
                               ss: siteModel.SiteSettings,
                               siteId: siteModel.SiteId))
                       .Html(
                           "#SiteImageSettingsEditor",
                           new HtmlBuilder().SiteImageSettingsEditor(
                               context: context,
                               ss: siteModel.SiteSettings))
                       .Message(Messages.FileUpdateCompleted())
                       .ToJson());
            }
        }
コード例 #16
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string TenantImagePrefix(
            Context context,
            SiteSettings ss,
            long referenceId,
            Libraries.Images.ImageData.SizeTypes sizeType)
        {
            var invalid = BinaryValidators.OnGetting(
                context: context,
                ss: ss);

            switch (invalid.Type)
            {
            case Error.Types.None: break;

            default: return(string.Empty);
            }
            return(new BinaryModel(referenceId).TenantImagePrefix(
                       context: context,
                       sizeType: sizeType));
        }
コード例 #17
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static byte[] SiteImageIcon(Context context, SiteModel siteModel)
        {
            siteModel.SiteSettings = SiteSettingsUtilities.Get(
                context: context,
                siteModel: siteModel,
                referenceId: siteModel.SiteId);
            var invalid = BinaryValidators.OnGetting(
                context: context,
                ss: siteModel.SiteSettings);

            switch (invalid.Type)
            {
            case Error.Types.None: break;

            default: return(null);
            }
            return(new BinaryModel(siteModel.SiteId).SiteImage(
                       context: context,
                       sizeType: Libraries.Images.ImageData.SizeTypes.Icon,
                       column: Rds.BinariesColumn().Icon()));
        }
コード例 #18
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UploadImage(System.Web.HttpPostedFileBase[] files, long id)
        {
            var controlId = Forms.ControlId();
            var ss        = new ItemModel(id).GetSite(initSiteSettings: true).SiteSettings;
            var invalid   = BinaryValidators.OnUploadingImage(files);

            switch (invalid)
            {
            case Error.Types.OverTenantStorageSize:
                return(Messages.ResponseOverTenantStorageSize(
                           Contract.TenantStorageSize().ToString()).ToJson());

            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var guid = Strings.NewGuid();
            var file = files[0];

            Rds.ExecuteNonQuery(statements:
                                Rds.InsertBinaries(
                                    param: Rds.BinariesParam()
                                    .TenantId(Sessions.TenantId())
                                    .ReferenceId(id)
                                    .Guid(guid)
                                    .BinaryType("Image")
                                    .Title(file.FileName)
                                    .Bin(file.Byte())
                                    .FileName(file.FileName)
                                    .Extension(file.Extension())
                                    .Size(file.ContentLength)
                                    .ContentType(file.ContentType)));
            var hb = new HtmlBuilder();

            return(new ResponseCollection()
                   .InsertText("#" + Forms.ControlId(), $"![image]({Locations.ShowFile(guid)})")
                   .ToJson());
        }
コード例 #19
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UpdateSiteImage(SiteModel siteModel)
        {
            siteModel.SiteSettings = SiteSettingsUtilities.Get(siteModel, siteModel.SiteId);
            var invalid = BinaryValidators.OnUpdating(siteModel.SiteSettings);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var error = new BinaryModel(siteModel.SiteId).UpdateSiteImage(
                Forms.File(Libraries.Images.ImageData.Types.SiteImage.ToString()));

            if (error.Has())
            {
                return(error.MessageJson());
            }
            else
            {
                return(Messages.ResponseFileUpdateCompleted().ToJson());
            }
        }
コード例 #20
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string MultiUpload(IContext context, long id)
        {
            var controlId = context.Forms.ControlId();
            var ss        = new ItemModel(
                context: context,
                referenceId: id).GetSite(
                context: context,
                initSiteSettings: true)
                            .SiteSettings;
            var column = ss.GetColumn(
                context: context,
                columnName: context.Forms.Data("ColumnName"));
            var attachments = context.Forms.Data("AttachmentsData").Deserialize <Attachments>();
            var invalid     = BinaryValidators.OnUploading(
                context: context,
                column: column,
                attachments: attachments);

            switch (invalid)
            {
            case Error.Types.OverLimitQuantity:
                return(Messages.ResponseOverLimitQuantity(
                           context: context,
                           data: column.LimitQuantity.ToString()).ToJson());

            case Error.Types.OverLimitSize:
                return(Messages.ResponseOverLimitSize(
                           context: context,
                           data: column.LimitSize.ToString()).ToJson());

            case Error.Types.OverTotalLimitSize:
                return(Messages.ResponseOverTotalLimitSize(
                           context: context,
                           data: column.TotalLimitSize.ToString()).ToJson());

            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));
            }
            context.PostedFiles.ForEach(file => attachments.Add(new Attachment()
            {
                Guid        = file.Guid,
                Name        = file.FileName.Split(System.IO.Path.DirectorySeparatorChar).Last(),
                Size        = file.Size,
                Extention   = file.Extension,
                ContentType = file.ContentType,
                Added       = true,
                Deleted     = false
            }));
            var hb = new HtmlBuilder();

            return(new ResponseCollection()
                   .ReplaceAll($"#{controlId}Field", new HtmlBuilder()
                               .Field(
                                   context: context,
                                   ss: ss,
                                   column: column,
                                   value: attachments.ToJson(),
                                   columnPermissionType: column
                                   .ColumnPermissionType(context: context)))
                   .SetData("#" + controlId)
                   .ToJson());
        }
コード例 #21
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string MultiUpload(Context context, long id)
        {
            var controlId = context.Forms.ControlId();
            var ss        = new ItemModel(
                context: context,
                referenceId: id).GetSite(
                context: context,
                initSiteSettings: true)
                            .SiteSettings;
            var column = ss.GetColumn(
                context: context,
                columnName: context.Forms.Data("ColumnName"));
            var attachments = context.Forms.Data("AttachmentsData").Deserialize <Attachments>();
            var invalid     = BinaryValidators.OnUploading(
                context: context,
                column: column,
                attachments: attachments);

            switch (invalid)
            {
            case Error.Types.OverLimitQuantity:
                return(Messages.ResponseOverLimitQuantity(
                           context: context,
                           data: column.LimitQuantity.ToString()).ToJson());

            case Error.Types.OverLimitSize:
                return(Messages.ResponseOverLimitSize(
                           context: context,
                           data: column.LimitSize.ToString()).ToJson());

            case Error.Types.OverTotalLimitSize:
                return(Messages.ResponseOverTotalLimitSize(
                           context: context,
                           data: column.TotalLimitSize.ToString()).ToJson());

            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));
            }
            context.PostedFiles.ForEach(file => attachments.Add(new Attachment()
            {
                Guid        = file.Guid,
                Name        = file.FileName.Split('\\').Last(),
                Size        = file.Size,
                Extention   = file.Extension,
                ContentType = file.ContentType,
                Added       = true,
                Deleted     = false
            }));
            var hb      = new HtmlBuilder();
            var fieldId = controlId + "Field";

            return(new ResponseCollection()
                   .ReplaceAll("#" + fieldId, new HtmlBuilder()
                               .FieldAttachments(
                                   context: context,
                                   fieldId: fieldId,
                                   controlId: controlId,
                                   columnName: column.ColumnName,
                                   fieldCss: column.FieldCss,
                                   fieldDescription: column.Description,
                                   controlCss: column.ControlCss,
                                   labelText: column.LabelText,
                                   value: attachments.ToJson(),
                                   placeholder: column.LabelText,
                                   readOnly: column.ColumnPermissionType(context: context)
                                   != Permissions.ColumnPermissionTypes.Update))
                   .SetData("#" + controlId)
                   .ToJson());
        }
コード例 #22
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());
        }
コード例 #23
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UploadFile(
            Context context,
            long id,
            System.Net.Http.Headers.ContentRangeHeaderValue contentRange)
        {
            var itemModel   = new ItemModel(context, id);
            var ss          = itemModel.GetSite(context, initSiteSettings: true).SiteSettings;
            var column      = ss.GetColumn(context, TrimIdSuffix(context.Forms.Get("ColumnName")));
            var attachments = context.Forms.Get("AttachmentsData").Deserialize <Attachments>();
            var fileHash    = context.Forms.Get("FileHash");

            contentRange = contentRange ?? context?.PostedFiles?.FirstOrDefault()?.ContentRange;
            {
                var invalid = HasPermission(context, ss, itemModel);
                switch (invalid.Type)
                {
                case Error.Types.None: break;

                default: return(invalid.MessageJson(context));
                }
            }
            {
                var invalid = BinaryValidators.OnUploading(context, column, attachments, context.PostedFiles, new[] { contentRange });
                switch (invalid)
                {
                case Error.Types.OverLimitQuantity:
                    return(Messages.ResponseOverLimitQuantity(
                               context: context,
                               data: column.LimitQuantity.ToString()).ToJson());

                case Error.Types.OverLimitSize:
                    return(Messages.ResponseOverLimitSize(
                               context: context,
                               data: column.LimitSize.ToString()).ToJson());

                case Error.Types.OverTotalLimitSize:
                    return(Messages.ResponseOverTotalLimitSize(
                               context: context,
                               data: column.TotalLimitSize.ToString()).ToJson());

                case Error.Types.OverLocalFolderLimitSize:
                    return(Messages.ResponseOverLimitSize(
                               context: context,
                               data: column.LocalFolderLimitSize.ToString()).ToJson());

                case Error.Types.OverLocalFolderTotalLimitSize:
                    return(Messages.ResponseOverTotalLimitSize(
                               context: context,
                               data: column.LocalFolderTotalLimitSize.ToString()).ToJson());

                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));
                }
            }
            var controlId       = context.Forms.Get("ControlId");
            var fileUuid        = context.Forms.Get("uuid")?.Split(',');
            var fileUuids       = context.Forms.Get("Uuids")?.Split(',');
            var fileNames       = context.Forms.Get("fileNames")?.Deserialize <string[]>();
            var fileSizes       = context.Forms.Get("fileSizes")?.Deserialize <string[]>();
            var fileTypes       = context.Forms.Get("fileTypes")?.Deserialize <string[]>();
            var resultFileNames = new List <KeyValuePair <PostedFile, System.IO.FileInfo> >();

            for (int filesIndex = 0; filesIndex < context.PostedFiles.Count; ++filesIndex)
            {
                var file     = context.PostedFiles[filesIndex];
                var saveFile = GetTempFileInfo(fileUuid[filesIndex], file.FileName);
                Save(file, saveFile);
                resultFileNames.Add(
                    new KeyValuePair <PostedFile, System.IO.FileInfo>(
                        file,
                        saveFile));
            }
            {
                var invalid = ValidateFileHash(resultFileNames[0].Value, contentRange, fileHash);
                if (invalid != Error.Types.None)
                {
                    return(invalid.MessageJson(context));
                }
            }
            return(CreateResult(resultFileNames,
                                CreateResponseJson(
                                    context,
                                    fileUuids,
                                    fileNames,
                                    fileSizes,
                                    fileTypes,
                                    ss,
                                    column,
                                    controlId,
                                    attachments,
                                    contentRange)));
        }