コード例 #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);
        }
コード例 #2
0
 public BinaryModel Get(
     Context context,
     Sqls.TableTypes tableType    = Sqls.TableTypes.Normal,
     SqlColumnCollection column   = null,
     SqlJoinCollection join       = null,
     SqlWhereCollection where     = null,
     SqlOrderByCollection orderBy = null,
     SqlParamCollection param     = null,
     bool distinct = false,
     int top       = 0)
 {
     where = where ?? Rds.BinariesWhereDefault(
         context: context,
         binaryModel: this);
     column = (column ?? Rds.BinariesDefaultColumns());
     join   = join ?? Rds.BinariesJoinDefault();
     Set(context, Repository.ExecuteTable(
             context: context,
             statements: Rds.SelectBinaries(
                 tableType: tableType,
                 column: column,
                 join: join,
                 where : where,
                 orderBy: orderBy,
                 param: param,
                 distinct: distinct,
                 top: top)));
     return(this);
 }
コード例 #3
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);
        }
コード例 #4
0
        private EnumerableRowCollection <DataRow> Get(
            SqlColumnCollection column   = null,
            SqlJoinCollection join       = null,
            SqlWhereCollection where     = null,
            SqlOrderByCollection orderBy = null,
            SqlParamCollection param     = null,
            Sqls.TableTypes tableType    = Sqls.TableTypes.Normal,
            bool distinct    = false,
            int top          = 0,
            int offset       = 0,
            int pageSize     = 0,
            bool history     = false,
            bool countRecord = false,
            IEnumerable <Aggregation> aggregations = null)
        {
            var statements = new List <SqlStatement>
            {
                Rds.SelectBinaries(
                    dataTableName: "Main",
                    column: column ?? Rds.BinariesDefaultColumns(),
                    join: join ?? Rds.BinariesJoinDefault(),
                    where : where,
                    orderBy: orderBy,
                    param: param,
                    tableType: tableType,
                    distinct: distinct,
                    top: top,
                    offset: offset,
                    pageSize: pageSize,
                    countRecord: countRecord)
            };

            if (aggregations != null)
            {
                statements.AddRange(Rds.BinariesAggregations(
                                        aggregations: aggregations,
                                        join: join ?? Rds.BinariesJoinDefault(),
                                        where : where));
            }
            var dataSet = Rds.ExecuteDataSet(
                transactional: false,
                statements: statements.ToArray());

            Aggregations.Set(dataSet, aggregations);
            return(dataSet.Tables["Main"].AsEnumerable());
        }
コード例 #5
0
        private EnumerableRowCollection <DataRow> Get(
            Context context,
            SqlColumnCollection column   = null,
            SqlJoinCollection join       = null,
            SqlWhereCollection where     = null,
            SqlOrderByCollection orderBy = null,
            SqlParamCollection param     = null,
            Sqls.TableTypes tableType    = Sqls.TableTypes.Normal,
            bool distinct = false,
            int top       = 0,
            int offset    = 0,
            int pageSize  = 0)
        {
            var statements = new List <SqlStatement>
            {
                Rds.SelectBinaries(
                    dataTableName: "Main",
                    column: column ?? Rds.BinariesDefaultColumns(),
                    join: join ?? Rds.BinariesJoinDefault(),
                    where : where,
                    orderBy: orderBy,
                    param: param,
                    tableType: tableType,
                    distinct: distinct,
                    top: top,
                    offset: offset,
                    pageSize: pageSize),
                Rds.SelectCount(
                    tableName: "Binaries",
                    tableType: tableType,
                    join: join ?? Rds.BinariesJoinDefault(),
                    where : where)
            };
            var dataSet = Rds.ExecuteDataSet(
                context: context,
                transactional: false,
                statements: statements.ToArray());

            TotalCount = Rds.Count(dataSet);
            return(dataSet.Tables["Main"].AsEnumerable());
        }
コード例 #6
0
 public BinaryModel Get(
     Sqls.TableTypes tableType    = Sqls.TableTypes.Normal,
     SqlColumnCollection column   = null,
     SqlJoinCollection join       = null,
     SqlWhereCollection where     = null,
     SqlOrderByCollection orderBy = null,
     SqlParamCollection param     = null,
     bool distinct = false,
     int top       = 0)
 {
     Set(Rds.ExecuteTable(statements: Rds.SelectBinaries(
                              tableType: tableType,
                              column: column ?? Rds.BinariesDefaultColumns(),
                              join: join ?? Rds.BinariesJoinDefault(),
                              where : where ?? Rds.BinariesWhereDefault(this),
                              orderBy: orderBy,
                              param: param,
                              distinct: distinct,
                              top: top)));
     return(this);
 }
コード例 #7
0
 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());
 }
コード例 #8
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);
        }