Ejemplo n.º 1
0
        public static FileContentResult Download(string guid)
        {
            var dataRow = Rds.ExecuteTable(statements:
                                           Rds.SelectBinaries(
                                               column: Rds.BinariesColumn()
                                               .Guid()
                                               .BinaryType()
                                               .Bin()
                                               .FileName()
                                               .ContentType(),
                                               join: Rds.BinariesJoinDefault()
                                               .Add(new SqlJoin(
                                                        tableBracket: "[Items]",
                                                        joinType: SqlJoin.JoinTypes.Inner,
                                                        joinExpression: "[Binaries].[ReferenceId]=[Items].[ReferenceId]"))
                                               .Add(new SqlJoin(
                                                        tableBracket: "[Sites]",
                                                        joinType: SqlJoin.JoinTypes.Inner,
                                                        joinExpression: "[Items].[SiteId]=[Sites].[SiteId]")),
                                               where : Rds.BinariesWhere()
                                               .TenantId(Sessions.TenantId())
                                               .Guid(guid)
                                               .CanRead("[Binaries].[ReferenceId]")))
                          .AsEnumerable()
                          .FirstOrDefault();

            return(dataRow != null
                ? new ResponseFile(
                       new MemoryStream(Bytes(dataRow), false),
                       dataRow.String("FileName"),
                       dataRow.String("ContentType")).FileStream()
                : null);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public static long GetReferenceId(Context context, string guid)
        {
            var referenceId = Rds.ExecuteScalar_long(
                context: context,
                statements: new SqlStatement[]
            {
                Rds.SelectBinaries(
                    column: Rds.BinariesColumn()
                    .ReferenceId(),
                    join: Rds.BinariesJoinDefault()
                    .Add(new SqlJoin(
                             tableBracket: "[Items]",
                             joinType: SqlJoin.JoinTypes.Inner,
                             joinExpression: "[Binaries].[ReferenceId]=[Items].[ReferenceId]"))
                    .Add(new SqlJoin(
                             tableBracket: "[Sites]",
                             joinType: SqlJoin.JoinTypes.Inner,
                             joinExpression: "[Items].[SiteId]=[Sites].[SiteId]")),
                    where : Rds.BinariesWhere()
                    .TenantId(context.TenantId)
                    .Guid(guid))
            });

            return(referenceId);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static decimal UsedTenantStorageSize(Context context)
 {
     return(Rds.ExecuteScalar_decimal(
                context: context,
                statements: Rds.SelectBinaries(
                    column: Rds.BinariesColumn().Size(function: Sqls.Functions.Sum),
                    where : Rds.BinariesWhere().TenantId(context.TenantId))));
 }
Ejemplo n.º 7
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()));
        }
Ejemplo n.º 8
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()));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public string SiteImagePrefix(Libraries.Images.ImageData.SizeTypes sizeType)
        {
            switch (Parameters.BinaryStorage.Provider)
            {
            case "Local":
                return(new Libraries.Images.ImageData(
                           ReferenceId, Libraries.Images.ImageData.Types.SiteImage)
                       .UrlPrefix(sizeType));

            default:
                return(Rds.ExecuteScalar_datetime(statements:
                                                  Rds.SelectBinaries(
                                                      column: Rds.BinariesColumn()
                                                      .UpdatedTime(function: Sqls.Functions.Max),
                                                      where : Rds.BinariesWhere().ReferenceId(ReferenceId)))
                       .ToString("?yyyyMMddHHmmss"));
            }
        }
