Ejemplo n.º 1
0
        public override void Process(HttpContext context)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["db"].ConnectionString;
            string database         = RegexHelper.Search(connectionString, @"Initial Catalog=(?<Cata>\w*)", "Cata");
            string owner            = "dbo";
            string title            = "数据字典";

            context.Response.ContentType = "text/html";
            Write("<h1>{0}</h1>", title);
            Write("<p>{0:yyyy-MM-dd HH:mm:ss}</p>", System.DateTime.Now);
            SqlServerFetcher f = new SqlServerFetcher(connectionString);

            foreach (var t in f.GetTables())
            {
                var fullName = string.Format("{0}.{1}", t.Schema, t.Name);
                Write("<h1><a href='DbGrid.aspx?table={0}' style='text-decoration:none'>{1}</a></h1>", fullName, fullName);
                Write("<table border=1 style='border-collapse:collapse' width='100%' cellpadding='2' cellspacing='0'>");
                Write("<tr><td width='200'>名称</td><td width='150'>类型</td><td width='150'>可为空</td><td width='150'>字符长度</td><td width='150'>数字精度</td><td>主键</td><td>备注</td></tr>");
                foreach (var c in f.GetColumns2008(database, owner, t.Name))
                {
                    Write("<tr><td>{0}&nbsp;</td><td>{1}&nbsp;</td><td>{2}&nbsp;</td><td>{3}&nbsp;</td><td>{4}&nbsp;</td><td>{5}&nbsp;</td><td>{6}&nbsp;</td></tr>",
                          c.Name,
                          c.DataType,
                          c.IsNullbable,
                          c.CharacterMaximumLength,
                          c.NumericPrecision,
                          c.Identity,
                          c.Description
                          );
                }
                Write("</table>");
            }
        }
Ejemplo n.º 2
0
        public void FetchNextJob_ShouldFetchAJob_FromTheSpecifiedQueue()
        {
            const string arrangeSql = @"
insert into HangFire.Job (InvocationData, Arguments, CreatedAt)
values (@invocationData, @arguments, getutcdate())
insert into HangFire.JobQueue (JobId, Queue)
values (scope_identity(), @queue)";

            // Arrange
            using (var connection = ConnectionUtils.CreateConnection())
            {
                connection.Execute(
                    arrangeSql,
                    new
                    {
                        invocationData = "{ Type: 'Type', Method: 'Method', ParameterTypes: 'Parameters' }",
                        arguments = "Arguments",
                        queue = "default"
                    });

                var fetcher = new SqlServerFetcher(connection, new[] { "default" });

                // Act
                var payload = fetcher.FetchNextJob(CreateTimingOutCancellationToken());

                // Assert
                Assert.NotEmpty(payload.Id);
                Assert.Equal("Type", payload.InvocationData.Type);
                Assert.Equal("Method", payload.InvocationData.Method);
                Assert.Equal("Parameters", payload.InvocationData.ParameterTypes);
                Assert.Equal("default", payload.Queue);
                Assert.Equal("Arguments", payload.Arguments);
            }
        }
Ejemplo n.º 3
0
        public void FetchNextJob_ThrowsOperationCanceled_WhenCancellationTokenIsSetAtTheBeginning()
        {
            var connection = new Mock<IDbConnection>();
            var fetcher = new SqlServerFetcher(connection.Object, new[] { "default" });
            var cts = new CancellationTokenSource();
            cts.Cancel();

            Assert.Throws<OperationCanceledException>(
                () => fetcher.FetchNextJob(cts.Token));
        }
Ejemplo n.º 4
0
        public void FetchNextJob_ShouldWaitIndefinitely_WhenThereAreNoJobs()
        {
            using (var connection = ConnectionUtils.CreateConnection())
            {
                var fetcher = new SqlServerFetcher(connection, new[] { "default" });
                var cts = new CancellationTokenSource(200);

                Assert.Throws<OperationCanceledException>(
                    () => fetcher.FetchNextJob(cts.Token));
            }
        }
Ejemplo n.º 5
0
        public void FetchNextJob_ShouldIgnoreNonExistentJobs_ButDeleteThemFromTheQueue()
        {
            const string arrangeSql = @"
insert into HangFire.JobQueue (JobId, Queue)
values (@id, @queue)";

            using (var connection = ConnectionUtils.CreateConnection())
            {
                connection.Execute(arrangeSql, new { id = 1, queue = "default" });

                var fetcher = new SqlServerFetcher(connection, new[] { "default" });

                Assert.Throws<OperationCanceledException>(
                    () => fetcher.FetchNextJob(CreateTimingOutCancellationToken()));

                var queuedJobCount = connection.Query<int>(
                    "select count(*) from HangFire.JobQueue").Single();
                Assert.Equal(0, queuedJobCount);
            }
        }
