Esempio n. 1
0
        public void Execute(IReportTaskRunContext taskContext)
        {
            var package = taskContext.Packages[Properties.PackageName];

            if (!RunIfVoidPackage && package.DataSets.Count == 0)
            {
                return;
            }

            var context = SqlContextProvider.DefaultInstance
                          .CreateContext(ConnectionString);


            if (context.CreateSimple($@" IF OBJECT_ID('{ExportTableName}') IS NOT NULL
                IF EXISTS(SELECT * FROM {ExportTableName} WHERE id = {taskContext.TaskId})
				AND OBJECT_ID('{ExportInstanceTableName}') IS NOT NULL
                AND  EXISTS(SELECT 1 FROM sys.columns 
				  WHERE Name = 'Id'
				  AND Object_ID = Object_ID('{ExportInstanceTableName}'))
				  AND  EXISTS(SELECT 1 FROM sys.columns 
				  WHERE Name = 'Created'
				  AND Object_ID = Object_ID('{ExportInstanceTableName}')) 
				  AND  EXISTS(SELECT 1 FROM sys.columns 
				  WHERE Name = 'ReportId'
				  AND Object_ID = Object_ID('{ExportInstanceTableName}')) 
				  AND  EXISTS(SELECT 1 FROM sys.columns 
				  WHERE Name = 'DataPackage'
				  AND Object_ID = Object_ID('{ExportInstanceTableName}'))  
                SELECT 1
                ELSE SELECT 0").ExecuteQueryFirstColumn <int>().First() != 1)
            {
                return;
            }

            byte[] archivedPackage;

            using (var stream = new MemoryStream())
            {
                package.WriteTo(stream);
                archivedPackage = archiver.CompressStream(stream);
            }

            var newInstance = new
            {
                ReportId         = taskContext.TaskId,
                ExecuteTime      = DateTime.Now,
                OperationPackage = archivedPackage
            };

            context.Insert(ExportInstanceTableName, newInstance, new QueryOptions(DbTimeOut), "Id");
        }
Esempio n. 2
0
        public byte[] GetCompressedPackage(string packageName)
        {
            using var stream = new MemoryStream();

            Packages[packageName].WriteTo(stream);
            return(archiver.CompressStream(stream));
        }
Esempio n. 3
0
        protected async Task ExportPackage(IReportTaskRunContext taskContext, DbConnection connection)
        {
            var package = taskContext.Packages[Properties.PackageName];

            if (!RunIfVoidPackage && package.DataSets.Count == 0)
            {
                return;
            }

            var token = taskContext.CancelSource.Token;

            var dbStructureExists = await dbStructureChecker.CheckIfDbStructureExists(connection, taskContext);

            if (!dbStructureExists)
            {
                var msg = $"The export database structure doesn't contain the data required for export. Required ExportTableName: {ExportTableName}, ExportInstanceTableName: {ExportInstanceTableName}.";
                throw new Exception(msg);
            }

            byte[] archivedPackage;

            await using (var stream = new MemoryStream())
            {
                package.WriteTo(stream);
                archivedPackage = archiver.CompressStream(stream);
            }

            var newInstance = new
            {
                ReportID    = taskContext.TaskId,
                Created     = DateTime.Now,
                DataPackage = archivedPackage
            };

            await connection.ExecuteAsync(new CommandDefinition(InsertQuery,
                                                                newInstance, commandTimeout : DbTimeOut,
                                                                cancellationToken : token));
        }