public void Serialization()
        {
            var m = InvocationData.Serialize(
                MethodInvocation.FromExpression(() => Foo(1, 2.2, "f", new DateTime(42))))
                    .Deserialize();

            m.Args.ElementAt(0).Should().Be(1);
            m.Args.ElementAt(1).Should().Be(2.2);
            m.Args.ElementAt(2).Should().Be("f");
            m.Args.ElementAt(3).Should().Be(new DateTime(42));
        }
Example #2
0
        private async Task EnqueueCore(DateTime?due, MethodInvocation method)
        {
            var data = InvocationData.Serialize(method);
            var job  = new Job(data.Serialize())
            {
                Due = due
            };

            await _connection.StoreJobAsync(job);

            if (job.Due == null)
            {
                _server.Pulse();
            }
        }
        private async Task EnqueueCore(DateTime?due, MethodInvocation method)
        {
            var data           = InvocationData.Serialize(method);
            var serializedData = data.Serialize();
            var job            = new Job(serializedData)
            {
                Due = due
            };

            await _connection.StoreJobAsync(job);

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                var methodCall = string.Format(
                    "{0}.{1}({2})",
                    method.Type.Name,
                    method.Method.Name,
                    string.Join(", ", method.Args.Select(arg => Helper.ToJson(arg))));

                if (due == null)
                {
                    _logger.LogDebug(
                        "Enqueuing a job to be executed immediately: {MethodCall}", methodCall);
                }
                else
                {
                    var diff  = due.Value - DateTime.UtcNow;
                    var after = diff.TotalSeconds < 60 ? $"{Math.Round(diff.TotalSeconds, 2)} secs" :
                                (diff.TotalMinutes < 60 ? $"{Math.Round(diff.TotalMinutes, 2)} minutes" :
                                 (diff.TotalHours < 24 ? $"{Math.Round(diff.TotalHours, 2)} hours" :
                                  ($"{Math.Round(diff.TotalDays, 2)} days")));

                    _logger.LogDebug(
                        "Enqueuing a job to be executed after {After}: {MethodCall}", after, methodCall);
                }
            }

            if (job.Due == null)
            {
                _server.Pulse();
            }
        }