BlueCollar.JobSerializer.Serialize C# (CSharp) Method

Serialize() public static method

Serializes the given IJob for storage.
public static Serialize ( IJob job ) : string
job IJob The to serialize.
return string
        public static string Serialize(IJob job)
        {
            if (job != null)
            {
                return JsonConvert.SerializeObject(job, Converters);
            }

            return string.Empty;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Enqueues a job for the given application name and queue name.
        /// </summary>
        /// <param name="applicationName">The name of the application to enqueue the job for.</param>
        /// <param name="queueName">The name of the queue to enqueue the job on, or null for the default queue.</param>
        /// <param name="repository">The repository to use when enqueueing the job record.</param>
        public virtual void Enqueue(string applicationName, string queueName, IRepository repository)
        {
            if (string.IsNullOrEmpty(applicationName))
            {
                throw new ArgumentNullException("applicationName", "applicationName must contain a value.");
            }

            if (string.IsNullOrEmpty(queueName))
            {
                queueName = "*";
            }

            if (repository == null)
            {
                throw new ArgumentNullException("repository", "repository cannot be null.");
            }

            QueueRecord record = new QueueRecord()
            {
                ApplicationName = applicationName,
                Data            = JobSerializer.Serialize(this),
                JobName         = this.Name,
                JobType         = JobSerializer.GetTypeName(this),
                QueuedOn        = DateTime.UtcNow,
                QueueName       = queueName,
                TryNumber       = 1
            };

            repository.CreateQueued(record, null);
        }