Ejemplo n.º 10
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()));
        }
 private static DataRow GetBinariesTable(Context context, string guid)
 {
     if (guid.IsNullOrEmpty())
     {
         return(null);
     }
     return(Rds.ExecuteTable(
                context: context,
                statements: new SqlStatement[]
     {
         Rds.SelectBinaries(
             column: Rds.BinariesColumn()
             .BinaryId()
             .ReferenceId()
             .Guid()
             .BinaryType()
             .Bin()
             .Thumbnail()
             .FileName()
             .ContentType()
             .Extension()
             .Size()
             .Creator()
             .Updator()
             .CreatedTime()
             .UpdatedTime(),
             join: Rds.BinariesJoinDefault()
             .Add(new SqlJoin(
                      tableBracket: "[Items]",
                      joinType: SqlJoin.JoinTypes.Inner,
                      joinExpression: "[Binaries].[ReferenceId]=[Items].[ReferenceId]"))
             .Add(new SqlJoin(
                      tableBracket: "[Sites]",
                      joinType: SqlJoin.JoinTypes.Inner,
                      joinExpression: "[Items].[SiteId]=[Sites].[SiteId]")),
             where : Rds.BinariesWhere()
             .TenantId(context.TenantId)
             .Guid(guid)
             .CanRead(
                 context: context,
                 idColumnBracket: "[Binaries].[ReferenceId]",
                 _using: !context.Publish)),
         Rds.SelectBinaries(
             column: Rds.BinariesColumn()
             .BinaryId()
             .ReferenceId()
             .Guid()
             .BinaryType()
             .Bin()
             .Thumbnail()
             .FileName()
             .ContentType()
             .Extension()
             .Size()
             .Creator()
             .Updator()
             .CreatedTime()
             .UpdatedTime(),
             join: Rds.BinariesJoinDefault()
             .Add(new SqlJoin(
                      tableBracket: "[Items]",
                      joinType: SqlJoin.JoinTypes.Inner,
                      joinExpression: "[Binaries].[ReferenceId]=[Items].[ReferenceId]"))
             .Add(new SqlJoin(
                      tableBracket: "[Sites]",
                      joinType: SqlJoin.JoinTypes.Inner,
                      joinExpression: "[Items].[SiteId]=[Sites].[SiteId]")),
             where : Rds.BinariesWhere()
             .TenantId(context.TenantId)
             .Guid(guid)
             .Add(raw: $"([Binaries].[CreatedTime]=[Binaries].[UpdatedTime] and [Binaries].[Creator]={context.UserId})"),
             unionType: Sqls.UnionTypes.UnionAll)
     })
            .AsEnumerable()
            .FirstOrDefault());
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static long UsedTenantStorageSize()
 {
     return(Rds.ExecuteScalar_long(statements: Rds.SelectBinaries(
                                       column: Rds.BinariesColumn().Size(function: Sqls.Functions.Sum),
                                       where : Rds.BinariesWhere().TenantId(Sessions.TenantId()))));
 }
Ejemplo n.º 13
0
        public static FileContentResult Download(Context context, string guid)
        {
            var dataRow = Rds.ExecuteTable(
                context: context,
                statements: new SqlStatement[]
            {
                Rds.SelectBinaries(
                    column: Rds.BinariesColumn()
                    .Guid()
                    .BinaryType()
                    .Bin()
                    .FileName()
                    .ContentType(),
                    join: Rds.BinariesJoinDefault()
                    .Add(new SqlJoin(
                             tableBracket: "[Items]",
                             joinType: SqlJoin.JoinTypes.Inner,
                             joinExpression: "[Binaries].[ReferenceId]=[Items].[ReferenceId]"))
                    .Add(new SqlJoin(
                             tableBracket: "[Sites]",
                             joinType: SqlJoin.JoinTypes.Inner,
                             joinExpression: "[Items].[SiteId]=[Sites].[SiteId]")),
                    where : Rds.BinariesWhere()
                    .TenantId(context.TenantId)
                    .Guid(guid)
                    .CanRead(
                        context: context,
                        idColumnBracket: "[Binaries].[ReferenceId]",
                        _using: !context.Publish)),
                Rds.SelectBinaries(
                    column: Rds.BinariesColumn()
                    .Guid()
                    .BinaryType()
                    .Bin()
                    .FileName()
                    .ContentType(),
                    join: Rds.BinariesJoinDefault()
                    .Add(new SqlJoin(
                             tableBracket: "[Items]",
                             joinType: SqlJoin.JoinTypes.Inner,
                             joinExpression: "[Binaries].[ReferenceId]=[Items].[ReferenceId]"))
                    .Add(new SqlJoin(
                             tableBracket: "[Sites]",
                             joinType: SqlJoin.JoinTypes.Inner,
                             joinExpression: "[Items].[SiteId]=[Sites].[SiteId]")),
                    where : Rds.BinariesWhere()
                    .TenantId(context.TenantId)
                    .Guid(guid)
                    .Add(raw: $"([Binaries].[CreatedTime]=[Binaries].[UpdatedTime] and [Binaries].[Creator]={context.UserId})"),
                    unionType: Sqls.UnionTypes.UnionAll)
            })
                          .AsEnumerable()
                          .FirstOrDefault();

            return(dataRow != null
                ? new ResponseFile(
                       new MemoryStream(Bytes(dataRow), false),
                       dataRow.String("FileName"),
                       dataRow.String("ContentType")).FileStream()
                : null);
        }