Ejemplo n.º 6
0
        public void FetchNextJob_ShouldFetchJobs_FromMultipleQueues()
        {
            const string arrangeSql = @"
insert into HangFire.Job (InvocationData, Arguments, CreatedAt)
values (@invocationData, @arguments, getutcdate())
insert into HangFire.JobQueue (JobId, Queue)
values (scope_identity(), @queue)";

            using (var connection = ConnectionUtils.CreateConnection())
            {
                connection.Execute(
                    arrangeSql,
                    new[]
                    {
                        new { queue = "default", invocationData = "", arguments = "" },
                        new { queue = "critical", invocationData = "", arguments = "" }
                    });

                var fetcher = new SqlServerFetcher(connection, new []{ "critical", "default" });

                var critical = fetcher.FetchNextJob(CreateTimingOutCancellationToken());
                Assert.NotNull(critical.Id);
                Assert.Equal("critical", critical.Queue);

                var @default = fetcher.FetchNextJob(CreateTimingOutCancellationToken());
                Assert.NotNull(@default.Id);
                Assert.Equal("default", @default.Queue);
            }
        }
Ejemplo n.º 7
0
        public void FetchNextJob_ShouldFetchJobs_OnlyFromSpecifiedQueues()
        {
            const string arrangeSql = @"
insert into HangFire.Job (InvocationData, Arguments, CreatedAt)
values (@invocationData, @arguments, getutcdate())
insert into HangFire.JobQueue (JobId, Queue)
values (scope_identity(), @queue)";

            using (var connection = ConnectionUtils.CreateConnection())
            {
                connection.Execute(
                    arrangeSql,
                    new { queue = "critical", invocationData = "", arguments = "" });

                var fetcher = new SqlServerFetcher(connection, new[] { "default" });

                Assert.Throws<OperationCanceledException>(
                    () => fetcher.FetchNextJob(CreateTimingOutCancellationToken()));
            }
        }
Ejemplo n.º 8
0
        public void FetchNextJob_ShouldSetFetchedAt_OnlyForTheFetchedJob()
        {
            const string arrangeSql = @"
insert into HangFire.Job (InvocationData, Arguments, CreatedAt)
values (@invocationData, @arguments, getutcdate())
insert into HangFire.JobQueue (JobId, Queue)
values (scope_identity(), @queue)";

            // Arrange
            using (var connection = ConnectionUtils.CreateConnection())
            {
                connection.Execute(
                    arrangeSql,
                    new[]
                    {
                        new { queue = "default", invocationData = "", arguments = "" },
                        new { queue = "default", invocationData = "", arguments = "" }
                    });

                var fetcher = new SqlServerFetcher(connection, new[] { "default" });

                // Act
                var payload = fetcher.FetchNextJob(CreateTimingOutCancellationToken());

                // Assert
                var otherJobFetchedAt = connection.Query<DateTime?>(
                    "select FetchedAt from HangFire.JobQueue where JobId != @id",
                    new { id = payload.Id }).Single();

                Assert.Null(otherJobFetchedAt);
            }
        }
Ejemplo n.º 9
0
        public void FetchNextJob_ShouldFetchATimedOutJobs_FromTheSpecifiedQueue()
        {
            const string arrangeSql = @"
insert into HangFire.Job (InvocationData, Arguments, CreatedAt)
values (@invocationData, @arguments, getutcdate())
insert into HangFire.JobQueue (JobId, Queue, FetchedAt)
values (scope_identity(), @queue, @fetchedAt)";

            // Arrange
            using (var connection = ConnectionUtils.CreateConnection())
            {
                connection.Execute(
                    arrangeSql,
                    new 
                    { 
                        queue = "default", 
                        fetchedAt = DateTime.UtcNow.AddDays(-1), 
                        invocationData = "", 
                        arguments = ""
                    });

                var fetcher = new SqlServerFetcher(connection, new[] { "default" });

                // Act
                var payload = fetcher.FetchNextJob(CreateTimingOutCancellationToken());

                // Assert
                Assert.NotEmpty(payload.Id);
            }
        }
Ejemplo n.º 10
0
        public void FetchNextJob_ShouldLeaveJobInTheQueue_ButSetItsFetchedAtValue()
        {
            const string arrangeSql = @"
insert into HangFire.Job (InvocationData, Arguments, CreatedAt)
values (@invocationData, @arguments, getutcdate())
insert into HangFire.JobQueue (JobId, Queue)
values (scope_identity(), @queue)";

            // Arrange
            using (var connection = ConnectionUtils.CreateConnection())
            {
                connection.Execute(
                    arrangeSql,
                    new { invocationData = "", arguments = "", queue = "default" });

                var fetcher = new SqlServerFetcher(connection, new[] { "default" });

                // Act
                var payload = fetcher.FetchNextJob(CreateTimingOutCancellationToken());

                // Assert
                Assert.NotNull(payload);

                var fetchedAt = connection.Query<DateTime?>(
                    "select FetchedAt from HangFire.JobQueue where JobId = @id",
                    new { id = payload.Id }).Single();

                Assert.NotNull(fetchedAt);
                Assert.True(fetchedAt > DateTime.UtcNow.AddMinutes(-1));
            }
        }