Exemplo n.º 1
0
 public static InvocationData Serialize(MethodInvocation job)
 {
     return(new InvocationData(
                job.Type.AssemblyQualifiedName,
                job.Method.Name,
                Helper.ToJson(job.Method.GetParameters().Select(x => x.ParameterType).ToArray()),
                Helper.ToJson(SerializeArguments(job.Args))));
 }
Exemplo n.º 2
0
        internal static string[] SerializeArguments(IReadOnlyCollection <object> arguments)
        {
            var serializedArguments = new List <string>(arguments.Count);

            foreach (var argument in arguments)
            {
                var value = default(string);
                if (argument != null)
                {
                    value = Helper.ToJson(argument);
                }

                serializedArguments.Add(value);
            }

            return(serializedArguments.ToArray());
        }
        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();
            }
        }
Exemplo n.º 4
0
 public string Serialize() => Helper.ToJson(this);